cleaning up grid2 interfaces
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
a142aa6f55
commit
2a2eeca701
@ -20,7 +20,6 @@ void fluid_grid2_advect(uint32_t chunk_mask, int b, float ** jrd, float ** jrd0,
|
||||
*/
|
||||
void fluid_grid2_addDensity(
|
||||
Environment * environment,
|
||||
int chunk_mask,
|
||||
float ** d,
|
||||
float ** d0,
|
||||
float dt
|
||||
@ -33,14 +32,9 @@ void fluid_grid2_addDensity(
|
||||
* A single iteration of the jacobi to solve density diffusion
|
||||
*/
|
||||
LIBRARY_API void fluid_grid2_solveDiffuseDensity(
|
||||
int chunk_mask,
|
||||
float ** d,
|
||||
float ** d0,
|
||||
float ** jru,
|
||||
float ** jrv,
|
||||
float ** jrw,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
);
|
||||
|
||||
@ -51,7 +45,7 @@ LIBRARY_API void fluid_grid2_solveDiffuseDensity(
|
||||
/**
|
||||
* Advects the density based on the vectors
|
||||
*/
|
||||
void fluid_grid2_advectDensity(uint32_t chunk_mask, float ** d, float ** d0, float ** ur, float ** vr, float ** wr, float dt);
|
||||
void fluid_grid2_advectDensity(float ** d, float ** d0, float ** ur, float ** vr, float ** wr, float dt);
|
||||
|
||||
|
||||
|
||||
|
||||
@ -23,17 +23,6 @@ LIBRARY_API void fluid_grid2_setBoundsToNeighborsRaw(
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* This exclusively copies neighbors to make sure zeroing out stuff doesn't break sim
|
||||
*/
|
||||
void fluid_grid2_copyNeighborsRaw(
|
||||
int chunk_mask,
|
||||
int cx,
|
||||
int vector_dir,
|
||||
float ** neighborArray
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -45,7 +34,7 @@ void fluid_grid2_copyNeighborsRaw(
|
||||
/**
|
||||
* Sums the density of the chunk
|
||||
*/
|
||||
double fluid_grid2_calculateSum(uint32_t chunk_mask, float ** d);
|
||||
double fluid_grid2_calculateSum(float ** d);
|
||||
|
||||
|
||||
|
||||
|
||||
@ -7,28 +7,39 @@
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Used for signaling the bounds setting method to not use adjacent cells when evaluating borders
|
||||
*/
|
||||
#define FLUID_GRID2_BOUND_NO_DIR 0
|
||||
|
||||
/**
|
||||
* Used for signaling the bounds setting method to use adjacent cells when evaluating x axis borders
|
||||
*/
|
||||
#define FLUID_GRID2_BOUND_DIR_U 1
|
||||
|
||||
/**
|
||||
* Used for signaling the bounds setting method to use adjacent cells when evaluating y axis borders
|
||||
*/
|
||||
#define FLUID_GRID2_BOUND_DIR_V 2
|
||||
|
||||
/**
|
||||
* Used for signaling the bounds setting method to use adjacent cells when evaluating z axis borders
|
||||
*/
|
||||
#define FLUID_GRID2_BOUND_DIR_W 3
|
||||
|
||||
|
||||
/**
|
||||
* Adds the sources to the destinations
|
||||
*/
|
||||
void fluid_grid2_addSourceToVectors
|
||||
(
|
||||
int chunk_mask,
|
||||
void fluid_grid2_addSourceToVectors(
|
||||
float ** jru,
|
||||
float ** jrv,
|
||||
float ** jrw,
|
||||
float ** jru0,
|
||||
float ** jrv0,
|
||||
float ** jrw0,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt);
|
||||
float dt
|
||||
);
|
||||
|
||||
|
||||
|
||||
@ -42,19 +53,14 @@ void fluid_grid2_addSourceToVectors
|
||||
* @param wr The z velocity grid
|
||||
* @param pr The grid that will contain the first derivative
|
||||
* @param divr The grid that will be zeroed out in preparation of the solver
|
||||
* @param DIFFUSION_CONST The diffusion constant
|
||||
* @param VISCOSITY_CONST The viscosity constant
|
||||
* @param dt The timestep for the simulation
|
||||
*/
|
||||
void fluid_grid2_setupProjection(
|
||||
int chunk_mask,
|
||||
float ** ur,
|
||||
float ** vr,
|
||||
float ** wr,
|
||||
float ** pr,
|
||||
float ** divr,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
);
|
||||
|
||||
@ -67,15 +73,8 @@ void fluid_grid2_setupProjection(
|
||||
* @param jrv0 The first derivative field
|
||||
*/
|
||||
void fluid_grid2_solveProjection(
|
||||
int chunk_mask,
|
||||
float ** jru,
|
||||
float ** jrv,
|
||||
float ** jrw,
|
||||
float ** jru0,
|
||||
float ** jrv0,
|
||||
float ** jrw0,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
);
|
||||
|
||||
@ -86,15 +85,11 @@ void fluid_grid2_solveProjection(
|
||||
* Thus we are left with an approximately mass-conserved field.
|
||||
*/
|
||||
void fluid_grid2_finalizeProjection(
|
||||
int chunk_mask,
|
||||
float ** jru,
|
||||
float ** jrv,
|
||||
float ** jrw,
|
||||
float ** jru0,
|
||||
float ** jrv0,
|
||||
float ** jrw0,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
);
|
||||
|
||||
@ -104,37 +99,31 @@ void fluid_grid2_finalizeProjection(
|
||||
* Advects u, v, and w
|
||||
*/
|
||||
void fluid_grid2_advectVectors(
|
||||
int chunk_mask,
|
||||
float ** jru,
|
||||
float ** jrv,
|
||||
float ** jrw,
|
||||
float ** jru0,
|
||||
float ** jrv0,
|
||||
float ** jrw0,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
);
|
||||
|
||||
/**
|
||||
* Actually performs the advection
|
||||
*/
|
||||
void fluid_grid2_advect_velocity(uint32_t chunk_mask, int b, float ** jrd, float ** jrd0, float * u, float * v, float * w, float dt);
|
||||
void fluid_grid2_advect_velocity(int b, float ** jrd, float ** jrd0, float * u, float * v, float * w, float dt);
|
||||
|
||||
|
||||
/*
|
||||
* Solves vector diffusion along all axis
|
||||
*/
|
||||
void fluid_grid2_solveVectorDiffuse (
|
||||
int chunk_mask,
|
||||
float ** jru,
|
||||
float ** jrv,
|
||||
float ** jrw,
|
||||
float ** jru0,
|
||||
float ** jrv0,
|
||||
float ** jrw0,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
);
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <immintrin.h>
|
||||
#include <stdint.h>
|
||||
#include <jni.h>
|
||||
|
||||
#include "fluid/env/utilities.h"
|
||||
#include "fluid/queue/chunkmask.h"
|
||||
@ -17,7 +16,6 @@
|
||||
*/
|
||||
void fluid_grid2_addDensity(
|
||||
Environment * environment,
|
||||
int chunk_mask,
|
||||
float ** d,
|
||||
float ** d0,
|
||||
float dt
|
||||
@ -42,14 +40,9 @@ void fluid_grid2_addDensity(
|
||||
* A single iteration of the jacobi to solve density diffusion
|
||||
*/
|
||||
LIBRARY_API void fluid_grid2_solveDiffuseDensity(
|
||||
int chunk_mask,
|
||||
float ** d,
|
||||
float ** d0,
|
||||
float ** jru,
|
||||
float ** jrv,
|
||||
float ** jrw,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
){
|
||||
float h = FLUID_GRID2_H;
|
||||
@ -92,7 +85,7 @@ LIBRARY_API void fluid_grid2_solveDiffuseDensity(
|
||||
/**
|
||||
* Advects the density based on the vectors
|
||||
*/
|
||||
void fluid_grid2_advectDensity(uint32_t chunk_mask, float ** d, float ** d0, float ** ur, float ** vr, float ** wr, float dt){
|
||||
void fluid_grid2_advectDensity(float ** d, float ** d0, float ** ur, float ** vr, float ** wr, float dt){
|
||||
int i, j, k, i0, j0, k0, i1, j1, k1;
|
||||
int m,n,o;
|
||||
float x, y, z, s0, t0, s1, t1, u1, u0, dtx,dty,dtz;
|
||||
@ -242,21 +235,6 @@ void fluid_grid2_advectDensity(uint32_t chunk_mask, float ** d, float ** d0, flo
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sums the density of the chunk
|
||||
*/
|
||||
double fluid_grid2_calculateSum(uint32_t chunk_mask, float ** d){
|
||||
int j;
|
||||
int size=DIM*DIM*DIM;
|
||||
float * x = GET_ARR_RAW(d,CENTER_LOC);
|
||||
double rVal = 0;
|
||||
for(j=0; j<size; j++){
|
||||
rVal = rVal + x[j];
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes the density array with a given ratio
|
||||
*/
|
||||
|
||||
@ -63,15 +63,12 @@ void fluid_grid2_simulate(
|
||||
//add velocity
|
||||
fluid_grid2_applyGravity(currentChunk,environment);
|
||||
fluid_grid2_addSourceToVectors(
|
||||
currentChunk->chunkMask,
|
||||
currentChunk->u,
|
||||
currentChunk->v,
|
||||
currentChunk->w,
|
||||
currentChunk->u0,
|
||||
currentChunk->v0,
|
||||
currentChunk->w0,
|
||||
FLUID_GRID2_DIFFUSION_CONSTANT,
|
||||
FLUID_GRID2_VISCOSITY_CONSTANT,
|
||||
timestep
|
||||
);
|
||||
//swap all vector fields
|
||||
@ -96,14 +93,14 @@ void fluid_grid2_simulate(
|
||||
//solve vector diffusion
|
||||
for(int l = 0; l < FLUID_GRID2_VECTOR_DIFFUSE_TIMES; l++){
|
||||
//solve vector diffusion
|
||||
fluid_grid2_solveVectorDiffuse(currentChunk->chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,FLUID_GRID2_DIFFUSION_CONSTANT,FLUID_GRID2_VISCOSITY_CONSTANT,timestep);
|
||||
fluid_grid2_solveVectorDiffuse(currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,timestep);
|
||||
//update array for vectors
|
||||
fluid_grid2_setBoundsToNeighborsRaw(currentChunk->chunkMask,FLUID_GRID2_BOUND_DIR_U,currentChunk->u);
|
||||
fluid_grid2_setBoundsToNeighborsRaw(currentChunk->chunkMask,FLUID_GRID2_BOUND_DIR_V,currentChunk->v);
|
||||
fluid_grid2_setBoundsToNeighborsRaw(currentChunk->chunkMask,FLUID_GRID2_BOUND_DIR_W,currentChunk->w);
|
||||
}
|
||||
//setup projection
|
||||
fluid_grid2_setupProjection(currentChunk->chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,FLUID_GRID2_DIFFUSION_CONSTANT,FLUID_GRID2_VISCOSITY_CONSTANT,timestep);
|
||||
fluid_grid2_setupProjection(currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,timestep);
|
||||
|
||||
//update array for vectors
|
||||
fluid_grid2_setBoundsToNeighborsRaw(currentChunk->chunkMask,FLUID_GRID2_BOUND_NO_DIR,currentChunk->u0);
|
||||
@ -115,13 +112,13 @@ void fluid_grid2_simulate(
|
||||
//
|
||||
//Perform main projection solver
|
||||
for(int l = 0; l < FLUID_GRID2_LINEARSOLVERTIMES; l++){
|
||||
fluid_grid2_solveProjection(currentChunk->chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,FLUID_GRID2_DIFFUSION_CONSTANT,FLUID_GRID2_VISCOSITY_CONSTANT,timestep);
|
||||
fluid_grid2_solveProjection(currentChunk->u0,currentChunk->v0,timestep);
|
||||
fluid_grid2_setBoundsToNeighborsRaw(currentChunk->chunkMask,FLUID_GRID2_BOUND_NO_DIR,currentChunk->u0);
|
||||
}
|
||||
//samples u,v,w,u0
|
||||
//sets u,v,w
|
||||
//Finalize projection
|
||||
fluid_grid2_finalizeProjection(currentChunk->chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,FLUID_GRID2_DIFFUSION_CONSTANT,FLUID_GRID2_VISCOSITY_CONSTANT,timestep);
|
||||
fluid_grid2_finalizeProjection(currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,timestep);
|
||||
|
||||
//set boundaries a final time for u,v,w
|
||||
//...
|
||||
@ -149,13 +146,13 @@ void fluid_grid2_simulate(
|
||||
}
|
||||
//advect vectors across boundaries
|
||||
//advect
|
||||
fluid_grid2_advectVectors(currentChunk->chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,FLUID_GRID2_DIFFUSION_CONSTANT,FLUID_GRID2_VISCOSITY_CONSTANT,timestep);
|
||||
fluid_grid2_advectVectors(currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,timestep);
|
||||
//update neighbor arr
|
||||
fluid_grid2_setBoundsToNeighborsRaw(currentChunk->chunkMask,FLUID_GRID2_BOUND_DIR_U,currentChunk->u);
|
||||
fluid_grid2_setBoundsToNeighborsRaw(currentChunk->chunkMask,FLUID_GRID2_BOUND_DIR_V,currentChunk->v);
|
||||
fluid_grid2_setBoundsToNeighborsRaw(currentChunk->chunkMask,FLUID_GRID2_BOUND_DIR_W,currentChunk->w);
|
||||
//setup projection
|
||||
fluid_grid2_setupProjection(currentChunk->chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,FLUID_GRID2_DIFFUSION_CONSTANT,FLUID_GRID2_VISCOSITY_CONSTANT,timestep);
|
||||
fluid_grid2_setupProjection(currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,timestep);
|
||||
//update array for vectors
|
||||
fluid_grid2_setBoundsToNeighborsRaw(currentChunk->chunkMask,FLUID_GRID2_BOUND_DIR_U,currentChunk->u0);
|
||||
fluid_grid2_setBoundsToNeighborsRaw(currentChunk->chunkMask,FLUID_GRID2_BOUND_DIR_V,currentChunk->v0);
|
||||
@ -165,13 +162,13 @@ void fluid_grid2_simulate(
|
||||
//
|
||||
//Perform main projection solver
|
||||
for(int l = 0; l < FLUID_GRID2_LINEARSOLVERTIMES; l++){
|
||||
fluid_grid2_solveProjection(currentChunk->chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,FLUID_GRID2_DIFFUSION_CONSTANT,FLUID_GRID2_VISCOSITY_CONSTANT,timestep);
|
||||
fluid_grid2_solveProjection(currentChunk->u0,currentChunk->v0,timestep);
|
||||
fluid_grid2_setBoundsToNeighborsRaw(currentChunk->chunkMask,FLUID_GRID2_BOUND_NO_DIR,currentChunk->u0);
|
||||
}
|
||||
//samples u,v,w,u0
|
||||
//sets u,v,w
|
||||
//Finalize projection
|
||||
fluid_grid2_finalizeProjection(currentChunk->chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,FLUID_GRID2_DIFFUSION_CONSTANT,FLUID_GRID2_VISCOSITY_CONSTANT,timestep);
|
||||
fluid_grid2_finalizeProjection(currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,timestep);
|
||||
//set boundaries a final time for u,v,w
|
||||
//...
|
||||
fluid_grid2_setBoundsToNeighborsRaw(currentChunk->chunkMask,FLUID_GRID2_BOUND_DIR_U,currentChunk->u);
|
||||
@ -197,7 +194,7 @@ void fluid_grid2_simulate(
|
||||
environment->state.newDensity = 0;
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
fluid_grid2_addDensity(environment,currentChunk->chunkMask,currentChunk->d,currentChunk->d0,timestep);
|
||||
fluid_grid2_addDensity(environment,currentChunk->d,currentChunk->d0,timestep);
|
||||
//swap all density arrays
|
||||
//swap vector fields
|
||||
|
||||
@ -209,7 +206,7 @@ void fluid_grid2_simulate(
|
||||
}
|
||||
//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,timestep);
|
||||
fluid_grid2_solveDiffuseDensity(currentChunk->d,currentChunk->d0,FLUID_GRID2_DIFFUSION_CONSTANT,timestep);
|
||||
fluid_grid2_setBoundsToNeighborsRaw(currentChunk->chunkMask,0,currentChunk->d);
|
||||
}
|
||||
//swap all density arrays
|
||||
@ -220,7 +217,7 @@ void fluid_grid2_simulate(
|
||||
currentChunk->d0[j] = tmpArr;
|
||||
}
|
||||
//advect density
|
||||
fluid_grid2_advectDensity(currentChunk->chunkMask,currentChunk->d,currentChunk->d0,currentChunk->u,currentChunk->v,currentChunk->w,timestep);
|
||||
fluid_grid2_advectDensity(currentChunk->d,currentChunk->d0,currentChunk->u,currentChunk->v,currentChunk->w,timestep);
|
||||
}
|
||||
//mirror densities
|
||||
{
|
||||
@ -234,7 +231,7 @@ void fluid_grid2_simulate(
|
||||
double transformedDensity = 0;
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
transformedDensity = transformedDensity + fluid_grid2_calculateSum(currentChunk->chunkMask,currentChunk->d);
|
||||
transformedDensity = transformedDensity + fluid_grid2_calculateSum(currentChunk->d);
|
||||
}
|
||||
float normalizationRatio = 0;
|
||||
if(transformedDensity != 0){
|
||||
|
||||
94
src/main/c/src/fluid/sim/grid2/utilities.c
Normal file
94
src/main/c/src/fluid/sim/grid2/utilities.c
Normal file
@ -0,0 +1,94 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "fluid/env/utilities.h"
|
||||
#include "fluid/queue/chunkmask.h"
|
||||
#include "fluid/env/environment.h"
|
||||
#include "fluid/queue/chunk.h"
|
||||
#include "fluid/sim/grid2/solver_consts.h"
|
||||
#include "fluid/sim/grid2/utilities.h"
|
||||
#include "fluid/sim/grid2/velocity.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds from a source array to a destination array
|
||||
*/
|
||||
void fluid_grid2_add_source(float * x, float * s, float dt){
|
||||
int i;
|
||||
int size=DIM*DIM*DIM;
|
||||
for(i=0; i<size; i++){
|
||||
x[i] += dt*s[i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bounds of this cube to those of its neighbor
|
||||
*/
|
||||
LIBRARY_API void fluid_grid2_setBoundsToNeighborsRaw(
|
||||
int chunk_mask,
|
||||
int vector_dir,
|
||||
float ** neighborArray
|
||||
){
|
||||
float * target = GET_ARR_RAW(neighborArray,CENTER_LOC);
|
||||
float * source;
|
||||
//set the faces bounds
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
for(int y = 1; y < DIM-1; y++){
|
||||
//((x)+(DIM)*(y) + (DIM)*(DIM)*(z))
|
||||
target[IX(0,x,y)] = vector_dir==FLUID_GRID2_BOUND_DIR_U ? -target[IX(1,x,y)] : target[IX(1,x,y)];
|
||||
target[IX(DIM-1,x,y)] = vector_dir==FLUID_GRID2_BOUND_DIR_U ? -target[IX(DIM-2,x,y)] : target[IX(DIM-2,x,y)];
|
||||
target[IX(x,0,y)] = vector_dir==FLUID_GRID2_BOUND_DIR_V ? -target[IX(x,1,y)] : target[IX(x,1,y)];
|
||||
target[IX(x,DIM-1,y)] = vector_dir==FLUID_GRID2_BOUND_DIR_V ? -target[IX(x,DIM-2,y)] : target[IX(x,DIM-2,y)];
|
||||
target[IX(x,y,0)] = vector_dir==FLUID_GRID2_BOUND_DIR_W ? -target[IX(x,y,1)] : target[IX(x,y,1)];
|
||||
target[IX(x,y,DIM-1)] = vector_dir==FLUID_GRID2_BOUND_DIR_W ? -target[IX(x,y,DIM-2)] : target[IX(x,y,DIM-2)];
|
||||
}
|
||||
}
|
||||
//sets the edges of the chunk
|
||||
for(int x = 1; x < DIM-1; x++){
|
||||
target[IX(x,0,0)] = (float)(0.5f * (target[IX(x,1,0)] + target[IX(x,0,1)]));
|
||||
target[IX(x,DIM-1,0)] = (float)(0.5f * (target[IX(x,DIM-2,0)] + target[IX(x,DIM-1,1)]));
|
||||
target[IX(x,0,DIM-1)] = (float)(0.5f * (target[IX(x,1,DIM-1)] + target[IX(x,0,DIM-2)]));
|
||||
target[IX(x,DIM-1,DIM-1)] = (float)(0.5f * (target[IX(x,DIM-2,DIM-1)] + target[IX(x,DIM-1,DIM-2)]));
|
||||
|
||||
target[IX(0,x,0)] = (float)(0.5f * (target[IX(1,x,0)] + target[IX(0,x,1)]));
|
||||
target[IX(DIM-1,x,0)] = (float)(0.5f * (target[IX(DIM-2,x,0)] + target[IX(DIM-1,x,1)]));
|
||||
target[IX(0,x,DIM-1)] = (float)(0.5f * (target[IX(1,x,DIM-1)] + target[IX(0,x,DIM-2)]));
|
||||
target[IX(DIM-1,x,DIM-1)] = (float)(0.5f * (target[IX(DIM-2,x,DIM-1)] + target[IX(DIM-1,x,DIM-2)]));
|
||||
|
||||
|
||||
target[IX(0,0,x)] = (float)(0.5f * (target[IX(1,0,x)] + target[IX(0,1,x)]));
|
||||
target[IX(DIM-1,0,x)] = (float)(0.5f * (target[IX(DIM-2,0,x)] + target[IX(DIM-1,1,x)]));
|
||||
target[IX(0,DIM-1,x)] = (float)(0.5f * (target[IX(1,DIM-1,x)] + target[IX(0,DIM-2,x)]));
|
||||
target[IX(DIM-1,DIM-1,x)] = (float)(0.5f * (target[IX(DIM-2,DIM-1,x)] + target[IX(DIM-1,DIM-2,x)]));
|
||||
|
||||
}
|
||||
//sets the corners of the chunk
|
||||
target[IX(0,0,0)] = (float)((target[IX(1,0,0)]+target[IX(0,1,0)]+target[IX(0,0,1)])/3.0);
|
||||
target[IX(DIM-1,0,0)] = (float)((target[IX(DIM-2,0,0)]+target[IX(DIM-1,1,0)]+target[IX(DIM-1,0,1)])/3.0);
|
||||
target[IX(0,DIM-1,0)] = (float)((target[IX(1,DIM-1,0)]+target[IX(0,DIM-2,0)]+target[IX(0,DIM-1,1)])/3.0);
|
||||
target[IX(0,0,DIM-1)] = (float)((target[IX(0,0,DIM-2)]+target[IX(1,0,DIM-1)]+target[IX(0,1,DIM-1)])/3.0);
|
||||
target[IX(DIM-1,DIM-1,0)] = (float)((target[IX(DIM-2,DIM-1,0)]+target[IX(DIM-1,DIM-2,0)]+target[IX(DIM-1,DIM-1,1)])/3.0);
|
||||
target[IX(0,DIM-1,DIM-1)] = (float)((target[IX(1,DIM-1,DIM-1)]+target[IX(0,DIM-2,DIM-1)]+target[IX(0,DIM-1,DIM-2)])/3.0);
|
||||
target[IX(DIM-1,0,DIM-1)] = (float)((target[IX(DIM-1,0,DIM-2)]+target[IX(DIM-2,0,DIM-1)]+target[IX(DIM-1,1,DIM-1)])/3.0);
|
||||
target[IX(DIM-1,DIM-1,DIM-1)] = (float)((target[IX(DIM-1,DIM-1,DIM-2)]+target[IX(DIM-1,DIM-2,DIM-1)]+target[IX(DIM-1,DIM-1,DIM-2)])/3.0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sums the density of the chunk
|
||||
*/
|
||||
double fluid_grid2_calculateSum(float ** d){
|
||||
int j;
|
||||
int size=DIM*DIM*DIM;
|
||||
float * x = GET_ARR_RAW(d,CENTER_LOC);
|
||||
double rVal = 0;
|
||||
for(j=0; j<size; j++){
|
||||
rVal = rVal + x[j];
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
@ -21,49 +21,32 @@ void fluid_grid2_advect(uint32_t chunk_mask, int b, float ** jrd, float ** jrd0,
|
||||
*/
|
||||
void fluid_grid2_addSourceToVectors
|
||||
(
|
||||
int chunk_mask,
|
||||
float ** jru,
|
||||
float ** jrv,
|
||||
float ** jrw,
|
||||
float ** jru0,
|
||||
float ** jrv0,
|
||||
float ** jrw0,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt){
|
||||
fluid_grid2_add_source(GET_ARR_RAW(jru,CENTER_LOC),GET_ARR_RAW(jru0,CENTER_LOC),dt);
|
||||
fluid_grid2_add_source(GET_ARR_RAW(jrv,CENTER_LOC),GET_ARR_RAW(jrv0,CENTER_LOC),dt);
|
||||
fluid_grid2_add_source(GET_ARR_RAW(jrw,CENTER_LOC),GET_ARR_RAW(jrw0,CENTER_LOC),dt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds from a source array to a destination array
|
||||
*/
|
||||
void fluid_grid2_add_source(float * x, float * s, float dt){
|
||||
int i;
|
||||
int size=DIM*DIM*DIM;
|
||||
for(i=0; i<size; i++){
|
||||
x[i] += dt*s[i];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Solves vector diffusion along all axis
|
||||
*/
|
||||
void fluid_grid2_solveVectorDiffuse (
|
||||
int chunk_mask,
|
||||
float ** jru,
|
||||
float ** jrv,
|
||||
float ** jrw,
|
||||
float ** jru0,
|
||||
float ** jrv0,
|
||||
float ** jrw0,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
){
|
||||
float h = FLUID_GRID2_H;
|
||||
float a=dt*VISCOSITY_CONST/(h*h);
|
||||
float a=dt*FLUID_GRID2_VISCOSITY_CONSTANT/(h*h);
|
||||
float c=1+6*a;
|
||||
int i, j, k, l, m;
|
||||
float * u = GET_ARR_RAW(jru,CENTER_LOC);
|
||||
@ -169,14 +152,11 @@ void fluid_grid2_solveVectorDiffuse (
|
||||
* @param dt The timestep for the simulation
|
||||
*/
|
||||
void fluid_grid2_setupProjection(
|
||||
int chunk_mask,
|
||||
float ** ur,
|
||||
float ** vr,
|
||||
float ** wr,
|
||||
float ** pr,
|
||||
float ** divr,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
){
|
||||
int i, j, k;
|
||||
@ -252,15 +232,8 @@ void fluid_grid2_setupProjection(
|
||||
* @param jrv0 The first derivative field
|
||||
*/
|
||||
void fluid_grid2_solveProjection(
|
||||
int chunk_mask,
|
||||
float ** jru,
|
||||
float ** jrv,
|
||||
float ** jrw,
|
||||
float ** jru0,
|
||||
float ** jrv0,
|
||||
float ** jrw0,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
){
|
||||
int a = 1;
|
||||
@ -304,15 +277,11 @@ void fluid_grid2_solveProjection(
|
||||
* Thus we are left with an approximately mass-conserved field.
|
||||
*/
|
||||
void fluid_grid2_finalizeProjection(
|
||||
int chunk_mask,
|
||||
float ** jru,
|
||||
float ** jrv,
|
||||
float ** jrw,
|
||||
float ** jru0,
|
||||
float ** jrv0,
|
||||
float ** jrw0,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
){
|
||||
int i, j, k;
|
||||
@ -388,26 +357,23 @@ void fluid_grid2_finalizeProjection(
|
||||
* Advects u, v, and w
|
||||
*/
|
||||
void fluid_grid2_advectVectors(
|
||||
int chunk_mask,
|
||||
float ** jru,
|
||||
float ** jrv,
|
||||
float ** jrw,
|
||||
float ** jru0,
|
||||
float ** jrv0,
|
||||
float ** jrw0,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
){
|
||||
fluid_grid2_advect_velocity(chunk_mask,1,jru,jru0,GET_ARR_RAW(jru0,CENTER_LOC),GET_ARR_RAW(jrv0,CENTER_LOC),GET_ARR_RAW(jrw0,CENTER_LOC),dt);
|
||||
fluid_grid2_advect_velocity(chunk_mask,2,jrv,jrv0,GET_ARR_RAW(jru0,CENTER_LOC),GET_ARR_RAW(jrv0,CENTER_LOC),GET_ARR_RAW(jrw0,CENTER_LOC),dt);
|
||||
fluid_grid2_advect_velocity(chunk_mask,3,jrw,jrw0,GET_ARR_RAW(jru0,CENTER_LOC),GET_ARR_RAW(jrv0,CENTER_LOC),GET_ARR_RAW(jrw0,CENTER_LOC),dt);
|
||||
fluid_grid2_advect_velocity(1,jru,jru0,GET_ARR_RAW(jru0,CENTER_LOC),GET_ARR_RAW(jrv0,CENTER_LOC),GET_ARR_RAW(jrw0,CENTER_LOC),dt);
|
||||
fluid_grid2_advect_velocity(2,jrv,jrv0,GET_ARR_RAW(jru0,CENTER_LOC),GET_ARR_RAW(jrv0,CENTER_LOC),GET_ARR_RAW(jrw0,CENTER_LOC),dt);
|
||||
fluid_grid2_advect_velocity(3,jrw,jrw0,GET_ARR_RAW(jru0,CENTER_LOC),GET_ARR_RAW(jrv0,CENTER_LOC),GET_ARR_RAW(jrw0,CENTER_LOC),dt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually performs the advection
|
||||
*/
|
||||
void fluid_grid2_advect_velocity(uint32_t chunk_mask, int b, float ** jrd, float ** jrd0, float * u, float * v, float * w, float dt){
|
||||
void fluid_grid2_advect_velocity(int b, float ** jrd, float ** jrd0, float * u, float * v, float * w, float dt){
|
||||
int i, j, k, i0, j0, k0, i1, j1, k1;
|
||||
int m,n,o;
|
||||
float x, y, z, s0, t0, s1, t1, u1, u0, dtx,dty,dtz;
|
||||
@ -437,7 +403,7 @@ void fluid_grid2_advect_velocity(uint32_t chunk_mask, int b, float ** jrd, float
|
||||
else if(z >= DIM){ o -= 1; }
|
||||
|
||||
//If the out of bounds coordinate is in bounds for a neighbor chunk, use that chunk as source instead
|
||||
if(CK(m,n,o) != CENTER_LOC && ARR_EXISTS(chunk_mask,m,n,o)){
|
||||
if(CK(m,n,o) != CENTER_LOC && GET_ARR_RAW(jrd,CK(m,n,o)) != NULL){
|
||||
|
||||
// if(i == 1 && j == 1 && k == 1){
|
||||
// printf("\narr indices: %d %d %d\n\n",m,n,o);
|
||||
@ -648,55 +614,3 @@ 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
|
||||
*/
|
||||
LIBRARY_API void fluid_grid2_setBoundsToNeighborsRaw(
|
||||
int chunk_mask,
|
||||
int vector_dir,
|
||||
float ** neighborArray
|
||||
){
|
||||
float * target = GET_ARR_RAW(neighborArray,CENTER_LOC);
|
||||
float * source;
|
||||
//set the faces bounds
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
for(int y = 1; y < DIM-1; y++){
|
||||
//((x)+(DIM)*(y) + (DIM)*(DIM)*(z))
|
||||
target[IX(0,x,y)] = vector_dir==FLUID_GRID2_BOUND_DIR_U ? -target[IX(1,x,y)] : target[IX(1,x,y)];
|
||||
target[IX(DIM-1,x,y)] = vector_dir==FLUID_GRID2_BOUND_DIR_U ? -target[IX(DIM-2,x,y)] : target[IX(DIM-2,x,y)];
|
||||
target[IX(x,0,y)] = vector_dir==FLUID_GRID2_BOUND_DIR_V ? -target[IX(x,1,y)] : target[IX(x,1,y)];
|
||||
target[IX(x,DIM-1,y)] = vector_dir==FLUID_GRID2_BOUND_DIR_V ? -target[IX(x,DIM-2,y)] : target[IX(x,DIM-2,y)];
|
||||
target[IX(x,y,0)] = vector_dir==FLUID_GRID2_BOUND_DIR_W ? -target[IX(x,y,1)] : target[IX(x,y,1)];
|
||||
target[IX(x,y,DIM-1)] = vector_dir==FLUID_GRID2_BOUND_DIR_W ? -target[IX(x,y,DIM-2)] : target[IX(x,y,DIM-2)];
|
||||
}
|
||||
}
|
||||
//sets the edges of the chunk
|
||||
for(int x = 1; x < DIM-1; x++){
|
||||
target[IX(x,0,0)] = (float)(0.5f * (target[IX(x,1,0)] + target[IX(x,0,1)]));
|
||||
target[IX(x,DIM-1,0)] = (float)(0.5f * (target[IX(x,DIM-2,0)] + target[IX(x,DIM-1,1)]));
|
||||
target[IX(x,0,DIM-1)] = (float)(0.5f * (target[IX(x,1,DIM-1)] + target[IX(x,0,DIM-2)]));
|
||||
target[IX(x,DIM-1,DIM-1)] = (float)(0.5f * (target[IX(x,DIM-2,DIM-1)] + target[IX(x,DIM-1,DIM-2)]));
|
||||
|
||||
target[IX(0,x,0)] = (float)(0.5f * (target[IX(1,x,0)] + target[IX(0,x,1)]));
|
||||
target[IX(DIM-1,x,0)] = (float)(0.5f * (target[IX(DIM-2,x,0)] + target[IX(DIM-1,x,1)]));
|
||||
target[IX(0,x,DIM-1)] = (float)(0.5f * (target[IX(1,x,DIM-1)] + target[IX(0,x,DIM-2)]));
|
||||
target[IX(DIM-1,x,DIM-1)] = (float)(0.5f * (target[IX(DIM-2,x,DIM-1)] + target[IX(DIM-1,x,DIM-2)]));
|
||||
|
||||
|
||||
target[IX(0,0,x)] = (float)(0.5f * (target[IX(1,0,x)] + target[IX(0,1,x)]));
|
||||
target[IX(DIM-1,0,x)] = (float)(0.5f * (target[IX(DIM-2,0,x)] + target[IX(DIM-1,1,x)]));
|
||||
target[IX(0,DIM-1,x)] = (float)(0.5f * (target[IX(1,DIM-1,x)] + target[IX(0,DIM-2,x)]));
|
||||
target[IX(DIM-1,DIM-1,x)] = (float)(0.5f * (target[IX(DIM-2,DIM-1,x)] + target[IX(DIM-1,DIM-2,x)]));
|
||||
|
||||
}
|
||||
//sets the corners of the chunk
|
||||
target[IX(0,0,0)] = (float)((target[IX(1,0,0)]+target[IX(0,1,0)]+target[IX(0,0,1)])/3.0);
|
||||
target[IX(DIM-1,0,0)] = (float)((target[IX(DIM-2,0,0)]+target[IX(DIM-1,1,0)]+target[IX(DIM-1,0,1)])/3.0);
|
||||
target[IX(0,DIM-1,0)] = (float)((target[IX(1,DIM-1,0)]+target[IX(0,DIM-2,0)]+target[IX(0,DIM-1,1)])/3.0);
|
||||
target[IX(0,0,DIM-1)] = (float)((target[IX(0,0,DIM-2)]+target[IX(1,0,DIM-1)]+target[IX(0,1,DIM-1)])/3.0);
|
||||
target[IX(DIM-1,DIM-1,0)] = (float)((target[IX(DIM-2,DIM-1,0)]+target[IX(DIM-1,DIM-2,0)]+target[IX(DIM-1,DIM-1,1)])/3.0);
|
||||
target[IX(0,DIM-1,DIM-1)] = (float)((target[IX(1,DIM-1,DIM-1)]+target[IX(0,DIM-2,DIM-1)]+target[IX(0,DIM-1,DIM-2)])/3.0);
|
||||
target[IX(DIM-1,0,DIM-1)] = (float)((target[IX(DIM-1,0,DIM-2)]+target[IX(DIM-2,0,DIM-1)]+target[IX(DIM-1,1,DIM-1)])/3.0);
|
||||
target[IX(DIM-1,DIM-1,DIM-1)] = (float)((target[IX(DIM-1,DIM-1,DIM-2)]+target[IX(DIM-1,DIM-2,DIM-1)]+target[IX(DIM-1,DIM-1,DIM-2)])/3.0);
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ int fluid_sim_grid2_density_diffuse_test1(){
|
||||
}
|
||||
//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_solveDiffuseDensity(currentChunk->d,currentChunk->d0,FLUID_GRID2_DIFFUSION_CONSTANT,FLUID_GRID2_SIM_STEP);
|
||||
fluid_grid2_setBoundsToNeighborsRaw(currentChunk->chunkMask,0,currentChunk->d);
|
||||
}
|
||||
//swap all density arrays
|
||||
|
||||
Loading…
Reference in New Issue
Block a user