lixiaojun
2024-12-31 1afdf4abcac876d16841e01862b2af670aaf9172
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
using DevExpress.Drawing.Internal.Interop;
using Yw.EPAnet;
using Yw.Hydro;
using Yw.Model;
 
namespace Yw.WinFrmUI
{
    /// <summary>
    /// 水力信息拓展
    /// </summary>
    public static class HydroModelInfoExtensions
    {
 
        #region 修复参数
 
        private const double _pipe_roughness_default = 110;//管道默认粗糙系数
        private const double _translation_roughness_default = 120;//过渡件默认粗糙系数
        private const double _translation_minorloss_default = 0.3;//过渡件默认局阻系数
        private const double _valve_minorloss_default = 0.3d; //阀门默认局阻系数
        private const double _resistance_minorloss_default = 9d;//阻件默认局阻系数
        private const double _blunthead_minorloss_default = 0.1d;//闷头局部阻力系数
 
        /// <summary>
        /// 修复参数
        /// </summary>
        public static void RepairParas(this Yw.Model.HydroModelInfo hydroInfo, HydroPropStatusHelper propStatusHelper, out string msg)
        {
            msg = string.Empty;
            if (hydroInfo == null)
            {
                return;
            }
 
            var allNodes = hydroInfo.GetAllNodes();
            var allLinks = hydroInfo.GetAllLinks();
 
            //管道
            if (hydroInfo.Pipes != null && hydroInfo.Pipes.Count > 0)
            {
                foreach (var pipe in hydroInfo.Pipes)
                {
                    if (pipe.Roughness <= 0)
                    {
                        pipe.Roughness = _pipe_roughness_default;
                        propStatusHelper.UpdatePropStatus(pipe, nameof(pipe.Roughness), ePropStatus.Abnormal, "【粗糙系数】数据异常");
                    }
                }
            }
 
            //过渡件
            if (hydroInfo.Translations != null && hydroInfo.Translations.Count > 0)
            {
                foreach (var translation in hydroInfo.Translations)
                {
                    double? tempDiameter = null;
                    var startNode = allNodes.Find(x => x.Code == translation.StartCode);
                    if (startNode != null)
                    {
                        var startLink = allLinks
                            .Find(x => (x.StartCode == startNode.Code || x.EndCode == startNode.Code) && x.Code != translation.Code);
                        if (startLink != null)
                        {
                            var startPipe = startLink as Yw.Model.HydroPipeInfo;
                            if (startPipe != null)
                            {
                                tempDiameter = startPipe.Diameter;
                                if (translation.StartDiameter != startPipe.Diameter)
                                {
                                    translation.StartDiameter = startPipe.Diameter;
                                }
                            }
                        }
                    }
 
                    var endNode = allNodes.Find(x => x.Code == translation.EndCode);
                    if (endNode != null)
                    {
                        var endLink = allLinks
                            .Find(x => (x.StartCode == endNode.Code || x.EndCode == endNode.Code) && x.Code != translation.Code);
                        if (endLink != null)
                        {
                            var endPipe = endLink as Yw.Model.HydroPipeInfo;
                            if (endPipe != null)
                            {
                                if (translation.EndDiameter != endPipe.Diameter)
                                {
                                    tempDiameter = endPipe.Diameter;
                                    translation.EndDiameter = endPipe.Diameter;
                                }
                            }
                        }
                    }
 
                    if (translation.StartDiameter <= 0)
                    {
                        if (tempDiameter.HasValue)
                        {
                            translation.StartDiameter = tempDiameter.Value;
                        }
                    }
                    if (translation.EndDiameter <= 0)
                    {
                        if (tempDiameter.HasValue)
                        {
                            translation.EndDiameter = tempDiameter.Value;
                        }
                    }
                }
            }
 
            //阀门
            if (hydroInfo.Valves != null && hydroInfo.Valves.Count > 0)
            {
                foreach (var valve in hydroInfo.Valves)
                {
                    if (valve.MinorLoss <= 0)
                    {
                        valve.MinorLoss = _valve_minorloss_default;
                    }
                    if (valve.Diameter <= 0)
                    {
                        var startNode = allNodes.Find(x => x.Code == valve.StartCode);
                        if (startNode != null)
                        {
                            var startPipe = allLinks
                                .Find(x => (x.StartCode == startNode.Code || x.EndCode == startNode.Code) && x.Code != valve.Code)
                                as Yw.Model.HydroPipeInfo;
                            if (startPipe != null)
                            {
                                valve.Diameter = startPipe.Diameter;
                            }
                            else
                            {
                                var endNode = allNodes.Find(x => x.Code == valve.EndCode);
                                if (endNode != null)
                                {
                                    var endPipe = allLinks
                                        .Find(x => (x.StartCode == endNode.Code || x.EndCode == endNode.Code) && x.Code != valve.Code)
                                        as Yw.Model.HydroPipeInfo;
                                    if (endPipe != null)
                                    {
                                        valve.Diameter = endPipe.Diameter;
                                    }
                                }
                            }
                        }
                    }
                }
            }
 
            //阻件
            var allResistanceList = hydroInfo.GetAllResistances();
            if (allResistanceList != null && allResistanceList.Count > 0)
            {
                foreach (var resistance in allResistanceList)
                {
                    if (resistance.MinorLoss <= 0)
                    {
                        resistance.MinorLoss = _resistance_minorloss_default;
                    }
                    var startNode = allNodes.Find(x => x.Code == resistance.StartCode);
                    if (startNode != null)
                    {
                        var startPipe = allLinks
                            .Find(x => (x.StartCode == startNode.Code || x.EndCode == startNode.Code) && x.Code != resistance.Code)
                                as Yw.Model.HydroPipeInfo;
                        if (startPipe != null)
                        {
                            resistance.Diameter = startPipe.Diameter;
                        }
                        else
                        {
                            var endNode = allNodes.Find(x => x.Code == resistance.EndCode);
                            if (endNode != null)
                            {
                                var endPipe = allLinks
                                    .Find(x => (x.StartCode == endNode.Code || x.EndCode == endNode.Code) && x.Code != resistance.Code)
                                     as Yw.Model.HydroPipeInfo;
                                if (endPipe != null)
                                {
                                    resistance.Diameter = endPipe.Diameter;
                                }
                            }
                        }
                    }
                }
            }
 
            //闷头
            if (hydroInfo.Bluntheads != null && hydroInfo.Bluntheads.Count > 0)
            {
                foreach (var visual in hydroInfo.Bluntheads)
                {
                    if (visual.MinorLoss <= 0)
                    {
                        visual.MinorLoss = _blunthead_minorloss_default;
                    }
                    if (visual.Caliber < 1)
                    {
                        var link = allLinks.Find(x => x.StartCode == visual.Code || x.EndCode == visual.Code);
                        if (link != null)
                        {
                            if (link is HydroResistanceInfo resistance)
                            {
                                visual.Caliber = resistance.Diameter;
                            }
                            else if (link is HydroValveInfo valve)
                            {
                                visual.Caliber = valve.Diameter;
                            }
                            else if (link is HydroTranslationInfo translation)
                            {
 
                            }
                            else if (link is HydroPipeInfo pipe)
                            {
                                visual.Caliber = pipe.Diameter;
                            }
                        }
                    }
 
                }
            }
 
            #region 弯头
 
            if (hydroInfo.Elbows != null && hydroInfo.Elbows.Count > 0)
            {
                foreach (var visual in hydroInfo.Elbows)
                {
                    if (visual.MinorLoss <= 0)
                    {
                        visual.MinorLoss = _blunthead_minorloss_default;
                    }
                    if (visual.Caliber < 1)
                    {
                        var link = allLinks.Find(x => x.StartCode == visual.Code || x.EndCode == visual.Code);
                        if (link != null)
                        {
                            if (link is HydroResistanceInfo resistance)
                            {
                                visual.Caliber = resistance.Diameter;
                            }
                            else if (link is HydroValveInfo valve)
                            {
                                visual.Caliber = valve.Diameter;
                            }
                            else if (link is HydroTranslationInfo translation)
                            {
 
                            }
                            else if (link is HydroPipeInfo pipe)
                            {
                                visual.Caliber = pipe.Diameter;
                            }
                        }
                    }
 
                }
            }
 
            #endregion
 
        }
 
 
        #endregion
 
        #region 装置计算
 
        /// <summary>
        /// 获取扬程
        /// </summary>
        public static double GetHead(this Yw.Model.HydroModelInfo hydroInfo)
        {
            if (hydroInfo == null)
            {
                return default;
            }
            double startHeadValue = 0;
            var allSourceList = hydroInfo.GetAllSources();
            if (allSourceList != null && allSourceList.Count > 0)
            {
                var startSource = allSourceList.Matching(new List<string>()
                {
                    Yw.Hydro.Flags.水源,
                    Yw.Hydro.Flags.始端,
                    Yw.Hydro.Flags.默认
                });
                if (startSource == null)
                {
                    startSource = allSourceList.Matching(new List<string>()
                    {
                        Yw.Hydro.Flags.水源,
                        Yw.Hydro.Flags.始端
                    });
                }
                if (startSource != null)
                {
                    if (startSource is HydroTankInfo tank)
                    {
                        startHeadValue = tank.PoolElev + tank.InitLevel;
                    }
                }
            }
 
            double endHeadValue = 0;
            var allNodeList = hydroInfo.GetAllNodes();
            if (allNodeList != null && allNodeList.Count > 0)
            {
                var endSource = allNodeList.Matching(new List<string>()
                {
                    Yw.Hydro.Flags.水源,
                    Yw.Hydro.Flags.末端,
                    Yw.Hydro.Flags.默认
                });
                if (endSource == null)
                {
                    endSource = allSourceList.Matching(new List<string>()
                    {
                        Yw.Hydro.Flags.水源,
                        Yw.Hydro.Flags.末端
                    });
                }
                if (endSource != null)
                {
                    if (endSource is HydroTankInfo tank)
                    {
                        endHeadValue = tank.PoolElev + tank.InitLevel;
                    }
                    else if (endSource is HydroEmitterInfo emitter)
                    {
                        endHeadValue = emitter.Elev;
                    }
                }
            }
 
            return endHeadValue - startHeadValue;
        }
 
        /// <summary>
        /// 获取总管流量
        /// </summary>
        public static double? GetPipeQ(this Yw.Model.HydroModelInfo hydroInfo, HydroCalcuResult calcuResult)
        {
            return GetPipeQ(hydroInfo, calcuResult?.GetVisualDict());
        }
 
        /// <summary>
        /// 获取总管流量
        /// </summary>
        public static double? GetPipeQ(this Yw.Model.HydroModelInfo hydroInfo, Dictionary<string, HydroCalcuVisualResult> allCalcuVisualDict)
        {
            if (hydroInfo == null)
            {
                return default;
            }
            if (allCalcuVisualDict == null || allCalcuVisualDict.Count < 1)
            {
                return default;
            }
            var allLinkList = hydroInfo.GetAllLinks();
            if (allLinkList == null || allLinkList.Count < 1)
            {
                return default;
            }
            var link = allLinkList.Matching(new List<string>()
            {
                Yw.Hydro.Flags.总管,
                Yw.Hydro.Flags.出口,
                Yw.Hydro.Flags.默认
            });
            if (link == null)
            {
                link = allLinkList.Matching(new List<string>()
                {
                    Yw.Hydro.Flags.总管,
                    Yw.Hydro.Flags.出口
                });
            }
            if (link == null)
            {
                return default;
            }
 
            var calcuVisualResult = allCalcuVisualDict.GetValue(link.Code);
            if (calcuVisualResult == null)
            {
                return default;
            }
            var calcuValue = calcuVisualResult.GetCalcuValue(Yw.Hydro.VisualCalcuProp.CalcuFlow);
            if (calcuValue == null)
            {
                return default;
            }
            return Math.Round(Math.Abs(calcuValue.Value), 1);
        }
 
        /// <summary>
        /// 获取总管压力(绝对压力)
        /// </summary>
        public static double? GetPipeHead(this Yw.Model.HydroModelInfo hydroInfo, HydroCalcuResult calcuResult)
        {
            return GetPipeHead(hydroInfo, calcuResult?.GetVisualDict());
        }
 
        /// <summary>
        /// 获取总管压力(绝对压力)
        /// </summary>
        public static double? GetPipeHead(this Yw.Model.HydroModelInfo hydroInfo, Dictionary<string, HydroCalcuVisualResult> allCalcuVisualDict)
        {
            if (hydroInfo == null)
            {
                return default;
            }
            if (allCalcuVisualDict == null || allCalcuVisualDict.Count < 1)
            {
                return default;
            }
            var allNodeList = hydroInfo.GetAllNodes();
            if (allNodeList == null || allNodeList.Count < 1)
            {
                return default;
            }
            var node = allNodeList.Matching(new List<string>()
            {
                Yw.Hydro.Flags.总管,
                Yw.Hydro.Flags.出口,
                Yw.Hydro.Flags.默认
            });
            if (node == null)
            {
                node = allNodeList.Matching(new List<string>()
                {
                    Yw.Hydro.Flags.总管,
                    Yw.Hydro.Flags.出口
                });
            }
            if (node == null)
            {
                return default;
            }
 
            var calcuVisualResult = allCalcuVisualDict.GetValue(node.Code);
            if (calcuVisualResult == null)
            {
                return default;
            }
            var calcuValue = calcuVisualResult.GetCalcuValue(Yw.Hydro.VisualCalcuProp.CalcuHead);
            if (calcuValue == null)
            {
                return default;
            }
            return Math.Round(calcuValue.Value, 2);
        }
 
        #endregion
 
    }
}