ningshuxia
5 天以前 eaf4edfeeb42590be28c59a393c6a868e1831396
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// 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();
    }
 
    /// <summary>
    /// 水力计算
    /// </summary>
    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<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();
        }
    }
 
 
 
}