Environment:
- Branch 663500
Problem:
- Radiation clamp doesn't work on cells blow the red line

Pseudocode:
void SimBase::UpdateData(SimData* simData) { // ... // Update Radiation if (simData->radiationEnabled) { // ... for (int yIdx = region.minimum.y; yIdx < region.maximum.y; yIdx++) { for (int xIdx = region.minimum.x; yIdx < region.maximum.x; xIdx++) { int cell = simData->width * yIdx + xIdx; // Radiation diffusion to surrounding cells float massFactor = gElementRadiationData[simData->updatedCells->elementIdx[cell]].rads_per_1000; if (massFactor > 0.0) { for (Vector3<float> offset : adjacentOffsets) { int xIdx2 = xIdx + (int)offset.x; int yIdx2 = yIdx + (int)offset.y; if (xIdx2< region.minimum.x || xIdx2 > region.maximum.x) continue; if (yIdx2< region.minimum.y || yIdx2 > region.maximum.y) continue; int cella = simData->width * yIdx2 + xIdx2; simData->updatedCells->radiation[cella] += simData->updatedCells->mass[cell] * 0.001f * massFactor * offset.z; } } // ... // Clamp simData->updatedCells->radiation[cell] = fminf(simData->updatedCells->radiation[cell], SIM_MAX_RADIATION); if (simData->updatedCells->radiation[cell] < 0.01) simData->updatedCells->radiation[cell] = 0; } } } // ... }
Reason:
- Clamp only applies to current cell.
- Current cell emits radiation to surrounding cells.
- Cells in Bottom/Left are clamped first then receive radiation and will not be clamped again.
Solution:
- Cut the loop into two parts. Do clamp after finishing all calculation
// ... } } for (int yIdx = region.minimum.y; yIdx < region.maximum.y; yIdx++) { for (int xIdx = region.minimum.x; yIdx < region.maximum.x; xIdx++) { int cell = simData->width * yIdx + xIdx; // Clamp simData->updatedCells->radiation[cell] = fminf(simData->updatedCells->radiation[cell], SIM_MAX_RADIATION);
Steps to Reproduce
Print many many nuclear fallout.
There are no comments to display.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now