#include #include #include "stb/stb_ds.h" #include "fluid/queue/chunk.h" #include "fluid/queue/sparse.h" #include "fluid/queue/chunkmask.h" #include "fluid/env/utilities.h" #include "fluid/queue/islandsolver.h" #include "fluid/queue/boundsolver.h" #include "fluid/dispatch/dispatcher.h" #include "fluid/sim/simulator.h" #include "../../../util/test.h" #include "../../../util/chunk_test_utils.h" #define CELLULAR_TEST_PLACE_VAL 0.1f int fluid_sim_cellular_cellular_tests_kernelx[27] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, }; int fluid_sim_cellular_cellular_tests_kernely[27] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2, }; int fluid_sim_cellular_cellular_tests_kernelz[27] = { 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, }; int fluid_sim_cellular_bounds_test1(){ int rVal = 0; printf("fluid_sim_cellular_bounds_test1\n"); Environment * env = fluid_environment_create(); int chunkCount = 27; Chunk ** queue = NULL; for(int i = 0; i < chunkCount; i++){ arrput(queue,chunk_create( fluid_sim_cellular_cellular_tests_kernelx[i], fluid_sim_cellular_cellular_tests_kernely[i], fluid_sim_cellular_cellular_tests_kernelz[i] )); } //link neighbors chunk_link_neighbors(queue); //fill them with values for(int i = 0; i < chunkCount; i++){ chunk_fill(queue[i],0); } //set border of 0,0,0 to push a value into z queue[0]->d[CENTER_LOC][IX(1,1,DIM-2)] = CELLULAR_TEST_PLACE_VAL; //call bounds setter fluid_solve_bounds(chunkCount,queue,env); { float borderVal = queue[0]->d[CENTER_LOC][IX(1,1,DIM-2)]; float transferedVal = queue[1]->d[CENTER_LOC][IX(1,1,0)]; rVal += assertEqualsFloat(borderVal,CELLULAR_TEST_PLACE_VAL,"Border value was overwritten! -- %f %f \n"); rVal += assertEqualsFloat(transferedVal,CELLULAR_TEST_PLACE_VAL,"Value was not transfered from border! -- %f %f \n"); } //dispatch and simulate fluid_dispatch(chunkCount,queue,env); fluid_simulate(env); //assert that the density moved { float borderVal = queue[0]->d[CENTER_LOC][IX(1,1,DIM-2)]; float orderBorderVal = queue[0]->d[CENTER_LOC][IX(1,1,DIM-3)]; float transferedVal = queue[1]->d[CENTER_LOC][IX(1,1,0)]; rVal += assertEqualsFloat(borderVal,MIN_FLUID_VALUE,"Border value has not changed! -- %f %f \n"); rVal += assertEqualsFloat(orderBorderVal,CELLULAR_TEST_PLACE_VAL,"Border value has not moved! -- %f %f \n"); rVal += assertEqualsFloat(transferedVal,CELLULAR_TEST_PLACE_VAL,"Value was overwritten on border! -- %f %f \n"); } return rVal; } int fluid_sim_cellular_bounds_test2(){ int rVal = 0; printf("fluid_sim_cellular_bounds_test2\n"); Environment * env = fluid_environment_create(); int chunkCount = 27; Chunk ** queue = NULL; for(int i = 0; i < chunkCount; i++){ arrput(queue,chunk_create( fluid_sim_cellular_cellular_tests_kernelx[i], fluid_sim_cellular_cellular_tests_kernely[i], fluid_sim_cellular_cellular_tests_kernelz[i] )); } //link neighbors chunk_link_neighbors(queue); //fill them with values for(int i = 0; i < chunkCount; i++){ chunk_fill(queue[i],0); } //set border of 0,0,0 to push a value into z queue[1]->d[CENTER_LOC][IX(1,1,1)] = CELLULAR_TEST_PLACE_VAL; //call bounds setter fluid_solve_bounds(chunkCount,queue,env); { float borderVal = queue[1]->d[CENTER_LOC][IX(1,1,1)]; float transferedVal = queue[0]->d[CENTER_LOC][IX(1,1,DIM-1)]; rVal += assertEqualsFloat(borderVal,CELLULAR_TEST_PLACE_VAL,"Border value was overwritten! -- %f %f \n"); rVal += assertEqualsFloat(transferedVal,CELLULAR_TEST_PLACE_VAL,"Value was not transfered from border! -- %f %f \n"); } //dispatch and simulate fluid_dispatch(chunkCount,queue,env); fluid_simulate(env); fluid_solve_bounds(chunkCount,queue,env); fluid_dispatch(chunkCount,queue,env); fluid_simulate(env); //assert that the density moved { float borderVal = queue[0]->d[CENTER_LOC][IX(1,1,DIM-2)]; float orderBorderVal = queue[0]->d[CENTER_LOC][IX(1,1,DIM-3)]; float transferedVal = queue[1]->d[CENTER_LOC][IX(1,1,0)]; rVal += assertEqualsFloat(borderVal,MIN_FLUID_VALUE,"Border value has not changed! -- %f %f \n"); rVal += assertEqualsFloat(orderBorderVal,CELLULAR_TEST_PLACE_VAL,"Border value has not moved! -- %f %f \n"); rVal += assertEqualsFloat(transferedVal,CELLULAR_TEST_PLACE_VAL,"Value was overwritten on border! -- %f %f \n"); } return rVal; } int fluid_sim_cellular_cellular_tests(int argc, char **argv){ int rVal = 0; rVal += fluid_sim_cellular_bounds_test1(); rVal += fluid_sim_cellular_bounds_test2(); return rVal; }