From 64e13e24574b92c37a334667325077fcc5587883 Mon Sep 17 00:00:00 2001 From: austin Date: Tue, 17 Dec 2024 17:48:24 -0500 Subject: [PATCH] normalization corner handling --- .../fluid/sim/pressurecell/normalization.c | 236 ++++++++++++++++++ .../sim/pressurecell/normalization_tests.c | 4 +- 2 files changed, 238 insertions(+), 2 deletions(-) diff --git a/src/main/c/src/fluid/sim/pressurecell/normalization.c b/src/main/c/src/fluid/sim/pressurecell/normalization.c index b8b7d9de..25c7c6f2 100644 --- a/src/main/c/src/fluid/sim/pressurecell/normalization.c +++ b/src/main/c/src/fluid/sim/pressurecell/normalization.c @@ -656,6 +656,242 @@ LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk * + + + + + + + + + + + + + + + + //check corner -x, -y, -z + neighbor = CK(0,0,0); + if(chunk->d[neighbor] == NULL){ + ghostIndex = IX(0,0,0); + adjacentIndex = IX(1,1,1); + 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; + pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; + if(overdraw > 0){ + chunk->pressureCellData.recaptureDensity += overdraw; + dArr[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]; + } + } + + + + //check corner -x, +y, -z + neighbor = CK(0,2,0); + if(chunk->d[neighbor] == NULL){ + ghostIndex = IX(0,DIM-1,0); + adjacentIndex = IX(1,DIM-2,1); + 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; + pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; + if(overdraw > 0){ + chunk->pressureCellData.recaptureDensity += overdraw; + dArr[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]; + } + } + + + //check corner +x, -y, -z + neighbor = CK(2,0,0); + 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){ + 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; + pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; + if(overdraw > 0){ + chunk->pressureCellData.recaptureDensity += overdraw; + dArr[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]; + } + } + + + + //check corner +x, +y, -z + neighbor = CK(2,2,0); + 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){ + 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; + pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; + if(overdraw > 0){ + chunk->pressureCellData.recaptureDensity += overdraw; + dArr[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]; + } + } + + + + + + + + //check corner -x, -y, +z + neighbor = CK(0,0,2); + 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){ + 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; + pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; + if(overdraw > 0){ + chunk->pressureCellData.recaptureDensity += overdraw; + dArr[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]; + } + } + + + + //check corner -x, +y, +z + neighbor = CK(0,2,2); + 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){ + 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; + pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; + if(overdraw > 0){ + chunk->pressureCellData.recaptureDensity += overdraw; + dArr[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]; + } + } + + + //check corner +x, -y, +z + neighbor = CK(2,0,2); + 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){ + 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; + pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; + if(overdraw > 0){ + chunk->pressureCellData.recaptureDensity += overdraw; + dArr[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]; + } + } + + + + //check corner +x, +y, +z + neighbor = CK(2,2,2); + 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){ + 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; + pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE; + if(overdraw > 0){ + chunk->pressureCellData.recaptureDensity += overdraw; + dArr[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]; + } + } + + + + + + + + + + + + + + } diff --git a/src/test/c/fluid/sim/pressurecell/normalization_tests.c b/src/test/c/fluid/sim/pressurecell/normalization_tests.c index 524489c6..2b146fa2 100644 --- a/src/test/c/fluid/sim/pressurecell/normalization_tests.c +++ b/src/test/c/fluid/sim/pressurecell/normalization_tests.c @@ -39,10 +39,10 @@ int fluid_sim_pressurecell_normalization_test1(){ //setup chunk values float deltaDensity = 0.01f; Chunk * currentChunk = queue[0]; - currentChunk->v[CENTER_LOC][IX(1,1,1)] = -0.8; + currentChunk->vTempCache[IX(1,1,1)] = -0.8; currentChunk->d[CENTER_LOC][IX(1,1,1)] = 0.2; - currentChunk->v[CENTER_LOC][IX(DIM-2,DIM-2,DIM-2)] = 0.8; + currentChunk->vTempCache[IX(DIM-2,DIM-2,DIM-2)] = 0.8; currentChunk->d[CENTER_LOC][IX(DIM-2,DIM-2,DIM-2)] = 0.2; //actually simulate