Known bad point (unphysical energy loss)
This commit is contained in:
@@ -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 (energy‑conserving)
|
||||
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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user