113 lines
3.8 KiB
C#
113 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace HydraulicSimulator.Models
|
|
{
|
|
/// <summary>
|
|
/// Resultado de la simulación de la red hidráulica
|
|
/// </summary>
|
|
public class SolutionResult
|
|
{
|
|
public bool Converged { get; set; }
|
|
public Dictionary<string, double> Flows { get; set; } = new Dictionary<string, double>();
|
|
public Dictionary<string, double> Pressures { get; set; } = new Dictionary<string, double>();
|
|
public int Iterations { get; set; }
|
|
public double Residual { get; set; }
|
|
public string ErrorMessage { get; set; } = "";
|
|
|
|
public SolutionResult(bool converged = false)
|
|
{
|
|
Converged = converged;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Red hidráulica - Pure data container para TSNet
|
|
/// NO realiza cálculos hidráulicos - solo almacena topología para generación INP
|
|
/// </summary>
|
|
public class HydraulicNetwork
|
|
{
|
|
public Fluid Fluid { get; set; }
|
|
public Dictionary<string, Node> Nodes { get; set; } = new Dictionary<string, Node>();
|
|
public List<Branch> Branches { get; set; } = new List<Branch>();
|
|
|
|
public HydraulicNetwork(Fluid fluid = null)
|
|
{
|
|
Fluid = fluid ?? Fluid.Water20C;
|
|
}
|
|
|
|
public void AddNode(string name, double? fixedP = null)
|
|
{
|
|
if (Nodes.ContainsKey(name))
|
|
return;
|
|
|
|
if (fixedP == null)
|
|
{
|
|
Nodes[name] = new Node(name, fixedP: false, p: 0.0);
|
|
}
|
|
else
|
|
{
|
|
Nodes[name] = new Node(name, fixedP: true, p: fixedP.Value);
|
|
}
|
|
}
|
|
|
|
public void AddElement(Element element, string n1, string n2, string name = "")
|
|
{
|
|
if (!Nodes.ContainsKey(n1) || !Nodes.ContainsKey(n2))
|
|
throw new ArgumentException("Nodos inexistentes");
|
|
|
|
var branchName = string.IsNullOrEmpty(name) ? $"{n1}->{n2}" : name;
|
|
Branches.Add(new Branch(n1, n2, new List<Element> { element }, branchName));
|
|
}
|
|
|
|
public void AddBranch(string n1, string n2, List<Element> elements, string name = "")
|
|
{
|
|
if (!Nodes.ContainsKey(n1) || !Nodes.ContainsKey(n2))
|
|
throw new ArgumentException("Nodos inexistentes");
|
|
|
|
Branches.Add(new Branch(n1, n2, elements, name));
|
|
}
|
|
|
|
/// <summary>
|
|
/// DEPRECATED: Cálculos hidráulicos delegados a TSNet
|
|
/// Mantiene la interfaz para compatibilidad pero no realiza cálculos
|
|
/// </summary>
|
|
public SolutionResult Solve(int maxIterations = 100, double tolerance = 1e-3,
|
|
double relaxationFactor = 0.1, bool verbose = false)
|
|
{
|
|
// TODO: Esta funcionalidad ha sido reemplazada por TSNet
|
|
// Retorna un resultado vacío para mantener compatibilidad
|
|
var result = new SolutionResult(true)
|
|
{
|
|
Iterations = 0,
|
|
Residual = 0.0,
|
|
ErrorMessage = "Hydraulic calculations delegated to TSNet"
|
|
};
|
|
|
|
// Llenar flows y pressures con valores por defecto
|
|
foreach (var b in Branches)
|
|
{
|
|
result.Flows[b.Name] = b.Q;
|
|
}
|
|
|
|
foreach (var kvp in Nodes)
|
|
{
|
|
result.Pressures[kvp.Key] = kvp.Value.P;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// DEPRECATED: Cálculos hidráulicos delegados a TSNet
|
|
/// Genera un reporte de la red (solo estructura, no cálculos)
|
|
/// </summary>
|
|
public void Report()
|
|
{
|
|
// Reporte de estructura solamente
|
|
// Los cálculos hidráulicos se realizan en TSNet
|
|
}
|
|
}
|
|
}
|