From cc5edb452b41989ebcd5392a77798ce202e21919 Mon Sep 17 00:00:00 2001 From: unknown <> Date: Mon, 24 Jul 2023 18:57:30 -0400 Subject: [PATCH] DENSITY TRANSITIONS! --- src/main/c/velocitystep.c | 32 +++++++++++------------ src/main/java/electrosphere/FluidSim.java | 16 +++++++++--- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/main/c/velocitystep.c b/src/main/c/velocitystep.c index 0275a69..17e8183 100644 --- a/src/main/c/velocitystep.c +++ b/src/main/c/velocitystep.c @@ -612,21 +612,21 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors int DIM = N; float * target = GET_ARR(env,neighborArray,CENTER_LOC); float * source; - // if(ARR_EXISTS(chunk_mask,0,1,1)){ - // source = GET_ARR(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,0,1,1)){ + source = GET_ARR(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(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,2,1,1)){ + source = GET_ARR(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)]; + } + } + } } \ No newline at end of file diff --git a/src/main/java/electrosphere/FluidSim.java b/src/main/java/electrosphere/FluidSim.java index af1903b..7925ab0 100644 --- a/src/main/java/electrosphere/FluidSim.java +++ b/src/main/java/electrosphere/FluidSim.java @@ -186,7 +186,9 @@ public class FluidSim { // //Density stage addDensity(simArray, timestep); + swapAllDensityArrays(simArray, timestep); diffuseDensity(simArray, timestep); + swapAllDensityArrays(simArray, timestep); advectDensity(simArray, timestep); // mirrorNeighborDensities(simArray, timestep); @@ -351,6 +353,9 @@ public class FluidSim { simArray[x][y][z].setBoundsToNeighborsWrapper(1, simArray[x][y][z].uVector); simArray[x][y][z].setBoundsToNeighborsWrapper(2, simArray[x][y][z].vVector); simArray[x][y][z].setBoundsToNeighborsWrapper(3, simArray[x][y][z].wVector); + simArray[x][y][z].copyNeighborsWrapper(2, simArray[x][y][z].uAdditionVector); + simArray[x][y][z].copyNeighborsWrapper(2, simArray[x][y][z].vAdditionVector); + simArray[x][y][z].copyNeighborsWrapper(2, simArray[x][y][z].wAdditionVector); } } } @@ -442,13 +447,13 @@ public class FluidSim { simArray[x][y][z].addDensityWrapper(timestep); //swap x <=> x0 //swap arrays in java side... - simArray[x][y][z].swapDensityArrays(); + // simArray[x][y][z].swapDensityArrays(); } } } } - private void swapAllDensityArrays(FluidSim[][][] simArray, float timestep){ + private static void swapAllDensityArrays(FluidSim[][][] simArray, float timestep){ for(int x = 0; x < simArray.length; x++){ for(int y = 0; y < simArray[0].length; y++){ for(int z = 0; z < simArray[0][0].length; z++){ @@ -499,7 +504,7 @@ public class FluidSim { for(int y = 0; y < simArray[0].length; y++){ for(int z = 0; z < simArray[0][0].length; z++){ //swap x <=> x0 again - simArray[x][y][z].swapDensityArrays(); + // simArray[x][y][z].swapDensityArrays(); //advect density simArray[x][y][z].advectDensityWrapper(timestep); } @@ -874,6 +879,10 @@ public class FluidSim { return density[getNeighborIndex(1,1,1)]; } + public ByteBuffer getDensityAdditionBuffer(){ + return densityAddition[getNeighborIndex(1,1,1)]; + } + public ByteBuffer getUBuffer(){ return uVector[getNeighborIndex(1,1,1)]; } @@ -900,6 +909,7 @@ public class FluidSim { public void setNeighbor(int x, int y, int z, FluidSim neighbor){ density[getNeighborIndex(x,y,z)] = neighbor.getDensityBuffer(); + densityAddition[getNeighborIndex(x,y,z)] = neighbor.getDensityAdditionBuffer(); uVector[getNeighborIndex(x,y,z)] = neighbor.getUBuffer(); vVector[getNeighborIndex(x,y,z)] = neighbor.getVBuffer(); wVector[getNeighborIndex(x,y,z)] = neighbor.getWBuffer();