// 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; /// /// Represents a Fluid Tank component in the BWR simulation. /// 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"); } } }