ningshuxia
2025-04-25 e372b432b52bedf58b7d3bd80bd679ae9c3cecb3
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
namespace Yw.Epanet
{
    /// <summary>
    /// 
    /// </summary>
    public static class NetworkRepairExtensions
    {
        /// <summary>
        /// 修复
        /// </summary>
        public static void Repair(this Network nw)
        {
            //验证
            if (nw == null)
            {
                return;
            }
            var allNodeList = nw.GetAllNodes();
            if (allNodeList == null || allNodeList.Count < 1)
            {
                return;
            }
            var allLinkList = nw.GetAllLinks();
            if (allLinkList == null || allLinkList.Count < 1)
            {
                return;
            }
            var allJunctionList = nw.GetAllJunctions();
            if (allJunctionList == null || allJunctionList.Count < 1)
            {
                return;
            }
 
            //节点links处理
            foreach (var node in allNodeList)
            {
                var links = allLinkList.Where(x => x.StartNodeId == node.Id || x.EndNodeId == node.Id).ToList();
                node.Links = links;
            }
 
            //管段上下游处理
            foreach (var link in allLinkList)
            {
                link.StartNode = allNodeList.Find(x => x.Id == link.StartNodeId);
                link.EndNode = allNodeList.Find(x => x.Id == link.EndNodeId);
            }
 
            //管道参数处理
            var allPipeList = nw.Pipes;
            if (allPipeList != null && allPipeList.Count > 0)
            {
                foreach (var pipe in allPipeList)
                {
                    if (pipe.Roughness < 10)
                    {
                        pipe.Roughness = ConstParas.DefaultRoughness;
                    }
                    if (pipe.Length < ConstParas.MinPipeLength)
                    {
                        pipe.Length = ConstParas.MinPipeLength;
                    }
                    pipe.StartMinorLoss = 0;
                    pipe.EndMinorLoss = 0;
                }
            }
 
            //连接节点参数处理
            foreach (var junction in allJunctionList)
            {
                if (junction.Demand < 0)
                {
                    junction.Demand = 0;
                }
                if (junction.MinorLoss < 0)
                {
                    junction.MinorLoss = 0;
                }
                if (junction.MinorLoss > 0)
                {
                    var pipes = junction.GetPipes();
                    if (pipes != null && pipes.Count > 0)
                    {
                        var littleMinorLoss = junction.MinorLoss / pipes.Count;
                        var nextPipes = junction.GetNextPipes();
                        nextPipes?.ForEach(x => x.StartMinorLoss += littleMinorLoss);
                        var prevPipes = junction.GetPrevPipes();
                        prevPipes?.ForEach(x => x.EndMinorLoss += littleMinorLoss);
                    }
                }
            }
 
 
 
 
        }
 
    }
}