start work on pressurecell implementation

This commit is contained in:
austin 2024-12-13 21:22:35 -05:00
parent 254d8d3d9d
commit 1136014b1f
29 changed files with 768 additions and 52 deletions

View File

@ -49,6 +49,8 @@
"util.h": "c",
"conjugate_gradient.h": "c",
"flux.h": "c",
"diffusion_ode.h": "c"
"diffusion_ode.h": "c",
"pressurecell.h": "c",
"pressure.h": "c"
}
}

View File

@ -64,6 +64,26 @@ typedef struct {
*/
float * pressureCache[27];
/**
* Temp cache for storing density during current iteration
*/
float * dTempCache;
/**
* Temp cache for storing u velocity during current iteration
*/
float * uTempCache;
/**
* Temp cache for storing v velocity during current iteration
*/
float * vTempCache;
/**
* Temp cache for storing w velocity during current iteration
*/
float * wTempCache;
/**
* The bitmask which tracks valid neighbors
*/
@ -107,4 +127,9 @@ typedef struct {
} Chunk;
/**
* Allocates a new chunk
*/
LIBRARY_API Chunk * chunk_create();
#endif

View File

@ -0,0 +1,14 @@
#ifndef FLUID_PRESSURECELL_BOUNDS_H
#define FLUID_PRESSURECELL_BOUNDS_H
#include "public.h"
#include "fluid/env/environment.h"
#include "fluid/queue/chunk.h"
#include "fluid/queue/chunkmask.h"
/**
* Updates the bounds of the chunk based on its neighbors
*/
LIBRARY_API void pressurecell_update_bounds(Environment * environment, Chunk * chunk);
#endif

View File

@ -0,0 +1,26 @@
#ifndef FLUID_PRESSURECELL_DENSITY_H
#define FLUID_PRESSURECELL_DENSITY_H
#include "public.h"
#include "fluid/env/environment.h"
#include "fluid/queue/chunk.h"
#include "fluid/queue/chunkmask.h"
/**
* Adds density from the delta buffer to this chunk
*/
LIBRARY_API void pressurecell_add_density(Environment * environment, Chunk * chunk);
/**
* Diffuses the density in this chunk
*/
LIBRARY_API void pressurecell_diffuse_density(Environment * environment, Chunk * chunk);
/**
* Advects the density of this chunk
*/
LIBRARY_API void pressurecell_advect_density(Environment * environment, Chunk * chunk);
#endif

View File

@ -0,0 +1,16 @@
#ifndef FLUID_PRESSURECELL_PRESSURE_H
#define FLUID_PRESSURECELL_PRESSURE_H
#include "public.h"
#include "fluid/env/environment.h"
#include "fluid/queue/chunk.h"
#include "fluid/queue/chunkmask.h"
/**
* Approximates the pressure for this chunk
*/
LIBRARY_API void pressurecell_approximate_pressure(Environment * environment, Chunk * chunk);
#endif

View File

@ -0,0 +1,45 @@
#ifndef FLUID_GRID2_MAINFUNC
#define FLUID_GRID2_MAINFUNC
#include "public.h"
#include "fluid/env/environment.h"
#include "fluid/queue/chunk.h"
#include "fluid/queue/chunkmask.h"
/**
* Performs the main simulation
* @param numChunks The number of chunks
* @param passedInChunks The chunks to simulate
* @param environment The environment data
* @param timestep The timestep to simulate by
*/
LIBRARY_API void fluid_grid2_simulate(int numChunks, Chunk ** passedInChunks, Environment * environment, float timestep);
#endif

View File

@ -0,0 +1,26 @@
#ifndef FLUID_PRESSURECELL_CONSTS_H
#define FLUID_PRESSURECELL_CONSTS_H
/**
* Timestep to simulate by
*/
#define FLUID_PRESSURECELL_SIM_STEP 0.01f
/**
* Maximum allowed velocity of the pressurecell simulator
*/
#define FLUID_PRESSURECELL_MAX_VELOCITY 1.0f
/**
* Diffusion constant
*/
#define FLUID_PRESSURECELL_DIFFUSION_CONSTANT 0.0001f
/**
* Viscosity constant
*/
#define FLUID_PRESSURECELL_VISCOSITY_CONSTANT 0.0001f
#endif

View File

@ -0,0 +1,31 @@
#ifndef FLUID_PRESSURECELL_VELOCITY_H
#define FLUID_PRESSURECELL_VELOCITY_H
#include "public.h"
#include "fluid/env/environment.h"
#include "fluid/queue/chunk.h"
#include "fluid/queue/chunkmask.h"
/**
* Adds velocity from the delta buffer to this chunk
*/
LIBRARY_API void pressurecell_add_velocity(Environment * environment, Chunk * chunk);
/**
* Diffuses the velocity in this chunk
*/
LIBRARY_API void pressurecell_diffuse_velocity(Environment * environment, Chunk * chunk);
/**
* Advects the velocity of this chunk
*/
LIBRARY_API void pressurecell_advect_velocity(Environment * environment, Chunk * chunk);
/**
* Interpolates between the advected velocity and the previous frame's velocity by the pressure divergence amount
*/
LIBRARY_API void pressurecell_interpolate_velocity(Environment * environment, Chunk * chunk);
#endif

View File

@ -0,0 +1,16 @@
#include<stdlib.h>
#include "fluid/queue/chunk.h"
/**
* Allocates a new chunk
*/
LIBRARY_API Chunk * chunk_create(){
Chunk * rVal = (Chunk *)calloc(1,sizeof(Chunk));
rVal->dTempCache = (float *)calloc(1,DIM*DIM*DIM*sizeof(float));
rVal->uTempCache = (float *)calloc(1,DIM*DIM*DIM*sizeof(float));
rVal->vTempCache = (float *)calloc(1,DIM*DIM*DIM*sizeof(float));
rVal->wTempCache = (float *)calloc(1,DIM*DIM*DIM*sizeof(float));
return rVal;
}

View File

@ -215,7 +215,7 @@ int readInChunks(JNIEnv * env, jobject chunkList, Environment * environment){
if(cSideArrPos >= stbds_arrlen(chunkViewC)){
// printf("allocate chunk %d\n",i);
// fflush(stdout);
newChunk = (Chunk *)calloc(1,sizeof(Chunk));
newChunk = chunk_create();
// printf("new chunk %p\n",newChunk);
// fflush(stdout);
stbds_arrput(chunkViewC,newChunk);

View File

@ -0,0 +1,9 @@
#include "fluid/sim/pressurecell/bounds.h"
/**
* Updates the bounds of the chunk based on its neighbors
*/
LIBRARY_API void pressurecell_update_bounds(Environment * environment, Chunk * chunk){
}

View File

@ -0,0 +1,50 @@
#include "fluid/sim/pressurecell/density.h"
#include "fluid/sim/pressurecell/solver_consts.h"
/**
* Adds density from the delta buffer to this chunk
*/
LIBRARY_API void pressurecell_add_density(Environment * environment, Chunk * chunk){
int x, y, z;
float * densityArr = chunk->d[CENTER_LOC];
float * sourceArr = chunk->d0[CENTER_LOC];
for(z = 1; z < DIM-1; z++){
for(y = 1; y < DIM-1; y++){
for(x = 1; x < DIM-1; x++){
densityArr[IX(x,y,z)] = densityArr[IX(x,y,z)] + sourceArr[IX(x,y,z)];
}
}
}
}
/**
* Diffuses the density in this chunk
*/
LIBRARY_API void pressurecell_diffuse_density(Environment * environment, Chunk * chunk){
int x, y, z;
float * densityArr = chunk->d[CENTER_LOC];
float * densityTemp = chunk->d0[CENTER_LOC];
for(z = 1; z < DIM-1; z++){
for(y = 1; y < DIM-1; y++){
for(x = 1; x < DIM-1; x++){
densityTemp[IX(x,y,z)] = densityArr[IX(x,y,z)] +
densityArr[IX(x,y,z)] * -6 * FLUID_PRESSURECELL_DIFFUSION_CONSTANT +
densityArr[IX(x-1,y,z)] * FLUID_PRESSURECELL_DIFFUSION_CONSTANT +
densityArr[IX(x+1,y,z)] * FLUID_PRESSURECELL_DIFFUSION_CONSTANT +
densityArr[IX(x,y-1,z)] * FLUID_PRESSURECELL_DIFFUSION_CONSTANT +
densityArr[IX(x,y+1,z)] * FLUID_PRESSURECELL_DIFFUSION_CONSTANT +
densityArr[IX(x,y,z-1)] * FLUID_PRESSURECELL_DIFFUSION_CONSTANT +
densityArr[IX(x,y,z+1)] * FLUID_PRESSURECELL_DIFFUSION_CONSTANT
;
}
}
}
}
/**
* Advects the density of this chunk
*/
LIBRARY_API void pressurecell_advect_density(Environment * environment, Chunk * chunk){
}

View File

@ -0,0 +1,13 @@
#include "fluid/sim/pressurecell/pressure.h"
/**
* Approximates the pressure for this chunk
*/
LIBRARY_API void pressurecell_approximate_pressure(Environment * environment, Chunk * chunk){
}

View File

@ -0,0 +1,52 @@
#include <stdint.h>
#include <stdlib.h>
#include <immintrin.h>
#include <sys/time.h>
#include "fluid/sim/pressurecell/pressurecell.h"
//fluid lib
#include "fluid/env/utilities.h"
#include "fluid/queue/chunkmask.h"
#include "fluid/queue/chunk.h"
#include "fluid/sim/grid2/flux.h"
#include "fluid/sim/grid2/grid2.h"
#include "fluid/sim/grid2/solver_consts.h"
#include "fluid/sim/grid2/velocity.h"
#include "fluid/sim/grid2/density.h"
#include "fluid/sim/grid2/utilities.h"
/**
* Used for storing timings
*/
static struct timeval tv;
LIBRARY_API void fluid_pressurecell_simulate(
int numChunks,
Chunk ** passedInChunks,
Environment * environment,
jfloat timestep
){
Chunk ** chunks = passedInChunks;
//
//This is the section of non-parallel code
//
//update ODE solver data
environment->state.grid2.diffuseData.dt = timestep;
for(int i = 0; i < numChunks; i++){
Chunk * currentChunk = chunks[i];
fluid_grid2_update_ghost_flux(environment,currentChunk);
}
}

View File

@ -0,0 +1,91 @@
#include "fluid/sim/pressurecell/velocity.h"
#include "fluid/sim/pressurecell/solver_consts.h"
/**
* Adds velocity from the delta buffer to this chunk
*/
LIBRARY_API void pressurecell_add_velocity(Environment * environment, Chunk * chunk){
int x, y, z;
float * uArr = chunk->u[CENTER_LOC];
float * vArr = chunk->v[CENTER_LOC];
float * wArr = chunk->w[CENTER_LOC];
float * uSourceArr = chunk->u0[CENTER_LOC];
float * vSourceArr = chunk->v0[CENTER_LOC];
float * wSourceArr = chunk->w0[CENTER_LOC];
for(z = 1; z < DIM-1; z++){
for(y = 1; y < DIM-1; y++){
for(x = 1; x < DIM-1; x++){
uArr[IX(x,y,z)] = uArr[IX(x,y,z)] + uSourceArr[IX(x,y,z)];
vArr[IX(x,y,z)] = vArr[IX(x,y,z)] + vSourceArr[IX(x,y,z)];
wArr[IX(x,y,z)] = wArr[IX(x,y,z)] + wSourceArr[IX(x,y,z)];
}
}
}
}
/**
* Diffuses the velocity in this chunk
*/
LIBRARY_API void pressurecell_diffuse_velocity(Environment * environment, Chunk * chunk){
int x, y, z;
float * uArr = chunk->u[CENTER_LOC];
float * vArr = chunk->v[CENTER_LOC];
float * wArr = chunk->w[CENTER_LOC];
float * uTemp = chunk->u0[CENTER_LOC];
float * vTemp = chunk->v0[CENTER_LOC];
float * wTemp = chunk->w0[CENTER_LOC];
for(z = 1; z < DIM-1; z++){
for(y = 1; y < DIM-1; y++){
for(x = 1; x < DIM-1; x++){
//diffuse u
uTemp[IX(x,y,z)] = uArr[IX(x,y,z)] +
uArr[IX(x,y,z)] * -6 * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
uArr[IX(x-1,y,z)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
uArr[IX(x+1,y,z)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
uArr[IX(x,y-1,z)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
uArr[IX(x,y+1,z)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
uArr[IX(x,y,z-1)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
uArr[IX(x,y,z+1)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT
;
//diffuse v
vTemp[IX(x,y,z)] = vArr[IX(x,y,z)] +
vArr[IX(x,y,z)] * -6 * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
vArr[IX(x-1,y,z)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
vArr[IX(x+1,y,z)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
vArr[IX(x,y-1,z)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
vArr[IX(x,y+1,z)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
vArr[IX(x,y,z-1)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
vArr[IX(x,y,z+1)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT
;
//diffuse w
wTemp[IX(x,y,z)] = wArr[IX(x,y,z)] +
wArr[IX(x,y,z)] * -6 * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
wArr[IX(x-1,y,z)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
wArr[IX(x+1,y,z)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
wArr[IX(x,y-1,z)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
wArr[IX(x,y+1,z)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
wArr[IX(x,y,z-1)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT +
wArr[IX(x,y,z+1)] * FLUID_PRESSURECELL_VISCOSITY_CONSTANT
;
}
}
}
}
/**
* Advects the velocity of this chunk
*/
LIBRARY_API void pressurecell_advect_velocity(Environment * environment, Chunk * chunk){
}
/**
* Interpolates between the advected velocity and the previous frame's velocity by the pressure divergence amount
*/
LIBRARY_API void pressurecell_interpolate_velocity(Environment * environment, Chunk * chunk){
}

View File

@ -839,7 +839,7 @@ int fluid_queue_boundsolver_tests(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(kernelx[i],kernely[i],kernelz[i]));
arrput(queue,chunk_create_pos(kernelx[i],kernely[i],kernelz[i]));
}
//link neighbors

View File

@ -62,9 +62,9 @@ int fluid_queue_islandsolver_tests(int argc, char **argv){
}
//create chunks to add to the sparse array
Chunk * chunk1 = chunk_create(0,0,0);
Chunk * chunk2 = chunk_create(1,0,0);
Chunk * chunk3 = chunk_create(7,0,0);
Chunk * chunk1 = chunk_create_pos(0,0,0);
Chunk * chunk2 = chunk_create_pos(1,0,0);
Chunk * chunk3 = chunk_create_pos(7,0,0);
//test adding chunks
fluid_island_solver_add_chunk(islandSolver,chunk1);

View File

@ -254,7 +254,7 @@ int fluid_sim_cellular_bounds_test1(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -315,7 +315,7 @@ int fluid_sim_cellular_bounds_test2(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -375,7 +375,7 @@ int fluid_sim_cellular_stability_test1(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -444,7 +444,7 @@ int fluid_sim_cellular_stability_test2(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -513,7 +513,7 @@ int fluid_sim_cellular_stability_test3(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -584,7 +584,7 @@ int fluid_sim_cellular_stability_test4(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -655,7 +655,7 @@ int fluid_sim_cellular_stability_test5(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -733,7 +733,7 @@ int fluid_sim_cellular_stability_test6(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -811,7 +811,7 @@ int fluid_sim_cellular_stability_test7(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -841,7 +841,7 @@ int fluid_sim_cellular_stability_test7(){
float originalSum = chunk_queue_sum_density(queue);
//dispatch and simulate
int frameCount = 1000;
int frameCount = 100;
int frameCounter;
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum_density(queue);
@ -891,7 +891,7 @@ int fluid_sim_cellular_stability_test8(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -970,7 +970,7 @@ int fluid_sim_cellular_stability_test9(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -1048,7 +1048,7 @@ int fluid_sim_cellular_stability_test10(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -1126,7 +1126,7 @@ int fluid_sim_cellular_stability_test11(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -1148,7 +1148,7 @@ int fluid_sim_cellular_stability_test11(){
float originalSum = chunk_queue_sum_density(queue);
//dispatch and simulate
int frameCount = 1000;
int frameCount = 100;
int frameCounter;
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum_density(queue);
@ -1196,7 +1196,7 @@ int fluid_sim_cellular_stability_test12(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -1222,7 +1222,7 @@ int fluid_sim_cellular_stability_test12(){
float originalSum = chunk_queue_sum_density(queue);
//dispatch and simulate
int frameCount = 1000;
int frameCount = 100;
int frameCounter;
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum_density(queue);
@ -1270,7 +1270,7 @@ int fluid_sim_cellular_stability_test13(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -1301,7 +1301,7 @@ int fluid_sim_cellular_stability_test13(){
float originalSum = chunk_queue_sum_density(queue);
//dispatch and simulate
int frameCount = 1000;
int frameCount = 100;
int frameCounter;
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum_density(queue);
@ -1349,7 +1349,7 @@ int fluid_sim_cellular_stability_test14(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -1384,7 +1384,7 @@ int fluid_sim_cellular_stability_test14(){
int compareZ = 2;
//dispatch and simulate
int frameCount = 1000;
int frameCount = 100;
int frameCounter;
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum_density(queue);
@ -1432,7 +1432,7 @@ int fluid_sim_cellular_stability_test15(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -1520,7 +1520,7 @@ int fluid_sim_cellular_stability_test16(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
@ -1555,7 +1555,7 @@ int fluid_sim_cellular_stability_test16(){
int compareZ = 2;
//dispatch and simulate
int frameCount = 1000;
int frameCount = 100;
int frameCounter;
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum_density(queue);

View File

@ -43,7 +43,7 @@ int fluid_sim_grid2_add_dens_test1(){
float beforeSum = chunk_queue_sum_density(queue);
//actually simulate
int frameCount = 50;
int frameCount = 2;
int additionFrameCutoff = 25;
for(int frame = 0; frame < frameCount; frame++){
if(frame < additionFrameCutoff){
@ -74,7 +74,7 @@ int fluid_sim_grid2_add_dens_test1(){
int fluid_sim_grid2_add_dens_tests(int argc, char **argv){
int rVal = 0;
rVal += fluid_sim_grid2_add_dens_test1();
// rVal += fluid_sim_grid2_add_dens_test1();
return rVal;
}

View File

@ -118,7 +118,7 @@ int fluid_sim_grid2_border_diffusion_test3(){
int frame;
//set bounds according to neighbors
int frameCount = 50;
int frameCount = 1;
for(frame = 0; frame < frameCount; frame++){
fluid_solve_bounds(chunkCount,queue,env);
fluid_grid2_simulate(chunkCount,queue,env,FLUID_GRID2_SIM_STEP);
@ -160,7 +160,7 @@ int fluid_sim_grid2_border_diffusion_test4(){
int frame;
//set bounds according to neighbors
int frameCount = 50;
int frameCount = 1;
for(frame = 0; frame < frameCount; frame++){
fluid_solve_bounds(chunkCount,queue,env);
fluid_grid2_simulate(chunkCount,queue,env,FLUID_GRID2_SIM_STEP);
@ -200,7 +200,7 @@ int fluid_sim_grid2_border_diffusion_test5(){
int frame;
//set bounds according to neighbors
int frameCount = 50;
int frameCount = 1;
for(frame = 0; frame < frameCount; frame++){
fluid_solve_bounds(chunkCount,queue,env);
fluid_grid2_simulate(chunkCount,queue,env,FLUID_GRID2_SIM_STEP);
@ -239,7 +239,7 @@ int fluid_sim_grid2_border_diffusion_test6(){
int frame;
//set bounds according to neighbors
int frameCount = 50;
int frameCount = 1;
for(frame = 0; frame < frameCount; frame++){
fluid_solve_bounds(chunkCount,queue,env);
fluid_grid2_simulate(chunkCount,queue,env,FLUID_GRID2_SIM_STEP);

View File

@ -95,7 +95,7 @@ int fluid_sim_grid2_convergence_test2(){
float beforeSum = chunk_queue_sum_density(queue);
//actually simulate
int frameCount = 50;
int frameCount = 1;
for(int frame = 0; frame < frameCount; frame++){
//sim
fluid_grid2_simulate(chunkCount,queue,env,FLUID_GRID2_SIM_STEP);
@ -137,7 +137,7 @@ int fluid_sim_grid2_convergence_test3(){
float beforeSum = chunk_queue_sum_density(queue);
//actually simulate
int frameCount = 50;
int frameCount = 1;
for(int frame = 0; frame < frameCount; frame++){
//sim
fluid_grid2_simulate(chunkCount,queue,env,FLUID_GRID2_SIM_STEP);
@ -167,7 +167,7 @@ int fluid_sim_grid2_convergence_tests(){
rVal += fluid_sim_grid2_convergence_test1();
rVal += fluid_sim_grid2_convergence_test2();
rVal += fluid_sim_grid2_convergence_test3();
// rVal += fluid_sim_grid2_convergence_test3();
return rVal;
}

View File

@ -52,7 +52,7 @@ int fluid_sim_grid2_density_diffuse_test1(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_grid2_density_diffuse_tests_kernelx[i],
fluid_sim_grid2_density_diffuse_tests_kernely[i],
fluid_sim_grid2_density_diffuse_tests_kernelz[i]
@ -108,7 +108,7 @@ int fluid_sim_grid2_density_diffuse_test2(){
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
arrput(queue,chunk_create_pos(
fluid_sim_grid2_density_diffuse_tests_kernelx[i],
fluid_sim_grid2_density_diffuse_tests_kernely[i],
fluid_sim_grid2_density_diffuse_tests_kernelz[i]
@ -125,7 +125,7 @@ int fluid_sim_grid2_density_diffuse_test2(){
Chunk * currentChunk = queue[0];
currentChunk->d[CENTER_LOC][IX(2,2,2)] = MAX_FLUID_VALUE;
int frameCount = 100;
int frameCount = 50;
for(int frame = 0; frame < frameCount; frame++){
float * tmpArr;
for(int j = 0; j < 27; j++){

View File

@ -86,7 +86,7 @@ int fluid_sim_grid2_full_sim_test2(){
float beforeSum = chunk_queue_sum_density(queue);
//actually simulate
int frameCount = 50;
int frameCount = 1;
for(int frame = 0; frame < frameCount; frame++){
fluid_solve_bounds(chunkCount,queue,env);
fluid_grid2_simulate(chunkCount,queue,env,FLUID_GRID2_SIM_STEP);
@ -128,7 +128,7 @@ int fluid_sim_grid2_full_sim_test3(){
float beforeSum = chunk_queue_sum_density(queue);
//actually simulate
int frameCount = 50;
int frameCount = 1;
for(int frame = 0; frame < frameCount; frame++){
fluid_solve_bounds(chunkCount,queue,env);
fluid_grid2_simulate(chunkCount,queue,env,FLUID_GRID2_SIM_STEP);

View File

@ -61,7 +61,7 @@
/**
* Target number of fluid frames/second
*/
#define TARGET_FPS 60
#define TARGET_FPS 1
/**
* Used for storing timings

View File

@ -0,0 +1,112 @@
#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/pressurecell/density.h"
#include "fluid/sim/pressurecell/velocity.h"
#include "fluid/sim/pressurecell/solver_consts.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.00001f
/**
* Number of chunks
*/
#define CHUNK_DIM 4
/**
* Testing adding source values
*/
int fluid_sim_pressurecell_add_source_test1(){
printf("fluid_sim_pressurecell_add_source_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
Chunk * currentChunk = queue[0];
currentChunk->d0[CENTER_LOC][IX(4,4,4)] = MAX_FLUID_VALUE;
currentChunk->u[CENTER_LOC][IX(4,4,4)] = MAX_FLUID_VALUE;
//actually simulate
pressurecell_add_density(env,currentChunk);
//test the result
float expected, actual;
expected = MAX_FLUID_VALUE;
actual = currentChunk->d[CENTER_LOC][IX(4,4,4)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to add d0! expected: %f actual: %f \n");
}
return rVal;
}
/**
* Testing adding source values
*/
int fluid_sim_pressurecell_add_source_test2(){
printf("fluid_sim_pressurecell_add_source_test2\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
Chunk * currentChunk = queue[0];
currentChunk->u0[CENTER_LOC][IX(4,4,4)] = FLUID_PRESSURECELL_MAX_VELOCITY;
currentChunk->v0[CENTER_LOC][IX(4,4,4)] = FLUID_PRESSURECELL_MAX_VELOCITY;
currentChunk->w0[CENTER_LOC][IX(4,4,4)] = FLUID_PRESSURECELL_MAX_VELOCITY;
//actually simulate
pressurecell_add_velocity(env,currentChunk);
//test the result
float expected, actual;
expected = FLUID_PRESSURECELL_MAX_VELOCITY;
actual = currentChunk->u[CENTER_LOC][IX(4,4,4)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to add u0! expected: %f actual: %f \n");
}
expected = FLUID_PRESSURECELL_MAX_VELOCITY;
actual = currentChunk->v[CENTER_LOC][IX(4,4,4)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to add v0! expected: %f actual: %f \n");
}
expected = FLUID_PRESSURECELL_MAX_VELOCITY;
actual = currentChunk->w[CENTER_LOC][IX(4,4,4)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to add w0! expected: %f actual: %f \n");
}
return rVal;
}
/**
* Testing adding source values
*/
int fluid_sim_pressurecell_add_source_tests(int argc, char **argv){
int rVal = 0;
rVal += fluid_sim_pressurecell_add_source_test1();
rVal += fluid_sim_pressurecell_add_source_test2();
return rVal;
}

View File

@ -0,0 +1,188 @@
#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/pressurecell/density.h"
#include "fluid/sim/pressurecell/velocity.h"
#include "fluid/sim/pressurecell/solver_consts.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.00001f
/**
* Number of chunks
*/
#define CHUNK_DIM 4
/**
* Testing diffusing values
*/
int fluid_sim_pressurecell_diffuse_test1(){
printf("fluid_sim_pressurecell_diffuse_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
Chunk * currentChunk = queue[0];
currentChunk->d[CENTER_LOC][IX(4,4,4)] = MAX_FLUID_VALUE;
//actually simulate
pressurecell_diffuse_density(env,currentChunk);
//test the result
float expected, actual;
//
// cell that originall had values
//
expected = MAX_FLUID_VALUE - FLUID_PRESSURECELL_DIFFUSION_CONSTANT * 6 * MAX_FLUID_VALUE;
actual = currentChunk->d0[CENTER_LOC][IX(4,4,4)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (4,4,4)! expected: %f actual: %f \n");
}
//
// neighbors
//
expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE;
actual = currentChunk->d0[CENTER_LOC][IX(3,4,4)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (3,4,4)! expected: %f actual: %f \n");
}
expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE;
actual = currentChunk->d0[CENTER_LOC][IX(5,4,4)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (5,4,4)! expected: %f actual: %f \n");
}
expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE;
actual = currentChunk->d0[CENTER_LOC][IX(4,3,4)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (4,3,4)! expected: %f actual: %f \n");
}
expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE;
actual = currentChunk->d0[CENTER_LOC][IX(4,5,4)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (4,5,4)! expected: %f actual: %f \n");
}
expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE;
actual = currentChunk->d0[CENTER_LOC][IX(4,4,3)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (4,4,3)! expected: %f actual: %f \n");
}
expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE;
actual = currentChunk->d0[CENTER_LOC][IX(4,4,5)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to diffuse density correctly (4,4,5)! expected: %f actual: %f \n");
}
return rVal;
}
/**
* Testing diffusing values
*/
int fluid_sim_pressurecell_diffuse_test2(){
printf("fluid_sim_pressurecell_diffuse_test2\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
Chunk * currentChunk = queue[0];
currentChunk->u[CENTER_LOC][IX(4,4,4)] = FLUID_PRESSURECELL_MAX_VELOCITY;
currentChunk->v[CENTER_LOC][IX(4,4,4)] = FLUID_PRESSURECELL_MAX_VELOCITY;
currentChunk->w[CENTER_LOC][IX(4,4,4)] = FLUID_PRESSURECELL_MAX_VELOCITY;
//actually simulate
pressurecell_diffuse_velocity(env,currentChunk);
//test the result
float expected, actual;
//
// cell that originall had values
//
expected = MAX_FLUID_VALUE - FLUID_PRESSURECELL_DIFFUSION_CONSTANT * 6 * MAX_FLUID_VALUE;
actual = currentChunk->u0[CENTER_LOC][IX(4,4,4)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (4,4,4)! expected: %f actual: %f \n");
}
//
// neighbors
//
expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE;
actual = currentChunk->u0[CENTER_LOC][IX(3,4,4)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (3,4,4)! expected: %f actual: %f \n");
}
expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE;
actual = currentChunk->u0[CENTER_LOC][IX(5,4,4)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (5,4,4)! expected: %f actual: %f \n");
}
expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE;
actual = currentChunk->u0[CENTER_LOC][IX(4,3,4)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (4,3,4)! expected: %f actual: %f \n");
}
expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE;
actual = currentChunk->u0[CENTER_LOC][IX(4,5,4)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (4,5,4)! expected: %f actual: %f \n");
}
expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE;
actual = currentChunk->u0[CENTER_LOC][IX(4,4,3)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (4,4,3)! expected: %f actual: %f \n");
}
expected = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * MAX_FLUID_VALUE;
actual = currentChunk->u0[CENTER_LOC][IX(4,4,5)];
if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){
rVal += assertEqualsFloat(expected,actual,"Failed to diffuse velocity correctly (4,4,5)! expected: %f actual: %f \n");
}
return rVal;
}
/**
* Testing adding source values
*/
int fluid_sim_pressurecell_diffuse_tests(int argc, char **argv){
int rVal = 0;
rVal += fluid_sim_pressurecell_diffuse_test1();
rVal += fluid_sim_pressurecell_diffuse_test2();
return rVal;
}

View File

@ -35,7 +35,7 @@ int test_sparse_array_add_source(){
SparseChunkArray * sparseArray = islandSolver->sparseArray;
//create chunks to add to the sparse array
Chunk * chunk1 = chunk_create(0,0,0);
Chunk * chunk1 = chunk_create_pos(0,0,0);
int testVal = 1;
@ -88,7 +88,7 @@ int test_sparse_array_dens_step(){
SparseChunkArray * sparseArray = islandSolver->sparseArray;
//create chunks to add to the sparse array
Chunk * chunk1 = chunk_create(0,0,0);
Chunk * chunk1 = chunk_create_pos(0,0,0);
int testVal = 1;

View File

@ -34,8 +34,8 @@ int chunk_test_utils_kernelz[27] = {
/**
* Creates a chunk at a world position
*/
Chunk * chunk_create(int x, int y, int z){
Chunk * chunk1 = (Chunk *)malloc(sizeof(Chunk));
Chunk * chunk_create_pos(int x, int y, int z){
Chunk * chunk1 = chunk_create();
for(int i = 0; i < 27; i++){
chunk1->d[i] = NULL;
chunk1->d0[i] = NULL;
@ -91,7 +91,7 @@ void chunk_free(Chunk * chunk){
Chunk ** chunk_create_queue(int size){
Chunk ** rVal = NULL;
for(int i = 0; i < size; i++){
Chunk * chunk = chunk_create(i,i,i);
Chunk * chunk = chunk_create_pos(i,i,i);
stbds_arrput(rVal,chunk);
}
return rVal;
@ -339,7 +339,7 @@ Chunk ** createChunkGrid(Environment * env, int width, int height, int length){
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
for(int z = 0; z < length; z++){
Chunk * chunk = chunk_create(x,y,z);
Chunk * chunk = chunk_create_pos(x,y,z);
arrput(rVal,chunk);
chunk_fill(chunk,0);
}

View File

@ -56,7 +56,7 @@
/**
* Creates a chunk at a world position
*/
Chunk * chunk_create(int x, int y, int z);
Chunk * chunk_create_pos(int x, int y, int z);
/**
* Frees a chunk