diff --git a/src/main/c/src/fluid/sim/pressurecell/density.c b/src/main/c/src/fluid/sim/pressurecell/density.c index 5d298af2..6d5778d5 100644 --- a/src/main/c/src/fluid/sim/pressurecell/density.c +++ b/src/main/c/src/fluid/sim/pressurecell/density.c @@ -54,6 +54,62 @@ LIBRARY_API void pressurecell_diffuse_density(Environment * environment, Chunk * if(bounds[IX(x,y,z)] > 0){ continue; } + // if(x == 4 && y == 4 && z == 4){ + // printf("arrs\n"); + // printf("%f \n", densityArr[IX(x,y,z)]); + // printf("%f \n", densityArr[IX(x-1,y,z)]); + // printf("%f \n", densityArr[IX(x+1,y,z)]); + // printf("%f \n", densityArr[IX(x,y-1,z)]); + // printf("%f \n", densityArr[IX(x,y+1,z)]); + // printf("%f \n", densityArr[IX(x,y,z-1)]); + // printf("%f \n", densityArr[IX(x,y,z+1)]); + + // printf("bounds\n"); + // printf("%f \n", bounds[IX(x-1,y,z)]); + // printf("%f \n", bounds[IX(x+1,y,z)]); + // printf("%f \n", bounds[IX(x,y-1,z)]); + // printf("%f \n", bounds[IX(x,y+1,z)]); + // printf("%f \n", bounds[IX(x,y,z-1)]); + // printf("%f \n", bounds[IX(x,y,z+1)]); + // printf("a: %f \n", a); + // float boundSum = -( + // (1.0f - bounds[IX(x-1,y,z)]) + + // (1.0f - bounds[IX(x+1,y,z)]) + + // (1.0f - bounds[IX(x,y-1,z)]) + + // (1.0f - bounds[IX(x,y+1,z)]) + + // (1.0f - bounds[IX(x,y,z-1)]) + + // (1.0f - bounds[IX(x,y,z+1)]) + // ); + // printf("boundSum: %f\n", boundSum); + // float neighborSum = ( + // densityArr[IX(x-1,y,z)] * (1.0f - bounds[IX(x-1,y,z)]) + + // densityArr[IX(x+1,y,z)] * (1.0f - bounds[IX(x+1,y,z)]) + + // densityArr[IX(x,y-1,z)] * (1.0f - bounds[IX(x,y-1,z)]) + + // densityArr[IX(x,y+1,z)] * (1.0f - bounds[IX(x,y+1,z)]) + + // densityArr[IX(x,y,z-1)] * (1.0f - bounds[IX(x,y,z-1)]) + + // densityArr[IX(x,y,z+1)] * (1.0f - bounds[IX(x,y,z+1)]) + // ); + // printf("neighborSum: %f\n", neighborSum); + // float combined = densityArr[IX(x,y,z)] * -( + // (1.0f - bounds[IX(x-1,y,z)]) + + // (1.0f - bounds[IX(x+1,y,z)]) + + // (1.0f - bounds[IX(x,y-1,z)]) + + // (1.0f - bounds[IX(x,y+1,z)]) + + // (1.0f - bounds[IX(x,y,z-1)]) + + // (1.0f - bounds[IX(x,y,z+1)]) + // ) + + // ( + // densityArr[IX(x-1,y,z)] * (1.0f - bounds[IX(x-1,y,z)]) + + // densityArr[IX(x+1,y,z)] * (1.0f - bounds[IX(x+1,y,z)]) + + // densityArr[IX(x,y-1,z)] * (1.0f - bounds[IX(x,y-1,z)]) + + // densityArr[IX(x,y+1,z)] * (1.0f - bounds[IX(x,y+1,z)]) + + // densityArr[IX(x,y,z-1)] * (1.0f - bounds[IX(x,y,z-1)]) + + // densityArr[IX(x,y,z+1)] * (1.0f - bounds[IX(x,y,z+1)]) + // ); + // printf("combined: %f\n", combined); + // float modified = combined * a; + // printf("modified: %f\n", modified); + // } densityTemp[IX(x,y,z)] = densityArr[IX(x,y,z)] + ( densityArr[IX(x,y,z)] * -( @@ -77,17 +133,17 @@ LIBRARY_API void pressurecell_diffuse_density(Environment * environment, Chunk * } } } - for(x = 1; x < DIM-1; x++){ - for(y = 1; y < DIM-1; y++){ - //diffuse back into the grid - densityTemp[IX(1,x,y)] = densityTemp[IX(1,x,y)] + densityTemp[IX(0,x,y)]; - densityTemp[IX(DIM-2,x,y)] = densityTemp[IX(DIM-2,x,y)] + densityTemp[IX(DIM-1,x,y)]; - densityTemp[IX(x,1,y)] = densityTemp[IX(x,1,y)] + densityTemp[IX(x,0,y)]; - densityTemp[IX(x,DIM-2,y)] = densityTemp[IX(x,DIM-2,y)] + densityTemp[IX(x,DIM-1,y)]; - densityTemp[IX(x,y,1)] = densityTemp[IX(x,y,1)] + densityTemp[IX(x,y,0)]; - densityTemp[IX(x,y,DIM-2)] = densityTemp[IX(x,y,DIM-2)] + densityTemp[IX(x,y,DIM-1)]; - } - } + // for(x = 1; x < DIM-1; x++){ + // for(y = 1; y < DIM-1; y++){ + // //diffuse back into the grid + // densityTemp[IX(1,x,y)] = densityTemp[IX(1,x,y)] + densityTemp[IX(0,x,y)]; + // densityTemp[IX(DIM-2,x,y)] = densityTemp[IX(DIM-2,x,y)] + densityTemp[IX(DIM-1,x,y)]; + // densityTemp[IX(x,1,y)] = densityTemp[IX(x,1,y)] + densityTemp[IX(x,0,y)]; + // densityTemp[IX(x,DIM-2,y)] = densityTemp[IX(x,DIM-2,y)] + densityTemp[IX(x,DIM-1,y)]; + // densityTemp[IX(x,y,1)] = densityTemp[IX(x,y,1)] + densityTemp[IX(x,y,0)]; + // densityTemp[IX(x,y,DIM-2)] = densityTemp[IX(x,y,DIM-2)] + densityTemp[IX(x,y,DIM-1)]; + // } + // } } /** diff --git a/src/test/c/fluid/sim/pressurecell/bounds_tests.c b/src/test/c/fluid/sim/pressurecell/bounds_tests.c index 43c5d53d..0d9eece2 100644 --- a/src/test/c/fluid/sim/pressurecell/bounds_tests.c +++ b/src/test/c/fluid/sim/pressurecell/bounds_tests.c @@ -40,6 +40,7 @@ int fluid_sim_pressurecell_bounds_test1(){ //setup chunk values float deltaDensity = 0.01f; Chunk * currentChunk = queue[0]; + float interpConst = 1.0f / FLUID_PRESSURECELL_SPACING; currentChunk->vTempCache[IX(1,1,1)] = -0.8; currentChunk->bounds[CENTER_LOC][IX(1,0,1)] = 1.0f; @@ -77,6 +78,7 @@ int fluid_sim_pressurecell_bounds_test2(){ //setup chunk values float deltaDensity = 0.01f; Chunk * currentChunk = queue[0]; + float interpConst = 1.0f / FLUID_PRESSURECELL_SPACING; currentChunk->vTempCache[IX(1,1,1)] = -0.8; currentChunk->dTempCache[IX(1,1,1)] = MAX_FLUID_VALUE; currentChunk->bounds[CENTER_LOC][IX(1,0,1)] = 1.0f; @@ -116,6 +118,7 @@ int fluid_sim_pressurecell_bounds_test3(){ //setup chunk values float deltaDensity = 0.01f; Chunk * currentChunk = queue[0]; + float interpConst = 1.0f / FLUID_PRESSURECELL_SPACING; currentChunk->vTempCache[IX(1,1,1)] = -0.8; currentChunk->dTempCache[IX(1,1,1)] = MAX_FLUID_VALUE; currentChunk->bounds[CENTER_LOC][IX(1,0,1)] = 1.0f; @@ -129,7 +132,7 @@ int fluid_sim_pressurecell_bounds_test3(){ // // cell that originall had values // - expected = MAX_FLUID_VALUE - MAX_FLUID_VALUE * env->consts.dt; + expected = MAX_FLUID_VALUE - MAX_FLUID_VALUE * -currentChunk->vTempCache[IX(1,1,1)] * env->consts.dt * interpConst; actual = chunk_sum_density(currentChunk); if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to enforce advection bounds! expected: %f actual: %f \n"); diff --git a/src/test/c/fluid/sim/pressurecell/diffuse_tests.c b/src/test/c/fluid/sim/pressurecell/diffuse_tests.c index f13ab62d..7ffee42f 100644 --- a/src/test/c/fluid/sim/pressurecell/diffuse_tests.c +++ b/src/test/c/fluid/sim/pressurecell/diffuse_tests.c @@ -40,6 +40,7 @@ int fluid_sim_pressurecell_diffuse_test1(){ //setup chunk values Chunk * currentChunk = queue[0]; currentChunk->d[CENTER_LOC][IX(4,4,4)] = MAX_FLUID_VALUE; + float diffuseConst = FLUID_PRESSURECELL_DIFFUSION_CONSTANT / (FLUID_PRESSURECELL_SPACING * FLUID_PRESSURECELL_SPACING); //actually simulate pressurecell_diffuse_density(env,currentChunk); @@ -50,7 +51,7 @@ int fluid_sim_pressurecell_diffuse_test1(){ // // cell that originall had values // - expected = MAX_FLUID_VALUE - FLUID_PRESSURECELL_DIFFUSION_CONSTANT * 6 * MAX_FLUID_VALUE * env->consts.dt; + expected = MAX_FLUID_VALUE - diffuseConst * 6 * MAX_FLUID_VALUE * env->consts.dt; actual = currentChunk->dTempCache[IX(4,4,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (4,4,4)! expected: %f actual: %f \n"); @@ -60,37 +61,37 @@ int fluid_sim_pressurecell_diffuse_test1(){ // // neighbors // - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE * env->consts.dt; + expected = diffuseConst * MAX_FLUID_VALUE * env->consts.dt; actual = currentChunk->dTempCache[IX(3,4,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (3,4,4)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE * env->consts.dt; + expected = diffuseConst * MAX_FLUID_VALUE * env->consts.dt; actual = currentChunk->dTempCache[IX(5,4,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN * env->consts.dt){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (5,4,4)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE * env->consts.dt; + expected = diffuseConst * MAX_FLUID_VALUE * env->consts.dt; actual = currentChunk->dTempCache[IX(4,3,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (4,3,4)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE * env->consts.dt; + expected = diffuseConst * MAX_FLUID_VALUE * env->consts.dt; actual = currentChunk->dTempCache[IX(4,5,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (4,5,4)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE * env->consts.dt; + expected = diffuseConst * MAX_FLUID_VALUE * env->consts.dt; actual = currentChunk->dTempCache[IX(4,4,3)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (4,4,3)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE * env->consts.dt; + expected = diffuseConst * MAX_FLUID_VALUE * env->consts.dt; actual = currentChunk->dTempCache[IX(4,4,5)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (4,4,5)! expected: %f actual: %f \n"); @@ -121,6 +122,7 @@ int fluid_sim_pressurecell_diffuse_test2(){ uTemp[IX(4,4,4)] = FLUID_PRESSURECELL_MAX_VELOCITY; vTemp[IX(4,4,4)] = FLUID_PRESSURECELL_MAX_VELOCITY; wTemp[IX(4,4,4)] = FLUID_PRESSURECELL_MAX_VELOCITY; + float diffuseConst = FLUID_PRESSURECELL_DIFFUSION_CONSTANT / (FLUID_PRESSURECELL_SPACING * FLUID_PRESSURECELL_SPACING); //actually simulate pressurecell_diffuse_velocity(env,currentChunk); @@ -130,7 +132,7 @@ int fluid_sim_pressurecell_diffuse_test2(){ // // cell that originall had values // - expected = MAX_FLUID_VALUE - FLUID_PRESSURECELL_DIFFUSION_CONSTANT * 6 * MAX_FLUID_VALUE * env->consts.dt; + expected = MAX_FLUID_VALUE - diffuseConst * 6 * MAX_FLUID_VALUE * env->consts.dt; actual = uArr[IX(4,4,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (4,4,4)! expected: %f actual: %f \n"); @@ -140,37 +142,37 @@ int fluid_sim_pressurecell_diffuse_test2(){ // // neighbors // - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE * env->consts.dt; + expected = diffuseConst * MAX_FLUID_VALUE * env->consts.dt; actual = uArr[IX(3,4,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (3,4,4)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE * env->consts.dt; + expected = diffuseConst * MAX_FLUID_VALUE * env->consts.dt; actual = uArr[IX(5,4,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (5,4,4)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE * env->consts.dt; + expected = diffuseConst * MAX_FLUID_VALUE * env->consts.dt; actual = uArr[IX(4,3,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (4,3,4)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE * env->consts.dt; + expected = diffuseConst * MAX_FLUID_VALUE * env->consts.dt; actual = uArr[IX(4,5,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (4,5,4)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE * env->consts.dt; + expected = diffuseConst * MAX_FLUID_VALUE * env->consts.dt; actual = uArr[IX(4,4,3)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (4,4,3)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE * env->consts.dt; + expected = diffuseConst * MAX_FLUID_VALUE * env->consts.dt; actual = uArr[IX(4,4,5)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (4,4,5)! expected: %f actual: %f \n"); @@ -197,6 +199,7 @@ int fluid_sim_pressurecell_diffuse_test3(){ float * dArr = currentChunk->d[CENTER_LOC]; float * dTemp = currentChunk->dTempCache; float * bounds = currentChunk->bounds[CENTER_LOC]; + float diffuseConst = FLUID_PRESSURECELL_DIFFUSION_CONSTANT / (FLUID_PRESSURECELL_SPACING * FLUID_PRESSURECELL_SPACING); dArr[IX(4,4,4)] = MAX_FLUID_VALUE; bounds[IX(4,5,4)] = 1.0f; @@ -209,7 +212,7 @@ int fluid_sim_pressurecell_diffuse_test3(){ // // cell that originall had values // - expected = MAX_FLUID_VALUE - FLUID_PRESSURECELL_DIFFUSION_CONSTANT * 5 * MAX_FLUID_VALUE * env->consts.dt; + expected = MAX_FLUID_VALUE - diffuseConst * 5 * MAX_FLUID_VALUE * env->consts.dt; actual = dTemp[IX(4,4,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (4,4,4)! expected: %f actual: %f \n"); @@ -219,19 +222,19 @@ int fluid_sim_pressurecell_diffuse_test3(){ // // neighbors // - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE * env->consts.dt; + expected = diffuseConst * MAX_FLUID_VALUE * env->consts.dt; actual = dTemp[IX(3,4,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (3,4,4)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE * env->consts.dt; + expected = diffuseConst * MAX_FLUID_VALUE * env->consts.dt; actual = dTemp[IX(5,4,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN * env->consts.dt){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (5,4,4)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE * env->consts.dt; + expected = diffuseConst * MAX_FLUID_VALUE * env->consts.dt; actual = dTemp[IX(4,3,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (4,3,4)! expected: %f actual: %f \n"); @@ -243,13 +246,13 @@ int fluid_sim_pressurecell_diffuse_test3(){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (4,5,4)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE * env->consts.dt; + expected = diffuseConst * MAX_FLUID_VALUE * env->consts.dt; actual = dTemp[IX(4,4,3)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (4,4,3)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE * env->consts.dt; + expected = diffuseConst * MAX_FLUID_VALUE * env->consts.dt; actual = dTemp[IX(4,4,5)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (4,4,5)! expected: %f actual: %f \n"); @@ -276,6 +279,7 @@ int fluid_sim_pressurecell_diffuse_test4(){ float * dArr = currentChunk->d[CENTER_LOC]; float * dTemp = currentChunk->dTempCache; float * bounds = currentChunk->bounds[CENTER_LOC]; + float diffuseConst = FLUID_PRESSURECELL_DIFFUSION_CONSTANT / (FLUID_PRESSURECELL_SPACING * FLUID_PRESSURECELL_SPACING); dArr[IX(4,4,4)] = MAX_FLUID_VALUE; bounds[IX(3,4,4)] = 1.0f; bounds[IX(5,4,4)] = 1.0f; @@ -363,6 +367,7 @@ int fluid_sim_pressurecell_diffuse_test5(){ float * wTemp = currentChunk->wTempCache; float * uArr = currentChunk->u0[CENTER_LOC]; float * bounds = currentChunk->bounds[CENTER_LOC]; + float diffuseConst = FLUID_PRESSURECELL_DIFFUSION_CONSTANT / (FLUID_PRESSURECELL_SPACING * FLUID_PRESSURECELL_SPACING); uTemp[IX(4,4,4)] = FLUID_PRESSURECELL_MAX_VELOCITY; vTemp[IX(4,4,4)] = FLUID_PRESSURECELL_MAX_VELOCITY; wTemp[IX(4,4,4)] = FLUID_PRESSURECELL_MAX_VELOCITY; @@ -376,7 +381,7 @@ int fluid_sim_pressurecell_diffuse_test5(){ // // cell that originall had values // - expected = FLUID_PRESSURECELL_MAX_VELOCITY - FLUID_PRESSURECELL_DIFFUSION_CONSTANT * 5 * FLUID_PRESSURECELL_MAX_VELOCITY * env->consts.dt; + expected = FLUID_PRESSURECELL_MAX_VELOCITY - diffuseConst * 5 * FLUID_PRESSURECELL_MAX_VELOCITY * env->consts.dt; actual = uArr[IX(4,4,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (4,4,4)! expected: %f actual: %f \n"); @@ -386,7 +391,7 @@ int fluid_sim_pressurecell_diffuse_test5(){ // // neighbors // - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * FLUID_PRESSURECELL_MAX_VELOCITY * env->consts.dt; + expected = diffuseConst * FLUID_PRESSURECELL_MAX_VELOCITY * env->consts.dt; actual = uArr[IX(3,4,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (3,4,4)! expected: %f actual: %f \n"); @@ -398,25 +403,25 @@ int fluid_sim_pressurecell_diffuse_test5(){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (5,4,4)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * FLUID_PRESSURECELL_MAX_VELOCITY * env->consts.dt; + expected = diffuseConst * FLUID_PRESSURECELL_MAX_VELOCITY * env->consts.dt; actual = uArr[IX(4,3,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (4,3,4)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * FLUID_PRESSURECELL_MAX_VELOCITY * env->consts.dt; + expected = diffuseConst * FLUID_PRESSURECELL_MAX_VELOCITY * env->consts.dt; actual = uArr[IX(4,5,4)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (4,5,4)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * FLUID_PRESSURECELL_MAX_VELOCITY * env->consts.dt; + expected = diffuseConst * FLUID_PRESSURECELL_MAX_VELOCITY * env->consts.dt; actual = uArr[IX(4,4,3)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (4,4,3)! expected: %f actual: %f \n"); } - expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * FLUID_PRESSURECELL_MAX_VELOCITY * env->consts.dt; + expected = diffuseConst * FLUID_PRESSURECELL_MAX_VELOCITY * env->consts.dt; actual = uArr[IX(4,4,5)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (4,4,5)! expected: %f actual: %f \n"); @@ -445,6 +450,7 @@ int fluid_sim_pressurecell_diffuse_test6(){ float * wTemp = currentChunk->wTempCache; float * uArr = currentChunk->u0[CENTER_LOC]; float * bounds = currentChunk->bounds[CENTER_LOC]; + float diffuseConst = FLUID_PRESSURECELL_DIFFUSION_CONSTANT / (FLUID_PRESSURECELL_SPACING * FLUID_PRESSURECELL_SPACING); uTemp[IX(4,4,4)] = FLUID_PRESSURECELL_MAX_VELOCITY; vTemp[IX(4,4,4)] = FLUID_PRESSURECELL_MAX_VELOCITY; wTemp[IX(4,4,4)] = FLUID_PRESSURECELL_MAX_VELOCITY;