velocity diffusion testing
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
2a2eeca701
commit
08177bebed
@ -6,7 +6,14 @@
|
|||||||
#ifndef CHUNK_H
|
#ifndef CHUNK_H
|
||||||
#define CHUNK_H
|
#define CHUNK_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The minimum fluid value
|
||||||
|
*/
|
||||||
#define MIN_FLUID_VALUE 0.0f
|
#define MIN_FLUID_VALUE 0.0f
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum fluid value
|
||||||
|
*/
|
||||||
#define MAX_FLUID_VALUE 1.0f
|
#define MAX_FLUID_VALUE 1.0f
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -24,13 +24,6 @@ LIBRARY_API void fluid_grid2_setBoundsToNeighborsRaw(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sums the density of the chunk
|
* Sums the density of the chunk
|
||||||
*/
|
*/
|
||||||
@ -38,6 +31,10 @@ double fluid_grid2_calculateSum(float ** d);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flips two array matricies
|
||||||
|
*/
|
||||||
|
LIBRARY_API void fluid_grid2_flip_arrays(float ** array1, float ** array2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -117,7 +117,7 @@ void fluid_grid2_advect_velocity(int b, float ** jrd, float ** jrd0, float * u,
|
|||||||
/*
|
/*
|
||||||
* Solves vector diffusion along all axis
|
* Solves vector diffusion along all axis
|
||||||
*/
|
*/
|
||||||
void fluid_grid2_solveVectorDiffuse (
|
LIBRARY_API void fluid_grid2_solveVectorDiffuse (
|
||||||
float ** jru,
|
float ** jru,
|
||||||
float ** jrv,
|
float ** jrv,
|
||||||
float ** jrw,
|
float ** jrw,
|
||||||
|
|||||||
@ -91,4 +91,15 @@ double fluid_grid2_calculateSum(float ** d){
|
|||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flips two array matricies
|
||||||
|
*/
|
||||||
|
LIBRARY_API void fluid_grid2_flip_arrays(float ** array1, float ** array2){
|
||||||
|
float * tmpArr;
|
||||||
|
for(int j = 0; j < 27; j++){
|
||||||
|
tmpArr = array1[j];
|
||||||
|
array1[j] = array2[j];
|
||||||
|
array2[j] = tmpArr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,7 @@ void fluid_grid2_addSourceToVectors
|
|||||||
/*
|
/*
|
||||||
* Solves vector diffusion along all axis
|
* Solves vector diffusion along all axis
|
||||||
*/
|
*/
|
||||||
void fluid_grid2_solveVectorDiffuse (
|
LIBRARY_API void fluid_grid2_solveVectorDiffuse (
|
||||||
float ** jru,
|
float ** jru,
|
||||||
float ** jrv,
|
float ** jrv,
|
||||||
float ** jrw,
|
float ** jrw,
|
||||||
|
|||||||
@ -394,13 +394,13 @@ int fluid_sim_cellular_stability_test1(){
|
|||||||
queue[1]->d[CENTER_LOC][IX(1,1,1)] = CELLULAR_TEST_PLACE_VAL;
|
queue[1]->d[CENTER_LOC][IX(1,1,1)] = CELLULAR_TEST_PLACE_VAL;
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float originalSum = chunk_queue_sum(queue);
|
float originalSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
|
|
||||||
//dispatch and simulate
|
//dispatch and simulate
|
||||||
int frameCount = 100;
|
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_density(queue);
|
||||||
if(currentSum != originalSum){
|
if(currentSum != originalSum){
|
||||||
printf("Failed to equal sums! \n");
|
printf("Failed to equal sums! \n");
|
||||||
rVal += assertEqualsFloat(currentSum,originalSum,"Sums are not identical! %f %f \n");
|
rVal += assertEqualsFloat(currentSum,originalSum,"Sums are not identical! %f %f \n");
|
||||||
@ -424,7 +424,7 @@ int fluid_sim_cellular_stability_test1(){
|
|||||||
// printf("transfered value: %f \n",transferedValue);
|
// printf("transfered value: %f \n",transferedValue);
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float afterSum = chunk_queue_sum(queue);
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
rVal += assertEqualsFloat(originalSum,afterSum,"cellular sim was unstable! %f %f \n");
|
rVal += assertEqualsFloat(originalSum,afterSum,"cellular sim was unstable! %f %f \n");
|
||||||
|
|
||||||
@ -463,13 +463,13 @@ int fluid_sim_cellular_stability_test2(){
|
|||||||
queue[13]->d[CENTER_LOC][IX(5,5,5)] = CELLULAR_TEST_PLACE_VAL;
|
queue[13]->d[CENTER_LOC][IX(5,5,5)] = CELLULAR_TEST_PLACE_VAL;
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float originalSum = chunk_queue_sum(queue);
|
float originalSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
|
|
||||||
//dispatch and simulate
|
//dispatch and simulate
|
||||||
int frameCount = 100;
|
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_density(queue);
|
||||||
if(currentSum != originalSum){
|
if(currentSum != originalSum){
|
||||||
printf("Failed to equal sums! \n");
|
printf("Failed to equal sums! \n");
|
||||||
rVal += assertEqualsFloat(currentSum,originalSum,"Sums are not identical! %f %f \n");
|
rVal += assertEqualsFloat(currentSum,originalSum,"Sums are not identical! %f %f \n");
|
||||||
@ -493,7 +493,7 @@ int fluid_sim_cellular_stability_test2(){
|
|||||||
// printf("transfered value: %f \n",transferedValue);
|
// printf("transfered value: %f \n",transferedValue);
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float afterSum = chunk_queue_sum(queue);
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
rVal += assertEqualsFloat(originalSum,afterSum,"cellular sim was unstable! %f %f \n");
|
rVal += assertEqualsFloat(originalSum,afterSum,"cellular sim was unstable! %f %f \n");
|
||||||
|
|
||||||
@ -532,13 +532,13 @@ int fluid_sim_cellular_stability_test3(){
|
|||||||
queue[13]->d[CENTER_LOC][IX(5,5,5)] = MAX_FLUID_VALUE;
|
queue[13]->d[CENTER_LOC][IX(5,5,5)] = MAX_FLUID_VALUE;
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float originalSum = chunk_queue_sum(queue);
|
float originalSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//dispatch and simulate
|
//dispatch and simulate
|
||||||
int frameCount = 100;
|
int frameCount = 100;
|
||||||
int frameCounter;
|
int frameCounter;
|
||||||
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
||||||
float currentSum = chunk_queue_sum(queue);
|
float currentSum = chunk_queue_sum_density(queue);
|
||||||
float delta = fabs(originalSum - currentSum);
|
float delta = fabs(originalSum - currentSum);
|
||||||
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD2){
|
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD2){
|
||||||
printf("Failed to equal sums! \n");
|
printf("Failed to equal sums! \n");
|
||||||
@ -562,7 +562,7 @@ int fluid_sim_cellular_stability_test3(){
|
|||||||
fluid_solve_bounds(chunkCount,queue,env);
|
fluid_solve_bounds(chunkCount,queue,env);
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float afterSum = chunk_queue_sum(queue);
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//diff the sums to see if we've changed value a lot
|
//diff the sums to see if we've changed value a lot
|
||||||
float delta = fabs(originalSum - afterSum);
|
float delta = fabs(originalSum - afterSum);
|
||||||
@ -603,13 +603,13 @@ int fluid_sim_cellular_stability_test4(){
|
|||||||
queue[13]->d[CENTER_LOC][IX(1,1,1)] = MAX_FLUID_VALUE;
|
queue[13]->d[CENTER_LOC][IX(1,1,1)] = MAX_FLUID_VALUE;
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float originalSum = chunk_queue_sum(queue);
|
float originalSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//dispatch and simulate
|
//dispatch and simulate
|
||||||
int frameCount = 100;
|
int frameCount = 100;
|
||||||
int frameCounter;
|
int frameCounter;
|
||||||
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
||||||
float currentSum = chunk_queue_sum(queue);
|
float currentSum = chunk_queue_sum_density(queue);
|
||||||
float delta = fabs(originalSum - currentSum);
|
float delta = fabs(originalSum - currentSum);
|
||||||
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD2){
|
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD2){
|
||||||
printf("Failed to equal sums! \n");
|
printf("Failed to equal sums! \n");
|
||||||
@ -633,7 +633,7 @@ int fluid_sim_cellular_stability_test4(){
|
|||||||
fluid_solve_bounds(chunkCount,queue,env);
|
fluid_solve_bounds(chunkCount,queue,env);
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float afterSum = chunk_queue_sum(queue);
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//diff the sums to see if we've changed value a lot
|
//diff the sums to see if we've changed value a lot
|
||||||
float delta = fabs(originalSum - afterSum);
|
float delta = fabs(originalSum - afterSum);
|
||||||
@ -681,13 +681,13 @@ int fluid_sim_cellular_stability_test5(){
|
|||||||
queue[13]->d[CENTER_LOC][IX(DIM-2,DIM-2,DIM-2)] = MAX_FLUID_VALUE;
|
queue[13]->d[CENTER_LOC][IX(DIM-2,DIM-2,DIM-2)] = MAX_FLUID_VALUE;
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float originalSum = chunk_queue_sum(queue);
|
float originalSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//dispatch and simulate
|
//dispatch and simulate
|
||||||
int frameCount = 100;
|
int frameCount = 100;
|
||||||
int frameCounter;
|
int frameCounter;
|
||||||
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
||||||
float currentSum = chunk_queue_sum(queue);
|
float currentSum = chunk_queue_sum_density(queue);
|
||||||
float delta = fabs(originalSum - currentSum);
|
float delta = fabs(originalSum - currentSum);
|
||||||
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD2){
|
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD2){
|
||||||
printf("Failed to equal sums! \n");
|
printf("Failed to equal sums! \n");
|
||||||
@ -711,7 +711,7 @@ int fluid_sim_cellular_stability_test5(){
|
|||||||
fluid_solve_bounds(chunkCount,queue,env);
|
fluid_solve_bounds(chunkCount,queue,env);
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float afterSum = chunk_queue_sum(queue);
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//diff the sums to see if we've changed value a lot
|
//diff the sums to see if we've changed value a lot
|
||||||
float delta = fabs(originalSum - afterSum);
|
float delta = fabs(originalSum - afterSum);
|
||||||
@ -759,13 +759,13 @@ int fluid_sim_cellular_stability_test6(){
|
|||||||
queue[13]->d[CENTER_LOC][IX(2,2,2)] = MAX_FLUID_VALUE;
|
queue[13]->d[CENTER_LOC][IX(2,2,2)] = MAX_FLUID_VALUE;
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float originalSum = chunk_queue_sum(queue);
|
float originalSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//dispatch and simulate
|
//dispatch and simulate
|
||||||
int frameCount = 100;
|
int frameCount = 100;
|
||||||
int frameCounter;
|
int frameCounter;
|
||||||
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
||||||
float currentSum = chunk_queue_sum(queue);
|
float currentSum = chunk_queue_sum_density(queue);
|
||||||
float delta = fabs(originalSum - currentSum);
|
float delta = fabs(originalSum - currentSum);
|
||||||
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD2){
|
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD2){
|
||||||
printf("Failed to equal sums! \n");
|
printf("Failed to equal sums! \n");
|
||||||
@ -789,7 +789,7 @@ int fluid_sim_cellular_stability_test6(){
|
|||||||
fluid_solve_bounds(chunkCount,queue,env);
|
fluid_solve_bounds(chunkCount,queue,env);
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float afterSum = chunk_queue_sum(queue);
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//diff the sums to see if we've changed value a lot
|
//diff the sums to see if we've changed value a lot
|
||||||
float delta = fabs(originalSum - afterSum);
|
float delta = fabs(originalSum - afterSum);
|
||||||
@ -838,19 +838,19 @@ int fluid_sim_cellular_stability_test7(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float originalSum = chunk_queue_sum(queue);
|
float originalSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//dispatch and simulate
|
//dispatch and simulate
|
||||||
int frameCount = 1000;
|
int frameCount = 1000;
|
||||||
int frameCounter;
|
int frameCounter;
|
||||||
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
||||||
float currentSum = chunk_queue_sum(queue);
|
float currentSum = chunk_queue_sum_density(queue);
|
||||||
// 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_DISPATCHER_OVERRIDE_CELLULAR);
|
fluid_dispatch(chunkCount,queue,env,FLUID_DISPATCHER_OVERRIDE_CELLULAR);
|
||||||
fluid_simulate(env);
|
fluid_simulate(env);
|
||||||
fluid_solve_bounds(chunkCount,queue,env);
|
fluid_solve_bounds(chunkCount,queue,env);
|
||||||
float postSum = chunk_queue_sum(queue);
|
float postSum = chunk_queue_sum_density(queue);
|
||||||
float delta = fabs(originalSum - postSum);
|
float delta = fabs(originalSum - postSum);
|
||||||
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD1){
|
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD1){
|
||||||
printf("Failed to equal sums! \n");
|
printf("Failed to equal sums! \n");
|
||||||
@ -869,7 +869,7 @@ int fluid_sim_cellular_stability_test7(){
|
|||||||
fluid_solve_bounds(chunkCount,queue,env);
|
fluid_solve_bounds(chunkCount,queue,env);
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float afterSum = chunk_queue_sum(queue);
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//diff the sums to see if we've changed value a lot
|
//diff the sums to see if we've changed value a lot
|
||||||
float delta = fabs(originalSum - afterSum);
|
float delta = fabs(originalSum - afterSum);
|
||||||
@ -917,13 +917,13 @@ int fluid_sim_cellular_stability_test8(){
|
|||||||
fluid_sim_cellular_test_get_chunk(queue,0,0,0)->d[CENTER_LOC][IX(DIM-2,DIM-2,DIM-2)] = 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
|
//check sum beforehand
|
||||||
float originalSum = chunk_queue_sum(queue);
|
float originalSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//dispatch and simulate
|
//dispatch and simulate
|
||||||
int frameCount = 100;
|
int frameCount = 100;
|
||||||
int frameCounter;
|
int frameCounter;
|
||||||
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
||||||
float currentSum = chunk_queue_sum(queue);
|
float currentSum = chunk_queue_sum_density(queue);
|
||||||
float delta = fabs(originalSum - currentSum);
|
float delta = fabs(originalSum - currentSum);
|
||||||
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD2){
|
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD2){
|
||||||
printf("Failed to equal sums! \n");
|
printf("Failed to equal sums! \n");
|
||||||
@ -947,7 +947,7 @@ int fluid_sim_cellular_stability_test8(){
|
|||||||
fluid_solve_bounds(chunkCount,queue,env);
|
fluid_solve_bounds(chunkCount,queue,env);
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float afterSum = chunk_queue_sum(queue);
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//diff the sums to see if we've changed value a lot
|
//diff the sums to see if we've changed value a lot
|
||||||
float delta = fabs(originalSum - afterSum);
|
float delta = fabs(originalSum - afterSum);
|
||||||
@ -996,13 +996,13 @@ int fluid_sim_cellular_stability_test9(){
|
|||||||
fluid_sim_cellular_test_get_chunk(queue,0,1,0)->d[CENTER_LOC][IX(DIM-2,DIM-2,DIM-2)] = 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
|
//check sum beforehand
|
||||||
float originalSum = chunk_queue_sum(queue);
|
float originalSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//dispatch and simulate
|
//dispatch and simulate
|
||||||
int frameCount = 100;
|
int frameCount = 100;
|
||||||
int frameCounter;
|
int frameCounter;
|
||||||
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
||||||
float currentSum = chunk_queue_sum(queue);
|
float currentSum = chunk_queue_sum_density(queue);
|
||||||
float delta = fabs(originalSum - currentSum);
|
float delta = fabs(originalSum - currentSum);
|
||||||
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD2){
|
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD2){
|
||||||
printf("Failed to equal sums! \n");
|
printf("Failed to equal sums! \n");
|
||||||
@ -1026,7 +1026,7 @@ int fluid_sim_cellular_stability_test9(){
|
|||||||
fluid_solve_bounds(chunkCount,queue,env);
|
fluid_solve_bounds(chunkCount,queue,env);
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float afterSum = chunk_queue_sum(queue);
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//diff the sums to see if we've changed value a lot
|
//diff the sums to see if we've changed value a lot
|
||||||
float delta = fabs(originalSum - afterSum);
|
float delta = fabs(originalSum - afterSum);
|
||||||
@ -1074,13 +1074,13 @@ int fluid_sim_cellular_stability_test10(){
|
|||||||
fluid_sim_cellular_test_get_chunk(queue,1,1,1)->d[CENTER_LOC][IX(DIM-2,DIM-2,DIM-2)] = 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
|
//check sum beforehand
|
||||||
float originalSum = chunk_queue_sum(queue);
|
float originalSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//dispatch and simulate
|
//dispatch and simulate
|
||||||
int frameCount = 100;
|
int frameCount = 100;
|
||||||
int frameCounter;
|
int frameCounter;
|
||||||
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
||||||
float currentSum = chunk_queue_sum(queue);
|
float currentSum = chunk_queue_sum_density(queue);
|
||||||
float delta = fabs(originalSum - currentSum);
|
float delta = fabs(originalSum - currentSum);
|
||||||
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD2){
|
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD2){
|
||||||
printf("Failed to equal sums! \n");
|
printf("Failed to equal sums! \n");
|
||||||
@ -1104,7 +1104,7 @@ int fluid_sim_cellular_stability_test10(){
|
|||||||
fluid_solve_bounds(chunkCount,queue,env);
|
fluid_solve_bounds(chunkCount,queue,env);
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float afterSum = chunk_queue_sum(queue);
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//diff the sums to see if we've changed value a lot
|
//diff the sums to see if we've changed value a lot
|
||||||
float delta = fabs(originalSum - afterSum);
|
float delta = fabs(originalSum - afterSum);
|
||||||
@ -1145,13 +1145,13 @@ int fluid_sim_cellular_stability_test11(){
|
|||||||
chunk_fill_real(queue[10]->d[CENTER_LOC],CELLULAR_TEST_PLACE_VAL);
|
chunk_fill_real(queue[10]->d[CENTER_LOC],CELLULAR_TEST_PLACE_VAL);
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float originalSum = chunk_queue_sum(queue);
|
float originalSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//dispatch and simulate
|
//dispatch and simulate
|
||||||
int frameCount = 1000;
|
int frameCount = 1000;
|
||||||
int frameCounter;
|
int frameCounter;
|
||||||
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
||||||
float currentSum = chunk_queue_sum(queue);
|
float currentSum = chunk_queue_sum_density(queue);
|
||||||
float delta = fabs(originalSum - currentSum);
|
float delta = fabs(originalSum - currentSum);
|
||||||
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD1){
|
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD1){
|
||||||
printf("Failed to equal sums! \n");
|
printf("Failed to equal sums! \n");
|
||||||
@ -1174,7 +1174,7 @@ int fluid_sim_cellular_stability_test11(){
|
|||||||
fluid_solve_bounds(chunkCount,queue,env);
|
fluid_solve_bounds(chunkCount,queue,env);
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float afterSum = chunk_queue_sum(queue);
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//diff the sums to see if we've changed value a lot
|
//diff the sums to see if we've changed value a lot
|
||||||
float delta = fabs(originalSum - afterSum);
|
float delta = fabs(originalSum - afterSum);
|
||||||
@ -1219,13 +1219,13 @@ int fluid_sim_cellular_stability_test12(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float originalSum = chunk_queue_sum(queue);
|
float originalSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//dispatch and simulate
|
//dispatch and simulate
|
||||||
int frameCount = 1000;
|
int frameCount = 1000;
|
||||||
int frameCounter;
|
int frameCounter;
|
||||||
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
||||||
float currentSum = chunk_queue_sum(queue);
|
float currentSum = chunk_queue_sum_density(queue);
|
||||||
float delta = fabs(originalSum - currentSum);
|
float delta = fabs(originalSum - currentSum);
|
||||||
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD1){
|
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD1){
|
||||||
printf("Failed to equal sums! \n");
|
printf("Failed to equal sums! \n");
|
||||||
@ -1248,7 +1248,7 @@ int fluid_sim_cellular_stability_test12(){
|
|||||||
fluid_solve_bounds(chunkCount,queue,env);
|
fluid_solve_bounds(chunkCount,queue,env);
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float afterSum = chunk_queue_sum(queue);
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//diff the sums to see if we've changed value a lot
|
//diff the sums to see if we've changed value a lot
|
||||||
float delta = fabs(originalSum - afterSum);
|
float delta = fabs(originalSum - afterSum);
|
||||||
@ -1298,13 +1298,13 @@ int fluid_sim_cellular_stability_test13(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float originalSum = chunk_queue_sum(queue);
|
float originalSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//dispatch and simulate
|
//dispatch and simulate
|
||||||
int frameCount = 1000;
|
int frameCount = 1000;
|
||||||
int frameCounter;
|
int frameCounter;
|
||||||
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
||||||
float currentSum = chunk_queue_sum(queue);
|
float currentSum = chunk_queue_sum_density(queue);
|
||||||
float delta = fabs(originalSum - currentSum);
|
float delta = fabs(originalSum - currentSum);
|
||||||
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD1){
|
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD1){
|
||||||
printf("Failed to equal sums! \n");
|
printf("Failed to equal sums! \n");
|
||||||
@ -1327,7 +1327,7 @@ int fluid_sim_cellular_stability_test13(){
|
|||||||
fluid_solve_bounds(chunkCount,queue,env);
|
fluid_solve_bounds(chunkCount,queue,env);
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float afterSum = chunk_queue_sum(queue);
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//diff the sums to see if we've changed value a lot
|
//diff the sums to see if we've changed value a lot
|
||||||
float delta = fabs(originalSum - afterSum);
|
float delta = fabs(originalSum - afterSum);
|
||||||
@ -1377,7 +1377,7 @@ int fluid_sim_cellular_stability_test14(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float originalSum = chunk_queue_sum(queue);
|
float originalSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
float slice[16 * 3][16 * 3];
|
float slice[16 * 3][16 * 3];
|
||||||
int compareX = 2;
|
int compareX = 2;
|
||||||
@ -1387,7 +1387,7 @@ int fluid_sim_cellular_stability_test14(){
|
|||||||
int frameCount = 1000;
|
int frameCount = 1000;
|
||||||
int frameCounter;
|
int frameCounter;
|
||||||
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
||||||
float currentSum = chunk_queue_sum(queue);
|
float currentSum = chunk_queue_sum_density(queue);
|
||||||
float delta = fabs(originalSum - currentSum);
|
float delta = fabs(originalSum - currentSum);
|
||||||
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD1){
|
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD1){
|
||||||
fluid_sim_cellular_test_print_slice_big_vis(queue,1);
|
fluid_sim_cellular_test_print_slice_big_vis(queue,1);
|
||||||
@ -1410,7 +1410,7 @@ int fluid_sim_cellular_stability_test14(){
|
|||||||
fluid_solve_bounds(chunkCount,queue,env);
|
fluid_solve_bounds(chunkCount,queue,env);
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float afterSum = chunk_queue_sum(queue);
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//diff the sums to see if we've changed value a lot
|
//diff the sums to see if we've changed value a lot
|
||||||
float delta = fabs(originalSum - afterSum);
|
float delta = fabs(originalSum - afterSum);
|
||||||
@ -1461,7 +1461,7 @@ int fluid_sim_cellular_stability_test15(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float originalSum = chunk_queue_sum(queue);
|
float originalSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
float slice[16 * 3][16 * 3];
|
float slice[16 * 3][16 * 3];
|
||||||
int compareX = 2;
|
int compareX = 2;
|
||||||
@ -1471,7 +1471,7 @@ int fluid_sim_cellular_stability_test15(){
|
|||||||
int frameCount = 100;
|
int frameCount = 100;
|
||||||
int frameCounter;
|
int frameCounter;
|
||||||
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
||||||
float currentSum = chunk_queue_sum(queue);
|
float currentSum = chunk_queue_sum_density(queue);
|
||||||
float delta = fabs(originalSum - currentSum);
|
float delta = fabs(originalSum - currentSum);
|
||||||
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD1){
|
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD1){
|
||||||
printf("SLICE 1\n\n");
|
printf("SLICE 1\n\n");
|
||||||
@ -1498,7 +1498,7 @@ int fluid_sim_cellular_stability_test15(){
|
|||||||
fluid_solve_bounds(chunkCount,queue,env);
|
fluid_solve_bounds(chunkCount,queue,env);
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float afterSum = chunk_queue_sum(queue);
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//diff the sums to see if we've changed value a lot
|
//diff the sums to see if we've changed value a lot
|
||||||
float delta = fabs(originalSum - afterSum);
|
float delta = fabs(originalSum - afterSum);
|
||||||
@ -1548,7 +1548,7 @@ int fluid_sim_cellular_stability_test16(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float originalSum = chunk_queue_sum(queue);
|
float originalSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
float slice[16 * 3][16 * 3];
|
float slice[16 * 3][16 * 3];
|
||||||
int compareX = 2;
|
int compareX = 2;
|
||||||
@ -1558,7 +1558,7 @@ int fluid_sim_cellular_stability_test16(){
|
|||||||
int frameCount = 1000;
|
int frameCount = 1000;
|
||||||
int frameCounter;
|
int frameCounter;
|
||||||
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
|
||||||
float currentSum = chunk_queue_sum(queue);
|
float currentSum = chunk_queue_sum_density(queue);
|
||||||
float delta = fabs(originalSum - currentSum);
|
float delta = fabs(originalSum - currentSum);
|
||||||
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD1){
|
if(delta > FLUID_CELLULAR_TOLLERABLE_LOSS_THRESHOLD1){
|
||||||
fluid_sim_cellular_test_print_slice_big_vis(queue,1);
|
fluid_sim_cellular_test_print_slice_big_vis(queue,1);
|
||||||
@ -1581,7 +1581,7 @@ int fluid_sim_cellular_stability_test16(){
|
|||||||
fluid_solve_bounds(chunkCount,queue,env);
|
fluid_solve_bounds(chunkCount,queue,env);
|
||||||
|
|
||||||
//check sum beforehand
|
//check sum beforehand
|
||||||
float afterSum = chunk_queue_sum(queue);
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
//diff the sums to see if we've changed value a lot
|
//diff the sums to see if we've changed value a lot
|
||||||
float delta = fabs(originalSum - afterSum);
|
float delta = fabs(originalSum - afterSum);
|
||||||
|
|||||||
@ -87,7 +87,66 @@ int fluid_sim_grid2_density_diffuse_test1(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//sum the result
|
//sum the result
|
||||||
float afterSum = chunk_queue_sum(queue);
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
|
rVal += assertEqualsFloat(afterSum,MAX_FLUID_VALUE,"Density diffuse step changed density sum! %f %f \n");
|
||||||
|
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing density diffusion
|
||||||
|
*/
|
||||||
|
int fluid_sim_grid2_density_diffuse_test2(){
|
||||||
|
int rVal = 0;
|
||||||
|
printf("fluid_sim_grid2_density_diffuse_test2\n");
|
||||||
|
Environment * env = fluid_environment_create();
|
||||||
|
int chunkCount = 27;
|
||||||
|
|
||||||
|
Chunk ** queue = NULL;
|
||||||
|
for(int i = 0; i < chunkCount; i++){
|
||||||
|
arrput(queue,chunk_create(
|
||||||
|
fluid_sim_grid2_density_diffuse_tests_kernelx[i],
|
||||||
|
fluid_sim_grid2_density_diffuse_tests_kernely[i],
|
||||||
|
fluid_sim_grid2_density_diffuse_tests_kernelz[i]
|
||||||
|
));
|
||||||
|
chunk_fill(queue[i],0);
|
||||||
|
}
|
||||||
|
//link neighbors
|
||||||
|
chunk_link_neighbors(queue);
|
||||||
|
fluid_solve_bounds(1,queue,env);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Chunk * currentChunk = queue[0];
|
||||||
|
currentChunk->d[CENTER_LOC][IX(2,2,2)] = MAX_FLUID_VALUE;
|
||||||
|
|
||||||
|
int frameCount = 100;
|
||||||
|
for(int frame = 0; frame < frameCount; frame++){
|
||||||
|
float * tmpArr;
|
||||||
|
for(int j = 0; j < 27; j++){
|
||||||
|
tmpArr = currentChunk->d[j];
|
||||||
|
currentChunk->d[j] = currentChunk->d0[j];
|
||||||
|
currentChunk->d0[j] = tmpArr;
|
||||||
|
}
|
||||||
|
//diffuse density
|
||||||
|
for(int l = 0; l < FLUID_GRID2_LINEARSOLVERTIMES; l++){
|
||||||
|
fluid_grid2_solveDiffuseDensity(currentChunk->d,currentChunk->d0,FLUID_GRID2_DIFFUSION_CONSTANT,FLUID_GRID2_SIM_STEP);
|
||||||
|
fluid_grid2_setBoundsToNeighborsRaw(currentChunk->chunkMask,0,currentChunk->d);
|
||||||
|
}
|
||||||
|
//swap all density arrays
|
||||||
|
//swap vector fields
|
||||||
|
for(int j = 0; j < 27; j++){
|
||||||
|
tmpArr = currentChunk->d[j];
|
||||||
|
currentChunk->d[j] = currentChunk->d0[j];
|
||||||
|
currentChunk->d0[j] = tmpArr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//sum the result
|
||||||
|
float afterSum = chunk_queue_sum_density(queue);
|
||||||
|
|
||||||
rVal += assertEqualsFloat(afterSum,MAX_FLUID_VALUE,"Density diffuse step changed density sum! %f %f \n");
|
rVal += assertEqualsFloat(afterSum,MAX_FLUID_VALUE,"Density diffuse step changed density sum! %f %f \n");
|
||||||
|
|
||||||
@ -103,6 +162,7 @@ int fluid_sim_grid2_density_diffuse_tests(int argc, char **argv){
|
|||||||
int rVal = 0;
|
int rVal = 0;
|
||||||
|
|
||||||
rVal += fluid_sim_grid2_density_diffuse_test1();
|
rVal += fluid_sim_grid2_density_diffuse_test1();
|
||||||
|
rVal += fluid_sim_grid2_density_diffuse_test2();
|
||||||
|
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
155
src/test/c/fluid/sim/grid2/velocity_diffuse_tests.c
Normal file
155
src/test/c/fluid/sim/grid2/velocity_diffuse_tests.c
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
|
||||||
|
#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/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"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Placement value for populating velocity arrays
|
||||||
|
*/
|
||||||
|
#define FLUID_GRID2_VELOCITY_DIFFUSE_TESTS_PLACEMENT_VAL 1.0f
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing velocity diffusion
|
||||||
|
*/
|
||||||
|
int fluid_sim_grid2_velocity_diffuse_test1(){
|
||||||
|
int rVal = 0;
|
||||||
|
printf("fluid_sim_grid2_velocity_diffuse_test1\n");
|
||||||
|
Environment * env = fluid_environment_create();
|
||||||
|
Chunk ** queue = NULL;
|
||||||
|
queue = createChunkGrid(env,3,3,3);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Chunk * currentChunk = queue[0];
|
||||||
|
currentChunk->u[CENTER_LOC][IX(2,2,2)] = FLUID_GRID2_VELOCITY_DIFFUSE_TESTS_PLACEMENT_VAL;
|
||||||
|
currentChunk->v[CENTER_LOC][IX(3,2,2)] = FLUID_GRID2_VELOCITY_DIFFUSE_TESTS_PLACEMENT_VAL;
|
||||||
|
currentChunk->w[CENTER_LOC][IX(2,2,3)] = FLUID_GRID2_VELOCITY_DIFFUSE_TESTS_PLACEMENT_VAL;
|
||||||
|
|
||||||
|
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);
|
||||||
|
rVal += assertEqualsFloat(beforeSumX,FLUID_GRID2_VELOCITY_DIFFUSE_TESTS_PLACEMENT_VAL,"x-velocity diffuse step changed velocity sum! %f %f \n");
|
||||||
|
rVal += assertEqualsFloat(beforeSumY,FLUID_GRID2_VELOCITY_DIFFUSE_TESTS_PLACEMENT_VAL,"y-velocity diffuse step changed velocity sum! %f %f \n");
|
||||||
|
rVal += assertEqualsFloat(beforeSumZ,FLUID_GRID2_VELOCITY_DIFFUSE_TESTS_PLACEMENT_VAL,"z-velocity diffuse step changed velocity sum! %f %f \n");
|
||||||
|
|
||||||
|
fluid_grid2_flip_arrays(currentChunk->u,currentChunk->u0);
|
||||||
|
fluid_grid2_flip_arrays(currentChunk->v,currentChunk->v0);
|
||||||
|
fluid_grid2_flip_arrays(currentChunk->w,currentChunk->w0);
|
||||||
|
//diffuse density
|
||||||
|
//solve vector diffusion
|
||||||
|
for(int l = 0; l < FLUID_GRID2_VECTOR_DIFFUSE_TIMES; l++){
|
||||||
|
//solve vector diffusion
|
||||||
|
fluid_grid2_solveVectorDiffuse(currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,FLUID_GRID2_SIM_STEP);
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
//swap all density arrays
|
||||||
|
//swap vector fields
|
||||||
|
fluid_grid2_flip_arrays(currentChunk->u,currentChunk->u0);
|
||||||
|
fluid_grid2_flip_arrays(currentChunk->v,currentChunk->v0);
|
||||||
|
fluid_grid2_flip_arrays(currentChunk->w,currentChunk->w0);
|
||||||
|
|
||||||
|
//sum 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);
|
||||||
|
|
||||||
|
//actually check
|
||||||
|
rVal += assertEqualsFloat(beforeSumX,afterSumX,"x-velocity diffuse step changed velocity sum! %f %f \n");
|
||||||
|
rVal += assertEqualsFloat(beforeSumY,afterSumY,"y-velocity diffuse step changed velocity sum! %f %f \n");
|
||||||
|
rVal += assertEqualsFloat(beforeSumZ,afterSumZ,"z-velocity diffuse step changed velocity sum! %f %f \n");
|
||||||
|
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing velocity diffusion
|
||||||
|
*/
|
||||||
|
int fluid_sim_grid2_velocity_diffuse_test2(){
|
||||||
|
int rVal = 0;
|
||||||
|
printf("fluid_sim_grid2_velocity_diffuse_test2\n");
|
||||||
|
Environment * env = fluid_environment_create();
|
||||||
|
Chunk ** queue = NULL;
|
||||||
|
queue = createChunkGrid(env,3,3,3);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Chunk * currentChunk = queue[0];
|
||||||
|
currentChunk->u[CENTER_LOC][IX(2,2,2)] = FLUID_GRID2_VELOCITY_DIFFUSE_TESTS_PLACEMENT_VAL;
|
||||||
|
currentChunk->v[CENTER_LOC][IX(3,2,2)] = FLUID_GRID2_VELOCITY_DIFFUSE_TESTS_PLACEMENT_VAL;
|
||||||
|
currentChunk->w[CENTER_LOC][IX(2,2,3)] = FLUID_GRID2_VELOCITY_DIFFUSE_TESTS_PLACEMENT_VAL;
|
||||||
|
|
||||||
|
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);
|
||||||
|
rVal += assertEqualsFloat(beforeSumX,FLUID_GRID2_VELOCITY_DIFFUSE_TESTS_PLACEMENT_VAL,"x-velocity diffuse step changed velocity sum! %f %f \n");
|
||||||
|
rVal += assertEqualsFloat(beforeSumY,FLUID_GRID2_VELOCITY_DIFFUSE_TESTS_PLACEMENT_VAL,"y-velocity diffuse step changed velocity sum! %f %f \n");
|
||||||
|
rVal += assertEqualsFloat(beforeSumZ,FLUID_GRID2_VELOCITY_DIFFUSE_TESTS_PLACEMENT_VAL,"z-velocity diffuse step changed velocity sum! %f %f \n");
|
||||||
|
|
||||||
|
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);
|
||||||
|
//diffuse density
|
||||||
|
//solve vector diffusion
|
||||||
|
for(int l = 0; l < FLUID_GRID2_VECTOR_DIFFUSE_TIMES; l++){
|
||||||
|
//solve vector diffusion
|
||||||
|
fluid_grid2_solveVectorDiffuse(currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,FLUID_GRID2_SIM_STEP);
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
//swap all density arrays
|
||||||
|
//swap vector fields
|
||||||
|
fluid_grid2_flip_arrays(currentChunk->u,currentChunk->u0);
|
||||||
|
fluid_grid2_flip_arrays(currentChunk->v,currentChunk->v0);
|
||||||
|
fluid_grid2_flip_arrays(currentChunk->w,currentChunk->w0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//sum 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);
|
||||||
|
|
||||||
|
//actually check
|
||||||
|
rVal += assertEqualsFloat(beforeSumX,afterSumX,"x-velocity diffuse step changed velocity sum! %f %f \n");
|
||||||
|
rVal += assertEqualsFloat(beforeSumY,afterSumY,"y-velocity diffuse step changed velocity sum! %f %f \n");
|
||||||
|
rVal += assertEqualsFloat(beforeSumZ,afterSumZ,"z-velocity diffuse step changed velocity sum! %f %f \n");
|
||||||
|
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing velocity diffusion
|
||||||
|
*/
|
||||||
|
int fluid_sim_grid2_velocity_diffuse_tests(int argc, char **argv){
|
||||||
|
int rVal = 0;
|
||||||
|
|
||||||
|
rVal += fluid_sim_grid2_velocity_diffuse_test1();
|
||||||
|
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
@ -1,9 +1,32 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "stb/stb_ds.h"
|
#include "stb/stb_ds.h"
|
||||||
|
#include "fluid/queue/boundsolver.h"
|
||||||
#include "fluid/queue/chunk.h"
|
#include "fluid/queue/chunk.h"
|
||||||
#include "fluid/queue/chunkmask.h"
|
#include "fluid/queue/chunkmask.h"
|
||||||
|
#include "fluid/env/environment.h"
|
||||||
#include "fluid/env/utilities.h"
|
#include "fluid/env/utilities.h"
|
||||||
|
#include "fluid/sim/grid2/velocity.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int chunk_test_utils_kernelx[27] = {
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
|
2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
int chunk_test_utils_kernely[27] = {
|
||||||
|
0, 0, 0, 1, 1, 1, 2, 2, 2,
|
||||||
|
0, 0, 0, 1, 1, 1, 2, 2, 2,
|
||||||
|
0, 0, 0, 1, 1, 1, 2, 2, 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
int chunk_test_utils_kernelz[27] = {
|
||||||
|
0, 1, 2, 0, 1, 2, 0, 1, 2,
|
||||||
|
0, 1, 2, 0, 1, 2, 0, 1, 2,
|
||||||
|
0, 1, 2, 0, 1, 2, 0, 1, 2,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a chunk at a world position
|
* Creates a chunk at a world position
|
||||||
@ -230,11 +253,10 @@ void chunk_link_neighbors(Chunk ** chunks){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sums all chunks in a queue
|
* Sums density all chunks in a queue
|
||||||
*/
|
*/
|
||||||
float chunk_queue_sum(Chunk ** chunks){
|
float chunk_queue_sum_density(Chunk ** chunks){
|
||||||
float sum = 0;
|
float sum = 0;
|
||||||
// printf("\nsum\n");
|
|
||||||
int chunkCount = arrlen(chunks);
|
int chunkCount = arrlen(chunks);
|
||||||
for(int i = 0; i < chunkCount; i++){
|
for(int i = 0; i < chunkCount; i++){
|
||||||
Chunk * current = chunks[i];
|
Chunk * current = chunks[i];
|
||||||
@ -242,14 +264,35 @@ float chunk_queue_sum(Chunk ** chunks){
|
|||||||
for(int y = 1; y < DIM - 1; y++){
|
for(int y = 1; y < DIM - 1; y++){
|
||||||
for(int z = 1; z < DIM - 1; z++){
|
for(int z = 1; z < DIM - 1; z++){
|
||||||
sum = sum + current->d[CENTER_LOC][IX(x,y,z)];
|
sum = sum + current->d[CENTER_LOC][IX(x,y,z)];
|
||||||
// if(current->d[CENTER_LOC][IX(x,y,z)] > 0){
|
|
||||||
// printf("%d %d %d\n",x,y,z);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// printf("\n\n");
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sums velocity in all chunks in a queue
|
||||||
|
*/
|
||||||
|
float chunk_queue_sum_velocity(Chunk ** chunks, int axis){
|
||||||
|
float sum = 0;
|
||||||
|
int chunkCount = arrlen(chunks);
|
||||||
|
for(int i = 0; i < chunkCount; i++){
|
||||||
|
Chunk * current = chunks[i];
|
||||||
|
for(int x = 1; x < DIM - 1; x++){
|
||||||
|
for(int y = 1; y < DIM - 1; y++){
|
||||||
|
for(int z = 1; z < DIM - 1; z++){
|
||||||
|
if(axis == FLUID_GRID2_BOUND_DIR_U){
|
||||||
|
sum = sum + current->u[CENTER_LOC][IX(x,y,z)];
|
||||||
|
} else if(axis == FLUID_GRID2_BOUND_DIR_V){
|
||||||
|
sum = sum + current->v[CENTER_LOC][IX(x,y,z)];
|
||||||
|
} else if(axis == FLUID_GRID2_BOUND_DIR_W){
|
||||||
|
sum = sum + current->w[CENTER_LOC][IX(x,y,z)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,4 +301,35 @@ float chunk_queue_sum(Chunk ** chunks){
|
|||||||
*/
|
*/
|
||||||
int util_chunk_test_utils(){
|
int util_chunk_test_utils(){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a grid of chunks with the specified dimensions
|
||||||
|
* @param env The simulation environment
|
||||||
|
* @param width The width of the grid in number of chunks
|
||||||
|
* @param height The height of the grid in number of chunks
|
||||||
|
* @param length The length of the grid in number of chunks
|
||||||
|
* @return The list of chunks
|
||||||
|
*/
|
||||||
|
Chunk ** createChunkGrid(Environment * env, int width, int height, int length){
|
||||||
|
Chunk ** rVal = NULL;
|
||||||
|
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);
|
||||||
|
arrput(rVal,chunk);
|
||||||
|
chunk_fill(chunk,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int numChunks = arrlen(rVal);
|
||||||
|
//link neighbors
|
||||||
|
chunk_link_neighbors(rVal);
|
||||||
|
//set bounds
|
||||||
|
fluid_solve_bounds(numChunks,rVal,env);
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#ifndef CHUNK_TEST_UTILS_H
|
#ifndef CHUNK_TEST_UTILS_H
|
||||||
#define CHUNK_TEST_UTILS_H
|
#define CHUNK_TEST_UTILS_H
|
||||||
|
|
||||||
|
#include "fluid/env/environment.h"
|
||||||
#include "fluid/queue/chunk.h"
|
#include "fluid/queue/chunk.h"
|
||||||
|
|
||||||
|
|
||||||
@ -96,8 +97,23 @@ void chunk_free_queue(Chunk ** chunks);
|
|||||||
void chunk_link_neighbors(Chunk ** chunks);
|
void chunk_link_neighbors(Chunk ** chunks);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sums all chunks in a queue
|
* Sums density all chunks in a queue
|
||||||
*/
|
*/
|
||||||
float chunk_queue_sum(Chunk ** chunks);
|
float chunk_queue_sum_density(Chunk ** chunks);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sums velocity in all chunks in a queue
|
||||||
|
*/
|
||||||
|
float chunk_queue_sum_velocity(Chunk ** chunks, int axis);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a grid of chunks with the specified dimensions
|
||||||
|
* @param env The simulation environment
|
||||||
|
* @param width The width of the grid in number of chunks
|
||||||
|
* @param height The height of the grid in number of chunks
|
||||||
|
* @param length The length of the grid in number of chunks
|
||||||
|
* @return The list of chunks
|
||||||
|
*/
|
||||||
|
Chunk ** createChunkGrid(Environment * env, int width, int height, int length);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Loading…
Reference in New Issue
Block a user