| | |
| | | // See https://aka.ms/new-console-template for more information |
| | | |
| | | using System.Diagnostics; |
| | | using Yw.Epanet; |
| | | |
| | | class Program |
| | | { |
| | |
| | | |
| | | static void Main() |
| | | { |
| | | |
| | | |
| | | // 创建一个 Stopwatch 实例 |
| | | Stopwatch stopwatch = new Stopwatch(); |
| | | |
| | | // 开始计时 |
| | | stopwatch.Start(); |
| | | |
| | | // 定义要执行的inp文件路径 |
| | | //string fileName = "easy.inp"; |
| | | string fileName = "1843913603388936192.inp"; |
| | | // Parallel.For(0, 5, i => RunEpanetSimulation(fileName, i)); |
| | | //Console.WriteLine($"正在执行第 {number + 1} 次模拟,文件:{fileName}"); |
| | | using (var helper = new Yw.Epanet.InteropXHelper()) |
| | | { |
| | | helper.Open(fileName, "", ""); |
| | | helper.OpenH(); |
| | | |
| | | for (int i = 0; i < 20000; i++) |
| | | { |
| | | var code = helper.SetNodeValue(1, Yw.Epanet.eNodeProperty.BaseDemand, 1); |
| | | |
| | | helper.InitH(false); |
| | | helper.RunH(out long t); |
| | | code = helper.GetNodeValue(1, Yw.Epanet.eNodeProperty.BaseDemand, out double vv); |
| | | helper.NextH(out long tstep); |
| | | //Console.WriteLine($"正在执行第 {number + 1} 次模拟,文件:{fileName}+{i}"); |
| | | Console.WriteLine(i); |
| | | } |
| | | |
| | | helper.CloseH(); |
| | | helper.Close(); |
| | | } |
| | | |
| | | Console.WriteLine("所有模拟已完成。"); |
| | | CalcuH(); |
| | | |
| | | // 停止计时 |
| | | stopwatch.Stop(); |
| | |
| | | Console.ReadLine(); |
| | | } |
| | | |
| | | static void RunEpanetSimulation(string fileName, int number) |
| | | /// <summary> |
| | | /// 水力计算 |
| | | /// </summary> |
| | | public static void CalcuH() |
| | | { |
| | | Console.WriteLine($"正在执行第 {number + 1} 次模拟,文件:{fileName}"); |
| | | using (var helper = new Yw.Epanet.InteropXHelper()) |
| | | { |
| | | helper.Open(fileName, "", ""); |
| | | helper.OpenH(); |
| | | |
| | | for (int i = 0; i < 4000; i++) |
| | | var result = new CalcuResult(); |
| | | |
| | | using (var helper = new InteropXHelper()) |
| | | { |
| | | var code = helper.Open("test.inp", "test.rpt", string.Empty); |
| | | if (code != eErrorCode.OK) |
| | | { |
| | | helper.SetNodeValue(1, Yw.Epanet.eNodeProperty.Demand, 0); |
| | | helper.InitH(false); |
| | | helper.RunH(out long t); |
| | | helper.NextH(out long tstep); |
| | | Console.WriteLine($"正在执行第 {number + 1} 次模拟,文件:{fileName}+{i}"); |
| | | helper.GetError(code, out string errorMsg); |
| | | result.FailedList.Add(new CalcuFailed() |
| | | { |
| | | Code = code, |
| | | Message = errorMsg |
| | | }); |
| | | helper.Close(); |
| | | return; |
| | | } |
| | | code = helper.SolveH(); |
| | | if (code != eErrorCode.OK) |
| | | { |
| | | if (code >= eErrorCode.Err101) |
| | | { |
| | | helper.GetError(code, out string errorMsg); |
| | | result.FailedList.Add(new CalcuFailed() |
| | | { |
| | | Code = code, |
| | | Message = errorMsg |
| | | }); |
| | | helper.Close(); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | helper.CloseH(); |
| | | //节点计算值遍历获取 |
| | | var allCalcuNodeDict = new Dictionary<string, CalcuNode>(); |
| | | helper.GetCount(eCountType.Node, out int nodeCount); |
| | | for (int i = 1; i <= nodeCount; i++) |
| | | { |
| | | helper.GetNodeId(i, out string nodeId); |
| | | helper.GetNodeValue(i, eNodeProperty.Head, out double headValue); |
| | | helper.GetNodeValue(i, eNodeProperty.Pressure, out double pressureValue); |
| | | helper.GetNodeValue(i, eNodeProperty.Demand, out double demandValue); |
| | | var calcuNode = new CalcuNode() |
| | | { |
| | | Id = nodeId, |
| | | Head = headValue, |
| | | Press = pressureValue, |
| | | Demand = demandValue |
| | | }; |
| | | result.VisualList.Add(calcuNode); |
| | | allCalcuNodeDict.Add(nodeId, calcuNode); |
| | | } |
| | | |
| | | //管段计算值遍历获取 |
| | | var allCalcuLinkDict = new Dictionary<string, CalcuLink>(); |
| | | helper.GetCount(eCountType.Link, out int linkCount); |
| | | for (int i = 1; i <= linkCount; i++) |
| | | { |
| | | helper.GetLinkId(i, out string linkId); |
| | | helper.GetLinkValue(i, eLinkProperty.Flow, out double flowValue); |
| | | helper.GetLinkValue(i, eLinkProperty.Velocity, out double velocityValue); |
| | | helper.GetLinkValue(i, eLinkProperty.HeadLoss, out double headLossValue); |
| | | var calcuLink = new CalcuLink() |
| | | { |
| | | Id = linkId, |
| | | Flow = flowValue, |
| | | Velocity = velocityValue, |
| | | HeadLoss = headLossValue, |
| | | }; |
| | | result.VisualList.Add(calcuLink); |
| | | allCalcuLinkDict.Add(linkId, calcuLink); |
| | | } |
| | | |
| | | helper.Close(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | |