diff --git a/docs/src/architecture/fluidsim/fluidsimindex.md b/docs/src/architecture/fluidsim/fluidsimindex.md index b99eb195..307cc9cd 100644 --- a/docs/src/architecture/fluidsim/fluidsimindex.md +++ b/docs/src/architecture/fluidsim/fluidsimindex.md @@ -1,4 +1,5 @@ @page fluidsimindex Fluid Simulation Architecture [TOC] -- @subpage fluidsimarchoverview \ No newline at end of file +- @subpage fluidsimarchoverview +- @subpage fluidsimnotes \ No newline at end of file diff --git a/docs/src/architecture/fluidsim/fluidsimnotes.md b/docs/src/architecture/fluidsim/fluidsimnotes.md new file mode 100644 index 00000000..def663d6 --- /dev/null +++ b/docs/src/architecture/fluidsim/fluidsimnotes.md @@ -0,0 +1,36 @@ +@page fluidsimnotes Fluid Sim Notes + + +approaches to improve speed + - Multithreading + - Caching phi values between evaluations to precompute multigrid or whatever solver we're using + - When precomputing phi, factor in density/gravity/whatever to get a better guess + + + + +multigrid improvements + loading/unloading + https://stackoverflow.com/questions/46468026/fast-copy-every-second-byte-to-new-memory-area + + +Pressure caching + Cache value of phi from projection on previous frame (gonna have to do this per chunk (yikes!)) + Use this to populate neighbors for next frame + + +internal boundaries approach 1 + calculate a normal mask from border values + normal uses 3x3x3 sample of border mask to generate an index into a lookup table that contains the normal + (think marching cubes) + could probably parallelize this by calculating it in parts + ie, grab -1,-1,-1 for a whole bunch, then -1,-1,0 for a whole bunch, etc + + +edge boundaries + "warm up" empty chunks by adding velocity to the edges of an empty chunk where it borders a non-empty chunk + +extension of the "warm up" idea + Run minified solver that just performs velocity step (no density) + when advecting, check if density is at the advection position + if there is density, pull it along as well and fully activate the empty chunk \ No newline at end of file diff --git a/src/main/c/includes/fluid/queue/chunk.h b/src/main/c/includes/fluid/queue/chunk.h index 059794b7..c553860c 100644 --- a/src/main/c/includes/fluid/queue/chunk.h +++ b/src/main/c/includes/fluid/queue/chunk.h @@ -1,11 +1,11 @@ -#include - -//Must be included for public functions to be imported/exported on windows -#include "public.h" - #ifndef CHUNK_H #define CHUNK_H +#include +#include + +#include "public.h" + /** * The minimum fluid value */ @@ -49,7 +49,7 @@ typedef struct { float * v0[27]; float * w0[27]; float * bounds[27]; - int chunkMask; + uint32_t chunkMask; jobject chunkJRaw; /** diff --git a/src/main/c/includes/fluid/queue/chunkmask.h b/src/main/c/includes/fluid/queue/chunkmask.h index 9eb5e7a1..9a981897 100644 --- a/src/main/c/includes/fluid/queue/chunkmask.h +++ b/src/main/c/includes/fluid/queue/chunkmask.h @@ -1,8 +1,8 @@ -#include - #ifndef CHUNKMASK_H #define CHUNKMASK_H +#include + /** * The number of entries in the neighbor array */ @@ -50,4 +50,9 @@ extern const char CHUNK_NORMALIZE_V[]; extern const char CHUNK_NORMALIZE_W[]; +/** + * Calculates the bitmask for available chunks for the provided chunk's neighbor array +*/ +LIBRARY_API uint32_t calculateChunkMask(JNIEnv * env, jobjectArray jrx); + #endif \ No newline at end of file diff --git a/src/main/c/src/fluid/queue/chunkmask.c b/src/main/c/src/fluid/queue/chunkmask.c index 647795e2..7ead556f 100644 --- a/src/main/c/src/fluid/queue/chunkmask.c +++ b/src/main/c/src/fluid/queue/chunkmask.c @@ -1,4 +1,5 @@ #include +#include #include "fluid/env/utilities.h" #include "fluid/queue/chunkmask.h" @@ -59,4 +60,48 @@ const char CHUNK_NORMALIZE_W[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -}; \ No newline at end of file +}; + + + + +/** + * Calculates a mask that represents all nearby chunks that are actually accessible and exist +*/ +uint32_t matrix_transform(JNIEnv * env, jobjectArray jrx){ + + //The returned value, an availability mask that contains the availability of each neighbor chunk + uint32_t rVal = 0; + + //Add to maks for initial chunks + for(int i = 0; i < CENTER_LOC; i++){ + if((*env)->GetObjectArrayElement(env,jrx,i)!=NULL){ + rVal = rVal + 1; + } + rVal = rVal << 1; + } + //add 1 for center chunk because we already have that + rVal = rVal + 1; + rVal = rVal << 1; + //continue on for remaining chunks + for(int i = CENTER_LOC+1; i < 27; i++){ + if((*env)->GetObjectArrayElement(env,jrx,i)!=NULL){ + rVal = rVal + 1; + } + if(i < 26){ + rVal = rVal << 1; + } + } + + return rVal; +} + + + +/** + * Calculates the bitmask for available chunks for the provided chunk's neighbor array +*/ +LIBRARY_API uint32_t calculateChunkMask(JNIEnv * env, jobjectArray jrx){ + return matrix_transform(env,jrx); +} + diff --git a/src/main/c/src/fluid/queue/javainterface.c b/src/main/c/src/fluid/queue/javainterface.c index bb57cafd..431ecfa6 100644 --- a/src/main/c/src/fluid/queue/javainterface.c +++ b/src/main/c/src/fluid/queue/javainterface.c @@ -31,8 +31,6 @@ //declarations int readInChunks(JNIEnv * env, jobject chunkList, Environment * environment); -int calculateChunkMask(JNIEnv * env, jobjectArray jrx); -uint32_t matrix_transform(JNIEnv * env, jobjectArray jrx); @@ -274,40 +272,3 @@ void * getArray(JNIEnv * env, jobjectArray arr, int index){ return (*env)->GetDirectBufferAddress(env,arrayEl); } -/** - * Calculates the bitmask for available chunks for the provided chunk's neighbor array -*/ -int calculateChunkMask(JNIEnv * env, jobjectArray jrx){ - return matrix_transform(env,jrx); -} - -/** - * Calculates a mask that represents all nearby chunks that are actually accessible and exist -*/ -uint32_t matrix_transform(JNIEnv * env, jobjectArray jrx){ - - //The returned value, an availability mask that contains the availability of each neighbor chunk - uint32_t rVal = 0; - - //Add to maks for initial chunks - for(int i = 0; i < CENTER_LOC; i++){ - if((*env)->GetObjectArrayElement(env,jrx,i)!=NULL){ - rVal = rVal + 1; - } - rVal = rVal << 1; - } - //add 1 for center chunk because we already have that - rVal = rVal + 1; - rVal = rVal << 1; - //continue on for remaining chunks - for(int i = CENTER_LOC+1; i < 27; i++){ - if((*env)->GetObjectArrayElement(env,jrx,i)!=NULL){ - rVal = rVal + 1; - } - if(i < 26){ - rVal = rVal << 1; - } - } - - return rVal; -} \ No newline at end of file