using System; using System.Collections.Generic; using System.Linq; namespace HydraulicSimulator.Models { /// /// Resultado de la simulación de la red hidráulica /// public class SolutionResult { public bool Converged { get; set; } public Dictionary Flows { get; set; } = new Dictionary(); public Dictionary Pressures { get; set; } = new Dictionary(); public int Iterations { get; set; } public double Residual { get; set; } public string ErrorMessage { get; set; } = ""; public SolutionResult(bool converged = false) { Converged = converged; } } /// /// Red hidráulica - Pure data container para TSNet /// NO realiza cálculos hidráulicos - solo almacena topología para generación INP /// public class HydraulicNetwork { public Fluid Fluid { get; set; } public Dictionary Nodes { get; set; } = new Dictionary(); public List Branches { get; set; } = new List(); 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 }, branchName)); } public void AddBranch(string n1, string n2, List elements, string name = "") { if (!Nodes.ContainsKey(n1) || !Nodes.ContainsKey(n2)) throw new ArgumentException("Nodos inexistentes"); Branches.Add(new Branch(n1, n2, elements, name)); } /// /// DEPRECATED: Cálculos hidráulicos delegados a TSNet /// Mantiene la interfaz para compatibilidad pero no realiza cálculos /// 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; } /// /// DEPRECATED: Cálculos hidráulicos delegados a TSNet /// Genera un reporte de la red (solo estructura, no cálculos) /// public void Report() { // Reporte de estructura solamente // Los cálculos hidráulicos se realizan en TSNet } } }