first density diffusion test
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-12-09 18:20:27 -05:00
parent 1b36112e24
commit a142aa6f55
7 changed files with 123 additions and 12 deletions

View File

@ -32,7 +32,7 @@ void fluid_grid2_addDensity(
/*
* A single iteration of the jacobi to solve density diffusion
*/
void fluid_grid2_solveDiffuseDensity(
LIBRARY_API void fluid_grid2_solveDiffuseDensity(
int chunk_mask,
float ** d,
float ** d0,

View File

@ -1,8 +1,40 @@
#ifndef FLUID_GRID2_SOLVER_CONSTS_H
#define FLUID_GRID2_SOLVER_CONSTS_H
/**
* The number of times to relax most solvers
*/
#define FLUID_GRID2_LINEARSOLVERTIMES 20
/**
* The number of times to relax the vector diffusion solver
*/
#define FLUID_GRID2_VECTOR_DIFFUSE_TIMES 20
/**
* Width of a single grid cell
*/
#define FLUID_GRID2_H (1)
/**
* Timestep to simulate by
*/
#define FLUID_GRID2_SIM_STEP 0.01f
/**
* Really small value used for something
*/
#define FLUID_GRID2_REALLY_SMALL_VALUE 0.00001
/**
* Diffusion constant
*/
#define FLUID_GRID2_DIFFUSION_CONSTANT 0.00001
/**
* Viscosity constant
*/
#define FLUID_GRID2_VISCOSITY_CONSTANT 0.00001
#endif

View File

@ -16,7 +16,7 @@ void fluid_grid2_add_source(float * x, float * s, float dt);
/**
* Sets the bounds of this cube to those of its neighbor
*/
void fluid_grid2_setBoundsToNeighborsRaw(
LIBRARY_API void fluid_grid2_setBoundsToNeighborsRaw(
int chunk_mask,
int vector_dir,
float ** neighborArray

View File

@ -41,7 +41,7 @@ void fluid_grid2_addDensity(
/*
* A single iteration of the jacobi to solve density diffusion
*/
void fluid_grid2_solveDiffuseDensity(
LIBRARY_API void fluid_grid2_solveDiffuseDensity(
int chunk_mask,
float ** d,
float ** d0,

View File

@ -19,12 +19,6 @@
#define SAVE_STEPS 0
#endif
#define FLUID_GRID2_REALLY_SMALL_VALUE 0.00001
#define FLUID_GRID2_DIFFUSION_CONSTANT 0.00001
#define FLUID_GRID2_VISCOSITY_CONSTANT 0.00001
static inline void fluid_grid2_saveStep(float * values, const char * name);
static inline void fluid_grid2_applyGravity(Chunk * currentChunk, Environment * environment);
static inline void fluid_grid2_clearArr(float ** d);

View File

@ -652,7 +652,7 @@ void fluid_grid2_advect_velocity(uint32_t chunk_mask, int b, float ** jrd, float
/**
* Sets the bounds of this cube to those of its neighbor
*/
void fluid_grid2_setBoundsToNeighborsRaw(
LIBRARY_API void fluid_grid2_setBoundsToNeighborsRaw(
int chunk_mask,
int vector_dir,
float ** neighborArray

View File

@ -1,4 +1,36 @@
#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/solver_consts.h"
#include "fluid/sim/grid2/utilities.h"
#include "../../../util/chunk_test_utils.h"
#include "../../../util/test.h"
int fluid_sim_grid2_density_diffuse_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_grid2_density_diffuse_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_grid2_density_diffuse_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,
};
@ -7,17 +39,70 @@
/**
* Testing density diffusion
*/
int fluid_sim_grid2_density_diffuse_test1(){
int rVal = 0;
printf("fluid_sim_grid2_density_diffuse_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_grid2_density_diffuse_tests_kernelx[i],
fluid_sim_grid2_density_diffuse_tests_kernely[i],
fluid_sim_grid2_density_diffuse_tests_kernelz[i]
));
chunk_fill(queue[i],0);
}
//link neighbors
chunk_link_neighbors(queue);
fluid_solve_bounds(1,queue,env);
Chunk * currentChunk = queue[0];
currentChunk->d[CENTER_LOC][IX(2,2,2)] = MAX_FLUID_VALUE;
float * tmpArr;
for(int j = 0; j < 27; j++){
tmpArr = currentChunk->d[j];
currentChunk->d[j] = currentChunk->d0[j];
currentChunk->d0[j] = tmpArr;
}
//diffuse density
for(int l = 0; l < FLUID_GRID2_LINEARSOLVERTIMES; l++){
fluid_grid2_solveDiffuseDensity(currentChunk->chunkMask,currentChunk->d,currentChunk->d0,currentChunk->u,currentChunk->v,currentChunk->w,FLUID_GRID2_DIFFUSION_CONSTANT,FLUID_GRID2_VISCOSITY_CONSTANT,FLUID_GRID2_SIM_STEP);
fluid_grid2_setBoundsToNeighborsRaw(currentChunk->chunkMask,0,currentChunk->d);
}
//swap all density arrays
//swap vector fields
for(int j = 0; j < 27; j++){
tmpArr = currentChunk->d[j];
currentChunk->d[j] = currentChunk->d0[j];
currentChunk->d0[j] = tmpArr;
}
//sum the result
float afterSum = chunk_queue_sum(queue);
rVal += assertEqualsFloat(afterSum,MAX_FLUID_VALUE,"Density diffuse step changed density sum! %f %f \n");
return rVal;
}
/**
* Testing density diffusion
*/
int fluid_sim_grid2_density_diffuse_tests(int argc, char **argv){
int rVal = 0;
rVal += fluid_sim_grid2_density_diffuse_test1();
return rVal;
}