Known bad point (unphysical energy loss)
This commit is contained in:
@@ -6,58 +6,46 @@ namespace FluidSim.Core
|
||||
{
|
||||
public static class Simulation
|
||||
{
|
||||
private static Solver solver;
|
||||
private static Volume0D volA, volB;
|
||||
private static Pipe1D pipe;
|
||||
private static Connection leftConn, rightConn; // dummy connections for orifice params
|
||||
private static Connection connA, connB;
|
||||
private static int stepCount;
|
||||
private static double time;
|
||||
private static double dt;
|
||||
private static int stepCount;
|
||||
|
||||
public static void Initialize(int sampleRate)
|
||||
{
|
||||
dt = 1.0 / sampleRate;
|
||||
|
||||
double V = 5.0 * Units.L;
|
||||
volA = new Volume0D(V, 1.1 * Units.atm, Units.Celsius(20), sampleRate);
|
||||
volB = new Volume0D(V, 1.0 * Units.atm, Units.Celsius(20), sampleRate);
|
||||
|
||||
double length = 150 * Units.mm;
|
||||
double diameter = 25 * Units.mm;
|
||||
double area = Units.AreaFromDiameter(25, Units.mm);
|
||||
int nCells = 10;
|
||||
|
||||
pipe = new Pipe1D(length, area, nCells, sampleRate);
|
||||
pipe.SetUniformState(1.2, 0.0, 1.0 * Units.atm); // start at 1 atm
|
||||
pipe.SetUniformState(volA.Density, 0.0, volA.Pressure);
|
||||
pipe.FrictionFactor = 0.02;
|
||||
|
||||
// Dummy connections – only used for orifice parameters
|
||||
leftConn = new Connection(null, null) { Area = area, DischargeCoefficient = 1.0, Gamma = 1.4 };
|
||||
rightConn = new Connection(null, null) { Area = area, DischargeCoefficient = 1.0, Gamma = 1.4 };
|
||||
// Connections with orifice area equal to pipe area (flange joint)
|
||||
connA = new Connection(volA.Port, pipe.PortA) { Area = area, DischargeCoefficient = 1.0, Gamma = 1.4 };
|
||||
connB = new Connection(pipe.PortB, volB.Port) { Area = area, DischargeCoefficient = 1.0, Gamma = 1.4 };
|
||||
|
||||
solver = new Solver();
|
||||
solver.AddVolume(volA);
|
||||
solver.AddVolume(volB);
|
||||
solver.AddPipe(pipe);
|
||||
solver.AddConnection(connA);
|
||||
solver.AddConnection(connB);
|
||||
}
|
||||
|
||||
public static float Process()
|
||||
{
|
||||
// Fixed boundary reservoirs
|
||||
double pLeft = 1.1 * Units.atm;
|
||||
double rhoLeft = 1.2;
|
||||
double uLeft = 0.0;
|
||||
|
||||
double pRight = 1.0 * Units.atm;
|
||||
double rhoRight = 1.2;
|
||||
double uRight = 0.0;
|
||||
|
||||
// Compute boundary fluxes via orifice model
|
||||
OrificeBoundary.PipeVolumeFlux(
|
||||
pipe.GetLeftPressure(), pipe.GetLeftDensity(), 0.0,
|
||||
pLeft, rhoLeft, uLeft,
|
||||
leftConn, pipe.Area, true,
|
||||
out double leftMassFlux, out double leftMomFlux, out double leftEnergyFlux);
|
||||
|
||||
OrificeBoundary.PipeVolumeFlux(
|
||||
pipe.GetRightPressure(), pipe.GetRightDensity(), 0.0,
|
||||
pRight, rhoRight, uRight,
|
||||
rightConn, pipe.Area, false,
|
||||
out double rightMassFlux, out double rightMomFlux, out double rightEnergyFlux);
|
||||
|
||||
pipe.SetLeftBoundaryFlux(leftMassFlux, leftMomFlux, leftEnergyFlux);
|
||||
pipe.SetRightBoundaryFlux(rightMassFlux, rightMomFlux, rightEnergyFlux);
|
||||
pipe.Simulate();
|
||||
|
||||
solver.Step();
|
||||
time += dt;
|
||||
stepCount++;
|
||||
Log();
|
||||
@@ -66,20 +54,13 @@ namespace FluidSim.Core
|
||||
|
||||
public static void Log()
|
||||
{
|
||||
if (stepCount <= 20 || stepCount % 50 == 0)
|
||||
if (stepCount <= 50 || stepCount % 200 == 0)
|
||||
{
|
||||
Console.WriteLine($"Step {stepCount:D4} t = {time * 1e3:F3} ms");
|
||||
for (int i = 0; i < pipe.GetCellCount(); i++)
|
||||
{
|
||||
double rho = pipe.GetCellDensity(i);
|
||||
double p = pipe.GetCellPressure(i);
|
||||
double u = pipe.GetCellVelocity(i);
|
||||
Console.WriteLine($" Cell {i}: ρ={rho:F4} kg/m³ p={p / 1e5:F6} bar u={u:F3} m/s");
|
||||
}
|
||||
double leftFlow = pipe.PortA.MassFlowRate;
|
||||
double rightFlow = pipe.PortB.MassFlowRate;
|
||||
Console.WriteLine($" Left flow = {leftFlow * 1e3:F4} g/s Right flow = {rightFlow * 1e3:F4} g/s");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(
|
||||
$"t = {time * 1e3:F3} ms Step {stepCount:D4}: " +
|
||||
$"PA = {volA.Pressure / 1e5:F6} bar, " +
|
||||
$"PB = {volB.Pressure / 1e5:F6} bar, " +
|
||||
$"FlowA = {pipe.PortA.MassFlowRate * 1e3:F2} g/s");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user