orifice confirmed working
This commit is contained in:
@@ -6,10 +6,6 @@ using FluidSim.Interfaces;
|
||||
|
||||
namespace FluidSim.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Top‑level solver that owns all components and couplings,
|
||||
/// orchestrates sub‑stepping, and exposes states for audio.
|
||||
/// </summary>
|
||||
public class Solver
|
||||
{
|
||||
private readonly List<IComponent> _components = new();
|
||||
@@ -19,6 +15,9 @@ namespace FluidSim.Core
|
||||
|
||||
private double _dt;
|
||||
|
||||
/// <summary>CFL target for sub‑stepping (0.3‑0.8). Lower values are safer for shocks.</summary>
|
||||
public double CflTarget { get; set; } = 0.8;
|
||||
|
||||
public void SetTimeStep(double dt) => _dt = dt;
|
||||
|
||||
public void AddComponent(IComponent component) => _components.Add(component);
|
||||
@@ -26,57 +25,38 @@ namespace FluidSim.Core
|
||||
public void AddJunction(Junction junction) => _junctions.Add(junction);
|
||||
public void AddOpenEndLink(OpenEndLink link) => _openEndLinks.Add(link);
|
||||
|
||||
// Convenience: first pipe’s port B mass flow (often the exhaust)
|
||||
public double ExhaustMassFlow
|
||||
{
|
||||
get
|
||||
{
|
||||
var pipes = _components.OfType<Pipe1D>().ToList();
|
||||
if (pipes.Count > 0)
|
||||
return Math.Abs(pipes[0].PortB.MassFlowRate);
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Advance the whole system by one global time step.
|
||||
/// </summary>
|
||||
public void Step()
|
||||
{
|
||||
var pipes = _components.OfType<Pipe1D>().ToList();
|
||||
if (pipes.Count == 0) return;
|
||||
|
||||
// 1. Determine sub‑step count (max CFL over all pipes)
|
||||
int nSub = 1;
|
||||
foreach (var p in pipes)
|
||||
nSub = Math.Max(nSub, p.GetRequiredSubSteps(_dt));
|
||||
nSub = Math.Max(nSub, p.GetRequiredSubSteps(_dt, CflTarget));
|
||||
double dtSub = _dt / nSub;
|
||||
|
||||
// 2. Sub‑step loop
|
||||
const int maxSubSteps = 10000;
|
||||
if (nSub > maxSubSteps)
|
||||
{
|
||||
Console.WriteLine($"Warning: required sub‑steps {nSub} exceeds limit. Simulation stopped.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int sub = 0; sub < nSub; sub++)
|
||||
{
|
||||
// a) Resolve all orifice links (volume ↔ pipe)
|
||||
foreach (var link in _orificeLinks)
|
||||
link.Resolve(dtSub);
|
||||
|
||||
// b) Resolve all open‑end links (pipe → atmosphere)
|
||||
foreach (var link in _openEndLinks)
|
||||
link.Resolve(dtSub);
|
||||
|
||||
// c) Resolve all junctions (pipe ↔ pipe)
|
||||
foreach (var junc in _junctions)
|
||||
junc.Resolve(dtSub);
|
||||
|
||||
// d) Advance all pipes
|
||||
foreach (var p in pipes)
|
||||
p.SimulateSingleStep(dtSub);
|
||||
}
|
||||
|
||||
// 3. Clear ghost flags
|
||||
foreach (var p in pipes)
|
||||
p.ClearGhostFlags();
|
||||
|
||||
// 4. Integrate non‑pipe components (volumes, atmosphere, etc.)
|
||||
foreach (var comp in _components)
|
||||
comp.UpdateState(_dt);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user