refactoring (broken right now)
This commit is contained in:
96
Scenarios/TestScenario.cs
Normal file
96
Scenarios/TestScenario.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using FluidSim.Components;
|
||||
using FluidSim.Core;
|
||||
|
||||
namespace FluidSim.Tests
|
||||
{
|
||||
public class TestScenario : Scenario
|
||||
{
|
||||
private Solver solver;
|
||||
private Volume0D volume;
|
||||
private Pipe1D pipe;
|
||||
private Atmosphere atmosphere;
|
||||
private OrificeLink orificeLink;
|
||||
private OpenEndLink openEndLink;
|
||||
private int stepCount;
|
||||
|
||||
public override void Initialize(int sampleRate)
|
||||
{
|
||||
double dt = 1.0 / sampleRate;
|
||||
|
||||
solver = new Solver();
|
||||
solver.SetTimeStep(dt);
|
||||
|
||||
volume = new Volume0D(1e-3, 150000.0, 300.0);
|
||||
solver.AddComponent(volume);
|
||||
|
||||
pipe = new Pipe1D(2.0, 1e-4, 20);
|
||||
solver.AddComponent(pipe);
|
||||
|
||||
atmosphere = new Atmosphere();
|
||||
solver.AddComponent(atmosphere);
|
||||
|
||||
// Volume → left pipe end (orifice)
|
||||
var volPort = volume.CreatePort();
|
||||
orificeLink = new OrificeLink(volPort, pipe, isPipeLeftEnd: true, areaProvider: () => 1e-5)
|
||||
{
|
||||
DischargeCoefficient = 0.62,
|
||||
Gamma = volume.Gamma,
|
||||
GasConstant = volume.GasConstant
|
||||
};
|
||||
solver.AddOrificeLink(orificeLink);
|
||||
|
||||
// Right pipe end → atmosphere (characteristic open‑end)
|
||||
openEndLink = new OpenEndLink(pipe, isLeftEnd: false)
|
||||
{
|
||||
AmbientPressure = 101325.0,
|
||||
Gamma = 1.4
|
||||
};
|
||||
solver.AddOpenEndLink(openEndLink);
|
||||
|
||||
stepCount = 0;
|
||||
Console.WriteLine("TestScenario initialized with sampleRate = " + sampleRate);
|
||||
}
|
||||
|
||||
public override float Process()
|
||||
{
|
||||
solver.Step();
|
||||
stepCount++;
|
||||
|
||||
if (stepCount % 100 == 0)
|
||||
{
|
||||
double volPressure = volume.Pressure;
|
||||
double volMass = volume.Mass;
|
||||
double pipeLeftPressure = pipe.GetCellPressure(0);
|
||||
double pipeRightPressure = pipe.GetCellPressure(pipe.CellCount - 1);
|
||||
double mdotOrifice = orificeLink.LastMassFlowRate;
|
||||
double mdotOpen = openEndLink.LastMassFlowRate;
|
||||
|
||||
Console.WriteLine($"Step {stepCount}:");
|
||||
Console.WriteLine($" Vol Pressure = {volPressure:F1} Pa, Mass = {volMass:E4} kg");
|
||||
Console.WriteLine($" Pipe left P = {pipeLeftPressure:F1} Pa, right P = {pipeRightPressure:F1} Pa");
|
||||
Console.WriteLine($" Orifice mdot = {mdotOrifice:E4} kg/s, Open‑end mdot = {mdotOpen:E4} kg/s");
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
// Audio sample from the open‑end mass flow
|
||||
return (float)openEndLink.LastMassFlowRate;
|
||||
}
|
||||
|
||||
public override void Draw(RenderWindow target)
|
||||
{
|
||||
float winWidth = target.GetView().Size.X;
|
||||
float winHeight = target.GetView().Size.Y;
|
||||
|
||||
float pipeCenterY = winHeight / 2f;
|
||||
float margin = 60f;
|
||||
float pipeStartX = margin;
|
||||
float pipeEndX = winWidth - margin;
|
||||
|
||||
// Use the shared pipe drawing from the base class
|
||||
DrawPipe(target, pipe, pipeCenterY, pipeStartX, pipeEndX);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user