lixiaojun
2025-03-12 a48cd440205c38e14e5f270168c1ed9f2ba1ab79
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
namespace Yw.Epanet
{
    /// <summary>
    /// 管网计算拓展
    /// </summary>
    public static class NetworkCalcuExtensions
    {
        /// <summary>
        /// 水力计算
        /// </summary>
        public static CalcuResult CalcuH(this Network nw)
        {
            if (nw == null)
            {
                return default;
            }
 
            var result = new CalcuResult();
 
            //所有可见字典
            var allVisualDict = nw.GetVisualDict();
            if (allVisualDict == null || allVisualDict.Count < 1)
            {
                result.Succeed = false;
                result.Message = "没有可见构件";
            }
 
            //Inp文件
            var inpFileName = nw.SaveInpFile();
            if (string.IsNullOrEmpty(inpFileName))
            {
                result.Succeed = false;
                result.Message = "INP文件生成失败";
                return result;
            }
 
            using (var helper = new InteropXHelper())
            {
                var code = helper.Open(inpFileName, string.Empty, string.Empty);
                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 result;
                    }
                }
                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 result;
                    }
                }
 
                //节点计算值遍历获取
                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);
 
                    var link = allVisualDict.GetValue(linkId);
                    if (link is Pipe pipe)
                    {//管道
                        if (pipe.MinorLoss > 0)
                        {
                            calcuLink.MinorLoss = CalcuHelper.CalcuMinorLoss(pipe.MinorLoss, calcuLink.Velocity);
                        }
                        if (pipe.StartMinorLoss > 0)
                        {
                            calcuLink.StartMinorLoss = CalcuHelper.CalcuMinorLoss(pipe.StartMinorLoss, calcuLink.Velocity);
                            var startCalcuNode = allCalcuNodeDict.GetValue(pipe.StartNodeId);
                            if (startCalcuNode != null)
                            {
                                startCalcuNode.MinorLoss += calcuLink.StartMinorLoss;
                            }
                        }
                        if (pipe.EndMinorLoss > 0)
                        {
                            calcuLink.EndMinorLoss = CalcuHelper.CalcuMinorLoss(pipe.EndMinorLoss, calcuLink.Velocity);
                            var endCalcuNode = allCalcuNodeDict.GetValue(pipe.EndNodeId);
                            if (endCalcuNode != null)
                            {
                                endCalcuNode.MinorLoss += calcuLink.EndMinorLoss;
                            }
                        }
                        calcuLink.FrictionLoss = calcuLink.HeadLoss - calcuLink.MinorLoss - calcuLink.StartMinorLoss - calcuLink.EndMinorLoss;
                    }
                    else if (link is Pump)
                    {//水泵
                        calcuLink.MinorLoss = calcuLink.HeadLoss;
                    }
                    else if (link is Valve)
                    {//阀门
                        calcuLink.MinorLoss = calcuLink.HeadLoss;
                    }
                }
 
                helper.Close();
            }
 
            return result;
        }
 
 
 
 
 
 
 
 
 
    }
}