Reduce gravity effects on ambient heat.

This commit is contained in:
Saveliy Skresanov
2025-04-19 11:13:44 +07:00
parent f2cd4dd15c
commit afe35312e1

View File

@@ -153,18 +153,40 @@ void Air::update_airh(void)
// We use the Boussinesq approximation, i.e. we assume density to be nonconstant only
// near the gravity term of the fluid equation, and we suppose that it depends linearly on the
// difference between the current temperature (hv[y][x]) and some "stationary" temperature (ambientAirTemp).
float dvx, dvy;
dvx = vx[y][x];
dvy = vy[y][x];
if (x>=2 && x<XCELLS-2 && y>=2 && y<YCELLS-2)
{
float convGravX, convGravY;
sim.GetGravityField(x*CELL, y*CELL, -1.0f, -1.0f, convGravX, convGravY);
// Cap the gravity field
float gravMagn = std::sqrt(convGravX*convGravX + convGravY*convGravY);
if (gravMagn > 10.0f)
{
convGravX /= 0.1f*gravMagn;
convGravY /= 0.1f*gravMagn;
}
auto weight = (hv[y][x] - ambientAirTemp) / 10000.0f;
// Our approximation works best when the temperature difference is small, so we cap it from above.
if (weight > 0.01f) weight = 0.01f;
vx[y][x] += weight * convGravX;
vy[y][x] += weight * convGravY;
dvx += weight * convGravX;
dvy += weight * convGravY;
}
// Velocity cap
if (dvx > MAX_PRESSURE) dvx = MAX_PRESSURE;
if (dvx < MIN_PRESSURE) dvx = MIN_PRESSURE;
if (dvy > MAX_PRESSURE) dvy = MAX_PRESSURE;
if (dvy < MIN_PRESSURE) dvy = MIN_PRESSURE;
vx[y][x] = dvx;
vy[y][x] = dvy;
}
}
memcpy(hv, ohv, sizeof(hv));