cloudflight
2023-12-20 ac3e88e5dc69c74c80045a86abe38caae81d0101
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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
 
using System.Text;
using System;
using System.Collections.Generic;
using System.ComponentModel;
 
namespace Hydro.HydraulicModel
{
    //public enum NodeValueType
    //{
    //    EN_ELEVATION = 0,  //  { Mode parameters }
    //    EN_BASEDEMAND = 1,
    //    EN_PATTERN = 2,
    //    EN_EMITTER = 3,
    //    EN_INITQUAL = 4,
    //    EN_SOURCEQUAL = 5,
    //    EN_SOURCEPAT = 6,
    //    EN_SOURCETYPE = 7,
    //    EN_TANKLEVEL = 8,
    //    EN_DEMAND = 9,
    //    EN_HEAD = 10,
    //    EN_PRESSURE = 11,
    //    EN_QUALITY = 12,
    //    EN_SOURCEMASS = 13,
    //    EN_INITVOLUME = 14,
    //    EN_MIXMODEL = 15,
    //    EN_MIXZONEVOL = 16,
    //}
    //public enum LinkValueType
    //{
    //    EN_DIAMETER = 0,  // { Link parameters }
    //    EN_LENGTH = 1,
    //    EN_ROUGHNESS = 2,
    //    EN_MINORLOSS = 3,
    //    EN_INITSTATUS = 4,
    //    EN_INITSETTING = 5,
    //    EN_KBULK = 6,
    //    EN_KWALL = 7,
    //    EN_FLOW = 8,
    //    EN_VELOCITY = 9,
    //    EN_HEADLOSS = 10,
    //    EN_STATUS = 11,
    //    EN_SETTING = 12,
    //    EN_ENERGY = 13,
    //}
    public enum NodeValueType
    {
        标高 = 0,  //  { Mode parameters }
        基本需水量 = 1,
        需水量模式 = 2,
        扩散器系数 = 3,
        初始物质浓度 = 4,
        输入物质浓度 = 5,
        浓度模式 = 6,
        水源类型 = 7,
        水池水位 = 8,
        需水量 = 9,
        绝对压力 = 10,
        自由压力 = 11,
        物质浓度 = 12,
        物质扩散浓度 = 13,
        初始容积 = 14,
        多物质混合模型 = 15,
        多物质混合容积 = 16,
    }
    public enum LinkValueType
    {
        管径 = 0,  // { Link parameters }
        管长 = 1,
        海森威廉系数 = 2,
        局部水头损失 = 3,
        初始状态 = 4,
        初始设置 = 5,
        水体反应系数 = 6,
        管壁反应系数 = 7,
        流量 = 8,
        流速 = 9,
        水损 = 10,
        状态 = 11,
        设置 = 12,
        功率 = 13,
    }
    public class HydraulicCore
    {
        public static class Const_class
        {
            public static class Const_Node
            {
                public const int EN_ELEVATION = 0;  //  { Mode parameters }
                public const int EN_BASEDEMAND = 1;
                public const int EN_PATTERN = 2;
                public const int EN_EMITTER = 3;
                public const int EN_INITQUAL = 4;
                public const int EN_SOURCEQUAL = 5;
                public const int EN_SOURCEPAT = 6;
                public const int EN_SOURCETYPE = 7;
                public const int EN_TANKLEVEL = 8;
                public const int EN_DEMAND = 9;
                public const int EN_HEAD = 10;
                public const int EN_PRESSURE = 11;
                public const int EN_QUALITY = 12;
                public const int EN_SOURCEMASS = 13;
                public const int EN_INITVOLUME = 14;
                public const int EN_MIXMODEL = 15;
                public const int EN_MIXZONEVOL = 16;
            }
 
            public static class Const_Tank
            {
                public const int EN_TANKDIAM = 17;
                public const int EN_MINVOLUME = 18;
                public const int EN_VOLCURVE = 19;
                public const int EN_MINLEVEL = 20;
                public const int EN_MAXLEVEL = 21;
                public const int EN_MIXFRACTION = 22;
                public const int EN_TANK_KBULK = 23;
            }
 
            public static class Const_Link
            {
 
                public const int EN_DIAMETER = 0;  // { Link parameters }
                public const int EN_LENGTH = 1;
                public const int EN_ROUGHNESS = 2;
                public const int EN_MINORLOSS = 3;
                public const int EN_INITSTATUS = 4;
                public const int EN_INITSETTING = 5;
                public const int EN_KBULK = 6;
                public const int EN_KWALL = 7;
                public const int EN_FLOW = 8;
                public const int EN_VELOCITY = 9;
                public const int EN_HEADLOSS = 10;
                public const int EN_STATUS = 11;
                public const int EN_SETTING = 12;
                public const int EN_ENERGY = 13;
            }
 
            public static class Const_Time
            {
                public const int EN_DURATION = 0; // { Time parameters }
                public const int EN_HYDSTEP = 1;
                public const int EN_QUALSTEP = 2;
                public const int EN_PATTERNSTEP = 3;
                public const int EN_PATTERNSTART = 4;
                public const int EN_REPORTSTEP = 5;
                public const int EN_REPORTSTART = 6;
                public const int EN_RULESTEP = 7;
                public const int EN_STATISTIC = 8;
                public const int EN_PERIODS = 9;
            }
 
            public static class Const_Component
            {
                public const int EN_NODECOUNT = 0; //{ Component counts }
                public const int EN_TANKCOUNT = 1;
                public const int EN_LINKCOUNT = 2;
                public const int EN_PATCOUNT = 3;
                public const int EN_CURVECOUNT = 4;
                public const int EN_CONTROLCOUNT = 5;
            }
 
            public static class Const_Node_Type
            {
                public const int EN_JUNCTION = 0;  // { Node types }
                public const int EN_RESERVOIR = 1;
                public const int EN_TANK = 2;
            }
 
            public static class Const_Link_types
            {
                public const int EN_CVPIPE = 0; //  { Link types }
                public const int EN_PIPE = 1;
                public const int EN_PUMP = 2;
                public const int EN_PRV = 3;
                public const int EN_PSV = 4;
                public const int EN_PBV = 5;
                public const int EN_FCV = 6;
                public const int EN_TCV = 7;
                public const int EN_GPV = 8;
            }
 
            public static class Const_Quality_analysis_types
            {
                public const int EN_NONE = 0; //  { Quality analysis types }
                public const int EN_CHEM = 1;
                public const int EN_AGE = 2;
                public const int EN_TRACE = 3;
            }
 
            public static class Const_Source_quality_types
            {
                public const int EN_CONCEN = 0;  // { Source quality types }
                public const int EN_MASS = 1;
                public const int EN_SETPOINT = 2;
                public const int EN_FLOWPACED = 3;
            }
 
            public static class Const_Flow_units_types
            {
                public const int EN_CFS = 0;  // { Flow units types }
                public const int EN_GPM = 1;
                public const int EN_MGD = 2;
                public const int EN_IMGD = 3;
                public const int EN_AFD = 4;
                public const int EN_LPS = 5;
                public const int EN_LPM = 6;
                public const int EN_MLD = 7;
                public const int EN_CMH = 8;
                public const int EN_CMD = 9;
            }
 
            public static class Const_Option_types
            {
                public const int EN_TRIALS = 0;  // { Option types }
                public const int EN_ACCURACY = 1;
                public const int EN_TOLERANCE = 2;
                public const int EN_EMITEXPON = 3;
                public const int EN_DEMANDMULT = 4;
            }
 
            public static class Const_Control_types
            {
                public const int EN_LOWLEVEL = 0;   //{ Control types }
                public const int EN_HILEVEL = 1;
                public const int EN_TIMER = 2;
                public const int EN_TIMEOFDAY = 3;
            }
 
            public static class Const_Time_statistic_types
            {
                public const int EN_AVERAGE = 1;  // { Time statistic types }
                public const int EN_MINIMUM = 2;
                public const int EN_MAXIMUM = 3;
                public const int EN_RANGE = 4;
            }
 
            public static class Const_Tank_mixing_models
            {
                public const int EN_MIX1 = 0;  // { Tank mixing models }
                public const int EN_MIX2 = 1;
                public const int EN_FIFO = 2;
                public const int EN_LIFO = 3;
            }
 
            public static class Const_Save_results_Mode
            {
                public const int EN_NOSAVE = 0;  // { Save-results-to-file flag }
                public const int EN_SAVE = 1;
                public const int EN_INITFLOW = 10; // { Re-initialize flow flag }
            }
            public static class Const_statuslevel
            {
                public const int EN_NONE = 0;
                public const int EN_NORMAL = 0;
                public const int EN_FULL = 0;
            }
 
        }
 
        static int ProjectCount=0;
        
        public void Dispose()
        {
            HydraulicCore.ProjectCount--;
        }
 
        int projectID;
 
        public int GetProjectID()
        {
            return projectID;
        }
        public HydraulicCore()
        {
            
            this.projectID = ProjectCount;
            HydraulicCore.ProjectCount++;
        }
        //        获取节点参数值
 
        public int getnodevalue(int index, int paramcode, ref float value)
        {
            return HydraulicCoreBase.ENgetnodevalue22(projectID, index, paramcode, ref value);
        }
        //        获取节点类型
 
        public float getvalue(string ID,int paramcode)
        {
            int err = 0;
            int index = 0;
            err=getnodeindex(ID,ref index);
            float value = 0;
            if (index>0)
            {
                err = getnodevalue(index,paramcode,ref value);
            }
            else
            {
                err = getlinkindex(ID, ref index);
                err = getlinkvalue(index, paramcode, ref value);
            }
            return value;
            
        }
        public float getvalue(string ID, int paramcode,bool isNode)
        {
            int err = 0;
            int index = 0;
            float value = 0;
            if (isNode)
            {
                err = getnodeindex(ID, ref index);
                
                if (index > 0)
                    err = getnodevalue(index, paramcode, ref value);
            }
            
            else
            {
                err = getlinkindex(ID, ref index);
                if (index > 0)
                    err = getlinkvalue(index, paramcode, ref value);
            }
            return value;
 
        }
        public int setvalue(string ID, int paramcode,double value, bool isNode)
        {
            int err = 0;
            int index = 0;
           
            if (isNode)
            {
                err = getnodeindex(ID, ref index);
 
                if (index > 0)
                    err = setnodevalue(index, paramcode,(float) value);
            }
 
            else
            {
                err = getlinkindex(ID, ref index);
                if (index > 0)
                    err = setlinkvalue(index, paramcode, (float)value);
            }
            
            return err;
 
        }
        public int getnodetype(int index, ref int typecode)
        {
            return HydraulicCoreBase.ENgetnodetype22(projectID, index, ref typecode);
        }
        //        获取节点编号
 
        public int getnodeindex(string nodeid, ref int nodeindex)
        {
            return HydraulicCoreBase.ENgetnodeindex22(projectID, nodeid, ref nodeindex);
        }
 
        //        获取节点        id
 
        public int getnodeid(int index, StringBuilder id)
        {
            return HydraulicCoreBase.ENgetnodeid22(projectID, index, id);
        }
        public int getnodecomment(int index, StringBuilder id)
        {
            return HydraulicCoreBase.ENgetnodecomment22(projectID, index, id);
        }
        public int addnode(string id, int nodeType, ref int index)
        {
            return HydraulicCoreBase.ENaddnode22(projectID, id, nodeType, ref index);
        }
 
 
        public int getcoord(int index, ref double x, ref double y)
        {
            return HydraulicCoreBase.ENgetcoord22(projectID, index, ref x, ref y);
        }
 
        public int setcoord(int index, double x, double y)
        {
            return HydraulicCoreBase.ENsetcoord22(projectID, index, x, y);
        }
 
        //        设置节点参数
 
        public int setnodevalue(int index, int paramcode, float value)
        {
            return HydraulicCoreBase.ENsetnodevalue22(projectID, index, paramcode, value);
        }
 
        
 
        #region 管段
 
        //        设置管段参数
 
        public int setlinkvalue(int index, int paramcode, float value)
        {
            return HydraulicCoreBase.ENsetlinkvalue22(projectID, index, paramcode, value);
        }
 
        //        获取管段        id
 
 
        public int getlinkid(int index, StringBuilder id)
        {
            return HydraulicCoreBase.ENgetlinkid22(projectID, index, id);
        }
        public int getlinkcomment(int index, StringBuilder id)
        {
            return HydraulicCoreBase.ENgetlinkcomment22(projectID, index, id);
        }
        //        获取管段        id
 
 
        public int getlinkindex(string id, ref int index)
        {
            return HydraulicCoreBase.ENgetlinkindex22(projectID, id, ref index);
        }
        //        获取管段节点
 
        public int getlinknodes(int index, ref int fromnode, ref int tonode)
        {
            return HydraulicCoreBase.ENgetlinknodes22(projectID, index, ref fromnode, ref tonode);
        }
 
 
        //        获得管段参数
 
        public int getlinkvalue(int index, int paramcode, ref float value)
        {
            return HydraulicCoreBase.ENgetlinkvalue22(projectID, index, paramcode, ref value);
        }
 
        //        设置管段类型
 
        public int getlinktype(int index, ref int typecode)
        {
            return HydraulicCoreBase.ENgetlinktype22(projectID, index, ref typecode);
        }
        //        增加管线
 
        public int addlink(string id, int linkType, string fromNode, string toNode, ref int index)
        {
            return HydraulicCoreBase.ENaddlink22(projectID, id, linkType, fromNode, toNode, ref index);
        }
 
 
        #endregion
 
        #region 模式
        //          获取模式id
 
        public int getpatternindex(string patternID, ref int patternindex)
        {
            return HydraulicCoreBase.ENgetpatternindex22(projectID, patternID, ref patternindex);
        }
 
 
        //        增加新的时间模式
 
        public int addpattern(string patternID)
        {
            return HydraulicCoreBase.ENaddpattern22(projectID, patternID);
        }
        //        设置时间模式的值
 
        public int setpatternvalue(int index, int period, float value)
        {
            return HydraulicCoreBase.ENsetpatternvalue22(projectID, index, period, value);
        }
 
 
 
        public int setpatternvalue_ex(string patternID, int period, float value)
        {
            return HydraulicCoreBase.ENsetpatternvalue_ex(projectID, patternID, period, value);
        }
 
 
 
 
 
        public int setpattern(int index, float[] values, int n)
        {
            return HydraulicCoreBase.ENsetpattern22(projectID, index, values, n);
        }
 
        /// <summary>
        /// 加强版添加模式,如果模式名称不存在,则自动新增模式;新增完后,自定绑定节点
        /// </summary>
        /// <param name="projectID"></param>
        /// <param name="nodeID"></param>
        /// <param name="patternID"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        public int setpatternvalue_ex(string nodeID, string patternID, double[] values)
        {
            return HydraulicCoreBase.ENsetpatternvalue_ex(projectID, nodeID, patternID, values);
        }
 
 
 
 
        public int setcurve(int index, float[] Xvalues, float[] Yvalues, int n)
        {
            return HydraulicCoreBase.ENsetcurve22(projectID, index, Xvalues, Yvalues, n);
        }
 
 
 
 
 
        #endregion
 
        #region 计算控制
 
        //epanet        完全模拟函数
 
        public int epanet(string f1, string f2, string f3, IntPtr vfunc)
        {
            return HydraulicCoreBase.ENepanet22(projectID, f1, f2, f3, vfunc);
        }
        //        关闭管网文件
 
        public int close()
        {
            ProjectCount--;
            return HydraulicCoreBase.ENclose22(projectID);
           
        }
        //        关闭水力模拟系统,释放内存
 
        public int closeH()
        {
            return HydraulicCoreBase.ENcloseH22(projectID);
        }
        //        关闭水质模拟系统,释放内存
 
        public int closeQ()
        {
            return HydraulicCoreBase.ENcloseQ22(projectID);
        }
        //        调用打开管网文件
 
        public int open(string f1, string f2, string f3)
        {
            return HydraulicCoreBase.ENopen22(projectID, f1, f2, f3);
        }
        //        调用打开水力分析系统
 
        public int openH()
        {
            return HydraulicCoreBase.ENopenH22(projectID);
        }
        //        调用打开水力分析系统
 
        public int openQ()
        {
            return HydraulicCoreBase.ENopenQ22(projectID);
        }
 
        /// <summary>
        /// 调用初始化水力计算系统
        /// </summary>
        /// <param name="saveflag">0-1标志,说明分析结果是否以均匀报告时段保存到EPANETH二进制输出文件。</param>
        /// <returns>返回错误编号,0表示无错误</returns>
 
        public int initH(int saveflag)
        {
            return HydraulicCoreBase.ENinitH22(projectID, saveflag);
        }
 
        //        调用运行水力计算
 
        public int runH(ref int t1)
        {
            return HydraulicCoreBase.ENrunH22(projectID, ref t1);
        }
        //        水力计算步长
 
        public int nextH(ref int tstep1)
        {
            return HydraulicCoreBase.ENnextH22(projectID, ref tstep1);
        }
        //        调用初始化水质计算系统
 
        public int initQ(int saveflag)
        {
            return HydraulicCoreBase.ENinitQ22(projectID, saveflag);
        }
        //        调用运行水力计算
 
        public int runQ(ref int t1)
        {
            return HydraulicCoreBase.ENrunQ22(projectID, ref t1);
        }
        //        水力计算步长
 
        public int nextQ(ref int tstep1)
        {
            return HydraulicCoreBase.ENnextQ22(projectID, ref tstep1);
        }
 
 
 
        //        全部水力模拟
 
        public int solveH()
        {
            return HydraulicCoreBase.ENsolveH22(projectID);
        }
        //        全部水质模拟
 
        public int solveQ()
        {
            return HydraulicCoreBase.ENsolveQ22(projectID);
        }
 
        //        生成报告
 
        public int saveH()
        {
            return HydraulicCoreBase.ENsaveH22(projectID);
        }
        #endregion
 
        #region 报告
        //        生成报告
 
        public int report()
        {
            return HydraulicCoreBase.ENreport22(projectID);
        }
        //        重置报告
 
        public int resetreport()
        {
            return HydraulicCoreBase.ENresetreport22(projectID);
        }
 
        //        重置报告
 
        public int setreport(string x)
        {
            return HydraulicCoreBase.ENsetreport22(projectID, x);
        }
        #endregion
 
        #region 其他
 
 
        //        获取管网元件数
 
        public int getcount(int countcode, ref int count)
        {
            return HydraulicCoreBase.ENgetcount22(projectID, countcode, ref count);
        }
 
        //        获取错误信息
 
        public int geterror(int errcode, StringBuilder errmsg, int nchar)
        {
            return HydraulicCoreBase.ENgeterror22(projectID, errcode, errmsg, nchar);
        }
 
        //  输出文件信息
 
        public int saveinpfile(string filename)
        {
            return HydraulicCoreBase.ENsaveinpfile22(projectID, filename);
        }
 
 
 
        //        获取简单控制状态的参数
 
        public int getcontrol(int cindex, ref int ctype, ref int index, ref
        float setting, ref int nindex, ref float level)
        {
            return HydraulicCoreBase.ENgetcontrol22(projectID, cindex, ref ctype, ref index, ref
        setting, ref nindex, ref level);
        }
 
 
 
        //   设置选项
 
        public int setoption(int code, float v)
        {
            return HydraulicCoreBase.ENsetoption22(projectID, code, v);
        }
        public int setstatusreport(int code)
        {
            
            return HydraulicCoreBase.ENsetstatusreport22(projectID, code);
        }
        public float getoption(int code )
        {
            float v = 0;
             HydraulicCoreBase.ENgetoption22(projectID, code,ref v);
            return v;
        }
 
        //   设置选项
 
        public int gettimeparam(int code, ref int v)
        {
            return HydraulicCoreBase.ENgettimeparam22(projectID, code, ref v);
        }
        //   设置水质类型
 
        public int setqualtype(int qualcode, string chemname,
                               string chemunits, string tracenode)
        {
            return HydraulicCoreBase.ENsetqualtype22(projectID, qualcode, chemname, chemunits, tracenode);
        }
 
 
 
 
        #endregion
 
        //补充
 
        public int setinistatus(string id, string value)
        {
            return HydraulicCoreBase.ENsetinistatus22(projectID, id, value);
        }
 
        //补充
 
        public int setprojectreport(int value)
        {
            return HydraulicCoreBase.ENsetprojectreport22(projectID, value);
        }
 
 
   
        public int getbasedemand( int nodeIndex, int demandIndex, out List<double> baseDemand)
        {
            return HydraulicCoreBase.ENgetbasedemand22(projectID, nodeIndex,demandIndex, out baseDemand);
        }
        //补充
 
        public int getdemandpattern(int nodeIndex, int demandIndex,
                                  out List<int> patIndex)
        {
            return HydraulicCoreBase.ENgetdemandpattern22(projectID, nodeIndex, demandIndex, out patIndex);
        }
 
        public int getTotalDemand(int p,  out double value)
        {
            return HydraulicCoreBase.ENgetTotalDemand22(projectID, p, out value);
        }
 
     
 
    }
}