add test to capture density adding to sky 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
a6cc3addf7
commit
dc79f1b0ba
@ -7,6 +7,11 @@
|
|||||||
*/
|
*/
|
||||||
#define FLUID_PRESSURECELL_SIM_STEP 0.01f
|
#define FLUID_PRESSURECELL_SIM_STEP 0.01f
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force of gravity in unit tests
|
||||||
|
*/
|
||||||
|
#define FLUID_PRESSURECELL_GRAVITY 1.0f
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Spacing of cells
|
* Spacing of cells
|
||||||
*/
|
*/
|
||||||
|
|||||||
2
src/main/c/src/fluid/env/environment.c
vendored
2
src/main/c/src/fluid/env/environment.c
vendored
@ -3,6 +3,7 @@
|
|||||||
#include "public.h"
|
#include "public.h"
|
||||||
#include "fluid/env/environment.h"
|
#include "fluid/env/environment.h"
|
||||||
#include "fluid/env/utilities.h"
|
#include "fluid/env/utilities.h"
|
||||||
|
#include "fluid/sim/pressurecell/solver_consts.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ LIBRARY_API Environment * fluid_environment_create(){
|
|||||||
rVal->queue.gridQueue = NULL;
|
rVal->queue.gridQueue = NULL;
|
||||||
rVal->queue.grid2Queue = NULL;
|
rVal->queue.grid2Queue = NULL;
|
||||||
rVal->consts.dt = 0.02f;
|
rVal->consts.dt = 0.02f;
|
||||||
|
rVal->consts.gravity = FLUID_PRESSURECELL_GRAVITY;
|
||||||
|
|
||||||
//allocate arrays
|
//allocate arrays
|
||||||
fluid_environment_allocate_arrays(rVal);
|
fluid_environment_allocate_arrays(rVal);
|
||||||
|
|||||||
86
src/test/c/fluid/sim/pressurecell/add_gravity_tests.c
Normal file
86
src/test/c/fluid/sim/pressurecell/add_gravity_tests.c
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "stb/stb_ds.h"
|
||||||
|
|
||||||
|
#include "fluid/queue/boundsolver.h"
|
||||||
|
#include "fluid/queue/chunkmask.h"
|
||||||
|
#include "fluid/queue/chunk.h"
|
||||||
|
#include "fluid/queue/metadatacalc.h"
|
||||||
|
#include "fluid/env/environment.h"
|
||||||
|
#include "fluid/env/utilities.h"
|
||||||
|
#include "fluid/dispatch/dispatcher.h"
|
||||||
|
#include "fluid/sim/simulator.h"
|
||||||
|
#include "fluid/sim/pressurecell/pressure.h"
|
||||||
|
#include "fluid/sim/pressurecell/pressurecell.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 4
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing normalizing values
|
||||||
|
*/
|
||||||
|
int fluid_sim_pressurecell_add_gravity_test1(){
|
||||||
|
printf("fluid_sim_pressurecell_add_gravity_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];
|
||||||
|
for(int x = 0; x < DIM; x++){
|
||||||
|
for(int y = 0; y < DIM; y++){
|
||||||
|
currentChunk->d[CENTER_LOC][IX(x,1,y)] = MAX_FLUID_VALUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//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;
|
||||||
|
|
||||||
|
//
|
||||||
|
// cell that originall had values
|
||||||
|
//
|
||||||
|
expected = 0;
|
||||||
|
actual = currentChunk->v[CENTER_LOC][IX(1,1,DIM-2)];
|
||||||
|
if(fabs(expected - actual) < 0.1f){
|
||||||
|
rVal++;
|
||||||
|
printf("Gravity not applied!\n");
|
||||||
|
printf("%f \n", currentChunk->v[CENTER_LOC][IX(1,1,DIM-2)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing pressure values
|
||||||
|
*/
|
||||||
|
int fluid_sim_pressurecell_add_gravity_tests(int argc, char **argv){
|
||||||
|
int rVal = 0;
|
||||||
|
|
||||||
|
rVal += fluid_sim_pressurecell_add_gravity_test1();
|
||||||
|
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
@ -64,7 +64,7 @@ int fluid_sim_pressurecell_sim_e2e_test2(){
|
|||||||
int rVal = 0;
|
int rVal = 0;
|
||||||
Environment * env = fluid_environment_create();
|
Environment * env = fluid_environment_create();
|
||||||
Chunk ** queue = NULL;
|
Chunk ** queue = NULL;
|
||||||
queue = createChunkGrid(env,1,1,1);
|
queue = createChunkGrid(env,CHUNK_DIM,CHUNK_DIM,CHUNK_DIM);
|
||||||
int chunkCount = arrlen(queue);
|
int chunkCount = arrlen(queue);
|
||||||
|
|
||||||
|
|
||||||
@ -79,11 +79,14 @@ int fluid_sim_pressurecell_sim_e2e_test2(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//actually simulate
|
//actually simulate
|
||||||
fluid_tracking_reset(env);
|
int frameCount = 50;
|
||||||
fluid_solve_bounds(chunkCount,queue,env);
|
for(int frame = 0; frame < frameCount; frame++){
|
||||||
fluid_dispatch(chunkCount,queue,env,FLUID_DISPATCHER_OVERRIDE_PRESSURECELL);
|
fluid_tracking_reset(env);
|
||||||
fluid_simulate(env);
|
fluid_solve_bounds(chunkCount,queue,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
|
//test the result
|
||||||
float expected, actual;
|
float expected, actual;
|
||||||
@ -91,18 +94,35 @@ int fluid_sim_pressurecell_sim_e2e_test2(){
|
|||||||
//
|
//
|
||||||
// cell that originall had values
|
// cell that originall had values
|
||||||
//
|
//
|
||||||
expected = MAX_FLUID_VALUE;
|
expected = 0;
|
||||||
actual = currentChunk->d[CENTER_LOC][IX(1,1,1)];
|
actual = currentChunk->d[CENTER_LOC][IX(1,2,DIM-2)];
|
||||||
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
|
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
|
||||||
rVal += assertEqualsFloat(expected,actual,"Failed to recapture density into (1,1,1)! expected: %f actual: %f \n");
|
rVal += assertEqualsFloat(expected,actual,"Failed to recapture density into (1,2,DIM-2)! expected: %f actual: %f \n");
|
||||||
|
printf("%f \n", currentChunk->v[CENTER_LOC][IX(1,2,DIM-2)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
expected = MAX_FLUID_VALUE;
|
expected = MAX_FLUID_VALUE;
|
||||||
actual = currentChunk->d[CENTER_LOC][IX(DIM-2,1,DIM-2)];
|
actual = currentChunk->d[CENTER_LOC][IX(DIM-2,1,DIM-2)];
|
||||||
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
|
if(fabs(expected - actual) < FLUID_PRESSURE_CELL_ERROR_MARGIN){
|
||||||
rVal += assertEqualsFloat(expected,actual,"Failed to recapture density into (DIM-2,DIM-2,DIM-2)! expected: %f actual: %f \n");
|
rVal += assertEqualsFloat(expected,actual,"Failed to recapture density into (DIM-2,DIM-2,DIM-2)! expected: %f actual: %f \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//assert that all y=1 chunks are empty (it's just a puddle on the floor, shouldn't be creating fluid in the sky)
|
||||||
|
for(int i = 0; i < chunkCount; i++){
|
||||||
|
Chunk * toEvaluate = queue[i];
|
||||||
|
if(toEvaluate->y < 1){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
float sum = chunk_sum_density_with_borders(toEvaluate);
|
||||||
|
if(sum > FLUID_PRESSURE_CELL_ERROR_MARGIN){
|
||||||
|
rVal++;
|
||||||
|
printf("Sky chunk has density! \n");
|
||||||
|
printf("sum: %f \n",sum);
|
||||||
|
printf("%d,%d,%d \n",toEvaluate->x,toEvaluate->y,toEvaluate->z);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -280,6 +280,21 @@ float chunk_sum_density(Chunk * chunk){
|
|||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sums the density of a chunk including its border values
|
||||||
|
*/
|
||||||
|
float chunk_sum_density_with_borders(Chunk * chunk){
|
||||||
|
float sum = 0;
|
||||||
|
for(int x = 0; x < DIM; x++){
|
||||||
|
for(int y = 0; y < DIM; y++){
|
||||||
|
for(int z = 0; z < DIM; z++){
|
||||||
|
sum = sum + chunk->d[CENTER_LOC][IX(x,y,z)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sums density all chunks in a queue
|
* Sums density all chunks in a queue
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -106,6 +106,11 @@ void chunk_link_neighbors(Chunk ** chunks);
|
|||||||
*/
|
*/
|
||||||
float chunk_queue_sum_density(Chunk ** chunks);
|
float chunk_queue_sum_density(Chunk ** chunks);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sums the density of a chunk including its border values
|
||||||
|
*/
|
||||||
|
float chunk_sum_density_with_borders(Chunk * chunk);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sums the density of a chunk
|
* Sums the density of a chunk
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user