lixiaojun
2024-08-13 0e0709e63ed50093d09fb88ac1ea4eb9b5a37afc
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
namespace Yw.EPAnet
{
    /// <summary>
    /// 管网检查拓展
    /// </summary>
    public static class NetworkCheckExtensions
    {
        /// <summary>
        /// 根据Inp文件计算
        /// </summary>
        /// <returns></returns>
        public static CheckResult Check(this Network network)
        {
            var result = new CheckResult();
            if (network == null)
            {
                result.Succeed = false;
                return result;
            }
 
            //验证水源
            var allSourceList = network.GetAllSources();
            if (allSourceList == null || allSourceList.Count < 1)
            {
                result.Succeed = false;
                result.FailedList.Add(new CheckFailed()
                {
                    ParterId = string.Empty,
                    FailType = eCheckFailType.LackSource,
                    FailReason = "缺少水源,至少需包含一座水库或水池"
                });
            }
 
            //验证连接节点
            var allJunctionList = network.GetAllJunctions();
            if (allJunctionList == null || allJunctionList.Count < 1)
            {
                result.Succeed = false;
                result.FailedList.Add(new CheckFailed()
                {
                    ParterId = string.Empty,
                    FailType = eCheckFailType.LackJunction,
                    FailReason = "缺少连接节点,至少需包含一个连接节点"
                });
            }
 
            //验证节点
            var allNodeList = network.GetAllNodes();
            foreach (var node in allNodeList)
            {
                if (node.Links == null || node.Links.Count < 1)
                {
                    result.Succeed = false;
                    result.FailedList.Add(new CheckFailed()
                    {
                        ParterId = node.Id,
                        FailType = eCheckFailType.AloneNode,
                        FailReason = "孤立节点,没有任何管段连接"
                    });
                }
                else
                {
                    if (node.Links.Exists(x => x is INode))
                    {
                        result.Succeed = false;
                        result.FailedList.Add(new CheckFailed()
                        {
                            ParterId = node.Id,
                            FailType = eCheckFailType.NodeAbnormalConnected,
                            FailReason = "节点异常连接,存在节点连接"
                        });
                    }
                }
            }
 
            //验证管段
            var allLinkList = network.GetAllLinks();
            foreach (var link in allLinkList)
            {
                if (link.StartNode == null && link.EndNode == null)
                {
                    result.Succeed = false;
                    result.FailedList.Add(new CheckFailed()
                    {
                        ParterId = link.Id,
                        FailType = eCheckFailType.AloneLink,
                        FailReason = "孤立管段,没有连接任何管段"
                    });
                }
                else
                {
                    if (link.StartNode == null)
                    {
                        result.Succeed = false;
                        result.FailedList.Add(new CheckFailed()
                        {
                            ParterId = link.Id,
                            FailType = eCheckFailType.LinkLossNode,
                            FailReason = "管段缺少节点,缺少上游节点"
                        });
                    }
                    else if (link.EndNode == null)
                    {
                        result.Succeed = false;
                        result.FailedList.Add(new CheckFailed()
                        {
                            ParterId = link.Id,
                            FailType = eCheckFailType.LinkLossNode,
                            FailReason = "管段缺少节点,缺少下游节点"
                        });
                    }
                    else
                    {
                        if (link.StartNode.Id == link.EndNode.Id)
                        {
                            result.Succeed = false;
                            result.FailedList.Add(new CheckFailed()
                            {
                                ParterId = link.Id,
                                FailType = eCheckFailType.LinkAbnormalConnected,
                                FailReason = "管段异常连接,上游与下游节点相同"
                            });
                        }
                        if (link.StartNode is not INode)
                        {
                            result.Succeed = false;
                            result.FailedList.Add(new CheckFailed()
                            {
                                ParterId = link.Id,
                                FailType = eCheckFailType.LinkAbnormalConnected,
                                FailReason = "管段异常连接,上游未连接节点"
                            });
                        }
                        if (link.EndNode is not INode)
                        {
                            result.Succeed = false;
                            result.FailedList.Add(new CheckFailed()
                            {
                                ParterId = link.Id,
                                FailType = eCheckFailType.LinkAbnormalConnected,
                                FailReason = "管段异常连接,下游未连接节点"
                            });
                        }
                    }
                }
 
                //验证管道
                if (link is Pipe pipe)
                {
                    if (pipe.Length <= 0)
                    {
                        result.Succeed = false;
                        result.FailedList.Add(new CheckFailed()
                        {
                            ParterId = pipe.Id,
                            FailType = eCheckFailType.PropSetError,
                            FailReason = "属性设置错误,管道长度必须大于0"
                        });
                    }
                    if (pipe.Roughness <= 0.1 || pipe.Roughness > 10000)
                    {
                        result.Succeed = false;
                        result.FailedList.Add(new CheckFailed()
                        {
                            ParterId = pipe.Id,
                            FailType = eCheckFailType.PropSetError,
                            FailReason = "属性设置错误,粗糙系数区间(0.1,10000】"
                        });
                    }
                    if (pipe.Diameter <= 0.1 || pipe.Diameter > 10000)
                    {
                        result.Succeed = false;
                        result.FailedList.Add(new CheckFailed()
                        {
                            ParterId = pipe.Id,
                            FailType = eCheckFailType.PropSetError,
                            FailReason = "属性设置错误,管径区间(0.1,10000】"
                        });
                    }
                }
            }
 
            return result;
        }
 
 
    }
}