seemingly working, added display text
This commit is contained in:
@@ -4,27 +4,18 @@ using FluidSim.Interfaces;
|
||||
|
||||
namespace FluidSim.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Connects a port (volume or atmosphere) to one end of a pipe via an orifice.
|
||||
/// Uses the isentropic nozzle model for the steady‑state relationship,
|
||||
/// and includes acoustic inertance for dynamic (Helmholtz) behaviour.
|
||||
/// </summary>
|
||||
public class OrificeLink
|
||||
{
|
||||
public Port VolumePort { get; }
|
||||
public Port? VolumePort { get; }
|
||||
public Pipe1D Pipe { get; }
|
||||
public bool IsPipeLeftEnd { get; }
|
||||
public Func<double> AreaProvider { get; set; }
|
||||
public double DischargeCoefficient { get; set; } = 0.62;
|
||||
|
||||
// Acoustic length (wall thickness + end correction) – controls the resonance frequency
|
||||
public double EffectiveLength { get; set; } = 0.001; // 1 mm
|
||||
|
||||
// Whether to include inertance; if false, uses the steady‑state nozzle model directly
|
||||
public double EffectiveLength { get; set; } = 0.001;
|
||||
public bool UseInertance { get; set; } = true;
|
||||
|
||||
// Current mass flow (kg/s, positive = volume → pipe)
|
||||
private double _mdot;
|
||||
private double _mdot; // positive = volume → pipe
|
||||
|
||||
public double LastMassFlowRate { get; private set; }
|
||||
public double LastFaceDensity { get; private set; }
|
||||
@@ -33,7 +24,7 @@ namespace FluidSim.Core
|
||||
|
||||
public OrificeLink(Port? volumePort, Pipe1D pipe, bool isPipeLeftEnd, Func<double> areaProvider)
|
||||
{
|
||||
VolumePort = volumePort; // null is allowed
|
||||
VolumePort = volumePort;
|
||||
Pipe = pipe ?? throw new ArgumentNullException(nameof(pipe));
|
||||
IsPipeLeftEnd = isPipeLeftEnd;
|
||||
AreaProvider = areaProvider ?? throw new ArgumentNullException(nameof(areaProvider));
|
||||
@@ -43,20 +34,18 @@ namespace FluidSim.Core
|
||||
public void Resolve(double dtSub)
|
||||
{
|
||||
double area = AreaProvider();
|
||||
// Closed wall or missing volume port => reflective boundary
|
||||
if (area < 1e-12 || VolumePort == null)
|
||||
{
|
||||
SetClosedWall();
|
||||
return;
|
||||
}
|
||||
|
||||
// Gather volume state
|
||||
// Gather states
|
||||
double volP = VolumePort.Pressure;
|
||||
double volRho = VolumePort.Density;
|
||||
double volT = VolumePort.Temperature;
|
||||
double volH = VolumePort.SpecificEnthalpy;
|
||||
|
||||
// Gather pipe interior state at the connected end
|
||||
(double pipeRho, double pipeU, double pipeP) = IsPipeLeftEnd
|
||||
? Pipe.GetInteriorStateLeft()
|
||||
: Pipe.GetInteriorStateRight();
|
||||
@@ -65,24 +54,23 @@ namespace FluidSim.Core
|
||||
double gamma = 1.4;
|
||||
double R = 287.0;
|
||||
|
||||
// ---- Steady‑state mass flow from isentropic nozzle ----
|
||||
double mdotSS; // positive = volume → pipe
|
||||
double rhoFace, uFace, pFace;
|
||||
|
||||
// ---- 1. Steady‑state nozzle solution (gives correct exit pressure) ----
|
||||
double mdotSS;
|
||||
double rhoFace0, uFace0, pFace0;
|
||||
if (volP >= pipeP)
|
||||
{
|
||||
IsentropicOrifice.Compute(volP, volRho, volT, pipeP, gamma, R, area, DischargeCoefficient,
|
||||
out double mdotUpToDown, out rhoFace, out uFace, out pFace);
|
||||
out double mdotUpToDown, out rhoFace0, out uFace0, out pFace0);
|
||||
mdotSS = mdotUpToDown; // volume → pipe
|
||||
}
|
||||
else
|
||||
{
|
||||
IsentropicOrifice.Compute(pipeP, pipeRho, pipeT, volP, gamma, R, area, DischargeCoefficient,
|
||||
out double mdotUpToDown, out rhoFace, out uFace, out pFace);
|
||||
out double mdotUpToDown, out rhoFace0, out uFace0, out pFace0);
|
||||
mdotSS = -mdotUpToDown; // pipe → volume → negative for volume→pipe convention
|
||||
}
|
||||
|
||||
// ---- Inertance ODE (optional) ----
|
||||
// ---- 2. Inertance dynamics ----
|
||||
if (UseInertance)
|
||||
{
|
||||
double rhoUp = _mdot >= 0 ? volRho : pipeRho;
|
||||
@@ -97,35 +85,31 @@ namespace FluidSim.Core
|
||||
_mdot = mdotSS;
|
||||
}
|
||||
|
||||
// Clamp outflow to available mass (if finite volume)
|
||||
// Clamp outflow to available mass
|
||||
if (VolumePort.Owner is Volume0D vol)
|
||||
{
|
||||
double maxOut = vol.Mass / dtSub;
|
||||
if (_mdot > maxOut) _mdot = maxOut;
|
||||
}
|
||||
|
||||
// ---- Ghost state ----
|
||||
// Density = upstream density (consistent with current flow direction)
|
||||
rhoFace = _mdot >= 0 ? volRho : pipeRho;
|
||||
// Pressure = downstream pressure (consistent with nozzle exit)
|
||||
pFace = _mdot >= 0 ? pipeP : volP;
|
||||
// Velocity magnitude derived from actual mass flow
|
||||
// ---- 3. Ghost state (use nozzle‑exit pressure!) ----
|
||||
double rhoFace = _mdot >= 0 ? volRho : pipeRho; // upstream density
|
||||
double pFace = pFace0; // correct exit pressure (choked/subsonic)
|
||||
double mdotMag = Math.Abs(_mdot);
|
||||
uFace = mdotMag / (rhoFace * area);
|
||||
double uFace = mdotMag / (rhoFace * area);
|
||||
|
||||
if (IsPipeLeftEnd)
|
||||
uFace = _mdot >= 0 ? uFace : -uFace; // left end: positive u = into pipe
|
||||
uFace = _mdot >= 0 ? uFace : -uFace; // left: +u into pipe
|
||||
else
|
||||
uFace = _mdot >= 0 ? -uFace : uFace; // right end: positive u = out of pipe
|
||||
uFace = _mdot >= 0 ? -uFace : uFace; // right: +u out of pipe
|
||||
|
||||
// Apply ghost to pipe
|
||||
if (IsPipeLeftEnd)
|
||||
Pipe.SetGhostLeft(rhoFace, uFace, pFace);
|
||||
else
|
||||
Pipe.SetGhostRight(rhoFace, uFace, pFace);
|
||||
|
||||
// ---- Store results ----
|
||||
double mdotIntoVolume = -_mdot; // positive = into volume
|
||||
// Store for monitoring
|
||||
double mdotIntoVolume = -_mdot;
|
||||
LastMassFlowRate = mdotIntoVolume;
|
||||
LastFaceDensity = rhoFace;
|
||||
LastFaceVelocity = uFace;
|
||||
@@ -133,13 +117,12 @@ namespace FluidSim.Core
|
||||
|
||||
VolumePort.MassFlowRate = mdotIntoVolume;
|
||||
|
||||
// Enthalpy for volume integration
|
||||
if (mdotIntoVolume >= 0) // inflow → pipe enthalpy
|
||||
if (mdotIntoVolume >= 0)
|
||||
{
|
||||
double hPipe = gamma / (gamma - 1.0) * pipeP / Math.Max(pipeRho, 1e-12);
|
||||
VolumePort.SpecificEnthalpy = hPipe;
|
||||
}
|
||||
else // outflow → volume's own enthalpy
|
||||
else
|
||||
{
|
||||
VolumePort.SpecificEnthalpy = volH;
|
||||
}
|
||||
@@ -160,7 +143,6 @@ namespace FluidSim.Core
|
||||
LastFaceDensity = rInt;
|
||||
LastFaceVelocity = 0.0;
|
||||
LastFacePressure = pInt;
|
||||
// Don't touch VolumePort if it's null
|
||||
if (VolumePort != null)
|
||||
VolumePort.MassFlowRate = 0.0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user