From 10c7a6c0c0bc28804b20709077d1790a99c85331 Mon Sep 17 00:00:00 2001 From: austin Date: Tue, 17 Dec 2024 18:26:05 -0500 Subject: [PATCH] normalization work --- .../fluid/sim/pressurecell/solver_consts.h | 4 +- .../fluid/sim/pressurecell/normalization.c | 615 +++++++++--------- .../sim/pressurecell/normalization_tests.c | 4 +- 3 files changed, 320 insertions(+), 303 deletions(-) diff --git a/src/main/c/includes/fluid/sim/pressurecell/solver_consts.h b/src/main/c/includes/fluid/sim/pressurecell/solver_consts.h index 8870455d..f37f5cc2 100644 --- a/src/main/c/includes/fluid/sim/pressurecell/solver_consts.h +++ b/src/main/c/includes/fluid/sim/pressurecell/solver_consts.h @@ -25,12 +25,12 @@ /** * Diffusion constant */ -#define FLUID_PRESSURECELL_DIFFUSION_CONSTANT 0.01f +#define FLUID_PRESSURECELL_DIFFUSION_CONSTANT 0.001f /** * Viscosity constant */ -#define FLUID_PRESSURECELL_VISCOSITY_CONSTANT 0.01f +#define FLUID_PRESSURECELL_VISCOSITY_CONSTANT 0.001f /** * Amount of the residual to add to the pressure field each frame diff --git a/src/main/c/src/fluid/sim/pressurecell/normalization.c b/src/main/c/src/fluid/sim/pressurecell/normalization.c index 25c7c6f2..ff884677 100644 --- a/src/main/c/src/fluid/sim/pressurecell/normalization.c +++ b/src/main/c/src/fluid/sim/pressurecell/normalization.c @@ -67,8 +67,9 @@ LIBRARY_API void fluid_pressurecell_normalize_chunk(Environment * env, Chunk * c * Recaptures density that has flowed into boundaries */ LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk * chunk){ - int x, y; + int x, y, z; float * dArr = chunk->d[CENTER_LOC]; + float * dTemp = chunk->dTempCache; float * uArr = chunk->uTempCache; float * vArr = chunk->vTempCache; float * wArr = chunk->wTempCache; @@ -81,194 +82,202 @@ LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk * chunk->pressureCellData.outgoingDensity[i] = 0; chunk->pressureCellData.outgoingPressure[i] = 0; } + //clear dtemp + for(x = 0; x < DIM; x++){ + for(y = 0; y < DIM; y++){ + for(z = 0; z < DIM; z++){ + dTemp[IX(x,y,z)] = dArr[IX(x,y,z)]; + } + } + } //check +x plane neighbor = CK(2,1,1); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ - for(y = 2; y < DIM-2; y++){ + for(x = 1; x < DIM-1; x++){ + for(y = 1; y < DIM-1; y++){ ghostIndex = IX(DIM-1,x,y); adjacentIndex = IX(DIM-2,x,y); if(uArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ invertedForce = 1.0f - fabs(uArr[adjacentIndex]); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } } else { - for(x = 2; x < DIM-2; x++){ - for(y = 2; y < DIM-2; y++){ - ghostIndex = IX(x,y,0); - adjacentIndex = IX(x,y,1); - if(dArr[ghostIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } - } + // for(x = 2; x < DIM-2; x++){ + // for(y = 2; y < DIM-2; y++){ + // ghostIndex = IX(x,y,0); + // adjacentIndex = IX(x,y,1); + // if(dArr[ghostIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } + // } } //check -x plane neighbor = CK(0,1,1); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ - for(y = 2; y < DIM-2; y++){ + for(x = 1; x < DIM-1; x++){ + for(y = 1; y < DIM-1; y++){ ghostIndex = IX(0,x,y); adjacentIndex = IX(1,x,y); if(uArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ invertedForce = 1.0f - fabs(uArr[adjacentIndex]); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } } else { - for(x = 2; x < DIM-2; x++){ - for(y = 2; y < DIM-2; y++){ - ghostIndex = IX(0,x,y); - adjacentIndex = IX(1,x,y); - if(dArr[ghostIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } - } + // for(x = 2; x < DIM-2; x++){ + // for(y = 2; y < DIM-2; y++){ + // ghostIndex = IX(0,x,y); + // adjacentIndex = IX(1,x,y); + // if(dArr[ghostIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } + // } } //check +y plane neighbor = CK(1,2,1); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ - for(y = 2; y < DIM-2; y++){ + for(x = 1; x < DIM-1; x++){ + for(y = 1; y < DIM-1; y++){ ghostIndex = IX(x,DIM-1,y); adjacentIndex = IX(x,DIM-2,y); if(vArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ invertedForce = 1.0f - fabs(vArr[adjacentIndex]); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } } else { - for(x = 2; x < DIM-2; x++){ - for(y = 2; y < DIM-2; y++){ - ghostIndex = IX(x,DIM-1,y); - adjacentIndex = IX(x,DIM-2,y); - if(dArr[ghostIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } - } + // for(x = 2; x < DIM-2; x++){ + // for(y = 2; y < DIM-2; y++){ + // ghostIndex = IX(x,DIM-1,y); + // adjacentIndex = IX(x,DIM-2,y); + // if(dArr[ghostIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } + // } } //check -y plane neighbor = CK(1,0,1); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ - for(y = 2; y < DIM-2; y++){ + for(x = 1; x < DIM-1; x++){ + for(y = 1; y < DIM-1; y++){ ghostIndex = IX(x,0,y); adjacentIndex = IX(x,1,y); if(vArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ invertedForce = 1.0f - fabs(vArr[adjacentIndex]); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } } else { - for(x = 2; x < DIM-2; x++){ - for(y = 2; y < DIM-2; y++){ - ghostIndex = IX(x,0,y); - adjacentIndex = IX(x,1,y); - if(dArr[ghostIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } - } + // for(x = 2; x < DIM-2; x++){ + // for(y = 2; y < DIM-2; y++){ + // ghostIndex = IX(x,0,y); + // adjacentIndex = IX(x,1,y); + // if(dArr[ghostIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } + // } } //check +z plane neighbor = CK(1,1,2); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ - for(y = 2; y < DIM-2; y++){ + for(x = 1; x < DIM-1; x++){ + for(y = 1; y < DIM-1; y++){ ghostIndex = IX(x,y,DIM-1); adjacentIndex = IX(x,y,DIM-2); if(wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ invertedForce = 1.0f - fabs(wArr[adjacentIndex]); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } } else { - for(x = 2; x < DIM-2; x++){ - for(y = 2; y < DIM-2; y++){ - ghostIndex = IX(x,y,DIM-1); - adjacentIndex = IX(x,y,DIM-2); - if(dArr[ghostIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } - } + // for(x = 2; x < DIM-2; x++){ + // for(y = 2; y < DIM-2; y++){ + // ghostIndex = IX(x,y,DIM-1); + // adjacentIndex = IX(x,y,DIM-2); + // if(dArr[ghostIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } + // } } //check -z plane neighbor = CK(1,1,0); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ - for(y = 2; y < DIM-2; y++){ + for(x = 1; x < DIM-1; x++){ + for(y = 1; y < DIM-1; y++){ ghostIndex = IX(x,y,0); adjacentIndex = IX(x,y,1); if(wArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ invertedForce = 1.0f - fabs(wArr[adjacentIndex]); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } } else { - for(x = 2; x < DIM-2; x++){ - for(y = 2; y < DIM-2; y++){ - ghostIndex = IX(x,y,0); - adjacentIndex = IX(x,y,1); - if(dArr[ghostIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } - } + // for(x = 2; x < DIM-2; x++){ + // for(y = 2; y < DIM-2; y++){ + // ghostIndex = IX(x,y,0); + // adjacentIndex = IX(x,y,1); + // if(dArr[ghostIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } + // } } @@ -294,113 +303,113 @@ LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk * //check -x,-y edge neighbor = CK(0,0,1); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ + for(x = 1; x < DIM-1; x++){ ghostIndex = IX(0,0,x); adjacentIndex = IX(1,1,x); - if(uArr[adjacentIndex] < 0 && vArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ + if((uArr[adjacentIndex] < 0 && vArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] - estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } else { - for(x = 2; x < DIM-2; x++){ - ghostIndex = IX(0,0,x); - adjacentIndex = IX(1,1,x); - if(uArr[adjacentIndex] < 0 && vArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } + // for(x = 2; x < DIM-2; x++){ + // ghostIndex = IX(0,0,x); + // adjacentIndex = IX(1,1,x); + // if(uArr[adjacentIndex] < 0 && vArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } } //check -x,+y edge neighbor = CK(0,2,1); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ + for(x = 1; x < DIM-1; x++){ ghostIndex = IX(0,DIM-1,x); adjacentIndex = IX(1,DIM-2,x); - if(uArr[adjacentIndex] < 0 && vArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + if((uArr[adjacentIndex] < 0 && vArr[adjacentIndex] > 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] - estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } else { - for(x = 2; x < DIM-2; x++){ - ghostIndex = IX(0,DIM-1,x); - adjacentIndex = IX(1,DIM-2,x); - if(uArr[adjacentIndex] < 0 && vArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } + // for(x = 2; x < DIM-2; x++){ + // ghostIndex = IX(0,DIM-1,x); + // adjacentIndex = IX(1,DIM-2,x); + // if(uArr[adjacentIndex] < 0 && vArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } } //check +x,-y edge neighbor = CK(2,0,1); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ + for(x = 1; x < DIM-1; x++){ ghostIndex = IX(DIM-1,0,x); adjacentIndex = IX(DIM-2,1,x); - if(uArr[adjacentIndex] > 0 && vArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ + if((uArr[adjacentIndex] > 0 && vArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] - estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } else { - for(x = 2; x < DIM-2; x++){ - ghostIndex = IX(DIM-1,0,x); - adjacentIndex = IX(DIM-2,1,x); - if(uArr[adjacentIndex] > 0 && vArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } + // for(x = 2; x < DIM-2; x++){ + // ghostIndex = IX(DIM-1,0,x); + // adjacentIndex = IX(DIM-2,1,x); + // if(uArr[adjacentIndex] > 0 && vArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } } //check +x,+y edge neighbor = CK(2,2,1); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ + for(x = 1; x < DIM-1; x++){ ghostIndex = IX(DIM-1,DIM-1,x); adjacentIndex = IX(DIM-2,DIM-2,x); - if(uArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + if((uArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] - estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } else { - for(x = 2; x < DIM-2; x++){ - ghostIndex = IX(DIM-1,DIM-1,x); - adjacentIndex = IX(DIM-2,DIM-2,x); - if(uArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } + // for(x = 2; x < DIM-2; x++){ + // ghostIndex = IX(DIM-1,DIM-1,x); + // adjacentIndex = IX(DIM-2,DIM-2,x); + // if(uArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } } @@ -412,113 +421,113 @@ LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk * //check -x,-z edge neighbor = CK(0,1,0); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ + for(x = 1; x < DIM-1; x++){ ghostIndex = IX(0,x,0); adjacentIndex = IX(1,x,1); - if(uArr[adjacentIndex] < 0 && wArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ + if((uArr[adjacentIndex] < 0 && wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] - estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } else { - for(x = 2; x < DIM-2; x++){ - ghostIndex = IX(0,x,0); - adjacentIndex = IX(1,x,1); - if(uArr[adjacentIndex] < 0 && wArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } + // for(x = 2; x < DIM-2; x++){ + // ghostIndex = IX(0,x,0); + // adjacentIndex = IX(1,x,1); + // if(uArr[adjacentIndex] < 0 && wArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } } //check -x,+z edge neighbor = CK(0,1,2); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ + for(x = 1; x < DIM-1; x++){ ghostIndex = IX(0,x,DIM-1); adjacentIndex = IX(1,x,DIM-2); - if(uArr[adjacentIndex] < 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + if((uArr[adjacentIndex] < 0 && wArr[adjacentIndex] > 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] - estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } else { - for(x = 2; x < DIM-2; x++){ - ghostIndex = IX(0,x,DIM-1); - adjacentIndex = IX(1,x,DIM-2); - if(uArr[adjacentIndex] < 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } + // for(x = 2; x < DIM-2; x++){ + // ghostIndex = IX(0,x,DIM-1); + // adjacentIndex = IX(1,x,DIM-2); + // if(uArr[adjacentIndex] < 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } } //check +x,-z edge neighbor = CK(2,1,0); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ + for(x = 1; x < DIM-1; x++){ ghostIndex = IX(DIM-1,x,0); adjacentIndex = IX(DIM-2,x,1); - if(uArr[adjacentIndex] > 0 && wArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ + if((uArr[adjacentIndex] > 0 && wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] - estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } else { - for(x = 2; x < DIM-2; x++){ - ghostIndex = IX(DIM-1,x,0); - adjacentIndex = IX(DIM-2,x,1); - if(uArr[adjacentIndex] > 0 && wArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } + // for(x = 2; x < DIM-2; x++){ + // ghostIndex = IX(DIM-1,x,0); + // adjacentIndex = IX(DIM-2,x,1); + // if(uArr[adjacentIndex] > 0 && wArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } } //check +x,+z edge neighbor = CK(2,1,2); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ + for(x = 1; x < DIM-1; x++){ ghostIndex = IX(DIM-1,x,DIM-1); adjacentIndex = IX(DIM-2,x,DIM-2); - if(uArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + if((uArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] - estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } else { - for(x = 2; x < DIM-2; x++){ - ghostIndex = IX(DIM-1,x,DIM-1); - adjacentIndex = IX(DIM-2,x,DIM-2); - if(uArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } + // for(x = 2; x < DIM-2; x++){ + // ghostIndex = IX(DIM-1,x,DIM-1); + // adjacentIndex = IX(DIM-2,x,DIM-2); + // if(uArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } } @@ -528,113 +537,113 @@ LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk * //check -y,-z edge neighbor = CK(1,0,0); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ + for(x = 1; x < DIM-1; x++){ ghostIndex = IX(x,0,0); adjacentIndex = IX(x,1,1); - if(vArr[adjacentIndex] < 0 && wArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ + if((vArr[adjacentIndex] < 0 && wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] - estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } else { - for(x = 2; x < DIM-2; x++){ - ghostIndex = IX(x,0,0); - adjacentIndex = IX(x,1,1); - if(vArr[adjacentIndex] < 0 && wArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } + // for(x = 2; x < DIM-2; x++){ + // ghostIndex = IX(x,0,0); + // adjacentIndex = IX(x,1,1); + // if(vArr[adjacentIndex] < 0 && wArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } } //check -y,+z edge neighbor = CK(1,0,2); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ + for(x = 1; x < DIM-1; x++){ ghostIndex = IX(x,0,DIM-1); adjacentIndex = IX(x,1,DIM-2); - if(vArr[adjacentIndex] < 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + if((vArr[adjacentIndex] < 0 && wArr[adjacentIndex] > 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] - estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } else { - for(x = 2; x < DIM-2; x++){ - ghostIndex = IX(x,0,DIM-1); - adjacentIndex = IX(x,1,DIM-2); - if(vArr[adjacentIndex] < 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } + // for(x = 2; x < DIM-2; x++){ + // ghostIndex = IX(x,0,DIM-1); + // adjacentIndex = IX(x,1,DIM-2); + // if(vArr[adjacentIndex] < 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } } //check +y,-z edge neighbor = CK(1,2,0); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ + for(x = 1; x < DIM-1; x++){ ghostIndex = IX(x,DIM-1,0); adjacentIndex = IX(x,DIM-2,1); - if(vArr[adjacentIndex] > 0 && wArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ + if((vArr[adjacentIndex] > 0 && wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] - estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } else { - for(x = 2; x < DIM-2; x++){ - ghostIndex = IX(x,DIM-1,0); - adjacentIndex = IX(x,DIM-2,1); - if(vArr[adjacentIndex] > 0 && wArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } + // for(x = 2; x < DIM-2; x++){ + // ghostIndex = IX(x,DIM-1,0); + // adjacentIndex = IX(x,DIM-2,1); + // if(vArr[adjacentIndex] > 0 && wArr[adjacentIndex] < 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } } //check +y,+z edge neighbor = CK(1,2,2); if(chunk->d[neighbor] == NULL){ - for(x = 2; x < DIM-2; x++){ + for(x = 1; x < DIM-1; x++){ ghostIndex = IX(x,DIM-1,DIM-1); adjacentIndex = IX(x,DIM-2,DIM-2); - if(vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + if((vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] - estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } } else { - for(x = 2; x < DIM-2; x++){ - ghostIndex = IX(x,DIM-1,DIM-1); - adjacentIndex = IX(x,DIM-2,DIM-2); - if(vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } - } + // for(x = 2; x < DIM-2; x++){ + // ghostIndex = IX(x,DIM-1,DIM-1); + // adjacentIndex = IX(x,DIM-2,DIM-2); + // if(vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } + // } } @@ -679,20 +688,20 @@ LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk * if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] < 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } else { - ghostIndex = IX(0,0,0); - adjacentIndex = IX(1,1,1); - if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } + // ghostIndex = IX(0,0,0); + // adjacentIndex = IX(1,1,1); + // if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } } @@ -705,20 +714,20 @@ LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk * if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] > 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } else { - ghostIndex = IX(0,DIM-1,0); - adjacentIndex = IX(1,DIM-2,1); - if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } + // ghostIndex = IX(0,DIM-1,0); + // adjacentIndex = IX(1,DIM-2,1); + // if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } } @@ -727,23 +736,23 @@ LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk * if(chunk->d[neighbor] == NULL){ ghostIndex = IX(DIM-1,0,0); adjacentIndex = IX(DIM-2,1,1); - if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] < 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){ + if((uArr[adjacentIndex] > 0 || vArr[adjacentIndex] < 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } else { - ghostIndex = IX(DIM-1,0,0); - adjacentIndex = IX(DIM-2,1,1); - if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } + // ghostIndex = IX(DIM-1,0,0); + // adjacentIndex = IX(DIM-2,1,1); + // if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } } @@ -753,23 +762,23 @@ LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk * if(chunk->d[neighbor] == NULL){ ghostIndex = IX(DIM-1,DIM-1,0); adjacentIndex = IX(DIM-2,DIM-2,1); - if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] > 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){ + if((uArr[adjacentIndex] > 0 || vArr[adjacentIndex] > 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } else { - ghostIndex = IX(DIM-1,DIM-1,0); - adjacentIndex = IX(DIM-2,DIM-2,1); - if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } + // ghostIndex = IX(DIM-1,DIM-1,0); + // adjacentIndex = IX(DIM-2,DIM-2,1); + // if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } } @@ -783,23 +792,23 @@ LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk * if(chunk->d[neighbor] == NULL){ ghostIndex = IX(0,0,DIM-1); adjacentIndex = IX(1,1,DIM-2); - if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] < 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){ + if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] < 0 || wArr[adjacentIndex] > 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } else { - ghostIndex = IX(0,0,DIM-1); - adjacentIndex = IX(1,1,DIM-2); - if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } + // ghostIndex = IX(0,0,DIM-1); + // adjacentIndex = IX(1,1,DIM-2); + // if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } } @@ -809,23 +818,23 @@ LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk * if(chunk->d[neighbor] == NULL){ ghostIndex = IX(0,DIM-1,DIM-1); adjacentIndex = IX(1,DIM-2,DIM-2); - if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] > 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){ + if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] > 0 || wArr[adjacentIndex] > 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } else { - ghostIndex = IX(0,DIM-1,DIM-1); - adjacentIndex = IX(1,DIM-2,DIM-2); - if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } + // ghostIndex = IX(0,DIM-1,DIM-1); + // adjacentIndex = IX(1,DIM-2,DIM-2); + // if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } } @@ -834,23 +843,23 @@ LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk * if(chunk->d[neighbor] == NULL){ ghostIndex = IX(DIM-1,0,DIM-1); adjacentIndex = IX(DIM-2,1,DIM-2); - if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] < 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){ + if((uArr[adjacentIndex] > 0 || vArr[adjacentIndex] < 0 || wArr[adjacentIndex] > 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } else { - ghostIndex = IX(DIM-1,0,DIM-1); - adjacentIndex = IX(DIM-2,1,DIM-2); - if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } + // ghostIndex = IX(DIM-1,0,DIM-1); + // adjacentIndex = IX(DIM-2,1,DIM-2); + // if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } } @@ -860,23 +869,23 @@ LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk * if(chunk->d[neighbor] == NULL){ ghostIndex = IX(DIM-1,DIM-1,DIM-1); adjacentIndex = IX(DIM-2,DIM-2,DIM-2); - if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] > 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){ + if((uArr[adjacentIndex] > 0 || vArr[adjacentIndex] > 0 || wArr[adjacentIndex] > 0) && dArr[adjacentIndex] > 0){ invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex])); estimatedLoss = dArr[adjacentIndex] / invertedForce; - dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; - overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE; + dTemp[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss; + overdraw = dTemp[adjacentIndex] - MAX_FLUID_VALUE; pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; if(overdraw > 0){ chunk->pressureCellData.recaptureDensity += overdraw; - dArr[adjacentIndex] = MAX_FLUID_VALUE; + dTemp[adjacentIndex] = MAX_FLUID_VALUE; } } } else { - ghostIndex = IX(DIM-1,DIM-1,DIM-1); - adjacentIndex = IX(DIM-2,DIM-2,DIM-2); - if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ - chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; - } + // ghostIndex = IX(DIM-1,DIM-1,DIM-1); + // adjacentIndex = IX(DIM-2,DIM-2,DIM-2); + // if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){ + // chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex]; + // } } @@ -887,6 +896,14 @@ LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk * + //clear dtemp + for(x = 0; x < DIM; x++){ + for(y = 0; y < DIM; y++){ + for(z = 0; z < DIM; z++){ + dArr[IX(x,y,z)] = dTemp[IX(x,y,z)]; + } + } + } diff --git a/src/test/c/fluid/sim/pressurecell/normalization_tests.c b/src/test/c/fluid/sim/pressurecell/normalization_tests.c index 2b146fa2..b214ed9b 100644 --- a/src/test/c/fluid/sim/pressurecell/normalization_tests.c +++ b/src/test/c/fluid/sim/pressurecell/normalization_tests.c @@ -55,13 +55,13 @@ int fluid_sim_pressurecell_normalization_test1(){ // cell that originall had values // expected = MAX_FLUID_VALUE; - actual = currentChunk->d[CENTER_LOC][IX(1,1,1)]; + actual = currentChunk->dTempCache[IX(1,1,1)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to recapture density into (1,1,1)! expected: %f actual: %f \n"); } expected = MAX_FLUID_VALUE; - actual = currentChunk->d[CENTER_LOC][IX(DIM-2,DIM-2,DIM-2)]; + actual = currentChunk->dTempCache[IX(DIM-2,DIM-2,DIM-2)]; if(fabs(expected - actual) > FLUID_PRESSURE_CELL_ERROR_MARGIN){ rVal += assertEqualsFloat(expected,actual,"Failed to recapture density into (DIM-2,DIM-2,DIM-2)! expected: %f actual: %f \n"); }