Adding initial Project to git
This commit is contained in:
74
BWR.core/Components/Concrete/Pump.cs
Normal file
74
BWR.core/Components/Concrete/Pump.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
// MyBWRSimulator.Core/Components/Concrete/Pump.cs
|
||||
namespace MyBWRSimulator.Core.Components.Concrete
|
||||
{
|
||||
using MyBWRSimulator.Core.Components.Abstract;
|
||||
using MyBWRSimulator.Core.Ports;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a Pump component in the BWR simulation.
|
||||
/// </summary>
|
||||
public class Pump : Component
|
||||
{
|
||||
public double PumpSpeed { get; set; } // 0.0 to 1.0 (0% to 100%)
|
||||
public double MaxFlowRate { get; private set; } // Max flow at 100% speed
|
||||
public double MaxHeadPressure { get; private set; } // Max pressure at 100% speed
|
||||
|
||||
// Publicly expose ports for easier named access if needed, but GetFluidPortById is preferred
|
||||
public FluidPort Inlet => GetFluidPortById("Inlet");
|
||||
public FluidPort Outlet => GetFluidPortById("Outlet");
|
||||
|
||||
|
||||
public Pump(string id, string name, double maxFlowRate, double maxHeadPressure)
|
||||
: base(id, name, $"A pump component with max flow {maxFlowRate} and max head {maxHeadPressure}.", 1) // Priority 1
|
||||
{
|
||||
MaxFlowRate = maxFlowRate;
|
||||
MaxHeadPressure = maxHeadPressure;
|
||||
PumpSpeed = 0.0; // Initially off
|
||||
|
||||
// Use descriptive IDs for ports
|
||||
AddFluidPort(new FluidPort("Inlet"));
|
||||
AddFluidPort(new FluidPort("Outlet"));
|
||||
}
|
||||
|
||||
public override void Update(double deltaTime)
|
||||
{
|
||||
if (PumpSpeed > 0)
|
||||
{
|
||||
// Simple pump model: Flow proportional to speed, pressure based on head
|
||||
double actualFlowRate = PumpSpeed * MaxFlowRate;
|
||||
double actualPressureIncrease = PumpSpeed * MaxHeadPressure;
|
||||
|
||||
// Read from inlet
|
||||
double inletPressure = Inlet.Pressure;
|
||||
double inletTemperature = Inlet.Temperature;
|
||||
|
||||
// Calculate outlet properties
|
||||
Outlet.FlowRate = actualFlowRate;
|
||||
Outlet.Pressure = inletPressure + actualPressureIncrease;
|
||||
Outlet.Temperature = inletTemperature; // Assuming no temperature change by pump
|
||||
|
||||
// Mirror values to connected ports
|
||||
Outlet.MirrorToConnectedPort();
|
||||
|
||||
Console.WriteLine($"{Name} ({ID}) - Flow: {actualFlowRate:F2} kg/s, Outlet P: {Outlet.Pressure:F2} Pa");
|
||||
}
|
||||
else
|
||||
{
|
||||
// If not powered or off, no flow
|
||||
Outlet.FlowRate = 0.0;
|
||||
Outlet.Pressure = Inlet.Pressure; // Outlet pressure equals inlet if no pumping
|
||||
Outlet.Temperature = Inlet.Temperature;
|
||||
Outlet.MirrorToConnectedPort();
|
||||
Console.WriteLine($"{Name} ({ID}) - Off/No Power.");
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPumpSpeed(double speed)
|
||||
{
|
||||
PumpSpeed = Math.Clamp(speed, 0.0, 1.0);
|
||||
Console.WriteLine($"{Name} ({ID}) - Pump speed set to {PumpSpeed * 100:F0}%.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user