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

@@ -20,7 +20,7 @@ namespace FluidSim.Core
foreach (var v in _volumes)
v.PushStateToPort();
// 2. Apply orifice boundaries to pipes
// 2. Compute boundary fluxes (orifice model)
foreach (var conn in _connections)
{
if (IsPipePort(conn.PortA) && IsVolumePort(conn.PortB))
@@ -31,20 +31,20 @@ namespace FluidSim.Core
VolumeToVolume(conn);
}
// 3. Pipes simulate
// 3. Pipe simulation step
foreach (var p in _pipes)
p.Simulate();
// 4. Transfer pipe flows to connected volumes
// 4. Transfer pipeport data to volumes
foreach (var conn in _connections)
{
if (IsPipePort(conn.PortA) && IsVolumePort(conn.PortB))
Transfer(conn.PortA, conn.PortB);
TransferPipeToVolume(conn.PortA, conn.PortB);
else if (IsVolumePort(conn.PortA) && IsPipePort(conn.PortB))
Transfer(conn.PortB, conn.PortA);
TransferPipeToVolume(conn.PortB, conn.PortA);
}
// 5. Volumes integrate
// 5. Integrate volumes
foreach (var v in _volumes)
v.Integrate();
}
@@ -61,34 +61,56 @@ namespace FluidSim.Core
double pP = isLeft ? pipe.GetLeftPressure() : pipe.GetRightPressure();
double rhoP = isLeft ? pipe.GetLeftDensity() : pipe.GetRightDensity();
double uP = 0.0;
double pV = volPort.Pressure, rhoV = volPort.Density, uV = 0.0;
double uP = isLeft ? pipe.GetCellVelocity(0)
: pipe.GetCellVelocity(pipe.GetCellCount() - 1);
double pV = volPort.Pressure;
double rhoV = volPort.Density;
double uV = 0.0; // volume has zero organized velocity
OrificeBoundary.PipeVolumeFlux(
pP, rhoP, uP,
pV, rhoV, uV,
conn, pipe.Area, isLeft,
out double massFlux, out double momFlux, out double energyFlux);
OrificeBoundary.PipeVolumeFlux(pP, rhoP, uP, pV, rhoV, uV, conn, pipe.Area,
isLeft, out double mf, out double pf, out double ef);
if (isLeft)
pipe.SetLeftBoundaryFlux(mf, pf, ef);
pipe.SetLeftBoundaryFlux(massFlux, momFlux, energyFlux);
else
pipe.SetRightBoundaryFlux(mf, pf, ef);
pipe.SetRightBoundaryFlux(massFlux, momFlux, energyFlux);
}
void VolumeToVolume(Connection conn)
{
double mdot = OrificeBoundary.MassFlow(conn.PortA.Pressure, conn.PortA.Density,
conn.PortB.Pressure, conn.PortB.Density, conn);
double mdot = OrificeBoundary.MassFlow(
conn.PortA.Pressure, conn.PortA.Density,
conn.PortB.Pressure, conn.PortB.Density, conn);
conn.PortA.MassFlowRate = -mdot;
conn.PortB.MassFlowRate = mdot;
if (mdot > 0)
conn.PortB.SpecificEnthalpy = conn.PortA.SpecificEnthalpy;
else if (mdot < 0)
conn.PortA.SpecificEnthalpy = conn.PortB.SpecificEnthalpy;
}
void Transfer(Port pipePort, Port volPort)
void TransferPipeToVolume(Port pipePort, Port volPort)
{
double mdot = pipePort.MassFlowRate;
// mdot > 0 → fluid enters pipe from volume
// mdot < 0 → fluid leaves pipe and enters volume
// Volume mass flow sign is opposite (positive into volume)
volPort.MassFlowRate = -mdot;
volPort.SpecificEnthalpy = pipePort.SpecificEnthalpy;
if (mdot < 0) // pipe → volume
{
// ★ pipePort.SpecificEnthalpy now contains TOTAL enthalpy
volPort.SpecificEnthalpy = pipePort.SpecificEnthalpy;
}
// else: fluid goes volume → pipe → volume owns its own (static) enthalpy,
// which is already correct.
}
}
}