General testing

This commit is contained in:
2026-05-05 10:32:30 +02:00
parent ff4c4aef23
commit d963032e74
11 changed files with 794 additions and 448 deletions

46
Core/NozzleFlow.cs Normal file
View File

@@ -0,0 +1,46 @@
using System;
using FluidSim.Components;
namespace FluidSim.Core
{
public static class NozzleFlow
{
public static void Compute(Volume0D vol, double area, double downstreamPressure,
out double massFlow, out double rhoFace, out double uFace, out double pFace,
double gamma = 1.4)
{
// Default fallback (no flow)
massFlow = 0.0;
rhoFace = 0.0;
uFace = 0.0;
pFace = 0.0;
if (vol == null || vol.Mass <= 0 || vol.Volume <= 0)
return;
double p0 = vol.Pressure;
double T0 = vol.Temperature;
double R = vol.GasConstant;
double rho0 = vol.Density;
if (double.IsNaN(p0) || double.IsNaN(T0) || double.IsNaN(rho0) ||
p0 <= 0 || T0 <= 0 || rho0 <= 0)
return;
double pr = downstreamPressure / p0;
double choked = Math.Pow(2.0 / (gamma + 1.0), gamma / (gamma - 1.0));
if (pr < choked) pr = choked;
double M = Math.Sqrt((2.0 / (gamma - 1.0)) * (Math.Pow(pr, -(gamma - 1.0) / gamma) - 1.0));
if (double.IsNaN(M)) return;
uFace = M * Math.Sqrt(gamma * R * T0);
rhoFace = rho0 * Math.Pow(pr, 1.0 / gamma);
pFace = p0 * pr;
massFlow = rhoFace * uFace * area;
if (double.IsNaN(massFlow) || double.IsInfinity(massFlow))
massFlow = 0.0;
}
}
}