cloudflight
2024-07-06 0340a1bb6012a97de0e029b26b5c882472749050
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
#define EPA2_2  //EPA2_0
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
 
 
namespace EPAModelNameSpace
{
 
    public class EpanetBase
    {
 
        const string DLLName = "epanet2.2.dll";//"epanet2.2.dll"
        //{ These are codes used by the DLL functions }
        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 }
            }
 
        }
 
 
 
 
 
 
        #region 节点
        //        获取节点参数值
        [DllImport(DLLName)]
        public static extern int ENgetnodevalue(int index, int paramcode, ref float value);
        //        获取节点类型
        [DllImport(DLLName)]
        public static extern int ENgetnodetype(int index, ref int typecode);
        //        获取节点编号
        [DllImport(DLLName)]
        public static extern int ENgetnodeindex(string nodeid, ref int nodeindex);
 
        //        获取节点        id
        [DllImport(DLLName)]
        public static extern int ENgetnodeid(int index, StringBuilder id);
 
 
 
 
 
        //        设置节点参数
        [DllImport(DLLName)]
        public static extern int ENsetnodevalue(int index, int paramcode, float value);
        #endregion
 
        #region 管段
 
        //        设置管段参数
        [DllImport(DLLName)]
        public static extern int ENsetlinkvalue(int index, int paramcode, float value);
 
        //        获取管段        id
        [DllImport(DLLName)]
 
        public static extern int ENgetlinkid(int index, StringBuilder id);
        //        获取管段        id
        [DllImport(DLLName)]
 
        public static extern int ENgetlinkindex(string id, ref int index);
        //        获取管段节点
        [DllImport(DLLName)]
        public static extern int ENgetlinknodes(int index, ref int fromnode, ref int tonode);
 
 
        //        获得管段参数
        [DllImport(DLLName)]
        public static extern int ENgetlinkvalue(int index, int paramcode, ref float value);
 
        //        设置管段类型
        [DllImport(DLLName)]
        public static extern int ENgetlinktype(int index, ref int typecode);
        #endregion
 
        #region 模式
        //          获取模式id
        [DllImport(DLLName)]
        public static extern int ENgetpatternindex(string nodeid, ref int patternindex);
 
 
        //        增加新的时间模式
        [DllImport(DLLName)]
        public static extern int ENaddpattern(string timeid);
        //        设置时间模式的值
        [DllImport(DLLName)]
        public static extern int ENsetpatternvalue(int index, int period, float value);
 
        [DllImport(DLLName)]
        public static extern int ENsetpattern(int index, float[] values, int n);
 
 
 
        public static int ENsetpatternvalue(string timeid, int period, float value)
        {
            int patternid = 0;
            ENgetpatternindex(timeid, ref patternid);
            return ENsetpatternvalue(patternid, period, value);
        }
 
 
 
        #endregion
 
        #region 计算控制
 
        //epanet        完全模拟函数
        [DllImport(DLLName)]
        public static extern int ENepanet(string f1, string f2, string f3, IntPtr vfunc);
        //        关闭管网文件
        [DllImport(DLLName)]
        public static extern int ENclose();
        //        关闭水力模拟系统,释放内存
        [DllImport(DLLName)]
        public static extern int ENcloseH();
        //        关闭水质模拟系统,释放内存
        [DllImport(DLLName)]
        public static extern int ENcloseQ();
        //        调用打开管网文件
        [DllImport(DLLName)]
        public static extern int ENopen(string f1, string f2, string f3);
        //        调用打开水力分析系统
        [DllImport(DLLName)]
        public static extern int ENopenH();
        //        调用打开水力分析系统
        [DllImport(DLLName)]
        public static extern int ENopenQ();
 
        /// <summary>
        /// 调用初始化水力计算系统
        /// </summary>
        /// <param name="saveflag">0-1标志,说明分析结果是否以均匀报告时段保存到EPANETH二进制输出文件。</param>
        /// <returns>返回错误编号,0表示无错误</returns>
        [DllImport(DLLName)]
        public static extern int ENinitH(int saveflag);
 
        //        调用运行水力计算
        [DllImport(DLLName)]
        public static extern int ENrunH(ref int t1);
        //        水力计算步长
        [DllImport(DLLName)]
        public static extern int ENnextH(ref int tstep1);
        //        调用初始化水质计算系统
        [DllImport(DLLName)]
        public static extern int ENinitQ(int saveflag);
        //        调用运行水力计算
        [DllImport(DLLName)]
        public static extern int ENrunQ(ref int t1);
        //        水力计算步长
        [DllImport(DLLName)]
        public static extern int ENnextQ(ref int tstep1);
 
 
 
        //        全部水力模拟
        [DllImport(DLLName)]
        public static extern int ENsolveH();
        //        全部水质模拟
        [DllImport(DLLName)]
        public static extern int ENsolveQ();
 
        //        生成报告
        [DllImport(DLLName)]
        public static extern int ENsaveH();
        #endregion
 
        #region 报告
        //        生成报告
        [DllImport(DLLName)]
        public static extern int ENreport();
        //        重置报告
        [DllImport(DLLName)]
        public static extern int ENresetreport();
 
        //        重置报告
        [DllImport(DLLName)]
        public static extern int ENsetreport(string x);
        #endregion
 
        #region 其他
 
 
        //        获取管网元件数
        [DllImport(DLLName)]
        public static extern int ENgetcount(int countcode, ref int count);
 
        //        获取错误信息
        [DllImport(DLLName)]
        public static extern int ENgeterror(int errcode, StringBuilder errmsg, int nchar);
 
        //  输出文件信息
        [DllImport(DLLName)]
        public static extern int ENsaveinpfile(string filename);
 
 
 
        //        获取简单控制状态的参数
        [DllImport(DLLName)]
        public static extern int ENgetcontrol(int cindex, ref int ctype, ref int index, ref
        float setting, ref int nindex, ref float level);
 
 
 
        //   设置选项
        [DllImport(DLLName)]
        public static extern int ENsetoption(int code, float v);
        //   设置水质类型
        [DllImport(DLLName)]
        public static extern int ENsetqualtype(int qualcode, string chemname,
                               string chemunits, string tracenode);
 
 
 
 
        #endregion
 
        //补充
        [DllImport(DLLName)]
        public static extern int ENsetinistatus(string id, string value);
 
 
   
    }
 
}