Fixed orifice with inertia, automatic R value
This commit is contained in:
@@ -38,7 +38,7 @@ namespace FluidSim.Tests
|
||||
int neckCells = 20;
|
||||
|
||||
// --- Volume (cavity) ---
|
||||
float initialPressure = 1.2f * 101325f; // slight overpressure
|
||||
float initialPressure = 1.1f * 101325f; // slight overpressure
|
||||
float initialTemperature = 300f;
|
||||
cavity = new Volume0D(cavityVolume, initialPressure, initialTemperature);
|
||||
cavityPort = cavity.CreatePort();
|
||||
@@ -56,24 +56,16 @@ namespace FluidSim.Tests
|
||||
|
||||
float rho0 = 101325f / (287f * 300f);
|
||||
pipeSystem = new PipeSystem(neckCells, pipeStart, pipeEnd, areas, dxs, rho0, 0f, 101325f);
|
||||
pipeSystem.DampingMultiplier = 500f;
|
||||
|
||||
// --- Boundary system ---
|
||||
boundaries = new BoundarySystem(pipeSystem, maxOrifices: 1, maxOpenEnds: 1);
|
||||
|
||||
float ComputeResistance(float decayTimeSeconds, float rho, float L_eff, float A)
|
||||
{
|
||||
// R = 2 * rho * L_eff / (A * decayTimeSeconds)
|
||||
return 2f * rho * L_eff / (A * MathF.Max(decayTimeSeconds, 1e-6f));
|
||||
}
|
||||
|
||||
// Use steady orifice – the pipe already provides the inertia
|
||||
// Standard orifice with built‑in minor loss (K = 0.5) – no inertance needed
|
||||
boundaries.AddOrificeWithInertance(
|
||||
cavityPort, pipeIndex: 0, isLeftEnd: true,
|
||||
areaIndex: cavityOrificeIdx,
|
||||
dischargeCoeff: 0.9f,
|
||||
effectiveLength: neckLength, // physical length (or L_eff)
|
||||
lossCoefficient: 7000 // start with this, adjust for decay time
|
||||
effectiveLength: neckLength // physical neck length
|
||||
);
|
||||
|
||||
// Open end at right side of pipe
|
||||
@@ -83,8 +75,7 @@ namespace FluidSim.Tests
|
||||
boundaries.SetOrificeAreas(orificeAreas);
|
||||
|
||||
// --- Solver ---
|
||||
// Slightly higher sub‑step count to ensure stability of the resonant oscillation
|
||||
solver = new Solver { SubStepCount = 6, EnableProfiling = false };
|
||||
solver = new Solver { SubStepCount = 8, EnableProfiling = false };
|
||||
solver.SetTimeStep(dt);
|
||||
solver.SetPipeSystem(pipeSystem);
|
||||
solver.SetBoundarySystem(boundaries);
|
||||
@@ -99,43 +90,12 @@ namespace FluidSim.Tests
|
||||
|
||||
public override float Process()
|
||||
{
|
||||
stepCount++;
|
||||
if (stepCount <= 8192) return 0f; // let buffer pre‑fill
|
||||
|
||||
solver.Step();
|
||||
stepCount++;
|
||||
|
||||
float flow = boundaries.GetOpenEndMassFlow(openEndIdx);
|
||||
float sample = soundProcessor.Process(flow);
|
||||
|
||||
if (stepCount % 10000 == 0)
|
||||
{
|
||||
float cavityP = cavity.Pressure;
|
||||
float cavityT = cavity.Temperature;
|
||||
float cavityRho = cavity.Density;
|
||||
float cCavity = MathF.Sqrt(1.4f * cavityP / MathF.Max(cavityRho, 1e-12f));
|
||||
|
||||
// Temperature in the middle of the neck
|
||||
int midCell = 10;
|
||||
float pMid = pipeSystem.GetCellPressure(midCell);
|
||||
float rhoMid = pipeSystem.GetCellDensity(midCell);
|
||||
float tMid = pMid / MathF.Max(rhoMid * 287f, 1e-12f);
|
||||
|
||||
// Neck effective length (physical + end correction)
|
||||
float neckLen = 0.05f; // physical
|
||||
float neckDia = 0.02f;
|
||||
float neckArea = MathF.PI * 0.25f * neckDia * neckDia;
|
||||
float endCorr = 0.85f * neckDia; // unflanged end
|
||||
float L_eff = neckLen + endCorr;
|
||||
|
||||
// Theoretical Helmholtz frequency from current cavity sound speed
|
||||
float fHelmholtz = cCavity / (2f * MathF.PI) *
|
||||
MathF.Sqrt(neckArea / (cavity.Volume * L_eff));
|
||||
|
||||
Console.WriteLine(
|
||||
$"Step {stepCount}: cav P={cavityP / 1e5f:F4} bar, T={cavityT:F1} K, " +
|
||||
$"pipeMid T={tMid:F1} K, est f={fHelmholtz:F1} Hz");
|
||||
}
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user