density diffusing across chunks
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
This commit is contained in:
parent
a05804da33
commit
533b8e3f76
@ -21,7 +21,7 @@ target_include_directories(StormEngine PUBLIC ${PROJECT_SOURCE_DIR}/src/main/c/i
|
||||
target_include_directories(StormEngine PUBLIC ${PROJECT_SOURCE_DIR}/src/main/c/lib)
|
||||
|
||||
# set props for the lib
|
||||
target_compile_options(StormEngine PRIVATE -m64 -mavx -mavx2 -lm)
|
||||
target_compile_options(StormEngine PRIVATE -m64 -mavx -mavx2)
|
||||
|
||||
|
||||
if (WIN32)
|
||||
|
||||
@ -203,6 +203,7 @@ void fluid_grid2_set_bounds_neighbor(
|
||||
){
|
||||
float * neighborArr;
|
||||
switch(sourceType){
|
||||
case BOUND_SET_DENSITY_PHI:
|
||||
case BOUND_SET_DENSITY: {
|
||||
neighborArr = environment->state.grid2.fluid_grid2_neighborArr_d;
|
||||
} break;
|
||||
@ -326,11 +327,11 @@ LIBRARY_API void fluid_grid2_set_bounds(
|
||||
case BOUND_SET_VECTOR_DIFFUSE_PHI_W: {
|
||||
fluid_grid2_set_bounds_reflection(environment,vector_dir,target);
|
||||
} break;
|
||||
case BOUND_SET_DENSITY_PHI:
|
||||
case BOUND_SET_PROJECTION_PHI:
|
||||
case BOUND_SET_PROJECTION_PHI_0: {
|
||||
fluid_grid2_set_bounds_continuity(environment,target);
|
||||
} break;
|
||||
case BOUND_SET_DENSITY_PHI:
|
||||
case BOUND_SET_VECTOR_U:
|
||||
case BOUND_SET_VECTOR_V:
|
||||
case BOUND_SET_VECTOR_W:
|
||||
|
||||
@ -58,7 +58,13 @@ foreach (TEST_FILE ${TEST_SOURCES})
|
||||
endif()
|
||||
endforeach ()
|
||||
|
||||
target_compile_options(test_runner PRIVATE -m64 -mavx -mavx2 -lm)
|
||||
target_compile_options(test_runner PRIVATE -m64 -mavx -mavx2)
|
||||
|
||||
#portably link math library
|
||||
find_library(MATH_LIBRARY m)
|
||||
if(MATH_LIBRARY)
|
||||
target_link_libraries(MyTarget PUBLIC ${MATH_LIBRARY})
|
||||
endif()
|
||||
|
||||
# make test runner depend on library
|
||||
add_dependencies(test_runner StormEngine)
|
||||
|
||||
@ -26,6 +26,11 @@
|
||||
*/
|
||||
#define FLUID_GRID2_PROJECTION_ERROR_MARGIN 0.00001f
|
||||
|
||||
/**
|
||||
* Difference in density between chunks that is allowed
|
||||
*/
|
||||
#define FLUID_GRID_BORDER_DIFFUSION_CHUNK_TEST4_THRESOLD 0.1f
|
||||
|
||||
/**
|
||||
* Testing full sim routine
|
||||
*/
|
||||
@ -40,7 +45,7 @@ int fluid_sim_grid2_border_diffusion_test1(){
|
||||
|
||||
|
||||
//setup chunk values
|
||||
queue[0]->d0[CENTER_LOC][IX(DIM-2,1,DIM-2)] = MAX_FLUID_VALUE; //this should immediately bleed into the [0 0 1] chunk
|
||||
queue[0]->d[CENTER_LOC][IX(DIM-2,1,DIM-2)] = MAX_FLUID_VALUE; //this should immediately bleed into the [0 0 1] chunk
|
||||
|
||||
//set bounds according to neighbors
|
||||
fluid_solve_bounds(chunkCount,queue,env);
|
||||
@ -68,7 +73,7 @@ int fluid_sim_grid2_border_diffusion_test2(){
|
||||
|
||||
|
||||
//setup chunk values
|
||||
queue[0]->d0[CENTER_LOC][IX(DIM-2,1,DIM-2)] = MAX_FLUID_VALUE; //this should immediately bleed into the [0 0 1] chunk
|
||||
queue[0]->d[CENTER_LOC][IX(DIM-2,1,DIM-2)] = MAX_FLUID_VALUE; //this should immediately bleed into the [0 0 1] chunk
|
||||
|
||||
//set bounds according to neighbors
|
||||
fluid_solve_bounds(chunkCount,queue,env);
|
||||
@ -94,6 +99,175 @@ int fluid_sim_grid2_border_diffusion_test2(){
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing full sim routine
|
||||
*/
|
||||
int fluid_sim_grid2_border_diffusion_test3(){
|
||||
printf("fluid_sim_grid2_border_diffusion_test3\n");
|
||||
int rVal = 0;
|
||||
Environment * env = fluid_environment_create();
|
||||
Chunk ** queue = NULL;
|
||||
queue = createChunkGrid(env,3,3,3);
|
||||
int chunkCount = arrlen(queue);
|
||||
|
||||
|
||||
|
||||
//setup chunk values
|
||||
queue[0]->d[CENTER_LOC][IX(DIM-2,1,DIM-2)] = MAX_FLUID_VALUE; //this should immediately bleed into the [0 0 1] chunk
|
||||
float afterSum, lastSum = 0;
|
||||
int frame;
|
||||
|
||||
//set bounds according to neighbors
|
||||
int frameCount = 50;
|
||||
for(frame = 0; frame < frameCount; frame++){
|
||||
fluid_solve_bounds(chunkCount,queue,env);
|
||||
fluid_grid2_simulate(chunkCount,queue,env,FLUID_GRID2_SIM_STEP);
|
||||
fluid_solve_bounds(chunkCount,queue,env);
|
||||
afterSum = chunk_sum_density(queue[1]);
|
||||
if(lastSum > afterSum){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//test the result
|
||||
if(afterSum <= lastSum){
|
||||
printf("Neighbor sum did not increase on frame %d\n",frame);
|
||||
printf("lastSum: %f \n", lastSum);
|
||||
printf("afterSum: %f \n", afterSum);
|
||||
printf("\n");
|
||||
rVal++;
|
||||
}
|
||||
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing full sim routine
|
||||
*/
|
||||
int fluid_sim_grid2_border_diffusion_test4(){
|
||||
printf("fluid_sim_grid2_border_diffusion_test4\n");
|
||||
int rVal = 0;
|
||||
Environment * env = fluid_environment_create();
|
||||
Chunk ** queue = NULL;
|
||||
queue = createChunkGrid(env,3,3,3);
|
||||
int chunkCount = arrlen(queue);
|
||||
|
||||
|
||||
|
||||
//setup chunk values
|
||||
queue[0]->d[CENTER_LOC][IX(DIM-2,1,DIM-2)] = MAX_FLUID_VALUE; //this should immediately bleed into the [0 0 1] chunk
|
||||
float chunk0Sum, chunk1Sum = 0;
|
||||
int frame;
|
||||
|
||||
//set bounds according to neighbors
|
||||
int frameCount = 50;
|
||||
for(frame = 0; frame < frameCount; frame++){
|
||||
fluid_solve_bounds(chunkCount,queue,env);
|
||||
fluid_grid2_simulate(chunkCount,queue,env,FLUID_GRID2_SIM_STEP);
|
||||
fluid_solve_bounds(chunkCount,queue,env);
|
||||
}
|
||||
|
||||
//test the result
|
||||
chunk0Sum = chunk_sum_density(queue[0]);
|
||||
chunk1Sum = chunk_sum_density(queue[1]);
|
||||
if(fabs(chunk0Sum - chunk1Sum) > FLUID_GRID_BORDER_DIFFUSION_CHUNK_TEST4_THRESOLD){
|
||||
printf("Neighbor has significantly different density\n");
|
||||
printf("chunk0Sum: %f \n", chunk0Sum);
|
||||
printf("chunk1Sum: %f \n", chunk1Sum);
|
||||
printf("\n");
|
||||
rVal++;
|
||||
}
|
||||
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing mass conservation
|
||||
*/
|
||||
int fluid_sim_grid2_border_diffusion_test5(){
|
||||
printf("fluid_sim_grid2_border_diffusion_test5\n");
|
||||
int rVal = 0;
|
||||
Environment * env = fluid_environment_create();
|
||||
Chunk ** queue = NULL;
|
||||
queue = createChunkGrid(env,3,3,3);
|
||||
int chunkCount = arrlen(queue);
|
||||
|
||||
|
||||
|
||||
//setup chunk values
|
||||
queue[0]->d[CENTER_LOC][IX(DIM-2,1,DIM-2)] = MAX_FLUID_VALUE; //this should immediately bleed into the [0 0 1] chunk
|
||||
float beforeSum = chunk_queue_sum_density(queue);
|
||||
int frame;
|
||||
|
||||
//set bounds according to neighbors
|
||||
int frameCount = 50;
|
||||
for(frame = 0; frame < frameCount; frame++){
|
||||
fluid_solve_bounds(chunkCount,queue,env);
|
||||
fluid_grid2_simulate(chunkCount,queue,env,FLUID_GRID2_SIM_STEP);
|
||||
fluid_solve_bounds(chunkCount,queue,env);
|
||||
}
|
||||
|
||||
//test the result
|
||||
float afterSum = chunk_queue_sum_density(queue);
|
||||
if(fabs(beforeSum - afterSum) > FLUID_GRID2_PROJECTION_ERROR_MARGIN){
|
||||
printf("Significantly different density between start and end! \n");
|
||||
printf("beforeSum: %f \n", beforeSum);
|
||||
printf("afterSum: %f \n", afterSum);
|
||||
printf("\n");
|
||||
rVal++;
|
||||
}
|
||||
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing mass conservation
|
||||
*/
|
||||
int fluid_sim_grid2_border_diffusion_test6(){
|
||||
printf("fluid_sim_grid2_border_diffusion_test6\n");
|
||||
int rVal = 0;
|
||||
Environment * env = fluid_environment_create();
|
||||
Chunk ** queue = NULL;
|
||||
queue = createChunkGrid(env,3,3,3);
|
||||
int chunkCount = arrlen(queue);
|
||||
|
||||
|
||||
|
||||
//setup chunk values
|
||||
queue[0]->d[CENTER_LOC][IX(3,1,DIM-2)] = MAX_FLUID_VALUE; //this should immediately bleed into the [0 0 1] chunk
|
||||
float invalidSum;
|
||||
int frame;
|
||||
|
||||
//set bounds according to neighbors
|
||||
int frameCount = 50;
|
||||
for(frame = 0; frame < frameCount; frame++){
|
||||
fluid_solve_bounds(chunkCount,queue,env);
|
||||
fluid_grid2_simulate(chunkCount,queue,env,FLUID_GRID2_SIM_STEP);
|
||||
fluid_solve_bounds(chunkCount,queue,env);
|
||||
invalidSum = 0;
|
||||
for(int i = 2; i < chunkCount; i++){
|
||||
float currSum = chunk_sum_density(queue[i]);
|
||||
invalidSum = invalidSum + currSum;
|
||||
if(currSum != 0){
|
||||
printf("Sum in: %d %f \n",i,currSum);
|
||||
}
|
||||
}
|
||||
if(invalidSum > 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//test the result
|
||||
if(invalidSum > FLUID_GRID2_PROJECTION_ERROR_MARGIN){
|
||||
printf("Significant amounts of fluid in invalid chunks! %d\n", frame);
|
||||
printf("invalidSum: %f \n", invalidSum);
|
||||
printf("\n");
|
||||
rVal++;
|
||||
}
|
||||
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing full sim routines
|
||||
*/
|
||||
@ -102,6 +276,10 @@ int fluid_sim_grid2_border_diffusion_tests(int argc, char **argv){
|
||||
|
||||
rVal += fluid_sim_grid2_border_diffusion_test1();
|
||||
rVal += fluid_sim_grid2_border_diffusion_test2();
|
||||
rVal += fluid_sim_grid2_border_diffusion_test3();
|
||||
rVal += fluid_sim_grid2_border_diffusion_test4();
|
||||
rVal += fluid_sim_grid2_border_diffusion_test5();
|
||||
rVal += fluid_sim_grid2_border_diffusion_test6();
|
||||
|
||||
return rVal;
|
||||
}
|
||||
@ -255,6 +255,21 @@ void chunk_link_neighbors(Chunk ** chunks){
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums the density of a chunk
|
||||
*/
|
||||
float chunk_sum_density(Chunk * chunk){
|
||||
float sum = 0;
|
||||
for(int x = 1; x < DIM - 1; x++){
|
||||
for(int y = 1; y < DIM - 1; y++){
|
||||
for(int z = 1; z < DIM - 1; z++){
|
||||
sum = sum + chunk->d[CENTER_LOC][IX(x,y,z)];
|
||||
}
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums density all chunks in a queue
|
||||
*/
|
||||
@ -263,13 +278,7 @@ float chunk_queue_sum_density(Chunk ** chunks){
|
||||
int chunkCount = arrlen(chunks);
|
||||
for(int i = 0; i < chunkCount; i++){
|
||||
Chunk * current = chunks[i];
|
||||
for(int x = 1; x < DIM - 1; x++){
|
||||
for(int y = 1; y < DIM - 1; y++){
|
||||
for(int z = 1; z < DIM - 1; z++){
|
||||
sum = sum + current->d[CENTER_LOC][IX(x,y,z)];
|
||||
}
|
||||
}
|
||||
}
|
||||
sum = sum + chunk_sum_density(current);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
@ -106,6 +106,11 @@ void chunk_link_neighbors(Chunk ** chunks);
|
||||
*/
|
||||
float chunk_queue_sum_density(Chunk ** chunks);
|
||||
|
||||
/**
|
||||
* Sums the density of a chunk
|
||||
*/
|
||||
float chunk_sum_density(Chunk * chunk);
|
||||
|
||||
/**
|
||||
* Sums velocity in all chunks in a queue
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user