Jump to content

SIM_MAX_RADIATION doesn't work properly


FIXBUGFIXBUGFIX
  • Branch: Live Branch Version: Windows Pending

Environment:

  • Branch 663500

Problem:

  • Radiation clamp doesn't work on cells blow the red line

image.png.f87481ad50ccc248023864fbd0010351.png

image.png.1520a9bb8c3bd82ff24c219547049092.pngimage.png.0f0511e17510a2554ff6da2c2d5a8adc.png

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.




User Feedback


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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
  • Create New...