From 70ab3b53e9e2db2e3bba05f4f133a44af8041eec Mon Sep 17 00:00:00 2001 From: unknown <> Date: Sun, 10 Mar 2024 17:31:31 -0400 Subject: [PATCH] swap neighbors raw --- src/main/c/fluidsim.c | 2 +- src/main/c/includes/mainFunctions.h | 8 ++++ src/main/c/velocitystep.c | 57 +++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/main/c/fluidsim.c b/src/main/c/fluidsim.c index 298405b..c070db3 100644 --- a/src/main/c/fluidsim.c +++ b/src/main/c/fluidsim.c @@ -853,7 +853,7 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_simulate( u0 = currentChunk->ju0; v0 = currentChunk->jv0; w0 = currentChunk->jw0; - Java_electrosphere_FluidSim_setBoundsToNeighbors(env,chunkJRaw,DIM,chunkMask,0,jd); + setBoundsToNeighborsRaw(env,chunkJRaw,DIM,chunkMask,0,currentChunk->d); } } } \ No newline at end of file diff --git a/src/main/c/includes/mainFunctions.h b/src/main/c/includes/mainFunctions.h index 109dad6..740f66d 100644 --- a/src/main/c/includes/mainFunctions.h +++ b/src/main/c/includes/mainFunctions.h @@ -91,6 +91,14 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_advectDensity JNIEXPORT void JNICALL Java_electrosphere_FluidSim_setBoundsToNeighbors (JNIEnv *, jobject, jint, jint, jint, jobjectArray); +JNIEXPORT void JNICALL setBoundsToNeighborsRaw + (JNIEnv * env, + jobject this, + jint N, + jint chunk_mask, + jint vector_dir, + float ** neighborArray); + /* * Class: electrosphere_FluidSim * Method: copyNeighbors diff --git a/src/main/c/velocitystep.c b/src/main/c/velocitystep.c index e731d2b..569f9b6 100644 --- a/src/main/c/velocitystep.c +++ b/src/main/c/velocitystep.c @@ -668,6 +668,63 @@ void advect(JNIEnv * env, uint32_t chunk_mask, int N, int b, jobjectArray jrd, j } } +JNIEXPORT void JNICALL setBoundsToNeighborsRaw + (JNIEnv * env, + jobject this, + jint N, + jint chunk_mask, + jint vector_dir, + float ** neighborArray){ + int DIM = N; + float * target = GET_ARR_RAW(env,neighborArray,CENTER_LOC); + float * source; + for(int x=1; x < DIM-1; x++){ + for(int y = 1; y < DIM-1; y++){ + target[IX(0,x,y)] = vector_dir==BOUND_DIR_U ? -target[IX(1,x,y)] : target[IX(1,x,y)]; + } + } + for(int x=1; x < DIM-1; x++){ + for(int y = 1; y < DIM-1; y++){ + target[IX(DIM-1,x,y)] = vector_dir==BOUND_DIR_U ? -target[IX(DIM-2,x,y)] : target[IX(DIM-2,x,y)]; + } + } + for(int x=1; x < DIM-1; x++){ + for(int y = 1; y < DIM-1; y++){ + //((x)+(DIM)*(y) + (DIM)*(DIM)*(z)) + target[IX(x,0,y)] = vector_dir==BOUND_DIR_V ? -target[IX(x,1,y)] : target[IX(x,1,y)]; + target[IX(x,DIM-1,y)] = vector_dir==BOUND_DIR_V ? -target[IX(x,DIM-2,y)] : target[IX(x,DIM-2,y)]; + target[IX(x,y,0)] = vector_dir==BOUND_DIR_W ? -target[IX(x,y,1)] : target[IX(x,y,1)]; + target[IX(x,y,DIM-1)] = vector_dir==BOUND_DIR_W ? -target[IX(x,y,DIM-2)] : target[IX(x,y,DIM-2)]; + } + } + for(int x = 1; x < DIM-1; x++){ + target[IX(x,0,0)] = (float)(0.5f * (target[IX(x,1,0)] + target[IX(x,0,1)])); + target[IX(x,DIM-1,0)] = (float)(0.5f * (target[IX(x,DIM-2,0)] + target[IX(x,DIM-1,1)])); + target[IX(x,0,DIM-1)] = (float)(0.5f * (target[IX(x,1,DIM-1)] + target[IX(x,0,DIM-2)])); + target[IX(x,DIM-1,DIM-1)] = (float)(0.5f * (target[IX(x,DIM-2,DIM-1)] + target[IX(x,DIM-1,DIM-2)])); + + target[IX(0,x,0)] = (float)(0.5f * (target[IX(1,x,0)] + target[IX(0,x,1)])); + target[IX(DIM-1,x,0)] = (float)(0.5f * (target[IX(DIM-2,x,0)] + target[IX(DIM-1,x,1)])); + target[IX(0,x,DIM-1)] = (float)(0.5f * (target[IX(1,x,DIM-1)] + target[IX(0,x,DIM-2)])); + target[IX(DIM-1,x,DIM-1)] = (float)(0.5f * (target[IX(DIM-2,x,DIM-1)] + target[IX(DIM-1,x,DIM-2)])); + + + target[IX(0,0,x)] = (float)(0.5f * (target[IX(1,0,x)] + target[IX(0,1,x)])); + target[IX(DIM-1,0,x)] = (float)(0.5f * (target[IX(DIM-2,0,x)] + target[IX(DIM-1,1,x)])); + target[IX(0,DIM-1,x)] = (float)(0.5f * (target[IX(1,DIM-1,x)] + target[IX(0,DIM-2,x)])); + target[IX(DIM-1,DIM-1,x)] = (float)(0.5f * (target[IX(DIM-2,DIM-1,x)] + target[IX(DIM-1,DIM-2,x)])); + + } + target[IX(0,0,0)] = (float)((target[IX(1,0,0)]+target[IX(0,1,0)]+target[IX(0,0,1)])/3.0); + target[IX(DIM-1,0,0)] = (float)((target[IX(DIM-2,0,0)]+target[IX(DIM-1,1,0)]+target[IX(DIM-1,0,1)])/3.0); + target[IX(0,DIM-1,0)] = (float)((target[IX(1,DIM-1,0)]+target[IX(0,DIM-2,0)]+target[IX(0,DIM-1,1)])/3.0); + target[IX(0,0,DIM-1)] = (float)((target[IX(0,0,DIM-2)]+target[IX(1,0,DIM-1)]+target[IX(0,1,DIM-1)])/3.0); + target[IX(DIM-1,DIM-1,0)] = (float)((target[IX(DIM-2,DIM-1,0)]+target[IX(DIM-1,DIM-2,0)]+target[IX(DIM-1,DIM-1,1)])/3.0); + target[IX(0,DIM-1,DIM-1)] = (float)((target[IX(1,DIM-1,DIM-1)]+target[IX(0,DIM-2,DIM-1)]+target[IX(0,DIM-1,DIM-2)])/3.0); + target[IX(DIM-1,0,DIM-1)] = (float)((target[IX(DIM-1,0,DIM-2)]+target[IX(DIM-2,0,DIM-1)]+target[IX(DIM-1,1,DIM-1)])/3.0); + target[IX(DIM-1,DIM-1,DIM-1)] = (float)((target[IX(DIM-1,DIM-1,DIM-2)]+target[IX(DIM-1,DIM-2,DIM-1)]+target[IX(DIM-1,DIM-1,DIM-2)])/3.0); +} + JNIEXPORT void JNICALL Java_electrosphere_FluidSim_setBoundsToNeighbors (JNIEnv * env, jobject this,