From 5fa6947054206e2e781eadd4effdcdf52eda28c4 Mon Sep 17 00:00:00 2001 From: cloudflight <cloudflight@126.com> Date: 星期二, 26 十二月 2023 11:02:28 +0800 Subject: [PATCH] 2023年12月26日 --- Hydro.Inp/NetWork.cs | 42 +++++++++++++++++++++++++++++++----------- 1 files changed, 31 insertions(+), 11 deletions(-) diff --git a/Hydro.Inp/NetWork.cs b/Hydro.Inp/NetWork.cs index abc2fc2..18fe610 100644 --- a/Hydro.Inp/NetWork.cs +++ b/Hydro.Inp/NetWork.cs @@ -2,6 +2,7 @@ //using Hydro.HydraulicModel; using System; using System.Collections.Generic; +using System.Data; using System.Drawing; using System.IO; using System.IO.Ports; @@ -16,6 +17,7 @@ namespace Hydro.Inp { + [Serializable] public class NetWork //: INetWork { public NetWork() @@ -174,20 +176,20 @@ nozzles.ForEach(nozzle => { AddNozzle(nozzle); }); } - private void CheckNodesExist(NodeModel node) + private void CheckNodesExist(NodeCalcModel node) { if (Nodes.Any(d => d.ID == node.ID)) throw new Exception("宸插瓨鍦ㄩ噸澶嶇殑瀵硅薄"); } - private void CheckLinksExist(LinkModel link) + private void CheckLinksExist(LinkCalcModel link) { if (Links.Any(d => d.ID == link.ID)) throw new Exception("宸插瓨鍦ㄩ噸澶嶇殑瀵硅薄"); } - public List<NodeModel> Nodes { get; set; } = new List<NodeModel>(); - public List<LinkModel> Links { get; set; } = new List<LinkModel>(); + public List<NodeCalcModel> Nodes { get; set; } = new List<NodeCalcModel>(); + public List<LinkCalcModel> Links { get; set; } = new List<LinkCalcModel>(); /// <summary> /// 鏍规嵁INP鏂囦欢鐢熸垚 @@ -465,7 +467,7 @@ #region 浼樺寲鏂规 int k1 = 0; int k2 = 0; - + Nodes.Sort((a, b) => string.Compare(a.ID, b.ID)); points.Sort((a, b) => string.Compare(a.ID, b.ID)); @@ -493,7 +495,7 @@ } #endregion - + //寤虹珛鐐圭嚎鍏崇郴閾捐〃StartNode锛屽厛灏嗙绾夸互Node1锛堣妭鐐�1鐨処D锛夋帓搴忥紝鍐嶅皢Nodes鎸塈D鎺掑簭锛屽缓绔嬩袱涓父鏍噆1銆乲2锛屾鍚戜竴娆″惊鐜紝寤虹珛閾捐〃鍏崇郴 //鏃堕棿澶嶆潅搴� O(n) @@ -564,10 +566,17 @@ } if (!File.Exists(tempPath)) { - throw new Exception("妯℃澘鏂囦欢涓嶅瓨鍦�"); + throw new Exception("妯℃澘鏂囦欢涓嶅瓨鍦�," + tempPath); } + if (!File.Exists(InpPath)) + { + FileInfo fi=new FileInfo(InpPath); + if (!Directory.Exists(fi.DirectoryName)) + Directory.CreateDirectory(fi.DirectoryName); File.Create(InpPath).Close(); + + } tempString = File.ReadAllText(tempPath); StringBuilder statusStringBuilder = new StringBuilder(); statusStringBuilder.AppendLine(";ID \tStatus/Setting\r\n"); @@ -951,12 +960,18 @@ /// <returns></returns> public virtual List<TimePoint> Calc(string InpPath) { - HydraulicModel.Epanet epanet = new HydraulicModel.Epanet(); + HydraulicModel.HydraulicCore epanet = new HydraulicModel.HydraulicCore(); var result = new List<TimePoint>(); - var err = epanet.open(InpPath, "d:\\5.log", ""); + var err = epanet.open(InpPath, "", ""); + if (err != 0) { - throw new Exception($"璁$畻澶辫触锛歿err}"); + throw new Exception($"鎵撳紑璁$畻鏂囦欢澶辫触锛歿err}"); + } + var errCal = epanet.solveH(); + if (errCal != 0) + { + throw new Exception($"璁$畻澶辫触锛歿errCal}"); } int nodeCount = 0, linkCount = 0; epanet.getcount((int)CountType.Node, ref nodeCount); @@ -1007,7 +1022,8 @@ /// <returns></returns> public virtual List<TimePoint> Calc() { - var inpPath = Path.Combine(Directory.GetCurrentDirectory(), @"data\inp\calc.inp"); + + var inpPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"data\inp\calc.inp"); BuildToInp(inpPath); return Calc(inpPath); } @@ -1057,4 +1073,8 @@ } } + + + + } -- Gitblit v1.9.3