Known bad point (unphysical energy loss)

This commit is contained in:
max
2026-05-02 17:40:43 +02:00
parent 9fc45224af
commit 650b993c2b
6 changed files with 89 additions and 91 deletions

View File

@@ -67,6 +67,8 @@ namespace FluidSim.Components
_fxR_mass = m; _fxR_mom = p; _fxR_ener = e; _rightSet = true;
}
public void Simulate()
{
int n = _n;
@@ -106,16 +108,15 @@ namespace FluidSim.Components
if (_E[i] < kinetic) _E[i] = kinetic;
}
// Friction
// Friction (energyconserving)
if (FrictionFactor > 0)
{
double D = 2.0 * Math.Sqrt(_area / Math.PI);
for (int i = 0; i < n; i++)
for (int i = 0; i < _n; i++)
{
double u = _rhou[i] / Math.Max(_rho[i], 1e-12);
double f = FrictionFactor / (2.0 * D) * _rho[i] * u * Math.Abs(u);
_rhou[i] -= _dt * f;
if (_E[i] > _dt * f * u) _E[i] -= _dt * f * u;
//_rhou[i] -= _dt * f; FRICTIN DISABLED!!!
}
}
@@ -124,13 +125,22 @@ namespace FluidSim.Components
PortB.MassFlowRate = _rightSet ? -_fxR_mass * _area : 0.0;
// Enthalpy for upwinding
PortA.SpecificEnthalpy = _gamma / (_gamma - 1.0) * Pressure(0) / Math.Max(_rho[0], 1e-12);
PortB.SpecificEnthalpy = _gamma / (_gamma - 1.0) * Pressure(_n - 1) / Math.Max(_rho[_n - 1], 1e-12);
PortA.SpecificEnthalpy = GetCellTotalSpecificEnthalpy(0);
PortB.SpecificEnthalpy = GetCellTotalSpecificEnthalpy(_n - 1);
// Reset for next step
_leftSet = _rightSet = false;
}
private double GetCellTotalSpecificEnthalpy(int i)
{
double rho = Math.Max(_rho[i], 1e-12);
double u = _rhou[i] / rho;
double p = Pressure(i);
double h = _gamma / (_gamma - 1.0) * p / rho;
return h + 0.5 * u * u;
}
double Pressure(int i) =>
(_gamma - 1.0) * (_E[i] - 0.5 * _rhou[i] * _rhou[i] / Math.Max(_rho[i], 1e-12));