Helmholtz testing (no decay bug)

This commit is contained in:
max
2026-05-09 01:44:35 +02:00
parent 9c9e23147a
commit 77ef4753a3
23 changed files with 1811 additions and 2118 deletions

View File

@@ -2,40 +2,30 @@ using System;
namespace FluidSim.Core
{
/// <summary>
/// Compressible flow through an orifice, modelled as an isentropic nozzle.
/// The caller provides the upstream stagnation state (pUp, rhoUp, TUp),
/// downstream pressure, orifice area, discharge coefficient, and gas properties.
/// Returns the face state and mass flow from upstream to downstream.
/// </summary>
public static class IsentropicOrifice
{
public static void Compute(
double pUp, double rhoUp, double TUp, // upstream stagnation
double pDown, // downstream back pressure
double gamma, double R, double area, double Cd,
out double mdot, out double rhoFace, out double uFace, out double pFace)
float pUp, float rhoUp, float TUp,
float pDown, float gamma, float R, float area, float Cd,
out float mdot, out float rhoFace, out float uFace, out float pFace)
{
mdot = 0; rhoFace = rhoUp; uFace = 0; pFace = pUp;
mdot = 0f; rhoFace = rhoUp; uFace = 0f; pFace = pUp;
if (area <= 0f || pUp <= 0f || rhoUp <= 0f || TUp <= 0f) return;
if (area <= 0 || pUp <= 0 || rhoUp <= 0 || TUp <= 0)
return;
float pr = MathF.Min(pDown / pUp, 1f);
if (pr < 1e-6f) pr = 1e-6f;
float prCrit = MathF.Pow(2f / (gamma + 1f), gamma / (gamma - 1f));
if (pr < prCrit) pr = prCrit;
double pr = pDown / pUp;
if (pr < 1e-6) pr = 1e-6;
float exponent = (gamma - 1f) / gamma;
float M = MathF.Sqrt((2f / (gamma - 1f)) * (MathF.Pow(pr, -exponent) - 1f));
if (float.IsNaN(M)) M = 0f;
double prCrit = Math.Pow(2.0 / (gamma + 1.0), gamma / (gamma - 1.0));
if (pr < prCrit) pr = prCrit; // choked flow
double exponent = (gamma - 1.0) / gamma;
double M = Math.Sqrt((2.0 / (gamma - 1.0)) * (Math.Pow(pr, -exponent) - 1.0));
if (double.IsNaN(M)) M = 0;
double aUp = Math.Sqrt(gamma * R * TUp);
float aUp = MathF.Sqrt(gamma * R * TUp);
uFace = M * aUp;
rhoFace = rhoUp * Math.Pow(pr, 1.0 / gamma);
rhoFace = rhoUp * MathF.Pow(pr, 1f / gamma);
pFace = pUp * pr;
mdot = rhoFace * uFace * area * Cd; // positive from upstream to downstream
mdot = rhoFace * uFace * area * Cd;
}
}
}