// See https://aka.ms/new-console-template for more information using System.Diagnostics; using Yw.Epanet; class Program { private static object _locer = new(); static void Main() { // 创建一个 Stopwatch 实例 Stopwatch stopwatch = new Stopwatch(); // 开始计时 stopwatch.Start(); CalcuH(); // 停止计时 stopwatch.Stop(); Console.WriteLine($"总时间:{stopwatch.Elapsed.TotalSeconds}"); Console.ReadLine(); } /// /// 水力计算 /// public static void CalcuH() { var result = new CalcuResult(); using (var helper = new InteropXHelper()) { var code = helper.Open("test.inp", "test.rpt", string.Empty); if (code != eErrorCode.OK) { 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; } } //节点计算值遍历获取 var allCalcuNodeDict = new Dictionary(); 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(); 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(); } } }