From 6b585b367b3c757c5d31ef1b02f38928c4cc797d Mon Sep 17 00:00:00 2001 From: unknown <> Date: Sun, 10 Mar 2024 17:43:48 -0400 Subject: [PATCH] swapped all density functions to raw arrays --- src/main/c/fluidsim.c | 8 +- src/main/c/includes/mainFunctions.h | 9 ++ src/main/c/velocitystep.c | 225 ++++++++++++++++++++++++++++ 3 files changed, 238 insertions(+), 4 deletions(-) diff --git a/src/main/c/fluidsim.c b/src/main/c/fluidsim.c index 28d00bd..0f888c5 100644 --- a/src/main/c/fluidsim.c +++ b/src/main/c/fluidsim.c @@ -753,8 +753,8 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_simulate( u0 = currentChunk->ju0; v0 = currentChunk->jv0; w0 = currentChunk->jw0; - Java_electrosphere_FluidSim_copyNeighbors(env,chunkJRaw,DIM,chunkMask,0,0,jd); - Java_electrosphere_FluidSim_copyNeighbors(env,chunkJRaw,DIM,chunkMask,0,0,jd0); + copyNeighborsRaw(env,chunkJRaw,DIM,chunkMask,0,0,currentChunk->d); + copyNeighborsRaw(env,chunkJRaw,DIM,chunkMask,0,0,currentChunk->d0); } } //diffuse density @@ -832,8 +832,8 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_simulate( u0 = currentChunk->ju0; v0 = currentChunk->jv0; w0 = currentChunk->jw0; - Java_electrosphere_FluidSim_copyNeighbors(env,chunkJRaw,DIM,chunkMask,0,0,jd); - Java_electrosphere_FluidSim_copyNeighbors(env,chunkJRaw,DIM,chunkMask,0,0,jd0); + copyNeighborsRaw(env,chunkJRaw,DIM,chunkMask,0,0,currentChunk->d); + copyNeighborsRaw(env,chunkJRaw,DIM,chunkMask,0,0,currentChunk->d0); } } //advect density diff --git a/src/main/c/includes/mainFunctions.h b/src/main/c/includes/mainFunctions.h index 03df600..11b309d 100644 --- a/src/main/c/includes/mainFunctions.h +++ b/src/main/c/includes/mainFunctions.h @@ -107,4 +107,13 @@ JNIEXPORT void JNICALL setBoundsToNeighborsRaw JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors (JNIEnv *, jobject, jint, jint, jint, jint, jobjectArray); +JNIEXPORT void JNICALL copyNeighborsRaw + (JNIEnv * env, + jobject this, + jint N, + jint chunk_mask, + jint cx, + jint vector_dir, + float ** neighborArray); + #endif \ No newline at end of file diff --git a/src/main/c/velocitystep.c b/src/main/c/velocitystep.c index 569f9b6..6942e2e 100644 --- a/src/main/c/velocitystep.c +++ b/src/main/c/velocitystep.c @@ -782,6 +782,231 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_setBoundsToNeighbors 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); } +/** + * This exclusively copies neighbors to make sure zeroing out stuff doesn't break sim +*/ +JNIEXPORT void JNICALL copyNeighborsRaw + (JNIEnv * env, + jobject this, + jint N, + jint chunk_mask, + jint cx, + jint vector_dir, + float ** neighborArray){ + int DIM = N; + float * target = GET_ARR_RAW(env,neighborArray,CENTER_LOC); + float * source; + + + // + // + // PLANES + // + // + if(ARR_EXISTS(chunk_mask,0,1,1)){ + source = GET_ARR_RAW(env,neighborArray,CK(0,1,1)); + for(int x=1; x < DIM-1; x++){ + for(int y = 1; y < DIM-1; y++){ + target[IX(0,x,y)] = source[IX(DIM-2,x,y)]; + } + } + } + + if(ARR_EXISTS(chunk_mask,2,1,1)){ + source = GET_ARR_RAW(env,neighborArray,CK(2,1,1)); + for(int x=1; x < DIM-1; x++){ + for(int y = 1; y < DIM-1; y++){ + target[IX(DIM-1,x,y)] = source[IX(1,x,y)]; + } + } + } + + if(ARR_EXISTS(chunk_mask,1,0,1)){ + source = GET_ARR_RAW(env,neighborArray,CK(1,0,1)); + for(int x=1; x < DIM-1; x++){ + for(int y = 1; y < DIM-1; y++){ + target[IX(x,0,y)] = source[IX(x,DIM-2,y)]; + } + } + } + + if(ARR_EXISTS(chunk_mask,1,2,1)){ + source = GET_ARR_RAW(env,neighborArray,CK(1,2,1)); + for(int x=1; x < DIM-1; x++){ + for(int y = 1; y < DIM-1; y++){ + target[IX(x,DIM-1,y)] = source[IX(x,1,y)]; + } + } + } + + if(ARR_EXISTS(chunk_mask,1,1,0)){ + source = GET_ARR_RAW(env,neighborArray,CK(1,1,0)); + for(int x=1; x < DIM-1; x++){ + for(int y = 1; y < DIM-1; y++){ + target[IX(x,y,0)] = source[IX(x,y,DIM-2)]; + } + } + } + + if(ARR_EXISTS(chunk_mask,1,1,2)){ + source = GET_ARR_RAW(env,neighborArray,CK(1,1,2)); + for(int x=1; x < DIM-1; x++){ + for(int y = 1; y < DIM-1; y++){ + target[IX(x,y,DIM-1)] = source[IX(x,y,1)]; + } + } + } + + + // + // + // EDGES + // + // + if(ARR_EXISTS(chunk_mask,0,0,1)){ + source = GET_ARR_RAW(env,neighborArray,CK(0,0,1)); + for(int x=1; x < DIM-1; x++){ + target[IX(0,0,x)] = source[IX(DIM-2,DIM-2,x)]; + } + } + + if(ARR_EXISTS(chunk_mask,2,0,1)){ + source = GET_ARR_RAW(env,neighborArray,CK(2,0,1)); + for(int x=1; x < DIM-1; x++){ + target[IX(DIM-1,0,x)] = source[IX(1,DIM-2,x)]; + } + } + + if(ARR_EXISTS(chunk_mask,0,2,1)){ + source = GET_ARR_RAW(env,neighborArray,CK(0,2,1)); + for(int x=1; x < DIM-1; x++){ + target[IX(0,DIM-1,x)] = source[IX(DIM-2,1,x)]; + } + } + + if(ARR_EXISTS(chunk_mask,2,2,1)){ + source = GET_ARR_RAW(env,neighborArray,CK(2,2,1)); + for(int x=1; x < DIM-1; x++){ + target[IX(DIM-1,DIM-1,x)] = source[IX(1,1,x)]; + } + } + + // + // + + if(ARR_EXISTS(chunk_mask,0,1,0)){ + source = GET_ARR_RAW(env,neighborArray,CK(0,1,0)); + for(int x=1; x < DIM-1; x++){ + target[IX(0,x,0)] = source[IX(DIM-2,x,DIM-2)]; + } + } + + if(ARR_EXISTS(chunk_mask,2,1,0)){ + source = GET_ARR_RAW(env,neighborArray,CK(2,1,0)); + for(int x=1; x < DIM-1; x++){ + target[IX(DIM-1,x,0)] = source[IX(1,x,DIM-2)]; + } + } + + if(ARR_EXISTS(chunk_mask,0,1,2)){ + source = GET_ARR_RAW(env,neighborArray,CK(0,1,2)); + for(int x=1; x < DIM-1; x++){ + target[IX(0,x,DIM-1)] = source[IX(DIM-2,x,1)]; + } + } + + if(ARR_EXISTS(chunk_mask,2,1,2)){ + source = GET_ARR_RAW(env,neighborArray,CK(2,1,2)); + for(int x=1; x < DIM-1; x++){ + target[IX(DIM-1,x,DIM-1)] = source[IX(1,x,1)]; + } + } + + // + // + + if(ARR_EXISTS(chunk_mask,1,0,0)){ + source = GET_ARR_RAW(env,neighborArray,CK(1,0,0)); + for(int x=1; x < DIM-1; x++){ + target[IX(x,0,0)] = source[IX(x,DIM-2,DIM-2)]; + } + } + + if(ARR_EXISTS(chunk_mask,1,2,0)){ + source = GET_ARR_RAW(env,neighborArray,CK(1,2,0)); + for(int x=1; x < DIM-1; x++){ + target[IX(x,DIM-1,0)] = source[IX(x,1,DIM-2)]; + } + } + + if(ARR_EXISTS(chunk_mask,1,0,2)){ + source = GET_ARR_RAW(env,neighborArray,CK(1,0,2)); + for(int x=1; x < DIM-1; x++){ + target[IX(x,0,DIM-1)] = source[IX(x,DIM-2,1)]; + } + } + + if(ARR_EXISTS(chunk_mask,1,2,2)){ + source = GET_ARR_RAW(env,neighborArray,CK(1,2,2)); + for(int x=1; x < DIM-1; x++){ + target[IX(x,DIM-1,DIM-1)] = source[IX(x,1,1)]; + } + } + + + // + // + // CORNERS + // + // + + if(ARR_EXISTS(chunk_mask,0,0,0)){ + source = GET_ARR_RAW(env,neighborArray,CK(0,0,0)); + target[IX(0,0,0)] = source[IX(DIM-2,DIM-2,DIM-2)]; + } + + if(ARR_EXISTS(chunk_mask,2,0,0)){ + source = GET_ARR_RAW(env,neighborArray,CK(2,0,0)); + target[IX(DIM-1,0,0)] = source[IX(1,DIM-2,DIM-2)]; + } + + if(ARR_EXISTS(chunk_mask,0,2,0)){ + source = GET_ARR_RAW(env,neighborArray,CK(0,2,0)); + target[IX(0,DIM-1,0)] = source[IX(DIM-2,1,DIM-2)]; + } + + if(ARR_EXISTS(chunk_mask,2,2,0)){ + source = GET_ARR_RAW(env,neighborArray,CK(2,2,0)); + target[IX(DIM-1,DIM-1,0)] = source[IX(1,1,DIM-2)]; + } + + // + // + + if(ARR_EXISTS(chunk_mask,0,0,2)){ + source = GET_ARR_RAW(env,neighborArray,CK(0,0,2)); + target[IX(0,0,DIM-1)] = source[IX(DIM-2,DIM-2,1)]; + } + + if(ARR_EXISTS(chunk_mask,2,0,2)){ + source = GET_ARR_RAW(env,neighborArray,CK(2,0,2)); + target[IX(DIM-1,0,DIM-1)] = source[IX(1,DIM-2,1)]; + } + + if(ARR_EXISTS(chunk_mask,0,2,2)){ + source = GET_ARR_RAW(env,neighborArray,CK(0,2,2)); + target[IX(0,DIM-1,DIM-1)] = source[IX(DIM-2,1,1)]; + } + + if(ARR_EXISTS(chunk_mask,2,2,2)){ + source = GET_ARR_RAW(env,neighborArray,CK(2,2,2)); + target[IX(DIM-1,DIM-1,DIM-1)] = source[IX(1,1,1)]; + } + + + +} + /** * This exclusively copies neighbors to make sure zeroing out stuff doesn't break sim */