border diffusion test
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
9bb8c2f360
commit
150f89497f
@ -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)
|
target_include_directories(StormEngine PUBLIC ${PROJECT_SOURCE_DIR}/src/main/c/lib)
|
||||||
|
|
||||||
# set props for the lib
|
# set props for the lib
|
||||||
target_compile_options(StormEngine PRIVATE -m64 -mavx -mavx2 -save-temps)
|
target_compile_options(StormEngine PRIVATE -m64 -mavx -mavx2)
|
||||||
|
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
|
|||||||
@ -71,7 +71,17 @@ LIBRARY_API void fluid_grid2_simulate(
|
|||||||
fluid_grid2_flip_arrays(currentChunk->w,currentChunk->w0);
|
fluid_grid2_flip_arrays(currentChunk->w,currentChunk->w0);
|
||||||
|
|
||||||
//solve vector diffusion
|
//solve vector diffusion
|
||||||
fluid_grid2_solveVectorDiffuse(environment,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,timestep);
|
fluid_grid2_solveVectorDiffuse(
|
||||||
|
environment,
|
||||||
|
currentChunk->u,
|
||||||
|
currentChunk->v,
|
||||||
|
currentChunk->w,
|
||||||
|
currentChunk->u0,
|
||||||
|
currentChunk->v0,
|
||||||
|
currentChunk->w0,
|
||||||
|
timestep
|
||||||
|
);
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// //time tracking
|
// //time tracking
|
||||||
@ -85,8 +95,17 @@ LIBRARY_API void fluid_grid2_simulate(
|
|||||||
// Chunk * currentChunk = chunks[i];
|
// Chunk * currentChunk = chunks[i];
|
||||||
// //update the bounds arrays
|
// //update the bounds arrays
|
||||||
// fluid_grid2_rewrite_bounds(currentChunk);
|
// fluid_grid2_rewrite_bounds(currentChunk);
|
||||||
|
|
||||||
// setup projection
|
// setup projection
|
||||||
fluid_grid2_setupProjection(environment,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,timestep);
|
fluid_grid2_setupProjection(
|
||||||
|
environment,
|
||||||
|
currentChunk->u,
|
||||||
|
currentChunk->v,
|
||||||
|
currentChunk->w,
|
||||||
|
currentChunk->u0,
|
||||||
|
currentChunk->v0,
|
||||||
|
timestep
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
//Perform main projection solver
|
//Perform main projection solver
|
||||||
@ -99,6 +118,7 @@ LIBRARY_API void fluid_grid2_simulate(
|
|||||||
fluid_grid2_flip_arrays(currentChunk->u,currentChunk->u0);
|
fluid_grid2_flip_arrays(currentChunk->u,currentChunk->u0);
|
||||||
fluid_grid2_flip_arrays(currentChunk->v,currentChunk->v0);
|
fluid_grid2_flip_arrays(currentChunk->v,currentChunk->v0);
|
||||||
fluid_grid2_flip_arrays(currentChunk->w,currentChunk->w0);
|
fluid_grid2_flip_arrays(currentChunk->w,currentChunk->w0);
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// //time tracking
|
// //time tracking
|
||||||
@ -113,6 +133,7 @@ LIBRARY_API void fluid_grid2_simulate(
|
|||||||
// Chunk * currentChunk = chunks[i];
|
// Chunk * currentChunk = chunks[i];
|
||||||
// //update the bounds arrays
|
// //update the bounds arrays
|
||||||
// fluid_grid2_rewrite_bounds(currentChunk);
|
// fluid_grid2_rewrite_bounds(currentChunk);
|
||||||
|
|
||||||
// advect
|
// advect
|
||||||
fluid_grid2_advectVectors(environment,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,timestep);
|
fluid_grid2_advectVectors(environment,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,timestep);
|
||||||
|
|
||||||
@ -129,6 +150,7 @@ LIBRARY_API void fluid_grid2_simulate(
|
|||||||
// Chunk * currentChunk = chunks[i];
|
// Chunk * currentChunk = chunks[i];
|
||||||
// //update the bounds arrays
|
// //update the bounds arrays
|
||||||
// fluid_grid2_rewrite_bounds(currentChunk);
|
// fluid_grid2_rewrite_bounds(currentChunk);
|
||||||
|
|
||||||
//setup projection
|
//setup projection
|
||||||
fluid_grid2_setupProjection(environment,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,timestep);
|
fluid_grid2_setupProjection(environment,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,timestep);
|
||||||
//Perform main projection solver
|
//Perform main projection solver
|
||||||
@ -164,7 +186,7 @@ LIBRARY_API void fluid_grid2_simulate(
|
|||||||
Chunk * currentChunk = chunks[i];
|
Chunk * currentChunk = chunks[i];
|
||||||
//update the bounds arrays
|
//update the bounds arrays
|
||||||
fluid_grid2_rewrite_bounds(environment, currentChunk);
|
fluid_grid2_rewrite_bounds(environment, currentChunk);
|
||||||
|
//add density
|
||||||
fluid_grid2_addDensity(environment,currentChunk->d,currentChunk->d0,timestep);
|
fluid_grid2_addDensity(environment,currentChunk->d,currentChunk->d0,timestep);
|
||||||
environment->state.existingDensity = environment->state.existingDensity + fluid_grid2_calculateSum(currentChunk->d);
|
environment->state.existingDensity = environment->state.existingDensity + fluid_grid2_calculateSum(currentChunk->d);
|
||||||
//swap all density arrays
|
//swap all density arrays
|
||||||
@ -173,19 +195,23 @@ LIBRARY_API void fluid_grid2_simulate(
|
|||||||
fluid_grid2_solveDiffuseDensity(environment,currentChunk->d,currentChunk->d0,timestep);
|
fluid_grid2_solveDiffuseDensity(environment,currentChunk->d,currentChunk->d0,timestep);
|
||||||
//swap all density arrays
|
//swap all density arrays
|
||||||
fluid_grid2_flip_arrays(currentChunk->d,currentChunk->d0);
|
fluid_grid2_flip_arrays(currentChunk->d,currentChunk->d0);
|
||||||
}
|
|
||||||
|
|
||||||
//time tracking
|
|
||||||
gettimeofday(&tv,NULL);
|
|
||||||
end = 1000000.0 * tv.tv_sec + tv.tv_usec;
|
|
||||||
perMilli = (end - start) / 1000.0f;
|
|
||||||
environment->state.timeTracking.densityDiffuse = perMilli;
|
|
||||||
start = end;
|
|
||||||
|
|
||||||
for(int i = 0; i < numChunks; i++){
|
// }
|
||||||
Chunk * currentChunk = chunks[i];
|
|
||||||
//update the bounds arrays
|
// //time tracking
|
||||||
fluid_grid2_rewrite_bounds(environment, currentChunk);
|
// gettimeofday(&tv,NULL);
|
||||||
|
// end = 1000000.0 * tv.tv_sec + tv.tv_usec;
|
||||||
|
// perMilli = (end - start) / 1000.0f;
|
||||||
|
// environment->state.timeTracking.densityDiffuse = perMilli;
|
||||||
|
// start = end;
|
||||||
|
|
||||||
|
// for(int i = 0; i < numChunks; i++){
|
||||||
|
// Chunk * currentChunk = chunks[i];
|
||||||
|
// //update the bounds arrays
|
||||||
|
// fluid_grid2_rewrite_bounds(environment, currentChunk);
|
||||||
|
|
||||||
|
|
||||||
//advect density
|
//advect density
|
||||||
fluid_grid2_advectDensity(environment,currentChunk->d,currentChunk->d0,currentChunk->u,currentChunk->v,currentChunk->w,timestep);
|
fluid_grid2_advectDensity(environment,currentChunk->d,currentChunk->d0,currentChunk->u,currentChunk->v,currentChunk->w,timestep);
|
||||||
}
|
}
|
||||||
|
|||||||
107
src/test/c/fluid/sim/grid2/border_diffusion_tests.c
Normal file
107
src/test/c/fluid/sim/grid2/border_diffusion_tests.c
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
#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/env/environment.h"
|
||||||
|
#include "fluid/env/utilities.h"
|
||||||
|
#include "fluid/sim/grid2/density.h"
|
||||||
|
#include "fluid/sim/grid2/grid2.h"
|
||||||
|
#include "fluid/sim/grid2/solver_consts.h"
|
||||||
|
#include "fluid/sim/grid2/utilities.h"
|
||||||
|
#include "fluid/sim/grid2/velocity.h"
|
||||||
|
#include "math/ode/multigrid.h"
|
||||||
|
#include "../../../util/chunk_test_utils.h"
|
||||||
|
#include "../../../util/test.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Center of the advection cell
|
||||||
|
*/
|
||||||
|
#define FLUID_GRID2_PROJECTION_CELL_CENTER 24
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error margin for tests
|
||||||
|
*/
|
||||||
|
#define FLUID_GRID2_PROJECTION_ERROR_MARGIN 0.00001f
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing full sim routine
|
||||||
|
*/
|
||||||
|
int fluid_sim_grid2_border_diffusion_test1(){
|
||||||
|
printf("fluid_sim_grid2_border_diffusion_test1\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]->d0[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);
|
||||||
|
|
||||||
|
//test the result
|
||||||
|
float neighboreVal = queue[1]->d0[CENTER_LOC][IX(DIM-2,1,0)];
|
||||||
|
if(neighboreVal != MAX_FLUID_VALUE){
|
||||||
|
rVal += assertEqualsFloat(MAX_FLUID_VALUE,neighboreVal,"Simulation did not properly add density! expected: %f actual: %f \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing full sim routine
|
||||||
|
*/
|
||||||
|
int fluid_sim_grid2_border_diffusion_test2(){
|
||||||
|
printf("fluid_sim_grid2_border_diffusion_test2\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]->d0[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);
|
||||||
|
fluid_grid2_simulate(chunkCount,queue,env,FLUID_GRID2_SIM_STEP);
|
||||||
|
fluid_solve_bounds(chunkCount,queue,env);
|
||||||
|
|
||||||
|
//test the result
|
||||||
|
float newVal = queue[0]->d[CENTER_LOC][IX(DIM-2,1,DIM-2)];
|
||||||
|
float originDiff = MAX_FLUID_VALUE - newVal;
|
||||||
|
|
||||||
|
float neighboreVal = queue[1]->d[CENTER_LOC][IX(DIM-2,1,0)];
|
||||||
|
float neighborDiff = MAX_FLUID_VALUE - neighboreVal;
|
||||||
|
if(originDiff != neighborDiff){
|
||||||
|
printf("Failed to set bounds after simulation! \n");
|
||||||
|
printf("neighborVal: %f \n", neighboreVal);
|
||||||
|
printf("neighborDiff: %f \n", neighborDiff);
|
||||||
|
printf("newVal: %f \n", newVal);
|
||||||
|
printf("originDiff: %f \n", originDiff);
|
||||||
|
printf("\n");
|
||||||
|
rVal++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing full sim routines
|
||||||
|
*/
|
||||||
|
int fluid_sim_grid2_border_diffusion_tests(int argc, char **argv){
|
||||||
|
int rVal = 0;
|
||||||
|
|
||||||
|
rVal += fluid_sim_grid2_border_diffusion_test1();
|
||||||
|
rVal += fluid_sim_grid2_border_diffusion_test2();
|
||||||
|
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user