fix divergence not crossing borders
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-01-19 20:46:09 -05:00
parent 923c5afd21
commit 6b1fab7fad
4 changed files with 169 additions and 29 deletions

View File

@ -48,7 +48,7 @@ LIBRARY_API void fluid_pressurecell_simulate(
fluid_pressurecell_clearArr(currentChunk->vTempCache);
fluid_pressurecell_clearArr(currentChunk->wTempCache);
fluid_pressurecell_calculate_expected_intake(environment,currentChunk);
fluid_pressurecell_update_bounds(environment,currentChunk);
// fluid_pressurecell_update_bounds(environment,currentChunk);
// pressurecell_update_interest(environment,currentChunk);
}

View File

@ -44,9 +44,9 @@ LIBRARY_API void pressurecell_add_velocity(Environment * environment, Chunk * ch
float * uSourceArr = chunk->u0[CENTER_LOC];
float * vSourceArr = chunk->v0[CENTER_LOC];
float * wSourceArr = chunk->w0[CENTER_LOC];
for(z = 1; z < DIM-1; z++){
for(y = 1; y < DIM-1; y++){
for(x = 1; x < DIM-1; x++){
for(z = 0; z < DIM; z++){
for(y = 0; y < DIM; y++){
for(x = 0; x < DIM; x++){
uTemp[IX(x,y,z)] = uArr[IX(x,y,z)] + uSourceArr[IX(x,y,z)];
vTemp[IX(x,y,z)] = vArr[IX(x,y,z)] + vSourceArr[IX(x,y,z)];
wTemp[IX(x,y,z)] = wArr[IX(x,y,z)] + wSourceArr[IX(x,y,z)];

View File

@ -41,12 +41,12 @@ int fluid_sim_pressurecell_divergence_test1(){
Chunk * currentChunk = queue[0];
currentChunk->divergenceCache[CENTER_LOC][IX(4,4,4)] = 0;
currentChunk->u[CENTER_LOC][IX(3,4,4)] = 1;
currentChunk->u[CENTER_LOC][IX(5,4,4)] = -1;
currentChunk->v[CENTER_LOC][IX(4,3,4)] = 1;
currentChunk->v[CENTER_LOC][IX(4,5,4)] = -1;
currentChunk->w[CENTER_LOC][IX(4,4,3)] = 1;
currentChunk->w[CENTER_LOC][IX(4,4,5)] = -1;
currentChunk->uTempCache[IX(3,4,4)] = 1;
currentChunk->uTempCache[IX(5,4,4)] = -1;
currentChunk->vTempCache[IX(4,3,4)] = 1;
currentChunk->vTempCache[IX(4,5,4)] = -1;
currentChunk->wTempCache[IX(4,4,3)] = 1;
currentChunk->wTempCache[IX(4,4,5)] = -1;
//actually simulate
pressurecell_approximate_divergence(env,currentChunk);
@ -57,7 +57,7 @@ int fluid_sim_pressurecell_divergence_test1(){
//
// cell that originall had values
//
expected = -3;
expected = 3;
actual = currentChunk->divergenceCache[CENTER_LOC][IX(4,4,4)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to calculate divergence correctly (4,4,4)! expected: %f actual: %f \n");
@ -83,12 +83,12 @@ int fluid_sim_pressurecell_divergence_test2(){
float deltaDensity = 0.01f;
Chunk * currentChunk = queue[0];
currentChunk->u[CENTER_LOC][IX(0,1,1)] = 0;
currentChunk->u[CENTER_LOC][IX(2,1,1)] = 1;
currentChunk->v[CENTER_LOC][IX(1,0,1)] = 0;
currentChunk->v[CENTER_LOC][IX(1,2,1)] = -1;
currentChunk->w[CENTER_LOC][IX(1,1,0)] = 0;
currentChunk->w[CENTER_LOC][IX(1,1,2)] = -1;
currentChunk->uTempCache[IX(0,1,1)] = 0;
currentChunk->uTempCache[IX(2,1,1)] = 1;
currentChunk->vTempCache[IX(1,0,1)] = 0;
currentChunk->vTempCache[IX(1,2,1)] = -1;
currentChunk->wTempCache[IX(1,1,0)] = 0;
currentChunk->wTempCache[IX(1,1,2)] = -1;
//actually simulate
pressurecell_approximate_divergence(env,currentChunk);
@ -99,7 +99,7 @@ int fluid_sim_pressurecell_divergence_test2(){
//
// cell that originall had values
//
expected = -0.5;
expected = 0.5;
actual = currentChunk->divergenceCache[CENTER_LOC][IX(1,1,1)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to calculate divergence correctly (1,1,1)! expected: %f actual: %f \n");
@ -125,13 +125,13 @@ int fluid_sim_pressurecell_divergence_test3(){
float deltaDensity = 0.01f;
Chunk * currentChunk = queue[0];
currentChunk->u[CENTER_LOC][IX(1,1,1)] = 1;
currentChunk->v[CENTER_LOC][IX(1,1,1)] = 1;
currentChunk->w[CENTER_LOC][IX(1,1,1)] = 1;
currentChunk->uTempCache[IX(1,1,1)] = 1;
currentChunk->vTempCache[IX(1,1,1)] = 1;
currentChunk->wTempCache[IX(1,1,1)] = 1;
currentChunk->u[CENTER_LOC][IX(2,1,1)] = 1;
currentChunk->v[CENTER_LOC][IX(1,2,1)] = 1;
currentChunk->w[CENTER_LOC][IX(1,1,2)] = -1;
currentChunk->uTempCache[IX(2,1,1)] = 1;
currentChunk->vTempCache[IX(1,2,1)] = 1;
currentChunk->wTempCache[IX(1,1,2)] = -1;
//actually simulate
pressurecell_approximate_divergence(env,currentChunk);
@ -149,7 +149,7 @@ int fluid_sim_pressurecell_divergence_test3(){
cy = 1;
cz = 1;
expected = currentChunk->divergenceCache[CENTER_LOC][IX(cx,cy,cz)];
if(expected != 0.5){ //we expect 1.5 velocity to leave this cell in one iteration
if(expected != -0.5){ //we expect 0.5 velocity to leave this cell in one iteration
rVal++;
printf("Divergence calc failed\n");
printf("at point (%d,%d,%d) \n", cx, cy, cz);
@ -168,7 +168,7 @@ int fluid_sim_pressurecell_divergence_test3(){
cy = 1;
cz = 1;
expected = currentChunk->divergenceCache[CENTER_LOC][IX(cx,cy,cz)];
if(expected != -0.5){//we expect 0.5 velocity to enter this cell in one iteration
if(expected != 0.5){//we expect 0.5 velocity to enter this cell in one iteration
rVal++;
printf("Divergence calc failed\n");
printf("at point (%d,%d,%d) \n", cx, cy, cz);
@ -192,9 +192,9 @@ int fluid_sim_pressurecell_divergence_test3(){
int fluid_sim_pressurecell_divergence_tests(int argc, char **argv){
int rVal = 0;
// rVal += fluid_sim_pressurecell_divergence_test1();
// rVal += fluid_sim_pressurecell_divergence_test2();
// rVal += fluid_sim_pressurecell_divergence_test3();
rVal += fluid_sim_pressurecell_divergence_test1();
rVal += fluid_sim_pressurecell_divergence_test2();
rVal += fluid_sim_pressurecell_divergence_test3();
return rVal;
}

View File

@ -0,0 +1,140 @@
#include <math.h>
#include "stb/stb_ds.h"
#include "fluid/dispatch/dispatcher.h"
#include "fluid/queue/boundsolver.h"
#include "fluid/queue/chunkmask.h"
#include "fluid/queue/chunk.h"
#include "fluid/env/environment.h"
#include "fluid/env/utilities.h"
#include "fluid/sim/simulator.h"
#include "fluid/sim/pressurecell/normalization.h"
#include "fluid/sim/pressurecell/solver_consts.h"
#include "fluid/tracking/tracking.h"
#include "math/ode/multigrid.h"
#include "../../../util/chunk_test_utils.h"
#include "../../../util/test.h"
/**
* Error margin for tests
*/
#define FLUID_PRESSURE_CELL_ERROR_MARGIN 0.01f
/**
* Number of chunks
*/
#define CHUNK_DIM 2
/**
* Testing normalizing values
*/
int fluid_sim_pressurecell_pressurecell_problemchunk_1_test1(){
printf("fluid_sim_pressurecell_border_transmission_test1\n");
int rVal = 0;
Environment * env = fluid_environment_create();
Chunk ** queue = NULL;
queue = createChunkGrid(env,CHUNK_DIM,CHUNK_DIM,CHUNK_DIM);
int chunkCount = arrlen(queue);
//setup chunk values
float deltaDensity = 0.01f;
Chunk * currentChunk = queue[0];
//should be chunk at 0,0,1
Chunk * furtherX = queue[1];
rVal += assertEquals(furtherX->x,0,"Chunk is not at 0,0,1 x: %d \n");
rVal += assertEquals(furtherX->y,0,"Chunk is not at 0,0,1 y: %d \n");
rVal += assertEquals(furtherX->z,1,"Chunk is not at 0,0,1 z: %d \n");
//setup the problem chunk
for(int x = 1; x < DIM-1; x++){
//setup the og chunk values
currentChunk->u[CENTER_LOC][IX(x,1,DIM-2)] = 0.5f;
currentChunk->v[CENTER_LOC][IX(x,1,DIM-2)] = -0.5f;
currentChunk->w[CENTER_LOC][IX(x,1,DIM-2)] = 0.5f;
currentChunk->d[CENTER_LOC][IX(x,1,DIM-2)] = 0.5f;
currentChunk->divergenceCache[CENTER_LOC][IX(x,1,DIM-2)] = 0.5f;
currentChunk->pressureCache[CENTER_LOC][IX(x,1,DIM-2)] = 0.5f;
//setup the problem chunk
for(int y = 1; y < DIM-1; y++){
furtherX->u[CENTER_LOC][IX(x,1,y)] = 0.00001f;
furtherX->v[CENTER_LOC][IX(x,1,y)] = -0.00001f;
furtherX->w[CENTER_LOC][IX(x,1,y)] = 0.00001f;
}
furtherX->u[CENTER_LOC][IX(x,1,0)] = 0.5f;
furtherX->v[CENTER_LOC][IX(x,1,0)] = -0.5f;
furtherX->w[CENTER_LOC][IX(x,1,0)] = 0.5f;
furtherX->d[CENTER_LOC][IX(x,1,0)] = 0.5f;
furtherX->divergenceCache[CENTER_LOC][IX(x,1,0)] = 0.5f;
furtherX->pressureCache[CENTER_LOC][IX(x,1,0)] = 0.5f;
}
//actually simulate
fluid_tracking_reset(env);
fluid_solve_bounds(chunkCount,queue,env);
fluid_dispatch(chunkCount,queue,env,FLUID_DISPATCHER_OVERRIDE_PRESSURECELL);
fluid_simulate(env);
fluid_solve_bounds(chunkCount,queue,env);
//test the result
float expected, actual;
//
// chunk in z direction should have density > 0 at 1,1,1
//
expected = MAX_FLUID_VALUE;
actual = furtherX->divergenceCache[CENTER_LOC][IX(5,1,1)];
if(actual < FLUID_PRESSURE_CELL_ERROR_MARGIN){
printf("Failed to gain divergence at (5,1,1)! actual: %f \n", actual);
rVal++;
}
expected = MAX_FLUID_VALUE;
actual = furtherX->w[CENTER_LOC][IX(5,1,1)];
if(actual < FLUID_PRESSURE_CELL_ERROR_MARGIN){
printf("Failed to gain z velocity at (5,1,1)! actual: %f \n", actual);
rVal++;
}
expected = MAX_FLUID_VALUE;
actual = furtherX->d[CENTER_LOC][IX(5,1,1)];
if(actual < FLUID_PRESSURE_CELL_ERROR_MARGIN){
printf("Failed to gain density at (5,1,1)! actual: %f \n", actual);
rVal++;
}
expected = MAX_FLUID_VALUE;
actual = furtherX->d[CENTER_LOC][IX(5,1,0)];
if(actual < FLUID_PRESSURE_CELL_ERROR_MARGIN){
printf("Failed to gain density at (5,1,0)! actual: %f \n", actual);
rVal++;
}
//
// origin chunk should have density > 0 at DIM-1,1,DIM-1
//
actual = currentChunk->d[CENTER_LOC][IX(DIM-2,1,DIM-2)];
if(actual < FLUID_PRESSURE_CELL_ERROR_MARGIN){
printf("Failed to retain density at (DIM-2,1,DIM-2)! actual: %f \n", actual);
rVal++;
}
return rVal;
}
/**
* Testing transmitting density across borders
*/
int fluid_sim_pressurecell_pressurecell_problemchunk_1_tests(int argc, char **argv){
int rVal = 0;
rVal += fluid_sim_pressurecell_pressurecell_problemchunk_1_test1();
return rVal;
}