cellular bounds desync fixes
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-12-07 23:52:22 -05:00
parent e40cc0a6d4
commit 2ec5ad9a93
4 changed files with 888 additions and 35 deletions

View File

@ -1271,6 +1271,7 @@ Fix memory leak in client fluid data chunks
Work on cellular sim determinism Work on cellular sim determinism
More cellular determinism verification More cellular determinism verification
reintroduce sleeping code reintroduce sleeping code
Cellular bounds desync fixes
# TODO # TODO

View File

@ -11,6 +11,16 @@
*/ */
#define FLUID_CELLULAR_DIFFUSE_RATE2 0.1f #define FLUID_CELLULAR_DIFFUSE_RATE2 0.1f
/**
* Gravity transfer rate/threshold
*/
#define FLUID_CELLULAR_DIFFUSE_RATE_GRAV 0.11f
/**
* Minimum density for lateral movement to occur
*/
#define FLUID_CELLULAR_SURFACE_TENSION_CONST 0.4
/** /**
* Simulates the cellular chunk queue * Simulates the cellular chunk queue
* @param environment The environment storing the simulation queues * @param environment The environment storing the simulation queues

View File

@ -25,6 +25,11 @@ int fluid_cellular_kernel_z[FLUID_CELLULAR_KERNEL_PERMUTATIONS][FLUID_CELLULAR_K
{-1, 0, 1, 0}, {-1, 0, 1, 0},
}; };
/**
* Tracks whether the second-to-highest lateral transfer happened or not (for preventing desync)
*/
int fluid_cellular_lat_tracker[DIM][DIM];
/** /**
* Simulates the cellular chunk queue * Simulates the cellular chunk queue
* @param environment The environment storing the simulation queues * @param environment The environment storing the simulation queues
@ -35,6 +40,7 @@ LIBRARY_API void fluid_cellular_simulate(Environment * environment){
int chunkCount = stbds_arrlen(chunks); int chunkCount = stbds_arrlen(chunks);
int worldX, worldY, worldZ; int worldX, worldY, worldZ;
int permuteX, permuteY, permuteZ; int permuteX, permuteY, permuteZ;
int frame = environment->state.frame;
for(int cellIndex = 0; cellIndex < chunkCount; cellIndex++){ for(int cellIndex = 0; cellIndex < chunkCount; cellIndex++){
Chunk * currentChunk = chunks[cellIndex]; Chunk * currentChunk = chunks[cellIndex];
@ -60,7 +66,7 @@ LIBRARY_API void fluid_cellular_simulate(Environment * environment){
permuteY = y + (CHUNK_SPACING * worldY); permuteY = y + (CHUNK_SPACING * worldY);
} }
// int shift = randutils_map(randutils_rand2(environment->state.frame,permuteY),0,FLUID_CELLULAR_KERNEL_PERMUTATIONS - 1); // int shift = randutils_map(randutils_rand2(environment->state.frame,permuteY),0,FLUID_CELLULAR_KERNEL_PERMUTATIONS - 1);
int shift = environment->state.frame % FLUID_CELLULAR_KERNEL_PERMUTATIONS; int shift = frame % FLUID_CELLULAR_KERNEL_PERMUTATIONS;
// int permutation = randutils_map(randutils_rand2(environment->state.frame,y + 1),0,FLUID_CELLULAR_KERNEL_PERMUTATIONS - 1); // int permutation = randutils_map(randutils_rand2(environment->state.frame,y + 1),0,FLUID_CELLULAR_KERNEL_PERMUTATIONS - 1);
for(int x = 0; x < DIM; x++){ for(int x = 0; x < DIM; x++){
for(int z = 0; z < DIM; z++){ for(int z = 0; z < DIM; z++){
@ -70,33 +76,12 @@ LIBRARY_API void fluid_cellular_simulate(Environment * environment){
if(d[IX(x,y,z)] <= MIN_FLUID_VALUE){ if(d[IX(x,y,z)] <= MIN_FLUID_VALUE){
continue; continue;
} else { } else {
//transfer straight down
if(y > 0){
float nBound = bounds[IX(x,y-1,z)];
if(nBound <= BOUND_CUTOFF_VALUE){
if(d[IX(x,y-1,z)] <= MAX_FLUID_VALUE - FLUID_CELLULAR_DIFFUSE_RATE2){
float transfer = FLUID_CELLULAR_DIFFUSE_RATE2;
if(d[IX(x,y,z)] < FLUID_CELLULAR_DIFFUSE_RATE2){
transfer = d[IX(x,y,z)];
}
// printf("[%d %d %d] <%d,%d,%d> --> <%d,%d,%d> %f \n",worldX,worldY,worldZ,x,y,z,x,y-1,z,transfer);
// printf("%f %f \n",d[IX(x,y,z)],d[IX(x,y,z)]);
d[IX(x,y-1,z)] = d[IX(x,y-1,z)] + transfer;
d[IX(x,y,z)] = d[IX(x,y,z)] - transfer;
// printf("%f %f \n",d[IX(x,y,z)],d[IX(x,y-1,z)]);
// printf("\n");
continue;
}
}
}
//transfer laterally
// [0 0 0]<1,1,17> -> 1,17 // [0 0 0]<1,1,17> -> 1,17
// [0 0 1]<1,1, 1> -> 1,17 // [0 0 1]<1,1, 1> -> 1,17
// [0 0 0]<1,1,15> -> 1,15 // [0 0 0]<1,1,15> -> 1,15
// [0 0 0]<1,1,16> -> 1,16 // [0 0 0]<1,1,16> -> 1,16
// [0 0 1]<1,1, 0> -> 1,16 // [0 0 1]<1,1, 0> -> 1,16
//calculate permutation based on the location of the cell //calculate permutation based on the location of the cell
if(x == 0){ if(x == 0){
permuteX = DIM-2 + (CHUNK_SPACING * (worldX - 1)); permuteX = DIM-2 + (CHUNK_SPACING * (worldX - 1));
@ -116,16 +101,94 @@ LIBRARY_API void fluid_cellular_simulate(Environment * environment){
} else { } else {
permuteZ = z + (CHUNK_SPACING * worldZ); permuteZ = z + (CHUNK_SPACING * worldZ);
} }
int permutation = (permuteZ % (FLUID_CELLULAR_KERNEL_PERMUTATIONS / 2)) + (((permuteX % (FLUID_CELLULAR_KERNEL_PERMUTATIONS / 2))) * (FLUID_CELLULAR_KERNEL_PERMUTATIONS / 2));
int nX = x + fluid_cellular_kernel_x[shift][permutation]; //transfer straight down
int nZ = z + fluid_cellular_kernel_z[shift][permutation]; if(y > 0){
if(permuteY % 16 == 16){
fluid_cellular_lat_tracker[x][z] = 0;
} else if(permuteY % 16 == 1 && fluid_cellular_lat_tracker[x][z] > 0){
continue;
}
float nBound = bounds[IX(x,y-1,z)];
if(nBound <= BOUND_CUTOFF_VALUE){
if(d[IX(x,y-1,z)] < MAX_FLUID_VALUE){
float transfer = FLUID_CELLULAR_DIFFUSE_RATE_GRAV;
if(d[IX(x,y,z)] < transfer){
transfer = d[IX(x,y,z)];
}
if(FLUID_CELLULAR_DIFFUSE_RATE_GRAV < transfer){
transfer = FLUID_CELLULAR_DIFFUSE_RATE_GRAV;
}
//lateral tracker
if(permuteY % 16 == 0){
fluid_cellular_lat_tracker[x][z] = 1;
}
// printf("vertical\n");
// printf("[%d %d %d] <%d,%d,%d> --> <%d,%d,%d> %f \n",worldX,worldY,worldZ,x,y,z,x,y-1,z,transfer);
// printf("%d %d %d --> %d %d %d \n",permuteX,y,permuteZ,permuteX,y-1,permuteZ);
// printf("%f %f \n",d[IX(x,y,z)],d[IX(x,y-1,z)]);
d[IX(x,y-1,z)] = d[IX(x,y-1,z)] + transfer;
d[IX(x,y,z)] = d[IX(x,y,z)] - transfer;
// printf("%f %f \n",d[IX(x,y,z)],d[IX(x,y-1,z)]);
// printf("\n");
continue;
}
}
}
//transfer laterally
if(d[IX(x,y,z)] < FLUID_CELLULAR_SURFACE_TENSION_CONST){
continue;
}
// float permutRand = randutils_rand3(permuteX,permuteZ,environment->state.frame);
int permuteRand = randutils_map(randutils_rand3(permuteX,permuteZ,frame),0,3);
// int permutation = (permuteZ % (FLUID_CELLULAR_KERNEL_PERMUTATIONS / 2)) + (((permuteX % (FLUID_CELLULAR_KERNEL_PERMUTATIONS / 2))) * (FLUID_CELLULAR_KERNEL_PERMUTATIONS / 2));
int permutation = permuteRand;
int xKernel = fluid_cellular_kernel_x[shift][permutation];
int zKernel = fluid_cellular_kernel_z[shift][permutation];
int nX = x + xKernel;
int nZ = z + zKernel;
// printf("[%d %d %d] <%d,%d,%d>\n",worldX,worldY,worldZ,x,y,z); // printf("[%d %d %d] <%d,%d,%d>\n",worldX,worldY,worldZ,x,y,z);
// printf("%d %d \n",permuteX,permuteZ); // printf("%d %d \n",permuteX,permuteZ);
if(nX < 0 || nX >= DIM || nZ < 0 || nZ >= DIM){ if(nX < 0 || nX >= DIM || nZ < 0 || nZ >= DIM){
continue; continue;
} }
if(d[IX(x,y,z)] < FLUID_CELLULAR_DIFFUSE_RATE2){ //basically if we're about to pull negative and the NEXT voxel is also pulling negative, don't
continue; //this prevents density desync between chunks
if(permuteX % 16 == 0 && xKernel == -1){
int permuteRand = randutils_map(randutils_rand3(permuteX+1,permuteZ,frame),0,3);
int adjacentXKernel = fluid_cellular_kernel_x[shift][permuteRand];
if(adjacentXKernel == -1){
continue;
}
}
//basically if we're about to pull negative and the NEXT voxel is also pulling negative, don't
//this prevents density desync between chunks
if(permuteZ % 16 == 0 && zKernel == -1){
int permuteRand = randutils_map(randutils_rand3(permuteX,permuteZ+1,frame),0,3);
int adjacentZKernel = fluid_cellular_kernel_z[shift][permuteRand];
if(adjacentZKernel == -1){
continue;
}
}
//basically if we're about to pull negative and the NEXT voxel is also pulling negative, don't
//this prevents density desync between chunks
if(permuteX % 16 == 1 && xKernel == 1){
int permuteRand = randutils_map(randutils_rand3(permuteX-1,permuteZ,frame),0,3);
int adjacentXKernel = fluid_cellular_kernel_x[shift][permuteRand];
if(adjacentXKernel == 1){
continue;
}
}
//basically if we're about to pull negative and the NEXT voxel is also pulling negative, don't
//this prevents density desync between chunks
if(permuteZ % 16 == 1 && zKernel == 1){
int permuteRand = randutils_map(randutils_rand3(permuteX,permuteZ-1,frame),0,3);
int adjacentZKernel = fluid_cellular_kernel_z[shift][permuteRand];
if(adjacentZKernel == 1){
continue;
}
} }
if(bounds[IX(nX,y,nZ)] <= BOUND_CUTOFF_VALUE){ if(bounds[IX(nX,y,nZ)] <= BOUND_CUTOFF_VALUE){
if(d[IX(nX,y,nZ)] <= MAX_FLUID_VALUE - FLUID_CELLULAR_DIFFUSE_RATE2 && d[IX(nX,y,nZ)] < d[IX(x,y,z)]){ if(d[IX(nX,y,nZ)] <= MAX_FLUID_VALUE - FLUID_CELLULAR_DIFFUSE_RATE2 && d[IX(nX,y,nZ)] < d[IX(x,y,z)]){
@ -133,8 +196,9 @@ LIBRARY_API void fluid_cellular_simulate(Environment * environment){
if(d[IX(x,y,z)] < FLUID_CELLULAR_DIFFUSE_RATE2){ if(d[IX(x,y,z)] < FLUID_CELLULAR_DIFFUSE_RATE2){
transfer = d[IX(x,y,z)]; transfer = d[IX(x,y,z)];
} }
// printf("lateral\n");
// printf("[%d %d %d] <%d,%d,%d> --> <%d,%d,%d> \n",worldX,worldY,worldZ,x,y,z,nX,y,nZ); // printf("[%d %d %d] <%d,%d,%d> --> <%d,%d,%d> \n",worldX,worldY,worldZ,x,y,z,nX,y,nZ);
// printf("%f %d %d \n",transfer,permuteX,permuteZ); // printf("%f %d %d --> %d %d \n",transfer,permuteX,permuteZ,permuteX + xKernel,permuteZ + zKernel);
// printf("%f %f \n",d[IX(x,y,z)],d[IX(nX,y,nZ)]); // printf("%f %f \n",d[IX(x,y,z)],d[IX(nX,y,nZ)]);
d[IX(nX,y,nZ)] = d[IX(nX,y,nZ)] + transfer; d[IX(nX,y,nZ)] = d[IX(nX,y,nZ)] + transfer;
d[IX(x,y,z)] = d[IX(x,y,z)] - transfer; d[IX(x,y,z)] = d[IX(x,y,z)] - transfer;

View File

@ -20,6 +20,7 @@
#define CELLULAR_TEST_PLACE_VAL (FLUID_CELLULAR_DIFFUSE_RATE2 + 0.13456f) #define CELLULAR_TEST_PLACE_VAL (FLUID_CELLULAR_DIFFUSE_RATE2 + 0.13456f)
#define TOLLERABLE_LOSS_THRESHOLD 0.1f #define TOLLERABLE_LOSS_THRESHOLD 0.1f
#define TOLLERABLE_LOSS_THRESHOLD2 0.0001f
int fluid_sim_cellular_cellular_tests_kernelx[27] = { int fluid_sim_cellular_cellular_tests_kernelx[27] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -39,6 +40,162 @@ int fluid_sim_cellular_cellular_tests_kernelz[27] = {
0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2,
}; };
Chunk * fluid_sim_cellular_test_get_chunk(Chunk ** queue, int x, int y, int z){
return queue[x * 3 * 3 + y * 3 + z];
}
void fluid_sim_cellular_test_diagnose_desync(Chunk ** queue){
int realX, realZ, worldX, worldY, worldZ;
int chunkCount = arrlen(queue);
for(int i = 0; i < chunkCount; i++){
Chunk * current = queue[i];
float ** d = current->d;
worldX = current->x;
worldY = current->y;
worldZ = current->z;
if(worldX > 0 && worldY > 0 && worldZ > 0){
float val0 = fluid_sim_cellular_test_get_chunk(queue,worldX + 0, worldY + 0, worldZ + 0)->d[CENTER_LOC][IX(1,1,1)];
float val1 = fluid_sim_cellular_test_get_chunk(queue,worldX - 1, worldY + 0, worldZ + 0)->d[CENTER_LOC][IX(DIM-1,1,1)];
float val2 = fluid_sim_cellular_test_get_chunk(queue,worldX + 0, worldY - 1, worldZ + 0)->d[CENTER_LOC][IX(1,DIM-1,1)];
float val3 = fluid_sim_cellular_test_get_chunk(queue,worldX + 0, worldY + 0, worldZ - 1)->d[CENTER_LOC][IX(1,1,DIM-1)];
float val4 = fluid_sim_cellular_test_get_chunk(queue,worldX + 0, worldY - 1, worldZ - 1)->d[CENTER_LOC][IX(1,DIM-1,DIM-1)];
float val5 = fluid_sim_cellular_test_get_chunk(queue,worldX - 1, worldY + 0, worldZ - 1)->d[CENTER_LOC][IX(DIM-1,1,DIM-1)];
float val6 = fluid_sim_cellular_test_get_chunk(queue,worldX - 1, worldY - 1, worldZ + 0)->d[CENTER_LOC][IX(DIM-1,DIM-1,1)];
float val7 = fluid_sim_cellular_test_get_chunk(queue,worldX - 1, worldY - 1, worldZ - 1)->d[CENTER_LOC][IX(DIM-1,DIM-1,DIM-1)];
if(
val0 != val1 ||
val0 != val2 ||
val0 != val3 ||
val0 != val4 ||
val0 != val5 ||
val0 != val6 ||
val0 != val7
){
printf("mismatch at [%d %d %d] <1,1,1> \n", worldX,worldY,worldZ);
}
}
if(worldX > 0 && worldY < 2 && worldZ > 0){
float val0 = fluid_sim_cellular_test_get_chunk(queue,worldX + 0, worldY + 0, worldZ + 0)->d[CENTER_LOC][IX( 1, DIM-1, 1)];
float val1 = fluid_sim_cellular_test_get_chunk(queue,worldX - 1, worldY + 0, worldZ + 0)->d[CENTER_LOC][IX( DIM-1, DIM-1, 1)];
float val2 = fluid_sim_cellular_test_get_chunk(queue,worldX + 0, worldY + 1, worldZ + 0)->d[CENTER_LOC][IX( 1, 1, 1)];
float val3 = fluid_sim_cellular_test_get_chunk(queue,worldX + 0, worldY + 0, worldZ - 1)->d[CENTER_LOC][IX( 1, DIM-1, DIM-1)];
float val4 = fluid_sim_cellular_test_get_chunk(queue,worldX + 0, worldY + 1, worldZ - 1)->d[CENTER_LOC][IX( 1, 1, DIM-1)];
float val5 = fluid_sim_cellular_test_get_chunk(queue,worldX - 1, worldY + 0, worldZ - 1)->d[CENTER_LOC][IX( DIM-1, DIM-1, DIM-1)];
float val6 = fluid_sim_cellular_test_get_chunk(queue,worldX - 1, worldY + 1, worldZ + 0)->d[CENTER_LOC][IX( DIM-1, 1, 1)];
float val7 = fluid_sim_cellular_test_get_chunk(queue,worldX - 1, worldY + 1, worldZ - 1)->d[CENTER_LOC][IX( DIM-1, 1, DIM-1)];
if(
val0 != val1 ||
val0 != val2 ||
val0 != val3 ||
val0 != val4 ||
val0 != val5 ||
val0 != val6 ||
val0 != val7
){
printf("mismatch at [%d %d %d] <1,1,1> \n", worldX,worldY,worldZ);
}
}
// if(d[CK(2,1,1)] != NULL){
// realX = worldX * 16 + 17;
// realZ = worldZ * 16 + 1;
// if(d[CENTER_LOC][IX(17,1,1)] != d[CK(2,1,1)][IX(1,1,1)]){
// printf("mismatch in [%d %d %d] / [%d %d %d] \n", worldX,worldY,worldZ, worldX+1,worldY,worldZ );
// printf("pos of mismatch %d %d\n",realX,realZ);
// printf("\n");
// }
// realX = worldX * 16 + 17;
// realZ = worldZ * 16 + 16;
// if(d[CENTER_LOC][IX(17,1,16)] != d[CK(2,1,1)][IX(1,1,16)]){
// printf("mismatch in [%d %d %d] / [%d %d %d] \n", worldX,worldY,worldZ, worldX+1,worldY,worldZ );
// printf("pos of mismatch %d %d\n",realX,realZ);
// printf("\n");
// }
// realX = worldX * 16 + 16;
// realZ = worldZ * 16 + 1;
// if(d[CENTER_LOC][IX(16,1,1)] != d[CK(2,1,1)][IX(0,1,1)]){
// printf("mismatch in [%d %d %d] / [%d %d %d] \n", worldX,worldY,worldZ, worldX+1,worldY,worldZ );
// printf("pos of mismatch %d %d\n",realX,realZ);
// printf("\n");
// }
// realX = worldX * 16 + 16;
// realZ = worldZ * 16 + 16;
// if(d[CENTER_LOC][IX(16,1,16)] != d[CK(2,1,1)][IX(0,1,16)]){
// printf("mismatch in [%d %d %d] / [%d %d %d] \n", worldX,worldY,worldZ, worldX+1,worldY,worldZ );
// printf("pos of mismatch %d %d\n",realX,realZ);
// printf("\n");
// }
// }
// if(d[CK(0,1,1)] != NULL){
// realX = worldX * 16 + 0;
// realZ = worldZ * 16 + 1;
// if(d[CENTER_LOC][IX(0,1,1)] != d[CK(0,1,1)][IX(16,1,1)]){
// printf("mismatch in [%d %d %d] / [%d %d %d] \n", worldX,worldY,worldZ, worldX+1,worldY,worldZ );
// printf("pos of mismatch %d %d\n",realX,realZ);
// printf("\n");
// }
// realX = worldX * 16 + 0;
// realZ = worldZ * 16 + 16;
// if(d[CENTER_LOC][IX(0,1,16)] != d[CK(0,1,1)][IX(16,1,16)]){
// printf("mismatch in [%d %d %d] / [%d %d %d] \n", worldX,worldY,worldZ, worldX+1,worldY,worldZ );
// printf("pos of mismatch %d %d\n",realX,realZ);
// printf("\n");
// }
// realX = worldX * 16 + 1;
// realZ = worldZ * 16 + 1;
// if(d[CENTER_LOC][IX(1,1,1)] != d[CK(0,1,1)][IX(17,1,1)]){
// printf("mismatch in [%d %d %d] / [%d %d %d] \n", worldX,worldY,worldZ, worldX+1,worldY,worldZ );
// printf("pos of mismatch %d %d\n",realX,realZ);
// printf("\n");
// }
// realX = worldX * 16 + 1;
// realZ = worldZ * 16 + 16;
// if(d[CENTER_LOC][IX(1,1,16)] != d[CK(0,1,1)][IX(17,1,16)]){
// printf("mismatch in [%d %d %d] / [%d %d %d] \n", worldX,worldY,worldZ, worldX+1,worldY,worldZ );
// printf("pos of mismatch %d %d\n",realX,realZ);
// printf("\n");
// }
// }
// if(d[CK(1,1,2)] != NULL){
// realX = worldX * 16 + 1;
// realZ = worldZ * 16 + 17;
// if(d[CENTER_LOC][IX(1,1,17)] != d[CK(1,1,2)][IX(1,1,1)]){
// printf("mismatch in [%d %d %d] / [%d %d %d] \n", worldX,worldY,worldZ, worldX+1,worldY,worldZ );
// printf("pos of mismatch %d %d\n",realX,realZ);
// printf("\n");
// }
// realX = worldX * 16 + 16;
// realZ = worldZ * 16 + 16;
// if(d[CENTER_LOC][IX(16,1,0)] != d[CK(0,1,1)][IX(16,1,16)]){
// printf("mismatch in [%d %d %d] / [%d %d %d] \n", worldX,worldY,worldZ, worldX+1,worldY,worldZ );
// printf("pos of mismatch %d %d\n",realX,realZ);
// printf("\n");
// }
// }
// if(d[CK(1,1,0)] != NULL){
// realX = worldX * 16 + 1;
// realZ = worldZ * 16 + 0;
// if(d[CENTER_LOC][IX(1,1,0)] != d[CK(1,1,0)][IX(1,1,16)]){
// printf("mismatch in [%d %d %d] / [%d %d %d] \n", worldX,worldY,worldZ, worldX+1,worldY,worldZ );
// printf("pos of mismatch %d %d\n",realX,realZ);
// printf("\n");
// }
// realX = worldX * 16 + 16;
// realZ = worldZ * 16 + 0;
// if(d[CENTER_LOC][IX(16,1,0)] != d[CK(1,1,0)][IX(16,1,16)]){
// printf("mismatch in [%d %d %d] / [%d %d %d] \n", worldX,worldY,worldZ, worldX+1,worldY,worldZ );
// printf("pos of mismatch %d %d\n",realX,realZ);
// printf("\n");
// }
// }
}
}
int fluid_sim_cellular_bounds_test1(){ int fluid_sim_cellular_bounds_test1(){
@ -196,7 +353,7 @@ int fluid_sim_cellular_stability_test1(){
//dispatch and simulate //dispatch and simulate
int frameCount = 1000; int frameCount = 100;
for(int frameCounter = 0; frameCounter < frameCount; frameCounter++){ for(int frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum(queue); float currentSum = chunk_queue_sum(queue);
if(currentSum != originalSum){ if(currentSum != originalSum){
@ -204,12 +361,12 @@ int fluid_sim_cellular_stability_test1(){
rVal += assertEqualsFloat(currentSum,originalSum,"Sums are not identical! %f %f \n"); rVal += assertEqualsFloat(currentSum,originalSum,"Sums are not identical! %f %f \n");
break; break;
} }
printf("frame: %d --- %f \n", frameCounter,currentSum); // printf("frame: %d --- %f \n", frameCounter,currentSum);
fluid_solve_bounds(chunkCount,queue,env); fluid_solve_bounds(chunkCount,queue,env);
fluid_dispatch(chunkCount,queue,env); fluid_dispatch(chunkCount,queue,env);
fluid_simulate(env); fluid_simulate(env);
fluid_solve_bounds(chunkCount,queue,env); fluid_solve_bounds(chunkCount,queue,env);
printf("\n"); // printf("\n");
env->state.frame++; env->state.frame++;
} }
@ -265,7 +422,7 @@ int fluid_sim_cellular_stability_test2(){
//dispatch and simulate //dispatch and simulate
int frameCount = 1000; int frameCount = 100;
for(int frameCounter = 0; frameCounter < frameCount; frameCounter++){ for(int frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum(queue); float currentSum = chunk_queue_sum(queue);
if(currentSum != originalSum){ if(currentSum != originalSum){
@ -273,12 +430,12 @@ int fluid_sim_cellular_stability_test2(){
rVal += assertEqualsFloat(currentSum,originalSum,"Sums are not identical! %f %f \n"); rVal += assertEqualsFloat(currentSum,originalSum,"Sums are not identical! %f %f \n");
break; break;
} }
printf("frame: %d --- %f \n", frameCounter,currentSum); // printf("frame: %d --- %f \n", frameCounter,currentSum);
fluid_solve_bounds(chunkCount,queue,env); fluid_solve_bounds(chunkCount,queue,env);
fluid_dispatch(chunkCount,queue,env); fluid_dispatch(chunkCount,queue,env);
fluid_simulate(env); fluid_simulate(env);
fluid_solve_bounds(chunkCount,queue,env); fluid_solve_bounds(chunkCount,queue,env);
printf("\n"); // printf("\n");
env->state.frame++; env->state.frame++;
} }
@ -326,6 +483,619 @@ int fluid_sim_cellular_stability_test3(){
chunk_fill(queue[i],0); chunk_fill(queue[i],0);
} }
//fill the 10th chunk
queue[13]->d[CENTER_LOC][IX(5,5,5)] = MAX_FLUID_VALUE;
//check sum beforehand
float originalSum = chunk_queue_sum(queue);
//dispatch and simulate
int frameCount = 100;
int frameCounter;
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum(queue);
float delta = fabs(originalSum - currentSum);
if(delta > TOLLERABLE_LOSS_THRESHOLD){
printf("Failed to equal sums! \n");
rVal += assertEqualsFloat(currentSum,originalSum,"Sums are not identical! %f %f \n");
printf("desync by frame %d \n",frameCounter);
fluid_sim_cellular_test_diagnose_desync(queue);
break;
}
// printf("frame: %d --- %f \n", frameCounter,currentSum);
fluid_solve_bounds(chunkCount,queue,env);
fluid_dispatch(chunkCount,queue,env);
fluid_simulate(env);
fluid_solve_bounds(chunkCount,queue,env);
// printf("\n");
env->state.frame++;
}
//solve bounds afterwards to properly push data back into real arrays
//ie, if data is pushed out of bounds from one chunk to another, must
//then copy it into the in-bounds chunk
fluid_solve_bounds(chunkCount,queue,env);
//check sum beforehand
float afterSum = chunk_queue_sum(queue);
//diff the sums to see if we've changed value a lot
float delta = fabs(originalSum - afterSum);
if(delta > TOLLERABLE_LOSS_THRESHOLD){
rVal += assertEqualsFloat(originalSum,afterSum,"cellular sim was unstable! %f %f \n");
}
printf("\n");
return rVal;
}
int fluid_sim_cellular_stability_test4(){
int rVal = 0;
printf("fluid_sim_cellular_stability_test4\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_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
));
}
//link neighbors
chunk_link_neighbors(queue);
//fill them with values
for(int i = 0; i < chunkCount; i++){
chunk_fill(queue[i],0);
}
//fill the 10th chunk
queue[13]->d[CENTER_LOC][IX(1,1,1)] = MAX_FLUID_VALUE;
//check sum beforehand
float originalSum = chunk_queue_sum(queue);
//dispatch and simulate
int frameCount = 100;
int frameCounter;
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum(queue);
float delta = fabs(originalSum - currentSum);
if(delta > TOLLERABLE_LOSS_THRESHOLD2){
printf("Failed to equal sums! \n");
rVal += assertEqualsFloat(currentSum,originalSum,"Sums are not identical! %f %f \n");
printf("desync by frame %d --- %f \n",frameCounter,delta);
fluid_sim_cellular_test_diagnose_desync(queue);
break;
}
// printf("frame: %d --- %f \n", frameCounter,currentSum);
fluid_solve_bounds(chunkCount,queue,env);
fluid_dispatch(chunkCount,queue,env);
fluid_simulate(env);
fluid_solve_bounds(chunkCount,queue,env);
// printf("\n");
env->state.frame++;
}
//solve bounds afterwards to properly push data back into real arrays
//ie, if data is pushed out of bounds from one chunk to another, must
//then copy it into the in-bounds chunk
fluid_solve_bounds(chunkCount,queue,env);
//check sum beforehand
float afterSum = chunk_queue_sum(queue);
//diff the sums to see if we've changed value a lot
float delta = fabs(originalSum - afterSum);
if(delta > TOLLERABLE_LOSS_THRESHOLD){
rVal += assertEqualsFloat(originalSum,afterSum,"cellular sim was unstable! %f %f \n");
}
printf("\n");
return rVal;
}
int fluid_sim_cellular_stability_test5(){
int rVal = 0;
printf("fluid_sim_cellular_stability_test5\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_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
));
}
//link neighbors
chunk_link_neighbors(queue);
//fill them with values
for(int i = 0; i < chunkCount; i++){
chunk_fill(queue[i],0);
}
//fill the 10th chunk
queue[13]->d[CENTER_LOC][IX(1,1,1)] = MAX_FLUID_VALUE;
queue[13]->d[CENTER_LOC][IX(DIM-2,1,1)] = MAX_FLUID_VALUE;
queue[13]->d[CENTER_LOC][IX(1,DIM-2,1)] = MAX_FLUID_VALUE;
queue[13]->d[CENTER_LOC][IX(1,1,DIM-2)] = MAX_FLUID_VALUE;
queue[13]->d[CENTER_LOC][IX(1,DIM-2,DIM-2)] = MAX_FLUID_VALUE;
queue[13]->d[CENTER_LOC][IX(DIM-2,1,DIM-2)] = MAX_FLUID_VALUE;
queue[13]->d[CENTER_LOC][IX(DIM-2,DIM-2,1)] = MAX_FLUID_VALUE;
queue[13]->d[CENTER_LOC][IX(DIM-2,DIM-2,DIM-2)] = MAX_FLUID_VALUE;
//check sum beforehand
float originalSum = chunk_queue_sum(queue);
//dispatch and simulate
int frameCount = 100;
int frameCounter;
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum(queue);
float delta = fabs(originalSum - currentSum);
if(delta > TOLLERABLE_LOSS_THRESHOLD2){
printf("Failed to equal sums! \n");
rVal += assertEqualsFloat(currentSum,originalSum,"Sums are not identical! %f %f \n");
printf("desync by frame %d \n",frameCounter);
fluid_sim_cellular_test_diagnose_desync(queue);
break;
}
// printf("frame: %d --- %f \n", frameCounter,currentSum);
fluid_solve_bounds(chunkCount,queue,env);
fluid_dispatch(chunkCount,queue,env);
fluid_simulate(env);
fluid_solve_bounds(chunkCount,queue,env);
// printf("\n");
env->state.frame++;
}
//solve bounds afterwards to properly push data back into real arrays
//ie, if data is pushed out of bounds from one chunk to another, must
//then copy it into the in-bounds chunk
fluid_solve_bounds(chunkCount,queue,env);
//check sum beforehand
float afterSum = chunk_queue_sum(queue);
//diff the sums to see if we've changed value a lot
float delta = fabs(originalSum - afterSum);
if(delta > TOLLERABLE_LOSS_THRESHOLD){
rVal += assertEqualsFloat(originalSum,afterSum,"cellular sim was unstable! %f %f \n");
}
printf("\n");
return rVal;
}
int fluid_sim_cellular_stability_test6(){
int rVal = 0;
printf("fluid_sim_cellular_stability_test6\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_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
));
}
//link neighbors
chunk_link_neighbors(queue);
//fill them with values
for(int i = 0; i < chunkCount; i++){
chunk_fill(queue[i],0);
}
//fill the 10th chunk
queue[13]->d[CENTER_LOC][IX(1,1,1)] = MAX_FLUID_VALUE;
queue[13]->d[CENTER_LOC][IX(2,1,1)] = MAX_FLUID_VALUE;
queue[13]->d[CENTER_LOC][IX(1,2,1)] = MAX_FLUID_VALUE;
queue[13]->d[CENTER_LOC][IX(1,1,2)] = MAX_FLUID_VALUE;
queue[13]->d[CENTER_LOC][IX(1,2,2)] = MAX_FLUID_VALUE;
queue[13]->d[CENTER_LOC][IX(2,1,2)] = MAX_FLUID_VALUE;
queue[13]->d[CENTER_LOC][IX(2,2,1)] = MAX_FLUID_VALUE;
queue[13]->d[CENTER_LOC][IX(2,2,2)] = MAX_FLUID_VALUE;
//check sum beforehand
float originalSum = chunk_queue_sum(queue);
//dispatch and simulate
int frameCount = 100;
int frameCounter;
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum(queue);
float delta = fabs(originalSum - currentSum);
if(delta > TOLLERABLE_LOSS_THRESHOLD2){
printf("Failed to equal sums! \n");
rVal += assertEqualsFloat(currentSum,originalSum,"Sums are not identical! %f %f \n");
printf("desync by frame %d \n",frameCounter);
fluid_sim_cellular_test_diagnose_desync(queue);
break;
}
// printf("frame: %d --- %f \n", frameCounter,currentSum);
fluid_solve_bounds(chunkCount,queue,env);
fluid_dispatch(chunkCount,queue,env);
fluid_simulate(env);
fluid_solve_bounds(chunkCount,queue,env);
// printf("\n");
env->state.frame++;
}
//solve bounds afterwards to properly push data back into real arrays
//ie, if data is pushed out of bounds from one chunk to another, must
//then copy it into the in-bounds chunk
fluid_solve_bounds(chunkCount,queue,env);
//check sum beforehand
float afterSum = chunk_queue_sum(queue);
//diff the sums to see if we've changed value a lot
float delta = fabs(originalSum - afterSum);
if(delta > TOLLERABLE_LOSS_THRESHOLD){
rVal += assertEqualsFloat(originalSum,afterSum,"cellular sim was unstable! %f %f \n");
}
printf("\n");
return rVal;
}
int fluid_sim_cellular_stability_test7(){
int rVal = 0;
printf("fluid_sim_cellular_stability_test7\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_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
));
}
//link neighbors
chunk_link_neighbors(queue);
//fill them with values
for(int i = 0; i < chunkCount; i++){
chunk_fill(queue[i],0);
}
//fill the 10th chunk
int size = 16;
for(int x = 1; x < size+1; x++){
for(int y = 1; y < size+1; y++){
for(int z = 1; z < size+1; z++){
queue[13]->d[CENTER_LOC][IX(x,y,z)] = MAX_FLUID_VALUE;
}
}
}
//check sum beforehand
float originalSum = chunk_queue_sum(queue);
//dispatch and simulate
int frameCount = 1000;
int frameCounter;
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum(queue);
// printf("frame: %d --- %f \n", frameCounter,currentSum);
fluid_solve_bounds(chunkCount,queue,env);
fluid_dispatch(chunkCount,queue,env);
fluid_simulate(env);
float postSum = chunk_queue_sum(queue);
float delta = fabs(originalSum - postSum);
fluid_solve_bounds(chunkCount,queue,env);
if(delta > TOLLERABLE_LOSS_THRESHOLD2){
printf("Failed to equal sums! \n");
rVal += assertEqualsFloat(postSum,originalSum,"Sums are not identical! %f %f \n");
printf("desync on frame %d \n",frameCounter);
fluid_sim_cellular_test_diagnose_desync(queue);
break;
}
// printf("\n");
env->state.frame++;
}
//solve bounds afterwards to properly push data back into real arrays
//ie, if data is pushed out of bounds from one chunk to another, must
//then copy it into the in-bounds chunk
fluid_solve_bounds(chunkCount,queue,env);
//check sum beforehand
float afterSum = chunk_queue_sum(queue);
//diff the sums to see if we've changed value a lot
float delta = fabs(originalSum - afterSum);
if(delta > TOLLERABLE_LOSS_THRESHOLD){
rVal += assertEqualsFloat(originalSum,afterSum,"cellular sim was unstable! %f %f \n");
}
printf("\n");
return rVal;
}
int fluid_sim_cellular_stability_test8(){
int rVal = 0;
printf("fluid_sim_cellular_stability_test8\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_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
));
}
//link neighbors
chunk_link_neighbors(queue);
//fill them with values
for(int i = 0; i < chunkCount; i++){
chunk_fill(queue[i],0);
}
//fill the 10th chunk
fluid_sim_cellular_test_get_chunk(queue,1,1,1)->d[CENTER_LOC][IX(1,1,1)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,0,1,1)->d[CENTER_LOC][IX(DIM-2,1,1)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,1,0,1)->d[CENTER_LOC][IX(1,DIM-2,1)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,1,1,0)->d[CENTER_LOC][IX(1,1,DIM-2)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,1,0,0)->d[CENTER_LOC][IX(1,DIM-2,DIM-2)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,0,1,0)->d[CENTER_LOC][IX(DIM-2,1,DIM-2)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,0,0,1)->d[CENTER_LOC][IX(DIM-2,DIM-2,1)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,0,0,0)->d[CENTER_LOC][IX(DIM-2,DIM-2,DIM-2)] = MAX_FLUID_VALUE;
//check sum beforehand
float originalSum = chunk_queue_sum(queue);
//dispatch and simulate
int frameCount = 100;
int frameCounter;
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum(queue);
float delta = fabs(originalSum - currentSum);
if(delta > TOLLERABLE_LOSS_THRESHOLD2){
printf("Failed to equal sums! \n");
rVal += assertEqualsFloat(currentSum,originalSum,"Sums are not identical! %f %f \n");
printf("desync by frame %d \n",frameCounter);
fluid_sim_cellular_test_diagnose_desync(queue);
break;
}
// printf("frame: %d --- %f \n", frameCounter,currentSum);
fluid_solve_bounds(chunkCount,queue,env);
fluid_dispatch(chunkCount,queue,env);
fluid_simulate(env);
fluid_solve_bounds(chunkCount,queue,env);
// printf("\n");
env->state.frame++;
}
//solve bounds afterwards to properly push data back into real arrays
//ie, if data is pushed out of bounds from one chunk to another, must
//then copy it into the in-bounds chunk
fluid_solve_bounds(chunkCount,queue,env);
//check sum beforehand
float afterSum = chunk_queue_sum(queue);
//diff the sums to see if we've changed value a lot
float delta = fabs(originalSum - afterSum);
if(delta > TOLLERABLE_LOSS_THRESHOLD){
rVal += assertEqualsFloat(originalSum,afterSum,"cellular sim was unstable! %f %f \n");
}
printf("\n");
return rVal;
}
int fluid_sim_cellular_stability_test9(){
int rVal = 0;
printf("fluid_sim_cellular_stability_test9\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_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
));
}
//link neighbors
chunk_link_neighbors(queue);
//fill them with values
for(int i = 0; i < chunkCount; i++){
chunk_fill(queue[i],0);
}
//fill the 10th chunk
fluid_sim_cellular_test_get_chunk(queue,1,2,1)->d[CENTER_LOC][IX(1,1,1)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,0,2,1)->d[CENTER_LOC][IX(DIM-2,1,1)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,1,1,1)->d[CENTER_LOC][IX(1,DIM-2,1)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,1,2,0)->d[CENTER_LOC][IX(1,1,DIM-2)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,1,1,0)->d[CENTER_LOC][IX(1,DIM-2,DIM-2)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,0,2,0)->d[CENTER_LOC][IX(DIM-2,1,DIM-2)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,0,1,1)->d[CENTER_LOC][IX(DIM-2,DIM-2,1)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,0,1,0)->d[CENTER_LOC][IX(DIM-2,DIM-2,DIM-2)] = MAX_FLUID_VALUE;
//check sum beforehand
float originalSum = chunk_queue_sum(queue);
//dispatch and simulate
int frameCount = 100;
int frameCounter;
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum(queue);
float delta = fabs(originalSum - currentSum);
if(delta > TOLLERABLE_LOSS_THRESHOLD2){
printf("Failed to equal sums! \n");
rVal += assertEqualsFloat(currentSum,originalSum,"Sums are not identical! %f %f \n");
printf("desync by frame %d \n",frameCounter);
fluid_sim_cellular_test_diagnose_desync(queue);
break;
}
// printf("frame: %d --- %f \n", frameCounter,currentSum);
fluid_solve_bounds(chunkCount,queue,env);
fluid_dispatch(chunkCount,queue,env);
fluid_simulate(env);
fluid_solve_bounds(chunkCount,queue,env);
// printf("\n");
env->state.frame++;
}
//solve bounds afterwards to properly push data back into real arrays
//ie, if data is pushed out of bounds from one chunk to another, must
//then copy it into the in-bounds chunk
fluid_solve_bounds(chunkCount,queue,env);
//check sum beforehand
float afterSum = chunk_queue_sum(queue);
//diff the sums to see if we've changed value a lot
float delta = fabs(originalSum - afterSum);
if(delta > TOLLERABLE_LOSS_THRESHOLD){
rVal += assertEqualsFloat(originalSum,afterSum,"cellular sim was unstable! %f %f \n");
}
printf("\n");
return rVal;
}
int fluid_sim_cellular_stability_test10(){
int rVal = 0;
printf("fluid_sim_cellular_stability_test10\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_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
));
}
//link neighbors
chunk_link_neighbors(queue);
//fill them with values
for(int i = 0; i < chunkCount; i++){
chunk_fill(queue[i],0);
}
//fill the 10th chunk
fluid_sim_cellular_test_get_chunk(queue,2,2,2)->d[CENTER_LOC][IX(1,1,1)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,1,2,2)->d[CENTER_LOC][IX(DIM-2,1,1)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,2,1,2)->d[CENTER_LOC][IX(1,DIM-2,1)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,2,2,1)->d[CENTER_LOC][IX(1,1,DIM-2)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,2,1,1)->d[CENTER_LOC][IX(1,DIM-2,DIM-2)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,1,2,1)->d[CENTER_LOC][IX(DIM-2,1,DIM-2)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,1,1,2)->d[CENTER_LOC][IX(DIM-2,DIM-2,1)] = MAX_FLUID_VALUE;
fluid_sim_cellular_test_get_chunk(queue,1,1,1)->d[CENTER_LOC][IX(DIM-2,DIM-2,DIM-2)] = MAX_FLUID_VALUE;
//check sum beforehand
float originalSum = chunk_queue_sum(queue);
//dispatch and simulate
int frameCount = 100;
int frameCounter;
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum(queue);
float delta = fabs(originalSum - currentSum);
if(delta > TOLLERABLE_LOSS_THRESHOLD2){
printf("Failed to equal sums! \n");
rVal += assertEqualsFloat(currentSum,originalSum,"Sums are not identical! %f %f \n");
printf("desync by frame %d \n",frameCounter);
fluid_sim_cellular_test_diagnose_desync(queue);
break;
}
// printf("frame: %d --- %f \n", frameCounter,currentSum);
fluid_solve_bounds(chunkCount,queue,env);
fluid_dispatch(chunkCount,queue,env);
fluid_simulate(env);
fluid_solve_bounds(chunkCount,queue,env);
// printf("\n");
env->state.frame++;
}
//solve bounds afterwards to properly push data back into real arrays
//ie, if data is pushed out of bounds from one chunk to another, must
//then copy it into the in-bounds chunk
fluid_solve_bounds(chunkCount,queue,env);
//check sum beforehand
float afterSum = chunk_queue_sum(queue);
//diff the sums to see if we've changed value a lot
float delta = fabs(originalSum - afterSum);
if(delta > TOLLERABLE_LOSS_THRESHOLD){
rVal += assertEqualsFloat(originalSum,afterSum,"cellular sim was unstable! %f %f \n");
}
printf("\n");
return rVal;
}
int fluid_sim_cellular_stability_test_full_chunk(){
int rVal = 0;
printf("fluid_sim_cellular_stability_test_full_chunk\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_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
));
}
//link neighbors
chunk_link_neighbors(queue);
//fill them with values
for(int i = 0; i < chunkCount; i++){
chunk_fill(queue[i],0);
}
//fill the 10th chunk //fill the 10th chunk
chunk_fill_real(queue[10]->d[CENTER_LOC],CELLULAR_TEST_PLACE_VAL); chunk_fill_real(queue[10]->d[CENTER_LOC],CELLULAR_TEST_PLACE_VAL);
@ -379,7 +1149,15 @@ int fluid_sim_cellular_cellular_tests(int argc, char **argv){
// rVal += fluid_sim_cellular_bounds_test2(); // rVal += fluid_sim_cellular_bounds_test2();
rVal += fluid_sim_cellular_stability_test1(); rVal += fluid_sim_cellular_stability_test1();
rVal += fluid_sim_cellular_stability_test2(); rVal += fluid_sim_cellular_stability_test2();
// rVal += fluid_sim_cellular_stability_test3(); rVal += fluid_sim_cellular_stability_test3();
rVal += fluid_sim_cellular_stability_test4();
rVal += fluid_sim_cellular_stability_test5();
rVal += fluid_sim_cellular_stability_test6();
// rVal += fluid_sim_cellular_stability_test7();
rVal += fluid_sim_cellular_stability_test8();
rVal += fluid_sim_cellular_stability_test9();
rVal += fluid_sim_cellular_stability_test10();
// rVal += fluid_sim_cellular_stability_test_full_chunk();
return rVal; return rVal;
} }