added 4 cyl
This commit is contained in:
@@ -20,17 +20,11 @@ namespace FluidSim.Core
|
||||
|
||||
// ---------- Timing accumulators (reset every LogInterval steps) ----------
|
||||
private long _stepCount;
|
||||
private double _timeTotal;
|
||||
private double _timeCFL;
|
||||
private double _timeOrifice;
|
||||
private double _timeOpenEnd;
|
||||
private double _timeJunction;
|
||||
private double _timePipe;
|
||||
private double _timeClearGhosts;
|
||||
private double _timeUpdateState;
|
||||
private double _timeTotal, _timeCFL, _timeOrifice, _timeOpenEnd,
|
||||
_timePipe, _timeClearGhosts, _timeUpdateState;
|
||||
|
||||
private const int LogInterval = 5000; // print once per second (at 44.1 kHz)
|
||||
private const bool EnableLogging = false;
|
||||
private const int LogInterval = 5000;
|
||||
private const bool EnableLogging = false; // temporarily ON for debugging
|
||||
|
||||
public void SetTimeStep(double dt) => _dt = dt;
|
||||
|
||||
@@ -45,18 +39,44 @@ namespace FluidSim.Core
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
||||
// CFL count
|
||||
// CFL count – track which pipe demands the most sub‑steps
|
||||
int nSub = 1;
|
||||
Pipe1D worstPipe = pipes[0];
|
||||
foreach (var p in pipes)
|
||||
nSub = Math.Max(nSub, p.GetRequiredSubSteps(_dt, CflTarget));
|
||||
{
|
||||
int n = p.GetRequiredSubSteps(_dt, CflTarget);
|
||||
if (n > nSub)
|
||||
{
|
||||
nSub = n;
|
||||
worstPipe = p;
|
||||
}
|
||||
}
|
||||
double dtSub = _dt / nSub;
|
||||
|
||||
// ----- Diagnostic: warn if nSub is high -----
|
||||
if (nSub > 50)
|
||||
{
|
||||
double maxW = 0;
|
||||
for (int i = 0; i < worstPipe.CellCount; i++)
|
||||
{
|
||||
double rho = worstPipe.GetCellDensity(i);
|
||||
double u = Math.Abs(worstPipe.GetCellVelocity(i));
|
||||
double p = worstPipe.GetCellPressure(i);
|
||||
double c = Math.Sqrt(1.4 * p / Math.Max(rho, 1e-12));
|
||||
if (u + c > maxW) maxW = u + c;
|
||||
}
|
||||
Console.WriteLine($"nSub = {nSub} (worst pipe: {worstPipe.Name}, maxW = {maxW:F0} m/s)");
|
||||
}
|
||||
|
||||
_timeCFL += sw.Elapsed.TotalSeconds;
|
||||
|
||||
// ----- Safety cap – prevent the solver from hanging -----
|
||||
const int maxSubSteps = 10000;
|
||||
if (nSub > maxSubSteps)
|
||||
const int hardLimit = 500; // temporary low cap for debugging
|
||||
|
||||
if (nSub > hardLimit)
|
||||
{
|
||||
Console.WriteLine($"Warning: required sub‑steps {nSub} exceeds limit. Simulation stopped.");
|
||||
Console.WriteLine($"nSub ({nSub}) exceeds hard limit {hardLimit}. Simulation step skipped.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -90,49 +110,33 @@ namespace FluidSim.Core
|
||||
comp.UpdateState(_dt);
|
||||
_timeUpdateState += sw.Elapsed.TotalSeconds - tUS;
|
||||
|
||||
// accumulate total step time (includes CFL, sub‑steps, clear ghosts, update state)
|
||||
_timeTotal += sw.Elapsed.TotalSeconds;
|
||||
|
||||
// ---------- Periodic report ----------
|
||||
_stepCount++;
|
||||
if (_stepCount % LogInterval == 0 && EnableLogging)
|
||||
{
|
||||
if (_timeTotal > 0)
|
||||
{
|
||||
double totalMs = _timeTotal * 1000.0;
|
||||
double avgUs = (_timeTotal / LogInterval) * 1e6; // µs per step
|
||||
double stepsPerSec = LogInterval / _timeTotal; // steps per second
|
||||
double stepsPerSec = LogInterval / _timeTotal;
|
||||
double avgUs = (_timeTotal / LogInterval) * 1e6;
|
||||
|
||||
Console.WriteLine($"--- Solver timing ({LogInterval} steps) ---");
|
||||
Console.WriteLine($" Steps per second: {stepsPerSec:F1}");
|
||||
Console.WriteLine($" Avg step time: {avgUs:F1} µs (last nSub = {nSub})");
|
||||
Console.WriteLine($" CFL calc: {_timeCFL / _timeTotal * 100:F1} % ({_timeCFL * 1e6 / LogInterval:F1} µs/step)");
|
||||
Console.WriteLine($" CFL calc: {_timeCFL / _timeTotal * 100:F1} %");
|
||||
Console.WriteLine($" Sub‑step loop:");
|
||||
Console.WriteLine($" Orifice: {_timeOrifice / _timeTotal * 100:F1} % ({_timeOrifice * 1e6 / LogInterval:F1} µs/step)");
|
||||
Console.WriteLine($" OpenEnd: {_timeOpenEnd / _timeTotal * 100:F1} % ({_timeOpenEnd * 1e6 / LogInterval:F1} µs/step)");
|
||||
Console.WriteLine($" Junctions: {_timeJunction / _timeTotal * 100:F1} % ({_timeJunction * 1e6 / LogInterval:F1} µs/step)");
|
||||
Console.WriteLine($" Pipe steps: {_timePipe / _timeTotal * 100:F1} % ({_timePipe * 1e6 / LogInterval:F1} µs/step)");
|
||||
Console.WriteLine($" Clear ghosts: {_timeClearGhosts / _timeTotal * 100:F1} % ({_timeClearGhosts * 1e6 / LogInterval:F1} µs/step)");
|
||||
Console.WriteLine($" Update state: {_timeUpdateState / _timeTotal * 100:F1} % ({_timeUpdateState * 1e6 / LogInterval:F1} µs/step)");
|
||||
Console.WriteLine($" Orifice: {_timeOrifice / _timeTotal * 100:F1} %");
|
||||
Console.WriteLine($" OpenEnd: {_timeOpenEnd / _timeTotal * 100:F1} %");
|
||||
Console.WriteLine($" Pipe steps: {_timePipe / _timeTotal * 100:F1} %");
|
||||
Console.WriteLine($" Clear ghosts: {_timeClearGhosts / _timeTotal * 100:F1} %");
|
||||
Console.WriteLine($" Update state: {_timeUpdateState / _timeTotal * 100:F1} %");
|
||||
Console.WriteLine();
|
||||
|
||||
// ---------- Optional detailed pipe profiling ----------
|
||||
if (Pipe1D.EnableDetailedProfiling)
|
||||
{
|
||||
foreach (var pipe in pipes)
|
||||
{
|
||||
Console.WriteLine(pipe.GetDetailProfileReport());
|
||||
pipe.ResetDetailCounters();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reset accumulators for next interval
|
||||
_timeTotal = 0;
|
||||
_timeCFL = 0;
|
||||
_timeOrifice = 0;
|
||||
_timeOpenEnd = 0;
|
||||
_timeJunction = 0;
|
||||
_timePipe = 0;
|
||||
_timeClearGhosts = 0;
|
||||
_timeUpdateState = 0;
|
||||
|
||||
Reference in New Issue
Block a user