added valves display

This commit is contained in:
maxwes08
2026-05-06 14:05:37 +02:00
parent d6b1d214f5
commit bc4e077924
4 changed files with 103 additions and 29 deletions

View File

@@ -31,7 +31,7 @@ namespace FluidSim.Core
private const int LogInterval = 1000;
public double Throttle { get; set; } = 0.15;
private const double FullLoadPeakPressure = 60.0 * Units.bar;
private const double FullLoadPeakPressure = 140.0 * Units.bar;
public override void Initialize(int sampleRate)
{
@@ -41,29 +41,29 @@ namespace FluidSim.Core
crankshaft = new Crankshaft(initialRPM: 2000.0)
{
Inertia = 0.05,
FrictionConstant = 0.5,
FrictionViscous = 0.01
FrictionConstant = 0.2,
FrictionViscous = 0.025
};
// Exhaust pipe (longer, larger)
double exhLength = 1;
double exhRadius = 0.02;
double exhLength = 0.5;
double exhRadius = 1.5 * Units.cm;
exhPipeArea = Math.PI * exhRadius * exhRadius;
exhaustPipe = new Pipe1D(exhLength, exhPipeArea, sampleRate, forcedCellCount: 100);
exhaustPipe = new Pipe1D(exhLength, exhPipeArea, sampleRate, forcedCellCount: 30);
exhaustPipe.SetUniformState(1.225, 0.0, AmbientPressure);
exhaustPipe.DampingMultiplier = 0.0;
exhaustPipe.EnergyRelaxationRate = 100.0f;
// Intake pipe (shorter, narrower)
double intLength = 1;
double intRadius = 0.01;
double intLength = 0.1;
double intRadius = 1 * Units.cm;
intPipeArea = Math.PI * intRadius * intRadius;
intakePipe = new Pipe1D(intLength, intPipeArea, sampleRate, forcedCellCount: 50);
intakePipe = new Pipe1D(intLength, intPipeArea, sampleRate, forcedCellCount: 10);
intakePipe.SetUniformState(1.225, 0.0, AmbientPressure);
// Cylinder (starts at BDC, fresh charge)
engineCyl = new EngineCylinder(crankshaft,
bore: 0.065, stroke: 0.0565, compressionRatio: 8.0,
bore: 56 * Units.mm, stroke: 57 * Units.mm, compressionRatio: 9.5,
exhPipeArea: exhPipeArea, intPipeArea: intPipeArea, sampleRate: sampleRate);
engineCyl.ignition = true;
@@ -107,7 +107,9 @@ namespace FluidSim.Core
public override float Process()
{
double throttle = Math.Clamp(Throttle, 0.2, 1.0);
double idleThrottle = 0.1;
if (crankshaft.AngularVelocity < 80) idleThrottle = 0.2;
double throttle = Math.Clamp(Throttle, idleThrottle, 1.0);
double targetPressure = throttle * FullLoadPeakPressure;
engineCyl.TargetPeakPressure = targetPressure;
@@ -211,10 +213,10 @@ namespace FluidSim.Core
float centerY = winH / 2f;
const float T_ambient = 293.15f;
const float T_hot = 1500f;
const float T_cold = 0f;
const float R = 287.05f;
float deltaHot = T_hot - T_ambient;
const float T_hot = 1500f;
const float T_cold = 0f;
const float R = 287.05f;
float deltaHot = T_hot - T_ambient;
float deltaCold = T_ambient - T_cold;
float NormaliseTemperature(double T)
@@ -240,7 +242,7 @@ namespace FluidSim.Core
target.Draw(cylRect);
// ---- Piston ----
float pistonWidth = cylW - 12f;
float pistonWidth = cylW - 12f;
float pistonHeight = 16f;
float pistonFraction = (float)engineCyl.PistonPositionFraction;
float pistonTopY = cylRect.Position.Y + pistonFraction * (cylH - pistonHeight);
@@ -251,12 +253,36 @@ namespace FluidSim.Core
};
target.Draw(pistonRect);
// ---------- NEW: Valve lift indicators ----------
float barWidth = 30f;
float barHeight = 10f;
float exhLift = (float)engineCyl.ExhaustValveLiftCurrent;
float intLift = (float)engineCyl.IntakeValveLiftCurrent;
// Exhaust valve indicator (right side of cylinder)
var exhBar = new RectangleShape(new Vector2f(barWidth, barHeight))
{
Position = new Vector2f(cylRect.Position.X + cylW - 10,
cylRect.Position.Y - 20 - exhLift * 20),
FillColor = new Color(200, 200, 200)
};
target.Draw(exhBar);
// Intake valve indicator (left side of cylinder)
var intBar = new RectangleShape(new Vector2f(barWidth, barHeight))
{
Position = new Vector2f(cylRect.Position.X - 20,
cylRect.Position.Y - 20 - intLift * 20),
FillColor = new Color(200, 200, 200)
};
target.Draw(intBar);
// ---- Exhaust pipe (rightwards) ----
DrawPipe(target, exhaustPipe, startX: 280f, endX: winW - 60f, centerY,
DrawPipe(target, exhaustPipe, startX: 280f, endX: winW - 60f, centerY + 10 - cylRect.Size.Y / 2,
T_ambient, T_hot, T_cold, R, NormaliseTemperature, true);
// ---- Intake pipe (leftwards) ----
DrawPipe(target, intakePipe, startX: 200f, endX: 20f, centerY,
DrawPipe(target, intakePipe, startX: 200f, endX: 20f, centerY + 10 - cylRect.Size.Y / 2,
T_ambient, T_hot, T_cold, R, NormaliseTemperature, false);
}
@@ -276,11 +302,11 @@ namespace FluidSim.Core
for (int i = 0; i < n; i++)
{
float x = startX + i * dx;
double p = pipe.GetCellPressure(i);
double p = pipe.GetCellPressure(i);
double rho = pipe.GetCellDensity(i);
double T = p / (rho * R);
double T = p / (rho * R);
float r = baseRadius * 0.3f * (float)(1.0 + (p - ambPress) / ambPress);
float r = baseRadius * 0.2f * (float)(1.0 + (p - ambPress) / ambPress);
if (r < 2f) r = 2f;
float tn = normaliseTemp(T);
@@ -289,7 +315,7 @@ namespace FluidSim.Core
byte gC = (byte)(255 * (1 - Math.Abs(tn)));
var col = new Color(rC, gC, bC);
vertices[i * 2] = new Vertex(new Vector2f(x, centerY - r), col);
vertices[i * 2] = new Vertex(new Vector2f(x, centerY - r), col);
vertices[i * 2 + 1] = new Vertex(new Vector2f(x, centerY + r), col);
}