@model-create/epanet-engine 0.7.1-alpha.2 → 0.8.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1131 +0,0 @@
1
- #include <emscripten/bind.h>
2
- #include "epanet2_2.h"
3
- #include <stdio.h>
4
-
5
- using namespace emscripten;
6
-
7
- int getversion(uintptr_t i)
8
- {
9
- int *ptr = reinterpret_cast<int *>(i);
10
- return EN_getversion(ptr);
11
- }
12
-
13
- int geterror(int errcode, intptr_t out_errmsg)
14
- {
15
- char *ptr1 = reinterpret_cast<char *>(out_errmsg);
16
- return EN_geterror(errcode, ptr1, EN_MAXMSG);
17
- }
18
-
19
- class Epanet
20
- {
21
- private:
22
- EN_Project ph;
23
-
24
- public:
25
- Epanet()
26
- {
27
- EN_createproject(&ph);
28
- }
29
-
30
- ~Epanet()
31
- {
32
- EN_deleteproject(ph);
33
- }
34
-
35
- // Project Functions
36
-
37
- int open(std::string inputFile, std::string reportFile, std::string outputFile)
38
- {
39
-
40
- int errcode;
41
- char *inpFile = new char[inputFile.length() + 1];
42
- char *rptFile = new char[reportFile.length() + 1];
43
- char *outFile = new char[outputFile.length() + 1];
44
-
45
- strcpy(inpFile, inputFile.c_str());
46
- strcpy(rptFile, reportFile.c_str());
47
- strcpy(outFile, outputFile.c_str());
48
-
49
- errcode = EN_open(ph, inpFile, rptFile, outFile);
50
-
51
- delete[] inpFile;
52
- delete[] rptFile;
53
- delete[] outFile;
54
-
55
- return errcode;
56
- }
57
-
58
- int close()
59
- {
60
- return EN_close(ph);
61
- }
62
-
63
- int runproject(std::string inputFile, std::string reportFile, std::string outputFile)
64
- {
65
-
66
- int errcode;
67
- char *inpFile = new char[inputFile.length() + 1];
68
- char *rptFile = new char[reportFile.length() + 1];
69
- char *outFile = new char[outputFile.length() + 1];
70
-
71
- strcpy(inpFile, inputFile.c_str());
72
- strcpy(rptFile, reportFile.c_str());
73
- strcpy(outFile, outputFile.c_str());
74
-
75
- errcode = EN_runproject(ph, inpFile, rptFile, outFile, NULL);
76
-
77
- delete[] inpFile;
78
- delete[] rptFile;
79
- delete[] outFile;
80
-
81
- return errcode;
82
- }
83
-
84
- int init(std::string reportFile, std::string outputFile, int unitsType, int headLossType)
85
- {
86
- int errcode;
87
- char *rptFile = new char[reportFile.length() + 1];
88
- char *outFile = new char[outputFile.length() + 1];
89
-
90
- strcpy(rptFile, reportFile.c_str());
91
- strcpy(outFile, outputFile.c_str());
92
-
93
- errcode = EN_init(ph, rptFile, outFile, unitsType, headLossType);
94
-
95
- delete[] rptFile;
96
- delete[] outFile;
97
-
98
- return errcode;
99
- }
100
-
101
- int getcount(int obj, uintptr_t count)
102
- {
103
- int *ptr = reinterpret_cast<int *>(count);
104
- return EN_getcount(ph, obj, ptr);
105
- }
106
-
107
- int gettitle(intptr_t out_line1, intptr_t out_line2, intptr_t out_line3)
108
- {
109
- char *ptr1 = reinterpret_cast<char *>(out_line1);
110
- char *ptr2 = reinterpret_cast<char *>(out_line2);
111
- char *ptr3 = reinterpret_cast<char *>(out_line3);
112
- return EN_gettitle(ph, ptr1, ptr2, ptr3);
113
- }
114
-
115
- int settitle(std::string line1, std::string line2, std::string line3)
116
- {
117
- int errcode;
118
- char *l1 = new char[line1.length() + 1];
119
- char *l2 = new char[line2.length() + 1];
120
- char *l3 = new char[line3.length() + 1];
121
-
122
- strcpy(l1, line1.c_str());
123
- strcpy(l2, line2.c_str());
124
- strcpy(l3, line3.c_str());
125
-
126
- errcode = EN_settitle(ph, l1, l2, l3);
127
-
128
- delete[] l1;
129
- delete[] l2;
130
- delete[] l3;
131
-
132
- return errcode;
133
- }
134
-
135
- int saveinpfile(std::string filename)
136
- {
137
- int errcode;
138
- char *fName = new char[filename.length() + 1];
139
-
140
- strcpy(fName, filename.c_str());
141
-
142
- errcode = EN_saveinpfile(ph, fName);
143
-
144
- delete[] fName;
145
-
146
- return errcode;
147
- }
148
-
149
- // Hydraulic Analysis Functions
150
-
151
- int solveH()
152
- {
153
- return EN_solveH(ph);
154
- }
155
-
156
- int usehydfile(std::string filename)
157
- {
158
- int errcode;
159
- char *fName = new char[filename.length() + 1];
160
-
161
- strcpy(fName, filename.c_str());
162
-
163
- errcode = EN_usehydfile(ph, fName);
164
-
165
- delete[] fName;
166
-
167
- return errcode;
168
- }
169
-
170
- int openH()
171
- {
172
- return EN_openH(ph);
173
- }
174
-
175
- int initH(int initFlag)
176
- {
177
- return EN_initH(ph, initFlag);
178
- }
179
-
180
- int runH(uintptr_t currentTime)
181
- {
182
- long *ptr = reinterpret_cast<long *>(currentTime);
183
- return EN_runH(ph, ptr);
184
- }
185
-
186
- int nextH(uintptr_t tStep)
187
- {
188
- long *ptr = reinterpret_cast<long *>(tStep);
189
- return EN_nextH(ph, ptr);
190
- }
191
-
192
- int saveH()
193
- {
194
- return EN_saveH(ph);
195
- }
196
-
197
- int savehydfile(std::string filename)
198
- {
199
- int errcode;
200
- char *fName = new char[filename.length() + 1];
201
-
202
- strcpy(fName, filename.c_str());
203
-
204
- errcode = EN_savehydfile(ph, fName);
205
-
206
- delete[] fName;
207
-
208
- return errcode;
209
- }
210
-
211
- int closeH()
212
- {
213
- return EN_closeH(ph);
214
- }
215
-
216
- //Water Quality Analysis Functions
217
-
218
- int solveQ()
219
- {
220
- return EN_solveQ(ph);
221
- }
222
- int openQ()
223
- {
224
- return EN_openQ(ph);
225
- }
226
-
227
- int initQ(int initFlag)
228
- {
229
- return EN_initQ(ph, initFlag);
230
- }
231
-
232
- int runQ(uintptr_t currentTime)
233
- {
234
- long *ptr = reinterpret_cast<long *>(currentTime);
235
- return EN_runQ(ph, ptr);
236
- }
237
-
238
- int nextQ(uintptr_t tStep)
239
- {
240
- long *ptr = reinterpret_cast<long *>(tStep);
241
- return EN_nextQ(ph, ptr);
242
- }
243
-
244
- int stepQ(uintptr_t timeLeft)
245
- {
246
- long *ptr = reinterpret_cast<long *>(timeLeft);
247
- return EN_stepQ(ph, ptr);
248
- }
249
-
250
- int closeQ()
251
- {
252
- return EN_closeQ(ph);
253
- }
254
-
255
- // Reporting Functions
256
-
257
- int writeline(std::string line)
258
- {
259
- int errcode;
260
-
261
- char *l1 = new char[line.length() + 1];
262
- strcpy(l1, line.c_str());
263
-
264
- errcode = EN_writeline(ph, l1);
265
- delete[] l1;
266
-
267
- return errcode;
268
- }
269
-
270
- int report()
271
- {
272
- return EN_report(ph);
273
- }
274
-
275
- int copyreport(std::string filename)
276
- {
277
- int errcode;
278
-
279
- char *fname = new char[filename.length() + 1];
280
- strcpy(fname, filename.c_str());
281
-
282
- errcode = EN_copyreport(ph, fname);
283
- delete[] fname;
284
-
285
- return errcode;
286
- }
287
-
288
- int clearreport()
289
- {
290
- return EN_clearreport(ph);
291
- }
292
-
293
- int resetreport()
294
- {
295
- return EN_resetreport(ph);
296
- }
297
-
298
- int setreport(std::string format)
299
- {
300
- int errcode;
301
-
302
- char *f = new char[format.length() + 1];
303
- strcpy(f, format.c_str());
304
-
305
- errcode = EN_copyreport(ph, f);
306
- delete[] f;
307
-
308
- return errcode;
309
- }
310
-
311
- int setstatusreport(int level)
312
- {
313
- return EN_setstatusreport(ph, level);
314
- }
315
-
316
- int getstatistic(int type, intptr_t value)
317
- {
318
- double *ptr1 = reinterpret_cast<double *>(value);
319
- return EN_getstatistic(ph, type, ptr1);
320
- }
321
-
322
- int getresultindex(int type, int index, intptr_t value)
323
- {
324
- int *ptr1 = reinterpret_cast<int *>(value);
325
- return EN_getresultindex(ph, type, index, ptr1);
326
- }
327
-
328
- // Analysis Options Functions
329
- int getflowunits(uintptr_t units)
330
- {
331
- int *ptr = reinterpret_cast<int *>(units);
332
- return EN_getflowunits(ph, ptr);
333
- }
334
-
335
- int getoption(int option, uintptr_t value)
336
- {
337
- double *ptr = reinterpret_cast<double *>(value);
338
- return EN_getoption(ph, option, ptr);
339
- }
340
-
341
- int getqualinfo(uintptr_t qualType, uintptr_t out_chemName, uintptr_t out_chemUnits, uintptr_t traceNode)
342
- {
343
- int *ptr1 = reinterpret_cast<int *>(qualType);
344
- char *ptr2 = reinterpret_cast<char *>(out_chemName);
345
- char *ptr3 = reinterpret_cast<char *>(out_chemUnits);
346
- int *ptr4 = reinterpret_cast<int *>(traceNode);
347
-
348
- return EN_getqualinfo(ph, ptr1, ptr2, ptr3, ptr4);
349
- }
350
- int getqualtype(uintptr_t qualType, uintptr_t traceNode)
351
- {
352
- int *ptr1 = reinterpret_cast<int *>(qualType);
353
- int *ptr2 = reinterpret_cast<int *>(traceNode);
354
- return EN_getqualtype(ph, ptr1, ptr2);
355
- }
356
- int gettimeparam(int param, uintptr_t value)
357
- {
358
- long *ptr1 = reinterpret_cast<long *>(value);
359
- return EN_gettimeparam(ph, param, ptr1);
360
- }
361
- int setflowunits(int units)
362
- {
363
- return EN_setflowunits(ph, units);
364
- }
365
- int setoption(int option, double value)
366
- {
367
- return EN_setoption(ph, option, value);
368
- }
369
- int setqualtype(int qualType, std::string chemName, std::string chemUnits, std::string traceNode)
370
- {
371
- int errcode;
372
- char *p1 = new char[chemName.length() + 1];
373
- char *p2 = new char[chemUnits.length() + 1];
374
- char *p3 = new char[traceNode.length() + 1];
375
-
376
- strcpy(p1, chemName.c_str());
377
- strcpy(p2, chemUnits.c_str());
378
- strcpy(p3, traceNode.c_str());
379
-
380
- errcode = EN_setqualtype(ph, qualType, p1, p2, p3);
381
-
382
- delete[] p1;
383
- delete[] p2;
384
- delete[] p3;
385
-
386
- return errcode;
387
- }
388
-
389
- int settimeparam(int param, long value)
390
- {
391
- return EN_settimeparam(ph, param, value);
392
- }
393
- // Network Node Functions
394
- int addnode(std::string id, int nodeType, intptr_t index)
395
- {
396
- int errcode;
397
- int *ptr1 = reinterpret_cast<int *>(index);
398
- char *idChar = new char[id.length() + 1];
399
-
400
- strcpy(idChar, id.c_str());
401
-
402
- errcode = EN_addnode(ph, idChar, nodeType, ptr1);
403
-
404
- delete[] idChar;
405
- return errcode;
406
- }
407
- int deletenode(int index, int actionCode)
408
- {
409
- return EN_deletenode(ph, index, actionCode);
410
- }
411
- int getnodeindex(std::string id, intptr_t index)
412
- {
413
- int errcode;
414
- int *ptr1 = reinterpret_cast<int *>(index);
415
- char *idChar = new char[id.length() + 1];
416
-
417
- strcpy(idChar, id.c_str());
418
-
419
- errcode = EN_getnodeindex(ph, idChar, ptr1);
420
-
421
- delete[] idChar;
422
- return errcode;
423
- }
424
- int getnodeid(int index, intptr_t out_id)
425
- {
426
- char *ptr1 = reinterpret_cast<char *>(out_id);
427
- return EN_getnodeid(ph, index, ptr1);
428
- }
429
- int setnodeid(int index, std::string newid)
430
- {
431
- int errcode;
432
- char *idChar = new char[newid.length() + 1];
433
- strcpy(idChar, newid.c_str());
434
-
435
- errcode = EN_setnodeid(ph, index, idChar);
436
-
437
- delete[] idChar;
438
- return errcode;
439
- }
440
- int getnodetype(int index, intptr_t nodeType)
441
- {
442
- int *ptr1 = reinterpret_cast<int *>(nodeType);
443
- return EN_getnodetype(ph, index, ptr1);
444
- }
445
- int getnodevalue(int index, int property, intptr_t value)
446
- {
447
- double *ptr1 = reinterpret_cast<double *>(value);
448
- return EN_getnodevalue(ph, index, property, ptr1);
449
- }
450
- int setnodevalue(int index, int property, double value)
451
- {
452
- return EN_setnodevalue(ph, index, property, value);
453
- }
454
- int setjuncdata(int index, double elev, double dmnd, std::string dmndpat)
455
- {
456
- int errcode;
457
- char *dmndpatChar = new char[dmndpat.length() + 1];
458
- strcpy(dmndpatChar, dmndpat.c_str());
459
-
460
- errcode = EN_setjuncdata(ph, index, elev, dmnd, dmndpatChar);
461
-
462
- delete[] dmndpatChar;
463
- return errcode;
464
- }
465
- int settankdata(int index, double elev, double initlvl, double minlvl, double maxlvl, double diam, double minvol, std::string volcurve)
466
- {
467
- int errcode;
468
- char *volcurveChar = new char[volcurve.length() + 1];
469
- strcpy(volcurveChar, volcurve.c_str());
470
-
471
- errcode = EN_settankdata(ph, index, elev, initlvl, minlvl, maxlvl, diam, minvol, volcurveChar);
472
-
473
- delete[] volcurveChar;
474
- return errcode;
475
- }
476
- int getcoord(int index, intptr_t x, intptr_t y)
477
- {
478
- double *ptr1 = reinterpret_cast<double *>(x);
479
- double *ptr2 = reinterpret_cast<double *>(y);
480
- return EN_getcoord(ph, index, ptr1, ptr2);
481
- }
482
- int setcoord(int index, double x, double y)
483
- {
484
- return EN_setcoord(ph, index, x, y);
485
- }
486
- // Nodal Demand Functions
487
- int adddemand(int nodeIndex, double baseDemand, std::string demandPattern, std::string demandName)
488
- {
489
- int errcode;
490
- char *demandPatternChar = new char[demandPattern.length() + 1];
491
- char *demandNameChar = new char[demandName.length() + 1];
492
- strcpy(demandPatternChar, demandPattern.c_str());
493
- strcpy(demandNameChar, demandName.c_str());
494
-
495
- errcode = EN_adddemand(ph, nodeIndex, baseDemand, demandPatternChar, demandNameChar);
496
-
497
- delete[] demandPatternChar;
498
- delete[] demandNameChar;
499
- return errcode;
500
- }
501
- int deletedemand(int nodeIndex, int demandIndex)
502
- {
503
- return EN_deletedemand(ph, nodeIndex, demandIndex);
504
- }
505
-
506
- int getbasedemand(int nodeIndex, int demandIndex, intptr_t baseDemand)
507
- {
508
- double *ptr1 = reinterpret_cast<double *>(baseDemand);
509
- return EN_getbasedemand(ph, nodeIndex, demandIndex, ptr1);
510
- }
511
-
512
- int getdemandindex(int nodeIndex, std::string demandName, intptr_t demandIndex)
513
- {
514
- int errcode;
515
-
516
- int *ptr1 = reinterpret_cast<int *>(demandIndex);
517
-
518
- char *demandNameChar = new char[demandName.length() + 1];
519
- strcpy(demandNameChar, demandName.c_str());
520
-
521
- errcode = EN_getdemandindex(ph, nodeIndex, demandNameChar, ptr1);
522
-
523
- delete[] demandNameChar;
524
- return errcode;
525
- }
526
-
527
- int getdemandmodel(intptr_t type, intptr_t pmin, intptr_t preq, intptr_t pexp)
528
- {
529
- int *ptr1 = reinterpret_cast<int *>(type);
530
- double *ptr2 = reinterpret_cast<double *>(pmin);
531
- double *ptr3 = reinterpret_cast<double *>(preq);
532
- double *ptr4 = reinterpret_cast<double *>(pexp);
533
- return EN_getdemandmodel(ph, ptr1, ptr2, ptr3, ptr4);
534
- }
535
-
536
- int getdemandname(int nodeIndex, int demandIndex, intptr_t out_demandName)
537
- {
538
- char *ptr1 = reinterpret_cast<char *>(out_demandName);
539
- return EN_getdemandname(ph, nodeIndex, demandIndex, ptr1);
540
- }
541
-
542
- int getdemandpattern(int nodeIndex, int demandIndex, intptr_t patIndex)
543
- {
544
- int *ptr1 = reinterpret_cast<int *>(patIndex);
545
- return EN_getdemandpattern(ph, nodeIndex, demandIndex, ptr1);
546
- }
547
-
548
- int getnumdemands(int nodeIndex, intptr_t numDemands)
549
- {
550
- int *ptr1 = reinterpret_cast<int *>(numDemands);
551
- return EN_getnumdemands(ph, nodeIndex, ptr1);
552
- }
553
-
554
- int setbasedemand(int nodeIndex, int demandIndex, double baseDemand)
555
- {
556
- return EN_setbasedemand(ph, nodeIndex, demandIndex, baseDemand);
557
- }
558
-
559
- int setdemandmodel(int type, double pmin, double preq, double pexp)
560
- {
561
- return EN_setdemandmodel(ph, type, pmin, preq, pexp);
562
- }
563
-
564
- int setdemandname(int nodeIndex, int demandIdx, std::string demandName)
565
- {
566
- int errcode;
567
-
568
- char *demandNameChar = new char[demandName.length() + 1];
569
- strcpy(demandNameChar, demandName.c_str());
570
-
571
- errcode = EN_setdemandname(ph, nodeIndex, demandIdx, demandNameChar);
572
-
573
- delete[] demandNameChar;
574
- return errcode;
575
- }
576
-
577
- int setdemandpattern(int nodeIndex, int demandIndex, int patIndex)
578
- {
579
- return EN_setdemandpattern(ph, nodeIndex, demandIndex, patIndex);
580
- }
581
- // Network Link Functions
582
- int addlink(std::string id, int linkType, std::string fromNode, std::string toNode, intptr_t index)
583
- {
584
- int errcode;
585
- int *ptr1 = reinterpret_cast<int *>(index);
586
-
587
- char *idChar = new char[id.length() + 1];
588
- char *fromNodeChar = new char[fromNode.length() + 1];
589
- char *toNodeChar = new char[toNode.length() + 1];
590
- strcpy(idChar, id.c_str());
591
- strcpy(fromNodeChar, fromNode.c_str());
592
- strcpy(toNodeChar, toNode.c_str());
593
-
594
- errcode = EN_addlink(ph, idChar, linkType, fromNodeChar, toNodeChar, ptr1);
595
-
596
- delete[] idChar;
597
- delete[] fromNodeChar;
598
- delete[] toNodeChar;
599
- return errcode;
600
- }
601
-
602
- int deletelink(int index, int actionCode)
603
- {
604
- return EN_deletelink(ph, index, actionCode);
605
- }
606
-
607
- int getlinkindex(std::string id, intptr_t index)
608
- {
609
- int errcode;
610
- int *ptr1 = reinterpret_cast<int *>(index);
611
- char *idChar = new char[id.length() + 1];
612
- strcpy(idChar, id.c_str());
613
-
614
- errcode = EN_getlinkindex(ph, idChar, ptr1);
615
-
616
- delete[] idChar;
617
- return errcode;
618
- }
619
-
620
- int getlinkid(int index, intptr_t out_id)
621
- {
622
- char *ptr1 = reinterpret_cast<char *>(out_id);
623
- return EN_getlinkid(ph, index, ptr1);
624
- }
625
-
626
- int setlinkid(int index, std::string newid)
627
- {
628
- int errcode;
629
- char *newidChar = new char[newid.length() + 1];
630
- strcpy(newidChar, newid.c_str());
631
-
632
- errcode = EN_setlinkid(ph, index, newidChar);
633
-
634
- delete[] newidChar;
635
- return errcode;
636
- }
637
-
638
- int getlinktype(int index, intptr_t linkType)
639
- {
640
- int *ptr1 = reinterpret_cast<int *>(linkType);
641
- return EN_getlinktype(ph, index, ptr1);
642
- }
643
-
644
- int setlinktype(intptr_t inout_index, int linkType, int actionCode)
645
- {
646
- int *ptr1 = reinterpret_cast<int *>(inout_index);
647
- return EN_setlinktype(ph, ptr1, linkType, actionCode);
648
- }
649
-
650
- int getlinknodes(int index, intptr_t node1, intptr_t node2)
651
- {
652
- int *ptr1 = reinterpret_cast<int *>(node1);
653
- int *ptr2 = reinterpret_cast<int *>(node2);
654
- return EN_getlinknodes(ph, index, ptr1, ptr2);
655
- }
656
-
657
- int setlinknodes(int index, int node1, int node2)
658
- {
659
- return EN_setlinknodes(ph, index, node1, node2);
660
- }
661
-
662
- int getlinkvalue(int index, int property, intptr_t value)
663
- {
664
- double *ptr1 = reinterpret_cast<double *>(value);
665
- return EN_getlinkvalue(ph, index, property, ptr1);
666
- }
667
-
668
- int setlinkvalue(int index, int property, double value)
669
- {
670
- return EN_setlinkvalue(ph, index, property, value);
671
- }
672
-
673
- int setpipedata(int index, double length, double diam, double rough, double mloss)
674
- {
675
- return EN_setpipedata(ph, index, length, diam, rough, mloss);
676
- }
677
-
678
- int getpumptype(int linkIndex, intptr_t pumpType)
679
- {
680
- int *ptr1 = reinterpret_cast<int *>(pumpType);
681
- return EN_getpumptype(ph, linkIndex, ptr1);
682
- }
683
-
684
- int getheadcurveindex(int linkIndex, intptr_t curveIndex)
685
- {
686
- int *ptr1 = reinterpret_cast<int *>(curveIndex);
687
- return EN_getheadcurveindex(ph, linkIndex, ptr1);
688
- }
689
-
690
- int setheadcurveindex(int linkIndex, int curveIndex)
691
- {
692
- return EN_setheadcurveindex(ph, linkIndex, curveIndex);
693
- }
694
-
695
- int getvertexcount(int index, intptr_t count)
696
- {
697
- int *ptr1 = reinterpret_cast<int *>(count);
698
- return EN_getvertexcount(ph, index, ptr1);
699
- }
700
-
701
- int getvertex(int index, int vertex, intptr_t x, intptr_t y)
702
- {
703
- double *ptr1 = reinterpret_cast<double *>(x);
704
- double *ptr2 = reinterpret_cast<double *>(y);
705
- return EN_getvertex(ph, index, vertex, ptr1, ptr2);
706
- }
707
-
708
- int setvertices(int index, intptr_t x, intptr_t y, int count)
709
- {
710
- double *ptr1 = reinterpret_cast<double *>(x);
711
- double *ptr2 = reinterpret_cast<double *>(y);
712
- return EN_setvertices(ph, index, ptr1, ptr2, count);
713
- }
714
- // Time Pattern Functions
715
- int addpattern(std::string id)
716
- {
717
- int errcode;
718
- char *idChar = new char[id.length() + 1];
719
- strcpy(idChar, id.c_str());
720
-
721
- errcode = EN_addpattern(ph, idChar);
722
-
723
- delete[] idChar;
724
- return errcode;
725
- }
726
-
727
- int deletepattern(int index)
728
- {
729
- return EN_deletepattern(ph, index);
730
- }
731
-
732
- int getpatternindex(std::string id, intptr_t index)
733
- {
734
- int errcode;
735
- int *ptr1 = reinterpret_cast<int *>(index);
736
-
737
- char *idChar = new char[id.length() + 1];
738
- strcpy(idChar, id.c_str());
739
-
740
- errcode = EN_getpatternindex(ph, idChar, ptr1);
741
-
742
- delete[] idChar;
743
- return errcode;
744
- }
745
-
746
- int getpatternid(int index, intptr_t out_id)
747
- {
748
- char *ptr1 = reinterpret_cast<char *>(out_id);
749
-
750
- return EN_getpatternid(ph, index, ptr1);
751
- }
752
-
753
- int setpatternid(int index, std::string id)
754
- {
755
- int errcode;
756
- char *idChar = new char[id.length() + 1];
757
- strcpy(idChar, id.c_str());
758
-
759
- errcode = EN_setpatternid(ph, index, idChar);
760
-
761
- delete[] idChar;
762
- return errcode;
763
- }
764
-
765
- int getpatternlen(int index, intptr_t len)
766
- {
767
- int *ptr1 = reinterpret_cast<int *>(len);
768
- return EN_getpatternlen(ph, index, ptr1);
769
- }
770
-
771
- int getpatternvalue(int index, int period, intptr_t value)
772
- {
773
- double *ptr1 = reinterpret_cast<double *>(value);
774
- return EN_getpatternvalue(ph, index, period, ptr1);
775
- }
776
-
777
- int setpatternvalue(int index, int period, double value)
778
- {
779
- return EN_setpatternvalue(ph, index, period, value);
780
- }
781
-
782
- int getaveragepatternvalue(int index, intptr_t value)
783
- {
784
- double *ptr1 = reinterpret_cast<double *>(value);
785
- return EN_getaveragepatternvalue(ph, index, ptr1);
786
- }
787
- int setpattern(int index, intptr_t values, int len)
788
- {
789
- double *ptr1 = reinterpret_cast<double *>(values);
790
- return EN_setpattern(ph, index, ptr1, len);
791
- }
792
-
793
- // Data Curve Functions
794
- int addcurve(std::string id)
795
- {
796
- int errcode;
797
- char *idChar = new char[id.length() + 1];
798
- strcpy(idChar, id.c_str());
799
-
800
- errcode = EN_addcurve(ph, idChar);
801
-
802
- delete[] idChar;
803
- return errcode;
804
- }
805
-
806
- int deletecurve(int index)
807
- {
808
- return EN_deletecurve(ph, index);
809
- }
810
-
811
- int getcurveindex(std::string id, intptr_t index)
812
- {
813
- int errcode;
814
- int *ptr1 = reinterpret_cast<int *>(index);
815
- char *idChar = new char[id.length() + 1];
816
- strcpy(idChar, id.c_str());
817
-
818
- errcode = EN_getcurveindex(ph, idChar, ptr1);
819
-
820
- delete[] idChar;
821
- return errcode;
822
- }
823
-
824
- int getcurveid(int index, intptr_t out_id)
825
- {
826
- char *ptr1 = reinterpret_cast<char *>(out_id);
827
- return EN_getcurveid(ph, index, ptr1);
828
- }
829
-
830
- int setcurveid(int index, std::string id)
831
- {
832
- int errcode;
833
- char *idChar = new char[id.length() + 1];
834
- strcpy(idChar, id.c_str());
835
-
836
- errcode = EN_setcurveid(ph, index, idChar);
837
-
838
- delete[] idChar;
839
- return errcode;
840
- }
841
-
842
- int getcurvelen(int index, intptr_t len)
843
- {
844
- int *ptr1 = reinterpret_cast<int *>(len);
845
- return EN_getcurvelen(ph, index, ptr1);
846
- }
847
-
848
- int getcurvetype(int index, intptr_t type)
849
- {
850
- int *ptr1 = reinterpret_cast<int *>(type);
851
- return EN_getcurvetype(ph, index, ptr1);
852
- }
853
- int getcurvevalue(int curveIndex, int pointIndex, intptr_t x, intptr_t y)
854
- {
855
- double *ptr1 = reinterpret_cast<double *>(x);
856
- double *ptr2 = reinterpret_cast<double *>(y);
857
- return EN_getcurvevalue(ph, curveIndex, pointIndex, ptr1, ptr2);
858
- }
859
-
860
- int setcurvevalue(int curveIndex, int pointIndex, double x, double y)
861
- {
862
- return EN_setcurvevalue(ph, curveIndex, pointIndex, x, y);
863
- }
864
-
865
- int setcurve(int index, intptr_t xValues, intptr_t yValues, int nPoints)
866
- {
867
- double *ptr1 = reinterpret_cast<double *>(xValues);
868
- double *ptr2 = reinterpret_cast<double *>(yValues);
869
- return EN_setcurve(ph, index, ptr1, ptr2, nPoints);
870
- }
871
-
872
- // Simple Control Functions
873
- int addcontrol(int type, int linkIndex, double setting, int nodeIndex, double level, intptr_t index)
874
- {
875
- int *ptr1 = reinterpret_cast<int *>(index);
876
- return EN_addcontrol(ph, type, linkIndex, setting, nodeIndex, level, ptr1);
877
- }
878
- int deletecontrol(int index)
879
- {
880
- return EN_deletecontrol(ph, index);
881
- }
882
- int getcontrol(int index, intptr_t type, intptr_t linkIndex, intptr_t setting, intptr_t nodeIndex, intptr_t level)
883
- {
884
- int *ptr1 = reinterpret_cast<int *>(type);
885
- int *ptr2 = reinterpret_cast<int *>(linkIndex);
886
- double *ptr3 = reinterpret_cast<double *>(setting);
887
- int *ptr4 = reinterpret_cast<int *>(nodeIndex);
888
- double *ptr5 = reinterpret_cast<double *>(level);
889
- return EN_getcontrol(ph, index, ptr1, ptr2, ptr3, ptr4, ptr5);
890
- }
891
- int setcontrol(int index, int type, int linkIndex, double setting, int nodeIndex, double level)
892
- {
893
- return EN_setcontrol(ph, index, type, linkIndex, setting, nodeIndex, level);
894
- }
895
- // Rule-Based Control Functions
896
- int addrule(std::string rule)
897
- {
898
- int errcode;
899
- char *ruleChar = new char[rule.length() + 1];
900
- strcpy(ruleChar, rule.c_str());
901
-
902
- errcode = EN_addrule(ph, ruleChar);
903
-
904
- delete[] ruleChar;
905
- return errcode;
906
- }
907
-
908
- int deleterule(int index)
909
- {
910
- return EN_deleterule(ph, index);
911
- }
912
-
913
- int getrule(int index, intptr_t nPremises, intptr_t nThenActions, intptr_t nElseActions, intptr_t priority)
914
- {
915
- int *ptr1 = reinterpret_cast<int *>(nPremises);
916
- int *ptr2 = reinterpret_cast<int *>(nThenActions);
917
- int *ptr3 = reinterpret_cast<int *>(nElseActions);
918
- double *ptr4 = reinterpret_cast<double *>(priority);
919
- return EN_getrule(ph, index, ptr1, ptr2, ptr3, ptr4);
920
- }
921
-
922
- int getruleID(int index, intptr_t out_id)
923
- {
924
- char *ptr1 = reinterpret_cast<char *>(out_id);
925
- return EN_getruleID(ph, index, ptr1);
926
- }
927
-
928
- int getpremise(int ruleIndex, int premiseIndex, intptr_t logop, intptr_t object, intptr_t objIndex, intptr_t variable, intptr_t relop, intptr_t status, intptr_t value)
929
- {
930
- int *ptr1 = reinterpret_cast<int *>(logop);
931
- int *ptr2 = reinterpret_cast<int *>(object);
932
- int *ptr3 = reinterpret_cast<int *>(objIndex);
933
- int *ptr4 = reinterpret_cast<int *>(variable);
934
- int *ptr5 = reinterpret_cast<int *>(relop);
935
- int *ptr6 = reinterpret_cast<int *>(status);
936
- double *ptr7 = reinterpret_cast<double *>(value);
937
- return EN_getpremise(ph, ruleIndex, premiseIndex, ptr1, ptr2, ptr3, ptr4, ptr5, ptr6, ptr7);
938
- }
939
-
940
- int setpremise(int ruleIndex, int premiseIndex, int logop, int object, int objIndex, int variable, int relop, int status, double value)
941
- {
942
- return EN_setpremise(ph, ruleIndex, premiseIndex, logop, object, objIndex, variable, relop, status, value);
943
- }
944
-
945
- int setpremiseindex(int ruleIndex, int premiseIndex, int objIndex)
946
- {
947
- return EN_setpremiseindex(ph, ruleIndex, premiseIndex, objIndex);
948
- }
949
-
950
- int setpremisestatus(int ruleIndex, int premiseIndex, int status)
951
- {
952
- return EN_setpremisestatus(ph, ruleIndex, premiseIndex, status);
953
- }
954
-
955
- int setpremisevalue(int ruleIndex, int premiseIndex, double value)
956
- {
957
- return EN_setpremisevalue(ph, ruleIndex, premiseIndex, value);
958
- }
959
-
960
- int getthenaction(int ruleIndex, int actionIndex, intptr_t linkIndex, intptr_t status, intptr_t setting)
961
- {
962
- int *ptr1 = reinterpret_cast<int *>(linkIndex);
963
- int *ptr2 = reinterpret_cast<int *>(status);
964
- double *ptr3 = reinterpret_cast<double *>(setting);
965
- return EN_getthenaction(ph, ruleIndex, actionIndex, ptr1, ptr2, ptr3);
966
- }
967
-
968
- int setthenaction(int ruleIndex, int actionIndex, int linkIndex, int status, double setting)
969
- {
970
- return EN_setthenaction(ph, ruleIndex, actionIndex, linkIndex, status, setting);
971
- }
972
-
973
- int getelseaction(int ruleIndex, int actionIndex, intptr_t linkIndex, intptr_t status, intptr_t setting)
974
- {
975
- int *ptr1 = reinterpret_cast<int *>(linkIndex);
976
- int *ptr2 = reinterpret_cast<int *>(status);
977
- double *ptr3 = reinterpret_cast<double *>(setting);
978
- return EN_getelseaction(ph, ruleIndex, actionIndex, ptr1, ptr2, ptr3);
979
- }
980
-
981
- int setelseaction(int ruleIndex, int actionIndex, int linkIndex, int status, double setting)
982
- {
983
- return EN_setelseaction(ph, ruleIndex, actionIndex, linkIndex, status, setting);
984
- }
985
- int setrulepriority(int index, double priority)
986
- {
987
- return EN_setrulepriority(ph, index, priority);
988
- }
989
- };
990
-
991
- EMSCRIPTEN_BINDINGS(my_module)
992
- {
993
- function("getversion", &getversion);
994
- function("geterror", &geterror);
995
-
996
- class_<Epanet>("Epanet")
997
- .constructor<>()
998
- .function("open", &Epanet::open)
999
- .function("close", &Epanet::close)
1000
- .function("runproject", &Epanet::runproject)
1001
- .function("init", &Epanet::init)
1002
- .function("getcount", &Epanet::getcount)
1003
- .function("gettitle", &Epanet::gettitle)
1004
- .function("settitle", &Epanet::settitle)
1005
- // Hydraulic Analysis Functions
1006
- .function("saveinpfile", &Epanet::saveinpfile)
1007
- .function("solveH", &Epanet::solveH)
1008
- .function("usehydfile", &Epanet::usehydfile)
1009
- .function("openH", &Epanet::openH)
1010
- .function("initH", &Epanet::initH)
1011
- .function("runH", &Epanet::runH)
1012
- .function("nextH", &Epanet::nextH)
1013
- .function("saveH", &Epanet::saveH)
1014
- .function("savehydfile", &Epanet::savehydfile)
1015
- .function("closeH", &Epanet::closeH)
1016
- //Water Quality Analysis Functions
1017
- .function("closeQ", &Epanet::closeQ)
1018
- .function("initQ", &Epanet::initQ)
1019
- .function("nextQ", &Epanet::nextQ)
1020
- .function("openQ", &Epanet::openQ)
1021
- .function("runQ", &Epanet::runQ)
1022
- .function("solveQ", &Epanet::solveQ)
1023
- .function("stepQ", &Epanet::stepQ)
1024
- // Reporting Functions
1025
- .function("clearreport", &Epanet::clearreport)
1026
- .function("copyreport", &Epanet::copyreport)
1027
- .function("getresultindex", &Epanet::getresultindex)
1028
- .function("getstatistic", &Epanet::getstatistic)
1029
- .function("report", &Epanet::report)
1030
- .function("resetreport", &Epanet::resetreport)
1031
- .function("setreport", &Epanet::setreport)
1032
- .function("setstatusreport", &Epanet::setstatusreport)
1033
- .function("writeline", &Epanet::writeline)
1034
- //Analysis Options Functions
1035
- .function("getflowunits", &Epanet::getflowunits)
1036
- .function("getoption", &Epanet::getoption)
1037
- .function("getqualinfo", &Epanet::getqualinfo)
1038
- .function("getqualtype", &Epanet::getqualtype)
1039
- .function("gettimeparam", &Epanet::gettimeparam)
1040
- .function("setflowunits", &Epanet::setflowunits)
1041
- .function("setoption", &Epanet::setoption)
1042
- .function("setqualtype", &Epanet::setqualtype)
1043
- .function("settimeparam", &Epanet::settimeparam)
1044
- // Network Node Functions
1045
- .function("addnode", &Epanet::addnode)
1046
- .function("deletenode", &Epanet::deletenode)
1047
- .function("getcoord", &Epanet::getcoord)
1048
- .function("getnodeid", &Epanet::getnodeid)
1049
- .function("getnodeindex", &Epanet::getnodeindex)
1050
- .function("getnodetype", &Epanet::getnodetype)
1051
- .function("getnodevalue", &Epanet::getnodevalue)
1052
- .function("setcoord", &Epanet::setcoord)
1053
- .function("setjuncdata", &Epanet::setjuncdata)
1054
- .function("setnodeid", &Epanet::setnodeid)
1055
- .function("setnodevalue", &Epanet::setnodevalue)
1056
- .function("settankdata", &Epanet::settankdata)
1057
- // Nodal Demand Functions
1058
- .function("adddemand", &Epanet::adddemand)
1059
- .function("deletedemand", &Epanet::deletedemand)
1060
- .function("getbasedemand", &Epanet::getbasedemand)
1061
- .function("getdemandindex", &Epanet::getdemandindex)
1062
- .function("getdemandmodel", &Epanet::getdemandmodel)
1063
- .function("getdemandname", &Epanet::getdemandname)
1064
- .function("getdemandpattern", &Epanet::getdemandpattern)
1065
- .function("getnumdemands", &Epanet::getnumdemands)
1066
- .function("setbasedemand", &Epanet::setbasedemand)
1067
- .function("setdemandmodel", &Epanet::setdemandmodel)
1068
- .function("setdemandname", &Epanet::setdemandname)
1069
- .function("setdemandpattern", &Epanet::setdemandpattern)
1070
- // Network Link Functions
1071
- .function("addlink", &Epanet::addlink)
1072
- .function("deletelink", &Epanet::deletelink)
1073
- .function("getheadcurveindex", &Epanet::getheadcurveindex)
1074
- .function("getlinkid", &Epanet::getlinkid)
1075
- .function("getlinkindex", &Epanet::getlinkindex)
1076
- .function("getlinknodes", &Epanet::getlinknodes)
1077
- .function("getlinktype", &Epanet::getlinktype)
1078
- .function("getlinkvalue", &Epanet::getlinkvalue)
1079
- .function("getpumptype", &Epanet::getpumptype)
1080
- .function("getvertex", &Epanet::getvertex)
1081
- .function("getvertexcount", &Epanet::getvertexcount)
1082
- .function("setheadcurveindex", &Epanet::setheadcurveindex)
1083
- .function("setlinkid", &Epanet::setlinkid)
1084
- .function("setlinknodes", &Epanet::setlinknodes)
1085
- .function("setlinktype", &Epanet::setlinktype)
1086
- .function("setlinkvalue", &Epanet::setlinkvalue)
1087
- .function("setpipedata", &Epanet::setpipedata)
1088
- .function("setvertices", &Epanet::setvertices)
1089
- // Time Pattern Functions
1090
- .function("addpattern", &Epanet::addpattern)
1091
- .function("deletepattern", &Epanet::deletepattern)
1092
- .function("getaveragepatternvalue", &Epanet::getaveragepatternvalue)
1093
- .function("getpatternid", &Epanet::getpatternid)
1094
- .function("getpatternindex", &Epanet::getpatternindex)
1095
- .function("getpatternlen", &Epanet::getpatternlen)
1096
- .function("getpatternvalue", &Epanet::getpatternvalue)
1097
- .function("setpattern", &Epanet::setpattern)
1098
- .function("setpatternid", &Epanet::setpatternid)
1099
- .function("setpatternvalue", &Epanet::setpatternvalue)
1100
- // Data Curve Functions
1101
- .function("addcurve", &Epanet::addcurve)
1102
- .function("deletecurve", &Epanet::deletecurve)
1103
- .function("getcurveid", &Epanet::getcurveid)
1104
- .function("getcurveindex", &Epanet::getcurveindex)
1105
- .function("getcurvelen", &Epanet::getcurvelen)
1106
- .function("getcurvetype", &Epanet::getcurvetype)
1107
- .function("getcurvevalue", &Epanet::getcurvevalue)
1108
- .function("setcurve", &Epanet::setcurve)
1109
- .function("setcurveid", &Epanet::setcurveid)
1110
- .function("setcurvevalue", &Epanet::setcurvevalue)
1111
- // Simple Control Functions
1112
- .function("addcontrol", &Epanet::addcontrol)
1113
- .function("deletecontrol", &Epanet::deletecontrol)
1114
- .function("getcontrol", &Epanet::getcontrol)
1115
- .function("setcontrol", &Epanet::setcontrol)
1116
- // Rule-Based Control Functions
1117
- .function("addrule", &Epanet::addrule)
1118
- .function("deleterule", &Epanet::deleterule)
1119
- .function("getelseaction", &Epanet::getelseaction)
1120
- .function("getpremise", &Epanet::getpremise)
1121
- .function("getrule", &Epanet::getrule)
1122
- .function("getruleID", &Epanet::getruleID)
1123
- .function("getthenaction", &Epanet::getthenaction)
1124
- .function("setelseaction", &Epanet::setelseaction)
1125
- .function("setpremise", &Epanet::setpremise)
1126
- .function("setpremiseindex", &Epanet::setpremiseindex)
1127
- .function("setpremisestatus", &Epanet::setpremisestatus)
1128
- .function("setpremisevalue", &Epanet::setpremisevalue)
1129
- .function("setrulepriority", &Epanet::setrulepriority)
1130
- .function("setthenaction", &Epanet::setthenaction);
1131
- }