diff --git a/src/main/c/includes/fluid/sim/pressurecell/solver_consts.h b/src/main/c/includes/fluid/sim/pressurecell/solver_consts.h index 72da0e2f..7889d7f4 100644 --- a/src/main/c/includes/fluid/sim/pressurecell/solver_consts.h +++ b/src/main/c/includes/fluid/sim/pressurecell/solver_consts.h @@ -10,7 +10,7 @@ /** * Spacing of cells */ -#define FLUID_PRESSURECELL_SPACING 1.0f +#define FLUID_PRESSURECELL_SPACING (1.0f/DIM) /** * Multiplier applied to pressure calculations to encourage advection @@ -25,17 +25,12 @@ /** * Diffusion constant */ -#define FLUID_PRESSURECELL_DIFFUSION_CONSTANT 0.0001f +#define FLUID_PRESSURECELL_DIFFUSION_CONSTANT 0.01f /** * Viscosity constant */ -#define FLUID_PRESSURECELL_VISCOSITY_CONSTANT 0.0001f - -/** - * Amount that density contributes to the pressure - */ -#define FLUID_PRESSURECELL_DENSITY_CONST 0.001f +#define FLUID_PRESSURECELL_VISCOSITY_CONSTANT 0.01f /** * Amount of the residual to add to the pressure field each frame diff --git a/src/main/c/src/fluid/sim/pressurecell/density.c b/src/main/c/src/fluid/sim/pressurecell/density.c index 09f9a9ee..8d3f2f59 100644 --- a/src/main/c/src/fluid/sim/pressurecell/density.c +++ b/src/main/c/src/fluid/sim/pressurecell/density.c @@ -66,14 +66,15 @@ LIBRARY_API void pressurecell_advect_density(Environment * environment, Chunk * float s0, s1, t0, t1, u0, u1; float interpolated; float vecU, vecV, vecW; + float interpConst = environment->consts.dt / FLUID_PRESSURECELL_SPACING; for(y = 1; y < DIM-1; y++){ //TODO: eventually skip y levels if there is no density to advect for(z = 1; z < DIM-1; z++){ for(x = 1; x < DIM-1; x++){ //calculate the real (float) position we are at - vecU = u[IX(x,y,z)] * environment->consts.dt; - vecV = v[IX(x,y,z)] * environment->consts.dt; - vecW = w[IX(x,y,z)] * environment->consts.dt; + vecU = u[IX(x,y,z)] * interpConst; + vecV = v[IX(x,y,z)] * interpConst; + vecW = w[IX(x,y,z)] * interpConst; if(vecU > 0.999f){ vecU = 0.999f; } else if(vecU < -0.999f){ diff --git a/src/main/c/src/fluid/sim/pressurecell/pressure.c b/src/main/c/src/fluid/sim/pressurecell/pressure.c index e6a65df2..62aabeb3 100644 --- a/src/main/c/src/fluid/sim/pressurecell/pressure.c +++ b/src/main/c/src/fluid/sim/pressurecell/pressure.c @@ -82,8 +82,8 @@ LIBRARY_API void pressurecell_approximate_pressure(Environment * environment, Ch for(y = 0; y < DIM; y++){ for(x = 0; x < DIM; x++){ phi0[IX(x,y,z)] = divArr[IX(x,y,z)]; - // pressureTemp[IX(x,y,z)] = pressureCache[IX(x,y,z)]; - pressureTemp[IX(x,y,z)] = 0; + pressureTemp[IX(x,y,z)] = pressureCache[IX(x,y,z)]; + // pressureTemp[IX(x,y,z)] = 0; if(divArr[IX(x,y,z)] > 3){ printf("invalid divergence!\n"); printf("%f \n", divArr[IX(x,y,z)]); diff --git a/src/main/c/src/fluid/sim/pressurecell/velocity.c b/src/main/c/src/fluid/sim/pressurecell/velocity.c index 281e28f5..94542dc1 100644 --- a/src/main/c/src/fluid/sim/pressurecell/velocity.c +++ b/src/main/c/src/fluid/sim/pressurecell/velocity.c @@ -59,7 +59,7 @@ LIBRARY_API void pressurecell_diffuse_velocity(Environment * environment, Chunk float * uTemp = chunk->uTempCache; float * vTemp = chunk->vTempCache; float * wTemp = chunk->wTempCache; - float D = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * environment->consts.dt; + float D = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * environment->consts.dt / (FLUID_PRESSURECELL_SPACING * FLUID_PRESSURECELL_SPACING); for(z = 1; z < DIM-1; z++){ for(y = 1; y < DIM-1; y++){ for(x = 1; x < DIM-1; x++){ @@ -125,7 +125,7 @@ LIBRARY_API void pressurecell_advect_velocity(Environment * environment, Chunk * float s0, s1, t0, t1, u0, u1; float interpolatedU, interpolatedV, interpolatedW; float magnitude; - float interpConst = environment->consts.dt; + float interpConst = environment->consts.dt / FLUID_PRESSURECELL_SPACING; for(y = 1; y < DIM-1; y++){ for(z = 1; z < DIM-1; z++){ for(x = 1; x < DIM-1; x++){ @@ -344,11 +344,11 @@ LIBRARY_API double pressurecell_project_velocity(Environment * environment, Chun //normalize if the projection has pushed us wayyy out of bounds //ie, large pressure differentials can create huge imbalances - if(magnitude > 1.0f){ - uArr[IX(x,y,z)] = uArr[IX(x,y,z)] / magnitude; - vArr[IX(x,y,z)] = vArr[IX(x,y,z)] / magnitude; - wArr[IX(x,y,z)] = wArr[IX(x,y,z)] / magnitude; - } + // if(magnitude > 1.0f){ + // uArr[IX(x,y,z)] = uArr[IX(x,y,z)] / magnitude; + // vArr[IX(x,y,z)] = vArr[IX(x,y,z)] / magnitude; + // wArr[IX(x,y,z)] = wArr[IX(x,y,z)] / magnitude; + // } // magnitude = sqrt(uTemp[IX(x,y,z)] * uTemp[IX(x,y,z)] + vTemp[IX(x,y,z)] * vTemp[IX(x,y,z)] + wTemp[IX(x,y,z)] * wTemp[IX(x,y,z)]); diff --git a/src/main/java/electrosphere/server/fluid/simulator/FluidAcceleratedSimulator.java b/src/main/java/electrosphere/server/fluid/simulator/FluidAcceleratedSimulator.java index 96c316cf..1d9c01d5 100644 --- a/src/main/java/electrosphere/server/fluid/simulator/FluidAcceleratedSimulator.java +++ b/src/main/java/electrosphere/server/fluid/simulator/FluidAcceleratedSimulator.java @@ -29,7 +29,7 @@ public class FluidAcceleratedSimulator implements ServerFluidSimulator { /** * The gravity constant */ - public static final float GRAVITY_CONST = -10000f; + public static final float GRAVITY_CONST = -100f; /** * Load fluid sim library