velocity advection tests
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
506cced695
commit
305ec1d600
@ -98,7 +98,7 @@ void fluid_grid2_finalizeProjection(
|
||||
/*
|
||||
* Advects u, v, and w
|
||||
*/
|
||||
void fluid_grid2_advectVectors(
|
||||
LIBRARY_API void fluid_grid2_advectVectors(
|
||||
float ** jru,
|
||||
float ** jrv,
|
||||
float ** jrw,
|
||||
|
||||
@ -356,7 +356,7 @@ void fluid_grid2_finalizeProjection(
|
||||
/*
|
||||
* Advects u, v, and w
|
||||
*/
|
||||
void fluid_grid2_advectVectors(
|
||||
LIBRARY_API void fluid_grid2_advectVectors(
|
||||
float ** jru,
|
||||
float ** jrv,
|
||||
float ** jrw,
|
||||
@ -403,62 +403,62 @@ void fluid_grid2_advect_velocity(int b, float ** jrd, float ** jrd0, float * u,
|
||||
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 && GET_ARR_RAW(jrd,CK(m,n,o)) != NULL){
|
||||
// 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);
|
||||
// }
|
||||
// // if(i == 1 && j == 1 && k == 1){
|
||||
// // printf("\narr indices: %d %d %d\n\n",m,n,o);
|
||||
// // }
|
||||
|
||||
//cases:
|
||||
//if x = 17.01, m = 2
|
||||
// 17 in current array is 1 in neighbor
|
||||
// 18 in current array is 2 in neighbor
|
||||
// 19 in current array is 3 in neighbor
|
||||
//want to sample neighbor array at 1 & 2
|
||||
//x becomes 1.01, sampling new array (keep in mind that 0 in the new array should contain the current array values)
|
||||
//modification: subtract 16
|
||||
// //cases:
|
||||
// //if x = 17.01, m = 2
|
||||
// // 17 in current array is 1 in neighbor
|
||||
// // 18 in current array is 2 in neighbor
|
||||
// // 19 in current array is 3 in neighbor
|
||||
// //want to sample neighbor array at 1 & 2
|
||||
// //x becomes 1.01, sampling new array (keep in mind that 0 in the new array should contain the current array values)
|
||||
// //modification: subtract 16
|
||||
|
||||
//cases:
|
||||
//if x = 16.99, m = 2
|
||||
// 16 in current array is 0 in neighbor
|
||||
// 17 in current array is 1 in neighbor
|
||||
// 18 in current array is 2 in neighbor
|
||||
// 19 in current array is 3 in neighbor
|
||||
//want to sample current array still
|
||||
//x becomes 1.01, sampling new array (keep in mind that 0 in the new array should contain the current array values)
|
||||
//modification: no modification
|
||||
// //cases:
|
||||
// //if x = 16.99, m = 2
|
||||
// // 16 in current array is 0 in neighbor
|
||||
// // 17 in current array is 1 in neighbor
|
||||
// // 18 in current array is 2 in neighbor
|
||||
// // 19 in current array is 3 in neighbor
|
||||
// //want to sample current array still
|
||||
// //x becomes 1.01, sampling new array (keep in mind that 0 in the new array should contain the current array values)
|
||||
// //modification: no modification
|
||||
|
||||
//if x = 0.01, m = 0
|
||||
// 0 in current array is 16 in neighbor
|
||||
//-1 in current array is 15 in neighbor
|
||||
//-2 in current array is 14 in neighbor
|
||||
//want to sample current array still
|
||||
//x becomes 15.01, sampling new array (keep in mind that 17 in the new array should contain the current array)
|
||||
//modification: no modification
|
||||
// //if x = 0.01, m = 0
|
||||
// // 0 in current array is 16 in neighbor
|
||||
// //-1 in current array is 15 in neighbor
|
||||
// //-2 in current array is 14 in neighbor
|
||||
// //want to sample current array still
|
||||
// //x becomes 15.01, sampling new array (keep in mind that 17 in the new array should contain the current array)
|
||||
// //modification: no modification
|
||||
|
||||
//if x = -0.01, m = 0
|
||||
// 0 in current array is 16 in neighbor
|
||||
//-1 in current array is 15 in neighbor
|
||||
//-2 in current array is 14 in neighbor
|
||||
//want to sample -1 & 0, so i0 becomes 15
|
||||
//x becomes 15.99, sampling new array (keep in mind that 17 in the new array should contain the current array)
|
||||
//modification: add 16
|
||||
// //if x = -0.01, m = 0
|
||||
// // 0 in current array is 16 in neighbor
|
||||
// //-1 in current array is 15 in neighbor
|
||||
// //-2 in current array is 14 in neighbor
|
||||
// //want to sample -1 & 0, so i0 becomes 15
|
||||
// //x becomes 15.99, sampling new array (keep in mind that 17 in the new array should contain the current array)
|
||||
// //modification: add 16
|
||||
|
||||
//if x = -2, m = 0
|
||||
// 0 in current array is 16 in neighbor
|
||||
//-1 in current array is 15 in neighbor
|
||||
//-2 in current array is 14 in neighbor
|
||||
//x becomes 14, sampling new array (keep in mind that 17 in the new array should contain the current array)
|
||||
//modification: add 16
|
||||
// //if x = -2, m = 0
|
||||
// // 0 in current array is 16 in neighbor
|
||||
// //-1 in current array is 15 in neighbor
|
||||
// //-2 in current array is 14 in neighbor
|
||||
// //x becomes 14, sampling new array (keep in mind that 17 in the new array should contain the current array)
|
||||
// //modification: add 16
|
||||
|
||||
|
||||
// printf("Hit other chunk\n");
|
||||
d0 = GET_ARR_RAW(jrd0,CK(m,n,o));
|
||||
x = x + CHUNK_NORMALIZE_U[CK(m,n,o)] * (DIM-2);
|
||||
// printf("%d => %f\n",m,x);
|
||||
y = y + CHUNK_NORMALIZE_V[CK(m,n,o)] * (DIM-2);
|
||||
z = z + CHUNK_NORMALIZE_W[CK(m,n,o)] * (DIM-2);
|
||||
}
|
||||
// // printf("Hit other chunk\n");
|
||||
// d0 = GET_ARR_RAW(jrd0,CK(m,n,o));
|
||||
// x = x + CHUNK_NORMALIZE_U[CK(m,n,o)] * (DIM-2);
|
||||
// // printf("%d => %f\n",m,x);
|
||||
// y = y + CHUNK_NORMALIZE_V[CK(m,n,o)] * (DIM-2);
|
||||
// z = z + CHUNK_NORMALIZE_W[CK(m,n,o)] * (DIM-2);
|
||||
// }
|
||||
|
||||
//clamp location within chunk
|
||||
//get indices, and calculate percentage to pull from each index
|
||||
@ -610,6 +610,51 @@ void fluid_grid2_advect_velocity(int b, float ** jrd, float ** jrd0, float * u,
|
||||
t0*u1*d0[IX(i1,j0,k1)]+
|
||||
t1*u1*d0[IX(i1,j1,k1)]
|
||||
);
|
||||
|
||||
// if(i == 14 && j == 14 && k == 14){
|
||||
// printf("density at <%d,%d,%d> \n",i,j,k);
|
||||
// printf("sample point precise: %.2f %.2f %.2f\n",x,y,z);
|
||||
// printf("sample box range: <%d,%d,%d> -> <%d,%d,%d> \n",i0,j0,k0,i1,j1,k1);
|
||||
// printf("sample values: %.2f %.2f %.2f %.2f \n",
|
||||
// d0[IX(i0,j0,k0)],
|
||||
// d0[IX(i0,j1,k0)],
|
||||
// d0[IX(i0,j0,k1)],
|
||||
// d0[IX(i0,j1,k1)]
|
||||
// );
|
||||
// printf("sample values: %.2f %.2f %.2f %.2f \n",
|
||||
// d0[IX(i1,j0,k0)],
|
||||
// d0[IX(i1,j1,k0)],
|
||||
// d0[IX(i1,j0,k1)],
|
||||
// d0[IX(i1,j1,k1)]
|
||||
// );
|
||||
// //print ints
|
||||
// // printf("i0: %d\n",i0);
|
||||
// // printf("j0: %d\n",j0);
|
||||
// // printf("k0: %d\n",k0);
|
||||
// // printf("i1: %d\n",i1);
|
||||
// // printf("j1: %d\n",j1);
|
||||
// // printf("k1: %d\n",k1);
|
||||
// // printf("m: %d\n",m);
|
||||
// // printf("n: %d\n",n);
|
||||
// // printf("o: %d\n",o);
|
||||
|
||||
// //print floats
|
||||
// // printf("x: %f\n",x);
|
||||
// // printf("y: %f\n",y);
|
||||
// // printf("z: %f\n",z);
|
||||
|
||||
// // printf("t0: %f\n",s0);
|
||||
// // printf("s0: %f\n",t0);
|
||||
// // printf("t1: %f\n",s1);
|
||||
// // printf("s1: %f\n",t1);
|
||||
// // printf("u0: %f\n",u0);
|
||||
// // printf("u1: %f\n",u1);
|
||||
|
||||
// // printf("dtx: %f\n",dtx);
|
||||
// // printf("dty: %f\n",dty);
|
||||
// // printf("dtz: %f\n",dtz);
|
||||
// printf("\n");
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,58 +24,6 @@
|
||||
*/
|
||||
#define FLUID_GRID2_DENSITY_ADVECTION_CELL_CENTER 24
|
||||
|
||||
/**
|
||||
* Creates a convection cell for testing advection
|
||||
*/
|
||||
void fluid_sim_grid2_density_advection_setup_convection_cell(Chunk ** queue){
|
||||
int chunkCount = arrlen(queue);
|
||||
int realX, realY, realZ;
|
||||
int worldX, worldY, worldZ;
|
||||
for(int chunkIndex = 0; chunkIndex < chunkCount; chunkIndex++){
|
||||
Chunk * chunk = queue[chunkIndex];
|
||||
worldX = chunk->x;
|
||||
worldY = chunk->y;
|
||||
worldZ = chunk->z;
|
||||
for(int x = 0; x < DIM; x++){
|
||||
for(int y = 0; y < DIM; y++){
|
||||
for(int z = 0; z < DIM; z++){
|
||||
double angle = ((x - FLUID_GRID2_DENSITY_ADVECTION_CELL_CENTER),(y - FLUID_GRID2_DENSITY_ADVECTION_CELL_CENTER));
|
||||
if(x == 0){
|
||||
realX = DIM-2 + (CHUNK_SPACING * (worldX - 1));
|
||||
|
||||
} else if(x == DIM-1){
|
||||
realX = 1 + (CHUNK_SPACING * (worldX + 1));
|
||||
|
||||
} else {
|
||||
realX = x + (CHUNK_SPACING * worldX);
|
||||
}
|
||||
if(y == 0){
|
||||
realY = DIM-2 + (CHUNK_SPACING * (worldY - 1));
|
||||
|
||||
} else if(y == DIM-1){
|
||||
realY = 1 + (CHUNK_SPACING * (worldY + 1));
|
||||
|
||||
} else {
|
||||
realY = y + (CHUNK_SPACING * worldY);
|
||||
}
|
||||
if(z == 0){
|
||||
realZ = DIM-2 + (CHUNK_SPACING * (worldZ - 1));
|
||||
|
||||
} else if(z == DIM-1){
|
||||
realZ = 1 + (CHUNK_SPACING * (worldZ + 1));
|
||||
|
||||
} else {
|
||||
realZ = z + (CHUNK_SPACING * worldZ);
|
||||
}
|
||||
chunk->u[CENTER_LOC][IX(x,y,z)] = (float)sin(angle);
|
||||
chunk->v[CENTER_LOC][IX(x,y,z)] = (float)cos(angle);
|
||||
chunk->w[CENTER_LOC][IX(x,y,z)] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing density diffusion
|
||||
*/
|
||||
@ -124,14 +72,18 @@ int fluid_sim_grid2_density_advection_test2(){
|
||||
Chunk * currentChunk = queue[0];
|
||||
currentChunk->d[CENTER_LOC][IX(2,2,2)] = MAX_FLUID_VALUE;
|
||||
float beforeSum = chunk_queue_sum_density(queue);
|
||||
fluid_sim_grid2_density_advection_setup_convection_cell(queue);
|
||||
advection_setup_convection_cell(queue, FLUID_GRID2_DENSITY_ADVECTION_CELL_CENTER);
|
||||
|
||||
//actually simulate
|
||||
int frameCount = 50;
|
||||
for(int frame = 0; frame < frameCount; frame++){
|
||||
fluid_grid2_flip_arrays(currentChunk->d,currentChunk->d0);
|
||||
fluid_grid2_advectDensity(currentChunk->d,currentChunk->d0,currentChunk->u,currentChunk->v,currentChunk->w,FLUID_GRID2_SIM_STEP);
|
||||
fluid_grid2_flip_arrays(currentChunk->d,currentChunk->d0);
|
||||
int chunkCount = arrlen(queue);
|
||||
for(int chunkIndex = 0; chunkIndex < 1; chunkIndex++){
|
||||
currentChunk = queue[chunkIndex];
|
||||
fluid_grid2_flip_arrays(currentChunk->d,currentChunk->d0);
|
||||
fluid_grid2_advectDensity(currentChunk->d,currentChunk->d0,currentChunk->u,currentChunk->v,currentChunk->w,FLUID_GRID2_SIM_STEP);
|
||||
fluid_grid2_flip_arrays(currentChunk->d,currentChunk->d0);
|
||||
}
|
||||
}
|
||||
|
||||
//test the result
|
||||
@ -160,7 +112,7 @@ int fluid_sim_grid2_density_advection_test3(){
|
||||
Chunk * currentChunk = queue[0];
|
||||
currentChunk->d[CENTER_LOC][IX(2,2,2)] = MAX_FLUID_VALUE;
|
||||
float beforeSum = chunk_queue_sum_density(queue);
|
||||
fluid_sim_grid2_density_advection_setup_convection_cell(queue);
|
||||
advection_setup_convection_cell(queue, FLUID_GRID2_DENSITY_ADVECTION_CELL_CENTER);
|
||||
|
||||
//actually simulate
|
||||
int frameCount = 400;
|
||||
@ -203,7 +155,7 @@ int fluid_sim_grid2_density_advection_test4(){
|
||||
currentChunk->d[CENTER_LOC][IX(2,2,7)] = MAX_FLUID_VALUE;
|
||||
currentChunk->d[CENTER_LOC][IX(12,2,2)] = MAX_FLUID_VALUE;
|
||||
float beforeSum = chunk_queue_sum_density(queue);
|
||||
fluid_sim_grid2_density_advection_setup_convection_cell(queue);
|
||||
advection_setup_convection_cell(queue, FLUID_GRID2_DENSITY_ADVECTION_CELL_CENTER);
|
||||
|
||||
//actually simulate
|
||||
int frameCount = 400;
|
||||
@ -243,7 +195,7 @@ int fluid_sim_grid2_density_advection_test5(){
|
||||
Chunk * currentChunk = queue[3 * 3 + 3];
|
||||
chunk_fill_real(currentChunk->d[CENTER_LOC],MAX_FLUID_VALUE);
|
||||
float beforeSum = chunk_queue_sum_density(queue);
|
||||
fluid_sim_grid2_density_advection_setup_convection_cell(queue);
|
||||
advection_setup_convection_cell(queue, FLUID_GRID2_DENSITY_ADVECTION_CELL_CENTER);
|
||||
|
||||
//actually simulate
|
||||
int frameCount = 400;
|
||||
|
||||
190
src/test/c/fluid/sim/grid2/velocity_advection_tests.c
Normal file
190
src/test/c/fluid/sim/grid2/velocity_advection_tests.c
Normal file
@ -0,0 +1,190 @@
|
||||
#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/solver_consts.h"
|
||||
#include "fluid/sim/grid2/utilities.h"
|
||||
#include "fluid/sim/grid2/velocity.h"
|
||||
#include "../../../util/chunk_test_utils.h"
|
||||
#include "../../../util/test.h"
|
||||
|
||||
/**
|
||||
* Center of the advection cell
|
||||
*/
|
||||
#define FLUID_GRID2_VELOCITY_ADVECTION_CELL_CENTER 24
|
||||
|
||||
|
||||
/**
|
||||
* Testing velocity advection
|
||||
*/
|
||||
int fluid_sim_grid2_velocity_advection_test1(){
|
||||
printf("fluid_sim_grid2_velocity_advection_test1\n");
|
||||
int rVal = 0;
|
||||
Environment * env = fluid_environment_create();
|
||||
Chunk ** queue = NULL;
|
||||
queue = createChunkGrid(env,3,3,3);
|
||||
|
||||
|
||||
|
||||
//setup chunk values
|
||||
Chunk * currentChunk = queue[0];
|
||||
currentChunk->d[CENTER_LOC][IX(2,2,2)] = MAX_FLUID_VALUE;
|
||||
advection_setup_convection_cell(queue, FLUID_GRID2_VELOCITY_ADVECTION_CELL_CENTER);
|
||||
float beforeSumX = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_U);
|
||||
float beforeSumY = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_V);
|
||||
float beforeSumZ = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_W);
|
||||
|
||||
//actually simulate
|
||||
int frameCount = 50;
|
||||
for(int frame = 0; frame < frameCount; frame++){
|
||||
fluid_grid2_flip_arrays(currentChunk->u,currentChunk->u0);
|
||||
fluid_grid2_flip_arrays(currentChunk->v,currentChunk->v0);
|
||||
fluid_grid2_flip_arrays(currentChunk->w,currentChunk->w0);
|
||||
fluid_grid2_advectVectors(currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,FLUID_GRID2_SIM_STEP);
|
||||
fluid_grid2_flip_arrays(currentChunk->u,currentChunk->u0);
|
||||
fluid_grid2_flip_arrays(currentChunk->v,currentChunk->v0);
|
||||
fluid_grid2_flip_arrays(currentChunk->w,currentChunk->w0);
|
||||
}
|
||||
|
||||
//test the result
|
||||
float afterSumX = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_U);
|
||||
float afterSumY = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_V);
|
||||
float afterSumZ = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_W);
|
||||
if(fabs(beforeSumX - afterSumX) > FLUID_GRID2_REALLY_SMALL_VALUE){
|
||||
rVal += assertEqualsFloat(beforeSumX,afterSumX,"Velocity advection step changed x-velocity sum! %f %f \n");
|
||||
}
|
||||
if(fabs(beforeSumY - afterSumY) > FLUID_GRID2_REALLY_SMALL_VALUE){
|
||||
rVal += assertEqualsFloat(beforeSumX,afterSumX,"Velocity advection step changed y-density sum! %f %f \n");
|
||||
}
|
||||
if(fabs(beforeSumZ - afterSumZ) > FLUID_GRID2_REALLY_SMALL_VALUE){
|
||||
rVal += assertEqualsFloat(beforeSumX,afterSumX,"Velocity advection step changed z-density sum! %f %f \n");
|
||||
}
|
||||
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing velocity advection
|
||||
*/
|
||||
int fluid_sim_grid2_velocity_advection_test2(){
|
||||
printf("fluid_sim_grid2_velocity_advection_test2\n");
|
||||
int rVal = 0;
|
||||
Environment * env = fluid_environment_create();
|
||||
Chunk ** queue = NULL;
|
||||
queue = createChunkGrid(env,3,3,3);
|
||||
|
||||
|
||||
|
||||
//setup chunk values
|
||||
Chunk * currentChunk = queue[0];
|
||||
queue[0]->u[CENTER_LOC][IX(15,15,15)] = 1;
|
||||
queue[0]->v[CENTER_LOC][IX(15,15,15)] = 1;
|
||||
queue[0]->w[CENTER_LOC][IX(15,15,15)] = 1;
|
||||
float beforeSumX = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_U);
|
||||
float beforeSumY = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_V);
|
||||
float beforeSumZ = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_W);
|
||||
|
||||
//actually simulate
|
||||
int frameCount = 1;
|
||||
for(int frame = 0; frame < frameCount; frame++){
|
||||
int chunkCount = arrlen(queue);
|
||||
for(int chunkIndex = 0; chunkIndex < 1; chunkIndex++){
|
||||
currentChunk = queue[chunkIndex];
|
||||
fluid_grid2_flip_arrays(currentChunk->u,currentChunk->u0);
|
||||
fluid_grid2_flip_arrays(currentChunk->v,currentChunk->v0);
|
||||
fluid_grid2_flip_arrays(currentChunk->w,currentChunk->w0);
|
||||
fluid_grid2_advectVectors(currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,FLUID_GRID2_SIM_STEP);
|
||||
fluid_grid2_flip_arrays(currentChunk->u,currentChunk->u0);
|
||||
fluid_grid2_flip_arrays(currentChunk->v,currentChunk->v0);
|
||||
fluid_grid2_flip_arrays(currentChunk->w,currentChunk->w0);
|
||||
}
|
||||
}
|
||||
|
||||
//test the result
|
||||
float afterSumX = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_U);
|
||||
float afterSumY = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_V);
|
||||
float afterSumZ = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_W);
|
||||
if(fabs(beforeSumX - afterSumX) > FLUID_GRID2_REALLY_SMALL_VALUE){
|
||||
rVal += assertEqualsFloat(beforeSumX,afterSumX,"Velocity advection step changed x-velocity sum! %f %f \n");
|
||||
}
|
||||
if(fabs(beforeSumY - afterSumY) > FLUID_GRID2_REALLY_SMALL_VALUE){
|
||||
rVal += assertEqualsFloat(beforeSumX,afterSumX,"Velocity advection step changed y-density sum! %f %f \n");
|
||||
}
|
||||
if(fabs(beforeSumZ - afterSumZ) > FLUID_GRID2_REALLY_SMALL_VALUE){
|
||||
rVal += assertEqualsFloat(beforeSumX,afterSumX,"Velocity advection step changed z-density sum! %f %f \n");
|
||||
}
|
||||
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Testing velocity advection
|
||||
*/
|
||||
int fluid_sim_grid2_velocity_advection_test3(){
|
||||
printf("fluid_sim_grid2_velocity_advection_test3\n");
|
||||
int rVal = 0;
|
||||
Environment * env = fluid_environment_create();
|
||||
Chunk ** queue = NULL;
|
||||
queue = createChunkGrid(env,3,3,3);
|
||||
|
||||
|
||||
|
||||
//setup chunk values
|
||||
Chunk * currentChunk = queue[0];
|
||||
currentChunk->d[CENTER_LOC][IX(2,2,2)] = MAX_FLUID_VALUE;
|
||||
advection_setup_convection_cell(queue, FLUID_GRID2_VELOCITY_ADVECTION_CELL_CENTER);
|
||||
float beforeSumX = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_U);
|
||||
float beforeSumY = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_V);
|
||||
float beforeSumZ = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_W);
|
||||
|
||||
//actually simulate
|
||||
int frameCount = 50;
|
||||
for(int frame = 0; frame < frameCount; frame++){
|
||||
fluid_grid2_flip_arrays(currentChunk->u,currentChunk->u0);
|
||||
fluid_grid2_flip_arrays(currentChunk->v,currentChunk->v0);
|
||||
fluid_grid2_flip_arrays(currentChunk->w,currentChunk->w0);
|
||||
fluid_grid2_advectVectors(currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,FLUID_GRID2_SIM_STEP);
|
||||
fluid_grid2_flip_arrays(currentChunk->u,currentChunk->u0);
|
||||
fluid_grid2_flip_arrays(currentChunk->v,currentChunk->v0);
|
||||
fluid_grid2_flip_arrays(currentChunk->w,currentChunk->w0);
|
||||
}
|
||||
|
||||
//test the result
|
||||
float afterSumX = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_U);
|
||||
float afterSumY = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_V);
|
||||
float afterSumZ = chunk_queue_sum_velocity(queue,FLUID_GRID2_BOUND_DIR_W);
|
||||
if(fabs(beforeSumX - afterSumX) > FLUID_GRID2_REALLY_SMALL_VALUE){
|
||||
rVal += assertEqualsFloat(beforeSumX,afterSumX,"Velocity advection step changed x-velocity sum! %f %f \n");
|
||||
}
|
||||
if(fabs(beforeSumY - afterSumY) > FLUID_GRID2_REALLY_SMALL_VALUE){
|
||||
rVal += assertEqualsFloat(beforeSumX,afterSumX,"Velocity advection step changed y-density sum! %f %f \n");
|
||||
}
|
||||
if(fabs(beforeSumZ - afterSumZ) > FLUID_GRID2_REALLY_SMALL_VALUE){
|
||||
rVal += assertEqualsFloat(beforeSumX,afterSumX,"Velocity advection step changed z-density sum! %f %f \n");
|
||||
}
|
||||
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Testing velocity advection
|
||||
*/
|
||||
int fluid_sim_grid2_velocity_advection_tests(int argc, char **argv){
|
||||
int rVal = 0;
|
||||
|
||||
rVal += fluid_sim_grid2_velocity_advection_test1();
|
||||
rVal += fluid_sim_grid2_velocity_advection_test2();
|
||||
rVal += fluid_sim_grid2_velocity_advection_test3();
|
||||
|
||||
return rVal;
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "stb/stb_ds.h"
|
||||
#include "fluid/queue/boundsolver.h"
|
||||
@ -7,6 +8,7 @@
|
||||
#include "fluid/env/environment.h"
|
||||
#include "fluid/env/utilities.h"
|
||||
#include "fluid/sim/grid2/velocity.h"
|
||||
#include "chunk_test_utils.h"
|
||||
|
||||
|
||||
|
||||
@ -333,3 +335,57 @@ Chunk ** createChunkGrid(Environment * env, int width, int height, int length){
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a convection cell for testing advection
|
||||
*/
|
||||
void advection_setup_convection_cell(Chunk ** queue, int center){
|
||||
int chunkCount = arrlen(queue);
|
||||
int realX, realY, realZ;
|
||||
int worldX, worldY, worldZ;
|
||||
for(int chunkIndex = 0; chunkIndex < chunkCount; chunkIndex++){
|
||||
Chunk * chunk = queue[chunkIndex];
|
||||
worldX = chunk->x;
|
||||
worldY = chunk->y;
|
||||
worldZ = chunk->z;
|
||||
for(int x = 0; x < DIM; x++){
|
||||
for(int y = 0; y < DIM; y++){
|
||||
for(int z = 0; z < DIM; z++){
|
||||
double angle = ((x - center),(y - center));
|
||||
if(x == 0){
|
||||
realX = DIM-2 + (CHUNK_SPACING * (worldX - 1));
|
||||
|
||||
} else if(x == DIM-1){
|
||||
realX = 1 + (CHUNK_SPACING * (worldX + 1));
|
||||
|
||||
} else {
|
||||
realX = x + (CHUNK_SPACING * worldX);
|
||||
}
|
||||
if(y == 0){
|
||||
realY = DIM-2 + (CHUNK_SPACING * (worldY - 1));
|
||||
|
||||
} else if(y == DIM-1){
|
||||
realY = 1 + (CHUNK_SPACING * (worldY + 1));
|
||||
|
||||
} else {
|
||||
realY = y + (CHUNK_SPACING * worldY);
|
||||
}
|
||||
if(z == 0){
|
||||
realZ = DIM-2 + (CHUNK_SPACING * (worldZ - 1));
|
||||
|
||||
} else if(z == DIM-1){
|
||||
realZ = 1 + (CHUNK_SPACING * (worldZ + 1));
|
||||
|
||||
} else {
|
||||
realZ = z + (CHUNK_SPACING * worldZ);
|
||||
}
|
||||
chunk->u[CENTER_LOC][IX(x,y,z)] = (float)sin(angle + CHUNK_TEST_UTILS_SMALL_VALUE);
|
||||
chunk->v[CENTER_LOC][IX(x,y,z)] = (float)cos(angle + CHUNK_TEST_UTILS_SMALL_VALUE);
|
||||
chunk->w[CENTER_LOC][IX(x,y,z)] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -6,6 +6,11 @@
|
||||
#include "fluid/queue/chunk.h"
|
||||
|
||||
|
||||
/**
|
||||
* A very small value
|
||||
*/
|
||||
#define CHUNK_TEST_UTILS_SMALL_VALUE 0.00001f
|
||||
|
||||
/**
|
||||
* Array id of the d array for chunk_set_val
|
||||
*/
|
||||
@ -116,4 +121,9 @@ float chunk_queue_sum_velocity(Chunk ** chunks, int axis);
|
||||
*/
|
||||
Chunk ** createChunkGrid(Environment * env, int width, int height, int length);
|
||||
|
||||
/**
|
||||
* Creates a convection cell for testing advection
|
||||
*/
|
||||
void advection_setup_convection_cell(Chunk ** queue, int center);
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue
Block a user