Adding initial Project to git

This commit is contained in:
2025-12-29 19:58:26 +00:00
parent 15f9dce88c
commit b54c9bbb1c
24 changed files with 1396 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
// MyBWRSimulator.Core/Components/Concrete/FluidTank.cs
namespace MyBWRSimulator.Core.Components.Concrete
{
using MyBWRSimulator.Core.Components.Abstract;
//using MyBWRSimulator.Core.Components.Enums;
using MyBWRSimulator.Core.Ports;
using System;
using System.Collections.Generic;
/// <summary>
/// Represents a Fluid Tank component in the BWR simulation.
/// </summary>
public class FluidTank : Component
{
public double MaxVolume { get; private set; } // Maximum capacity of the tank (m^3)
public double CurrentVolume { get; private set; } // Current fluid volume in the tank (m^3)
public double CurrentLevel => CurrentVolume / MaxVolume; // 0.0 to 1.0 (0% to 100%)
public double ContentsTemperature { get; private set; } // Average temperature of fluid in tank
public FluidPort Inlet => GetFluidPortById("Inlet");
public FluidPort Outlet => GetFluidPortById("Outlet");
public FluidTank(string id, string name, double maxVolume, int numInlets, int numOutlets, double initialVolume = 0.0, double initialTemp = 293.15)
: base(id, name, $"A fluid tank with max volume {maxVolume} m^3.", 5) // Priority 5 (updates last)
{
MaxVolume = maxVolume;
CurrentVolume = Math.Clamp(initialVolume, 0.0, MaxVolume);
ContentsTemperature = initialTemp;
AddFluidPort(new FluidPort("Inlet"));
AddFluidPort(new FluidPort("Outlet"));
}
public override void Update(double deltaTime)
{
double FlowVolume = 0.0;
double InletEnergy = 0.0; // For temperature calculation
FlowVolume += Inlet.FlowRate * deltaTime; // FlowRate is volume/time, so FlowRate * deltaTime = volume
InletEnergy += Inlet.FlowRate * Inlet.Temperature * deltaTime; // Simple energy balance
// Sum outgoing flow (assuming outlets draw based on their connected components)
// For a tank, outlets typically "demand" flow, and the tank supplies it if available.
// For simplicity here, we'll assume outlets simply remove fluid.
// In a real system, outlet flow depends on downstream pressure and tank level.
FlowVolume -= Outlet.FlowRate * deltaTime;
// Update volume
double newVolume = CurrentVolume + FlowVolume;
CurrentVolume = Math.Clamp(newVolume, 0.0, MaxVolume);
// Update outlet port properties (e.g., pressure based on level)
// This is a simplification; in reality, outlet pressure also depends on downstream pressure
double pressureFromLevel = CurrentLevel * 100000; // Example: 100kPa at full level
Outlet.Pressure = pressureFromLevel; // Or a more complex calculation
Outlet.Temperature = ContentsTemperature;
// Mirror values to connected ports
Outlet.MirrorToConnectedPort();
Console.WriteLine($"{Name} ({ID}) - Volume: {CurrentVolume:F2} m^3 ({CurrentLevel * 100:F1}%), Temp: {ContentsTemperature:F1} K");
}
}
}

View 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}%.");
}
}
}

View File

@@ -0,0 +1,25 @@
// MyBWRSimulator.Core/Components/Concrete/Pump.cs
namespace MyBWRSimulator.Core.Components.Concrete
{
using MyBWRSimulator.Core.Components.Abstract;
//using MyBWRSimulator.Core.Components.Enums;
using MyBWRSimulator.Core.Ports;
using System;
using System.Collections.Generic;
/// <summary>
/// Represents a Pump component in the BWR simulation.
/// </summary>
public class ReactorCore : Component
{
public ReactorCore(string id, string name, int priority)
: base(id, name, "Simulates all fuel rods and control rods", priority)
{
AddFluidPort(new FluidPort("FeedwaterInlet"));
}
public override void Update(double dt)
{
}
}
}

View File

@@ -0,0 +1,63 @@
// MyBWRSimulator.Core/Components/Concrete/Pipe.cs
namespace MyBWRSimulator.Core.Components.Concrete
{
using MyBWRSimulator.Core.Components.Abstract;
using MyBWRSimulator.Core.Ports;
using System;
using System.Collections.Generic;
/// <summary>
/// Represents a Pipe component in the BWR simulation.
/// </summary>
public class Pipe : Component
{
public double Length { get; private set; } // Length of the pipe (m)
public double Diameter { get; private set; } // Inner diameter of the pipe (m)
public double Roughness { get; private set; } = 0.000045; // Example roughness for steel (m)
// Publicly expose ports for easier named access if needed
public FluidPort Inlet => GetFluidPortById("Inlet");
public FluidPort Outlet => GetFluidPortById("Outlet");
public Pipe(string id, string name, double length, double diameter)
: base(id, name, $"A pipe of length {length}m and diameter {diameter}m.", 4) // Priority 4
{
Length = length;
Diameter = diameter;
// Use descriptive IDs for ports
AddFluidPort(new FluidPort("Inlet"));
AddFluidPort(new FluidPort("Outlet"));
}
public override void Update(double deltaTime)
{
// Read properties from the inlet port (which should have been updated by upstream component)
double inletFlowRate = Inlet.FlowRate;
double inletPressure = Inlet.Pressure;
double inletTemperature = Inlet.Temperature;
// Simple pressure drop calculation (e.g., Darcy-Weisbach or simpler linear drop)
// This is very simplified. For high fidelity, you'd need fluid properties (density, viscosity).
double pressureDrop = 0.0;
if (inletFlowRate > 0)
{
// A very basic linear pressure drop for demonstration
pressureDrop = (inletFlowRate * Length * 10.0) / (Diameter * Diameter);
}
// Simple heat loss/gain (e.g., based on ambient temperature, not modeled here)
double outletTemperature = inletTemperature; // Assuming no heat loss for now
// Update outlet port properties
Outlet.FlowRate = inletFlowRate;
Outlet.Pressure = inletPressure - pressureDrop;
Outlet.Temperature = outletTemperature;
// Mirror values to connected ports
Outlet.MirrorToConnectedPort();
Console.WriteLine($"{Name} ({ID}) - Flow: {inletFlowRate:F2} kg/s, Pressure Drop: {pressureDrop:F2} Pa");
}
}
}