Adding initial Project to git
This commit is contained in:
63
BWR.core/Components/Concrete/pipe.cs
Normal file
63
BWR.core/Components/Concrete/pipe.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user