forked from OpenWaterAnalytics/EPANET-Matlab-Toolkit
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathepanet.m
11494 lines (11403 loc) · 486 KB
/
epanet.m
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
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
classdef epanet <handle
%EPANET-Matlab Toolkit v2.1: A Matlab Class for EPANET and EPANET-MSX
%libraries
%
%
% How to run:
% d=epanet('Net1.inp');
%
% To select a different DLL version:
% d=epanet('Net1.inp','epanet2');
%
% EPANET is software that models water distribution piping systems
% developed by the US EPA and provided under a public domain licence.
% This Matlab Class serves as an interface between Matlab and
% EPANET/EPANET-MSX, to assist researchers and the industry when
% solving problems related with water distribution systems.
%
% EPANET and EPANET-MSX were developed by the Water Supply and Water
% Resources Division of the U.S. Environmental Protection Agency's
% National Risk Management Research Laboratory. EPANET is under the
% Public Domain and EPANET-MSX under GNU LGPL.
%
% The latest EPANET files can downloaded at:
% https://github.com/OpenWaterAnalytics/epanet
%
% Inspired by:
% EPANET-Matlab Wrappers (Jim Uber)
% EPANET-Matlab Toolkit (Demetrios Eliades)
% getwdsdata (Philip Jonkergouw)
%
% EPANET-Matlab Class Licence:
%
% Copyright 2016 KIOS Research Center for Intelligent Systems and
% Networks, University of Cyprus (www.kios.org.cy)
%
% Licensed under the EUPL, Version 1.1 or - as soon they will be
% approved by the European Commission - subsequent libepanets of the
% EUPL (the "Licence"); You may not use this work except in
% compliance with the Licence. You may obtain a copy of the Licence
% at:
%
% http://ec.europa.eu/idabc/eupl
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the Licence is distributed on an "AS IS" basis,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
% implied. See the Licence for the specific language governing
% permissions and limitations under the Licence.
properties
ControlLevelValues; % The control level values
ControlLinkIndex; % Set of control links index
ControlNodeIndex; % Set of control nodes index
ControlRules; % Retrieves the parameters of all control statements
ControlRulesCount; % Number of controls
Controls; % Controls info
ControlSettings; % Settings for the controls
ControlTypes; % Set of control types
ControlTypesIndex; % Index of the control types
CurveCount; % Number of curves
CurvesInfo; % Curves info
EnergyEfficiencyUnits; % Units for efficiency
EnergyUnits; % Units for energy
Errcode; % Code for the EPANET error message
InputFile; % Name of the input file
Iterations; % Iterations to reach solution
LibEPANET; % EPANET library dll
LibEPANETpath; % EPANET library dll path
libFunctions; % EPANET functions in dll
LinkBulkReactionCoeff; % Bulk reaction coefficient of each link
LinkCount; % Number of links
LinkDiameter; % Diameter of each link
LinkFlowUnits; % Units of flow
LinkFrictionFactorUnits; % Units for friction factor
LinkIndex; % Index of links
LinkInitialSetting; % Initial settings of links
LinkInitialStatus; % Initial status of links
LinkLength; % Length of links
LinkLengthsUnits; % Units of length
LinkLengthUnits; % Units of length
LinkMinorLossCoeff; % Minor loss coefficient of links
LinkMinorLossCoeffUnits; % Minor loss coefficient units
LinkNameID; % Name ID of links
LinkPipeCount; % Number of pipes
LinkPipeDiameterUnits; % Units for pipe diameters
LinkPipeIndex; % Index of pipe links
LinkPipeNameID; % Name ID of pipe links
LinkPipeRoughnessCoeffUnits; % Pipe roughness coefficient units
LinkPumpCount; % Number of pumps
LinkPumpHeadCurveIndex; % Head curve indices
LinkPumpIndex; % Index of pumps
LinkPumpNameID; % Name ID of pumps
LinkPumpPatternIndex; % Index of pump pattern
LinkPumpPatternNameID; % ID of pump pattern
LinkPumpPowerUnits; % Units of power
LinkPumpType; % Pump type e.g constant horsepower, power function, user-defined custom curv
LinkPumpTypeCode; % Pump index/code
LinkRoughnessCoeff; % Roughness coefficient of links
LinkType; % ID of link type
LinkTypeIndex; % Index of link type
LinkValveCount; % Number of valves
LinkValveIndex; % Index of valves
LinkValveNameID; % ID name of valves
LinkVelocityUnits; % Units for velocity
LinkWallReactionCoeff; % Wall reaction coefficient of links
NodeBaseDemands; % Base demands of nodes
NodeCoordinates; % Coordinates for each node (long/lat & intermediate pipe coordinates)
NodeCount; % Number of nodes
NodeDemandPatternIndex; % Index of demand patterns
NodeDemandPatternNameID; % ID of demand patterns
NodeDemandUnits; % Units for demand
NodeElevations; % Elevation of nodes
NodeElevationUnits; % Units for elevation
NodeEmitterCoeff; % Emmitter Coefficient of nodes
NodeEmitterCoefficientUnits; % Units for emitter coefficient
NodeHeadUnits; % Nodal head units
NodeIndex; % Index of nodes
NodeInitialQuality; % Initial quality of nodes
NodeJunctionCount; % Number of junctions
NodeJunctionIndex; % Index of node junctions
NodeJunctionNameID; % Name ID of node junctions
NodeNameID; % Name ID of all nodes
NodeDemandCategoriesNumber; % Number of demand categories for nodes
NodePatternIndex; % Node demand pattern indices
NodePressureUnits; % Units for Pressure
NodeReservoirCount; % Number of reservoirs
NodeReservoirIndex; % Index of reservoirs
NodeReservoirNameID; % Name ID of reservoirs
NodesConnectingLinksID; % Name IDs of nodes which connect links
NodesConnectingLinksIndex; % Indices of nodes which connect links
NodeSourcePatternIndex; % Index of pattern for node sources
NodeSourceQuality; % Quality of node sources
NodeSourceTypeIndex; % Index of source type
NodeTankBulkReactionCoeff; % Bulk reaction coefficients in tanks
NodeTankCount; % Number of tanks
NodeTankDiameter; % Diameters of tanks
NodeTankDiameterUnits; % Units for tank diameters
NodeTankIndex; % Indices of Tanks
NodeTankInitialLevel; % Initial water level in tanks
NodeTankInitialWaterVolume; % Initial water volume in tanks
NodeTankMaximumWaterLevel; % Maximum water level in tanks
NodeTankMaximumWaterVolume; % Maximum water volume
NodeTankMinimumFraction; % Fraction of the total tank volume devoted to the inlet/outlet compartment
NodeTankMinimumWaterLevel; % Minimum water level
NodeTankMinimumWaterVolume; % Minimum water volume
NodeTankMixingModelCode; % Code of mixing model (MIXED:0, 2COMP:1, FIFO:2, LIFO:3)
NodeTankMixingModelType; % Type of mixing model (MIXED, 2COMP, FIFO, or LIFO)
NodeTankMixZoneVolume; % Mixing zone volume
NodeTankNameID; % Name ID of Tanks
NodeTankReservoirCount; % Number of tanks and reservoirs
NodeTankVolumeCurveIndex; % Index of curve for tank volumes
NodeTankVolumeUnits; % Units for volume
NodeType; % ID of node type
NodeTypeIndex; % Index of nodetype
OptionsAccuracyValue; % Convergence value (0.001 is default)
OptionsEmitterExponent; % Exponent of pressure at an emmiter node (0.5 is default)
OptionsHeadloss; % Headloss formula (Hazen-Williams, Darcy-Weisbach or Chezy-Manning)*** Not implemented *** BinOptionsHeadloss
OptionsHydraulics; % Save or Use hydraulic soltion. *** Not implemented ***
OptionsMaxTrials; % Maximum number of trials (40 is default)
OptionsPattern; % *** Not implemented *** % but get with BinOptionsPattern
OptionsPatternDemandMultiplier; % Multiply demand values (1 is default)
OptionsQualityTolerance; % Tolerance for water quality (0.01 is default)
OptionsSpecificGravity; % *** Not implemented *** % but get with BinOptionsSpecificGravity
OptionsUnbalanced; % *** Not implemented *** % but get with BinOptionsUnbalanced
OptionsViscosity; % *** Not implemented *** % but get with BinOptionsViscosity
Pattern; % Get all patterns - matrix
PatternAverageValue; % Average value of patterns
PatternCount; % Number of patterns
PatternDemandsUnits; % Units for demands
PatternIndex; % Indices of the patterns
PatternLengths; % Length of the patterns
PatternNameID; % ID of the patterns
QualityChemName; % Quality Chem Name
QualityChemUnits; % Quality Chem Units
QualityCode; % Water quality analysis code (None:0/Chemical:1/Age:2/Trace:3)
QualityReactionCoeffBulkUnits; % Bulk reaction coefficient units
QualityReactionCoeffWallUnits; % Wall reaction coefficient units
QualitySourceMassInjectionUnits; % Units for source mass injection
QualityTraceNodeIndex; % Index of trace node (0 if QualityCode<3)
QualityType; % Water quality analysis type (None/Chemical/Age/Trace)
QualityUnits; % Units for quality concentration.
QualityWaterAgeUnits; % Units for water age
RelativeError; % Relative error - hydraulic simulation statistic
% RulePremises;
% RuleTrueActions;
% RuleFalseActions;
% RulePriority;
TempInpFile; % Name of the temporary input file
TimeHaltFlag; % Number of halt flag
TimeHTime; % Number of htime
TimeHydraulicStep; % Hydraulic time step
TimeNextEvent; % Find the lesser of the hydraulic time step length, or the time to next fill/empty
TimePatternStart; % Pattern start time
TimePatternStep; % Pattern Step
TimeQualityStep; % Quality Step
TimeReportingPeriods; % Reporting periods
TimeReportingStart; % Start time for reporting
TimeReportingStep; % Reporting time step
TimeRuleControlStep; % Time step for evaluating rule-based controls
TimeSimulationDuration; % Simulation duration
TimeStartTime; % Number of start time
TimeStatisticsIndex; % Index of time series post-processing type ('NONE':0,'AVERAGE':1,'MINIMUM':2,'MAXIMUM':3, 'RANGE':4)
TimeStatisticsType; % Type of time series post-processing ('NONE','AVERAGE','MINIMUM','MAXIMUM', 'RANGE')
ToolkitConstants; % Contains all parameters from epanet2.h
Units_SI_Metric; % Equal with 1 if is SI-Metric
Units_US_Customary; % Equal with 1 if is US-Customary
Version; % EPANET version
% Parameters used with EPANET MSX
MSXLibEPANET; % MSX EPANET library dll
MSXLibEPANETPath; % MSX EPANET library path
MSXConstantsNameID; % ID name of constants
MSXConstantsValue; % Value of constants
MSXConstantsCount; % Number of constants
MSXConstantsIndex; % Index of constants
MSXParametersCount; % Number of parameters
MSXPatternsCount; % Number of msx patterns
MSXSpeciesCount; % Number of species
MSXLinkInitqualValue; % Initial concentration of chemical species assigned to links of the pipe network
MSXNodeInitqualValue; % Initial concentration of chemical species assigned to nodes
MSXFile; % Name of the msx file
MSXTempFile; % Name of the temp msx file
MSXParametersNameID; % ID name of parameters
MSXParametersIndex; % Index name of parameters
MSXParametersPipesValue; % Value of reaction parameters for pipes
MSXParametersTanksValue; % Value of reaction parameters for tanks
MSXPatternsNameID; % ID name of msx patterns
MSXPatternsIndex; % Index of msx patterns
MSXPatternsLengths; % Number of time periods in all patterns
MSXPattern; % Get all msx patterns
MSXEquationsPipes; % Species dynamics in pipes
MSXSources; % Sources info
MSXSourceLevel; % Value of all nodes source level
MSXSourceNodeNameID; % ID label of all nodes
MSXSourcePatternIndex; % Value of all node source pattern index
MSXSourceType; % Value of all node source type 'CONCEN','MASS', 'SETPOINT', 'FLOWPACED'
MSXSourceTypeCode; % Code of source type
MSXSpeciesATOL; % Absolute tolerance used to determine when two concentration levels of a species are the same
MSXSpeciesIndex; % Index name of species
MSXSpeciesNameID; % ID name of species
MSXSpeciesRTOL; % Relative accuracy level on a species concentration used to adjust time steps in the RK5 and ROS2 integration methods
MSXSpeciesType; % Type of all species, bulk or wall
MSXSpeciesUnits; % Species mass units
MSXEquationsTanks; % Species dynamics in tanks
MSXEquationsTerms; % Species dynamics in terms
% Parameters used when the Binary mode is used
Bin; % Check if use Bin functions (use saveInputFile if is 1)
BinControlLinksID; % Set of control links ID
BinControlNodesID; % Set of control nodes ID
BinControlRulesCount; % Number of controls
BinControlsInfo; % Controls info
BinCountInitialQualitylines; % Count lines used by quality section
BinCountPatternlines; % Count lines used by pattern section
BinCountReactionlines; % Count lines used by reaction section
BinCountStatuslines; % Count lines used by status section
BinCurveAllLines; % Curves info from section
BinCurveCount; % Number of curves
BinCurveNameID; % ID name of curves
BinCurveTypes; % Type of curves
BinCurveXvalue; % X-value of curves
BinCurveYvalue; % Y-value of curves
BinLinkBulkReactionCoeff; % Bulk reaction coefficient of each link
BinLinkCount; % Number of links
BinLinkDiameters; % Diameter of each link
BinLinkFlowUnits; % Units of flow
BinLinkFromNode; % IDs of node at start of link
BinLinkGlobalBulkReactionCoeff;% Global Bulk Reaction Coeff
BinLinkGlobalWallReactionCoeff;% Global Wall Reaction Coeff
BinLinkInitialStatus; % Initial status of links
BinLinkInitialStatusNameID; % Name ID of links where is status refers in BinLinkInitialStatus
BinLinkLengths; % Length of links
BinLinkNameID; % Name ID of links
BinLinkPipeCount; % Number of pipes
BinLinkPipeDiameters; % Diameter of each pipe
BinLinkPipeIndex; % Index of pipe links
BinLinkPipeLengths; % Length of pipes
BinLinkPipeMinorLoss; % Minor loss coefficient of pipes
BinLinkPipeNameID; % Name ID of pipes
BinLinkPipeRoughness; % Roughness coefficient of pipes
BinLinkPipeStatus; % Initial status of pipes
BinLinkPumpCount; % Number of pumps
BinLinkPumpCurveNameID; % Curve Name ID used from pumps
BinLinkPumpIndex; % Index of pumps
BinLinkPumpNameID; % Name ID of pumps
BinLinkPumpNameIDPower; % Name ID of pumps with Power
BinLinkPumpPatterns; % Patterns used from pumps
BinLinkPumpPower; % Power of pumps
BinLinkPumpStatus; % Initial status of pumps
BinLinkPumpStatusNameID; % Name ID of pumps where is status refers in BinLinkPumpStatus
BinLinkRoughnessCoeff; % Roughness coefficient of links
BinLinkSettings; % Initial settings of links
BinLinkToNode; % IDs of node at start of link
BinLinkType; % ID of link type
BinLinkValveCount; % Number of valves
BinLinkValveDiameters; % Diameter of each valve
BinLinkValveIndex; % Index of valve links
BinLinkValveMinorLoss; % Minor loss coefficient of valves
BinLinkValveNameID; % Name ID of valves
BinLinkValveSetting; % Initial settings of valves
BinLinkValveStatus; % Initial status of valves
BinLinkValveStatusNameID; % Name ID of valves where is status refers in BinLinkValveStatus
BinLinkValveType; % Valve type, 'PRV', 'PSV', 'PBV', 'FCV', 'TCV', 'GPV'
BinLinkWallReactionCoeff; % Wall reaction coefficient of links
BinNodeBaseDemands; % Base demands of nodes
BinNodeCoordinates; % Coordinates for each node (long/lat & intermediate pipe coordinates) - vertices
BinNodeCount; % Number of nodes
BinNodeJunDemandPatternNameID;% ID of demand patterns
BinNodeElevations; % Elevation of nodes
BinNodeInitialQuality; % Initial quality of nodes
BinNodeJunctionCount; % Number of junctions
BinNodeJunctionElevation; % Elevation of junctions
BinNodeJunctionIndex; % Index of junctions
BinNodeJunctionNameID; % Name ID of junctions
BinNodeJunctionsBaseDemands; % Base demands of junctions
BinNodeJunctionsBaseDemandsID;% Name ID of junctions where is basedemand refers in BinNodeJunctionsBaseDemands
BinNodeNameID; % Name ID of nodes
BinNodePressureUnits; % Units for Pressure
BinNodeResDemandPatternNameID;% ID of demand patterns for reservoirs
BinNodeReservoirCount; % Number of reservoirs
BinNodeReservoirElevation; % Elevation of reservoirs
BinNodeReservoirIndex; % Index of reservoirs
BinNodeReservoirNameID; % Name ID of reservoirs
BinNodeSourcePatternIndex; % Index of pattern for node sources
BinNodeSourcePatternNameID; % ID of pattern for node sources
BinNodeSourceQuality; % Quality of node sources
BinNodeSourceType; % Source Types
BinNodeSourceTypeIndex; % Index of source type
BinNodeTankCount; % Number of tanks
BinNodeTankDiameter; % Diameters of tanks
BinNodeTankElevation; % Elevations of tanks
BinNodeTankIndex; % Index of tanks
BinNodeTankInitialLevel; % Initial water level in tanks
BinNodeTankMaximumWaterLevel;% Maximum water level in tanks
BinNodeTankMinimumFraction; % Fraction of the total tank volume devoted to the inlet/outlet compartment
BinNodeTankMinimumWaterLevel;% Minimum water level
BinNodeTankMinimumWaterVolume;% Minimum water volume
BinNodeTankMixID; % Name ID of tanks mix
BinNodeTankMixModel; % Mix Model Type
BinNodeTankNameID; % Name ID of tanks
BinNodeTankReservoirCount; % Number of reservoirs
BinNodeType; % ID of node type
BinOptionsAccuracyValue; % Convergence value (0.001 is default)
BinOptionsDiffusivity; % Diffusivity value (1 is default)
BinOptionsEmitterExponent; % Exponent of pressure at an emmiter node (0.5 is default)
BinOptionsHeadloss; % Headloss formula (Hazen-Williams, Darcy-Weisbach or Chezy-Manning)
BinOptionsMaxTrials; % Maximum number of trials (40 is default)
BinOptionsPattern; % Pattern to be applied to all junctions where no demand pattern was specified
BinOptionsPatternDemandMultiplier;% Multiply demand values (1 is default)
BinOptionsQualityTolerance; % Tolerance for water quality (0.01 is default)
BinOptionsSpecificGravity; % Ratio of the density of the fluid being modeled to that of water at 4 deg. C (unitless)
BinOptionsUnbalanced; % Determines what happens if a hydraulic solution cannot be reached (STOP is default) STOP/CONTINUE
BinOptionsViscosity; % Kinematic viscosity of the fluid being modeled relative to that of water at 20 deg. C (1.0 centistoke)(1 is default)
BinPatternCount; % Number of patterns
BinPatternLengths; % Length of the patterns
BinPatternMatrix; % Get all patterns - matrix
BinPatternNameID; % ID of the patterns
BinPatternValue; % Patterns values for all
BinQualityCode; % Water quality analysis code (None:0/Chemical:1/Age:2/Trace:3)
BinQualityTraceNodeID; % ID of trace node (0 if QualityCode<3)
BinQualityTraceNodeIndex; % Index of trace node (0 if QualityCode<3)
BinQualityType; % Water quality analysis type (None:0/Chemical:1/Age:2/Trace:3)
BinQualityUnits; % Units for quality concentration.
BinRulesControlLinksID; % Set of rule links ID
BinRulesControlNodesID; % Set of rule nodes ID
BinRulesControlsInfo; % Rules info from section
BinRulesCount; % Number of rules
BinUnits_SI_Metric; % Equal with 1 if is SI-Metric
BinTempfile; % Name of the temp input file
BinTimeHydraulicStep; % Hydraulic time step
BinTimePatternStart; % Pattern start time
BinTimePatternStep; % Pattern Step
BinTimeQualityStep; % Quality Step
BinTimeReportingStart; % Start time for reporting
BinTimeReportingStep; % Reporting time step
BinTimeSimulationDuration; % Simulation duration
BinTimeStatistics; % Type of time series post-processing ('NONE','AVERAGE','MINIMUM','MAXIMUM', 'RANGE')
BinTimeStatisticsIndex; % Index of time series post-processing type ('NONE':0,'AVERAGE':1,'MINIMUM':2,'MAXIMUM':3, 'RANGE':4)
BinUnits; % Units of all parameters
BinUnits_US_Customary; % Equal with 1 if is US-Customary
CMDCODE; % Code=1 Hide, Code=0 Show (messages at command window)
end
properties (Constant = true)
classversion='2.1.7'; % comment function for net-builder branch
TYPECONTROL={'LOWLEVEL','HIGHLEVEL', 'TIMER', 'TIMEOFDAY'}; % Constants for control: 'LOWLEVEL','HILEVEL', 'TIMER', 'TIMEOFDAY'
TYPECURVE={'VOLUME','PUMP','EFFICIENCY','HEADLOSS','GENERAL'}; % Constants for pump curves: 'PUMP','EFFICIENCY','VOLUME','HEADLOSS' % EPANET Version 2.2
TYPELINK={'CVPIPE', 'PIPE', 'PUMP', 'PRV', 'PSV', 'PBV', 'FCV', 'TCV', 'GPV'}; % Constants for links: 'CVPIPE', 'PIPE', 'PUMP', 'PRV', 'PSV', 'PBV', 'FCV', 'TCV', 'GPV', 'VALVE'
TYPEMIXMODEL={'MIX1','MIX2', 'FIFO','LIFO'}; % Constants for mixing models: 'MIX1','MIX2', 'FIFO','LIFO'
TYPENODE={'JUNCTION','RESERVOIR', 'TANK'}; % Contants for nodes: 'JUNCTION','RESERVOIR', 'TANK'
TYPEPUMP={'CONSTANT_HORSEPOWER', 'POWER_FUNCTION', 'CUSTOM'}; % Constants for pumps: 'CONSTANT_HORSEPOWER', 'POWER_FUNCTION', 'CUSTOM'
TYPEQUALITY={'NONE', 'CHEM', 'AGE', 'TRACE', 'MULTIS'}; % Constants for quality: 'NONE', 'CHEM', 'AGE', 'TRACE', 'MULTIS'
TYPEREPORT={'YES','NO','FULL'}; % Constants for report: 'YES','NO','FULL'
TYPESOURCE={'CONCEN','MASS', 'SETPOINT', 'FLOWPACED'}; % Constants for sources: 'CONCEN','MASS', 'SETPOINT', 'FLOWPACED'
TYPESTATS={'NONE','AVERAGE','MINIMUM','MAXIMUM', 'RANGE'}; % Constants for statistics: 'NONE','AVERAGE','MINIMUM','MAXIMUM', 'RANGE'
TYPEUNITS={'CFS', 'GPM', 'MGD', 'IMGD', 'AFD', 'LPS', 'LPM', 'MLD', 'CMH', 'CMD'}; % Constants for units: 'CFS', 'GPM', 'MGD', 'IMGD', 'AFD', 'LPS', 'LPM', 'MLD', 'CMH', 'CMD'
TYPESTATUS = {'CLOSED','OPEN'}; % Link status
MSXTYPEAREAUNITS={'FT2','M2','CM2'}; % sets the units used to express pipe wall surface area
MSXTYPERATEUNITS={'SEC','MIN','HR','DAY'}; % is the units in which all reaction rate terms are expressed
MSXTYPESOLVER={'EUL','RK5','ROS2'}; % is the choice of numerical integration method used to solve the reaction system
MSXTYPECOUPLING={'FULL','NONE'}; % is the choice of numerical integration method used to solve the reaction system
MSXTYPECOMPILER={'NONE','VC','GC'}; % is the choice of numerical integration method used to solve the reaction system
MSXTYPESOURCE={'NOSOURCE','CONCEN', 'MASS', 'SETPOINT','FLOWPACED'}; % Constants for sources: 'NO SOURCE''CONCEN','MASS', 'SETPOINT', 'FLOWPACED'
MSXTYPENODE=0; % for a node
MSXTYPELINK=1; % for a link
end
methods
function obj = epanet(varargin)
%Constructor of the EPANET Class
try unloadlibrary('epanet2');catch; end
try unloadlibrary('epanetmsx');catch; end
% DLLs
arch = computer('arch');
pwdepanet = fileparts(which(mfilename));
if strcmpi(arch,'win64')% if no DLL is given, select one automatically
obj.LibEPANETpath = [pwdepanet,'/64bit/'];
elseif strcmpi(arch,'win32')
obj.LibEPANETpath = [pwdepanet,'/32bit/'];
end
if isunix
obj.LibEPANETpath = [pwdepanet,'/glnx/'];
obj.LibEPANET = 'libepanet';
end
% if ismac
% obj.LibEPANETpath = [pwdepanet,'/mac/'];
% obj.LibEPANET = 'libepanet';
% end
if ~isdeployed
obj.InputFile=which(varargin{1}); % Get name of INP file
else
obj.InputFile=varargin{1};
end
% Bin functions
if nargin>1
if strcmpi(varargin{2},'BIN')
obj.LibEPANET = '';
obj.BinTempfile=[obj.InputFile(1:end-4),'_temp.inp'];
copyfile(obj.InputFile,obj.BinTempfile);
obj.InputFile=obj.BinTempfile;
obj.Bin=0;
if nargin==3, if strcmpi(varargin{3},'LOADFILE'); return; end; end
obj = BinUpdateClass(obj);
obj.saveBinInpFile;
return;
end
end
obj.Bin=1;
[~,inp]=fileparts(obj.InputFile);
if isempty(inp)
error(['File "', varargin{1}, '" is not a valid.']);
end
if nargin==2 && ~strcmpi(varargin{2},'loadfile')% e.g. d = epanet('Net1.inp', 'epanet2');
[pwdDLL,obj.LibEPANET] = fileparts(varargin{2}); % Get DLL LibEPANET (e.g. epanet20012x86 for 32-bit)
if isempty(pwdDLL)
pwdDLL = pwd;
end
obj.LibEPANETpath = [pwdDLL,'\'];
try ENLoadLibrary(obj.LibEPANETpath,obj.LibEPANET,0);
catch
obj.Errcode=-1;
error(['File "', obj.LibEPANET, '" is not a valid win application.']);
end
elseif ~isunix
obj.LibEPANET = 'epanet2';
end
if ~isdeployed
if ~exist(obj.InputFile,'file')
error(['File "', varargin{1}, '" does not exist in folder. (e.g. addpath(genpath(pwd));)']);
end
end
%Load EPANET Library
ENLoadLibrary(obj.LibEPANETpath,obj.LibEPANET);
%Load parameters
obj.ToolkitConstants = obj.getToolkitConstants;
%Open the file
obj.Errcode=ENopen(obj.InputFile,[obj.InputFile(1:end-4),'.txt'],'',obj.LibEPANET);
if obj.Errcode
error('Could not open the file, please check INP file.');
end
%Save the temporary input file
obj.BinTempfile=[obj.InputFile(1:end-4),'_temp.inp'];
obj.saveInputFile(obj.BinTempfile); %create a new INP file (Working Copy) using the SAVE command of EPANET
obj.closeNetwork; %ENclose; %Close input file
%Load temporary file
obj.Errcode=ENopen(obj.BinTempfile,[obj.InputFile(1:end-4),'_temp.txt'], [obj.InputFile(1:end-4),'_temp.bin'],obj.LibEPANET);
if obj.Errcode
error('Could not open the file, please check INP file.');
else
disp(['Input File "', varargin{1}, '" loaded sucessfuly.'])
end
% Hide messages at command window from bin computed
obj.CMDCODE=1;
obj.TempInpFile = obj.BinTempfile;
% Load file only, return
if nargin==2
if strcmpi(varargin{2},'LOADFILE')
obj.libFunctions = libfunctions(obj.LibEPANET);
return;
end
end
% Get some link data
lnkInfo = obj.getLinksInfo;
getFields_link_info = fields(lnkInfo);
for i=1:length(getFields_link_info)
obj.(getFields_link_info{i}) = eval(['lnkInfo.',getFields_link_info{i}]);
end
% Get some node data
ndInfo = obj.getNodesInfo;
getFields_node_info = fields(ndInfo);
for i=1:length(getFields_node_info)
obj.(getFields_node_info{i}) = eval(['ndInfo.',getFields_node_info{i}]);
end
%Get all the countable network parameters
obj.NodeCount = obj.getNodeCount;
obj.NodeTankReservoirCount = obj.getNodeTankReservoirCount;
obj.LinkCount = obj.getLinkCount;
obj.PatternCount = obj.getPatternCount;
obj.CurveCount = obj.getCurveCount;
obj.ControlRulesCount = obj.getControlRulesCount;
obj.NodeJunctionCount = obj.NodeCount-obj.NodeTankReservoirCount; %obj.getNodeJunctionCount;
% Get type of the parameters
obj.LinkType=obj.TYPELINK(obj.LinkTypeIndex+1);
obj.NodeType=obj.TYPENODE(obj.NodeTypeIndex+1);
%Get all the countable network parameters
obj.LinkPipeCount = sum(strcmp(obj.LinkType,'PIPE')+strcmp(obj.LinkType,'CVPIPE')); %obj.getLinkPipeCount;
obj.LinkPumpCount = sum(strcmp(obj.LinkType,'PUMP')); %obj.getLinkPumpCount;
obj.NodeReservoirCount = sum(strcmp(obj.NodeType,'RESERVOIR')); %obj.getNodeReservoirCount;
obj.NodeTankCount = obj.NodeCount-obj.NodeJunctionCount-obj.NodeReservoirCount; %obj.getNodeTankCount;
obj.LinkValveCount = obj.LinkCount-obj.LinkPipeCount-obj.LinkPumpCount;%obj.getLinkValveCount;
%Get all the controls
obj.Controls = obj.getControls;
%Get the flow units
obj.LinkFlowUnits = obj.getFlowUnits;
%Get all the link data
obj.LinkNameID = obj.getLinkNameID;
obj.LinkIndex = 1:obj.LinkCount; %obj.getLinkIndex;
obj.LinkPipeIndex = 1:obj.LinkPipeCount; %find(strcmp(obj.LinkType,'PIPE'));
obj.LinkPumpIndex = obj.LinkPipeCount+1:obj.LinkPipeCount+obj.LinkPumpCount; %find(strcmp(obj.LinkType,'PUMP'));
obj.LinkValveIndex = find(obj.LinkTypeIndex>2);
obj.LinkPipeNameID = obj.LinkNameID(obj.LinkPipeIndex);
obj.LinkPumpNameID = obj.LinkNameID(obj.LinkPumpIndex);
obj.LinkValveNameID = obj.LinkNameID(obj.LinkValveIndex);
%Get all the node data
obj.NodeNameID = obj.getNodeNameID;
tmp(:,1)=obj.NodeNameID(obj.NodesConnectingLinksIndex(:,1)');
tmp(:,2) = obj.NodeNameID(obj.NodesConnectingLinksIndex(:,2)');
obj.NodesConnectingLinksID=tmp;
obj.NodeIndex = 1:obj.NodeCount; %obj.getNodeIndex;
obj.NodeReservoirIndex = find(obj.NodeTypeIndex==1); %find(strcmp(obj.NodeType,'RESERVOIR'));
obj.NodeTankIndex = find(obj.NodeTypeIndex==2); %find(strcmp(obj.NodeType,'TANK'));
obj.NodeJunctionIndex = 1:obj.NodeJunctionCount; %find(strcmp(obj.NodeType,'JUNCTION'));
obj.NodeReservoirNameID=obj.NodeNameID(obj.NodeReservoirIndex);
obj.NodeTankNameID=obj.NodeNameID(obj.NodeTankIndex);
obj.NodeJunctionNameID=obj.NodeNameID(obj.NodeJunctionIndex);
obj.NodePatternIndex=obj.getNodePatternIndex;
obj.NodeBaseDemands = obj.getNodeBaseDemands;
%Get all tank data
obj.NodeTankInitialLevel = obj.getNodeTankInitialLevel;
obj.NodeTankInitialWaterVolume = obj.getNodeTankInitialWaterVolume;
obj.NodeTankMixingModelCode = obj.getNodeTankMixingModelCode;
obj.NodeTankMixingModelType = obj.getNodeTankMixingModelType;
obj.NodeTankMixZoneVolume = obj.getNodeTankMixZoneVolume;
obj.NodeTankDiameter = obj.getNodeTankDiameter;
obj.NodeTankMinimumWaterVolume = obj.getNodeTankMinimumWaterVolume;
obj.NodeTankVolumeCurveIndex = obj.getNodeTankVolumeCurveIndex;
obj.NodeTankMinimumWaterLevel = obj.getNodeTankMinimumWaterLevel;
obj.NodeTankMaximumWaterLevel = obj.getNodeTankMaximumWaterLevel;
obj.NodeTankMinimumFraction = obj.getNodeTankMinimumFraction;
obj.NodeTankBulkReactionCoeff = obj.getNodeTankBulkReactionCoeff;
%Get all options
obj.OptionsMaxTrials = obj.getOptionsMaxTrials;
obj.OptionsAccuracyValue = obj.getOptionsAccuracyValue;
obj.OptionsQualityTolerance = obj.getOptionsQualityTolerance;
obj.OptionsEmitterExponent = obj.getOptionsEmitterExponent;
obj.OptionsPatternDemandMultiplier = obj.getOptionsPatternDemandMultiplier;
%Get pattern data
obj.PatternNameID = obj.getPatternNameID;
obj.PatternIndex = 1:obj.PatternCount; %obj.getPatternIndex;
obj.PatternLengths = obj.getPatternLengths;
obj.Pattern = obj.getPattern;
%Get quality types
obj.QualityCode = obj.getQualityCode;
obj.QualityTraceNodeIndex = obj.getQualityTraceNodeIndex;
% obj.QualityType = obj.getQualityType;
obj.libFunctions = libfunctions(obj.LibEPANET);
if sum(strcmp(obj.libFunctions,'ENgetqualinfo'))
n = obj.getQualityInfo;
obj.QualityChemUnits = n.QualityChemUnits;
obj.QualityChemName= n.QualityChemName;
end
%Get time parameters
obj.TimeSimulationDuration = obj.getTimeSimulationDuration;
obj.TimeHydraulicStep = obj.getTimeHydraulicStep;
obj.TimeQualityStep = obj.getTimeQualityStep;
obj.TimePatternStep = obj.getTimePatternStep;
obj.TimePatternStart = obj.getTimePatternStart;
obj.TimeReportingStep = obj.getTimeReportingStep;
obj.TimeReportingStart = obj.getTimeReportingStart;
obj.TimeRuleControlStep = obj.getTimeRuleControlStep;
obj.TimeStatisticsIndex = obj.getTimeStatisticsIndex;
obj.TimeStatisticsType = obj.getTimeStatisticsType;
obj.TimeReportingPeriods = obj.getTimeReportingPeriods;
% Get EPANET version
obj.Version = obj.getVersion;
try%EPANET Version 2.1.dll LibEPANET
obj.TimeStartTime = obj.getTimeStartTime;
obj.TimeHTime = obj.getTimeHTime;
obj.TimeHaltFlag = obj.getTimeHaltFlag;
obj.TimeNextEvent = obj.getTimeNextEvent;
obj.NodeTankMaximumWaterVolume = obj.getNodeTankMaximumWaterVolume;
obj.NodeBaseDemands = obj.getNodeBaseDemands;
obj.NodeDemandCategoriesNumber = obj.getNodeDemandCategoriesNumber;
obj.PatternAverageValue = obj.getPatternAverageValue;
n = obj.getStatistic;
obj.RelativeError = n.RelativeError;
obj.Iterations = n.Iterations;
obj.NodeDemandPatternNameID = obj.getNodeDemandPatternNameID;
obj.NodeDemandPatternIndex = obj.getNodeDemandPatternIndex;
obj.LinkPumpHeadCurveIndex = obj.getLinkPumpHeadCurveIndex;
obj.LinkPumpPatternNameID = obj.getLinkPumpPatternNameID;
obj.LinkPumpPatternIndex = obj.getLinkPumpPatternIndex;
obj.LinkPumpTypeCode = obj.getLinkPumpTypeCode;
obj.LinkPumpType = obj.getLinkPumpType;
obj.CurvesInfo = obj.getCurvesInfo; % EPANET Version 2.1
catch
end
%Get data from raw file (for information which cannot be
%accessed by the epanet library)
value=obj.getNodeCoordinates;
%Get coordinates
obj.NodeCoordinates{1} = value{1};
obj.NodeCoordinates{2} = value{2};
obj.NodeCoordinates{3} = value{3};
obj.NodeCoordinates{4} = value{4};
% US Customary - SI metric
if find(strcmp(obj.LinkFlowUnits, obj.TYPEUNITS))<6
obj.Units_US_Customary=1;
else
obj.Units_SI_Metric=1;
end
if obj.Units_US_Customary
obj.NodePressureUnits='pounds per square inch';
obj.PatternDemandsUnits=obj.LinkFlowUnits;
obj.LinkPipeDiameterUnits='inches';
obj.NodeTankDiameterUnits='feet';
obj.EnergyEfficiencyUnits='percent';
obj.NodeElevationUnits='feet';
obj.NodeDemandUnits=obj.LinkFlowUnits;
obj.NodeEmitterCoefficientUnits='flow units @ 1 psi drop';
obj.EnergyUnits='kwatt-hours';
obj.LinkFrictionFactorUnits='unitless';
obj.NodeHeadUnits='feet';
obj.LinkLengthsUnits='feet';
obj.LinkMinorLossCoeffUnits='unitless';
obj.LinkPumpPowerUnits='horsepower';
obj.QualityReactionCoeffBulkUnits='1/day (1st-order)';
obj.QualityReactionCoeffWallUnits='mass/sq-ft/day (0-order), ft/day (1st-order)';
obj.LinkPipeRoughnessCoeffUnits='millifeet(Darcy-Weisbach), unitless otherwise';
obj.QualitySourceMassInjectionUnits='mass/minute';
obj.LinkVelocityUnits='ft/sec';
obj.NodeTankVolumeUnits='cubic feet';
obj.QualityWaterAgeUnits='hours';
else % SI Metric
obj.NodePressureUnits='meters';
obj.PatternDemandsUnits=obj.LinkFlowUnits;
obj.LinkPipeDiameterUnits='millimeters';
obj.NodeTankDiameterUnits='meters';
obj.EnergyEfficiencyUnits='percent';
obj.NodeElevationUnits='meters';
obj.NodeDemandUnits=obj.LinkFlowUnits;
obj.NodeEmitterCoefficientUnits='flow units @ 1 meter drop';
obj.EnergyUnits='kwatt-hours';
obj.LinkFrictionFactorUnits='unitless';
obj.NodeHeadUnits='meters';
obj.LinkLengthsUnits='meters';
obj.LinkMinorLossCoeffUnits='unitless';
obj.LinkPumpPowerUnits='kwatts';
obj.QualityReactionCoeffBulkUnits='1/day (1st-order)';
obj.QualityReactionCoeffWallUnits='mass/sq-m/day(0-order), meters/day (1st-order)';
obj.LinkPipeRoughnessCoeffUnits='mm(Darcy-Weisbach), unitless otherwise';
obj.QualitySourceMassInjectionUnits='mass/minute';
obj.LinkVelocityUnits='meters/sec';
obj.NodeTankVolumeUnits='cubic meters';
obj.QualityWaterAgeUnits='hours';
end
end % End of epanet class constructor
function Errcode = loadEPANETFile(obj,varargin)
%Load epanet file when use bin functions
% example:
% d.loadEPANETFile(d.TempInpFile);
if nargin==2
[Errcode] = ENopen(varargin{1},[varargin{1}(1:end-4),'.txt'],[varargin{1}(1:end-4),'.bin'],obj.LibEPANET);
else
[Errcode] = ENopen(varargin{1},varargin{2},varargin{3},obj.LibEPANET);
end
end
function [value] = plot(obj,varargin)
%Plots network in a new Matlab figure
%Arguments:
% 'nodes': yes/no
% 'links': yes/no
% 'line' : yes/no
% 'point': yes/no
% 'highlightnode': array of node IDs
% 'highlightlink': array of link IDs
% 'fontsize': number (px)
% 'colornode': array of node IDs
% 'colorlink': array of link id
% 'axes': axes coordinates
% 'linksindex': yes
% 'nodesindex': yes
% 'legend': show/hide
% 'extend': yes/no
% 'legendposition':
% 'North' inside plot box near top
% 'South' inside bottom
% 'East' inside right
% 'West' inside left
% 'NorthEast' inside top right (default for 2-D plots)
% 'NorthWest' inside top left
% 'SouthEast' inside bottom right
% 'SouthWest' inside bottom left
% 'NorthOutside' outside plot box near top
% 'SouthOutside' outside bottom
% 'EastOutside' outside right
% 'WestOutside' outside left
% 'NorthEastOutside' outside top right (default for 3-D plots)
% 'NorthWestOutside' outside top left
% 'SouthEastOutside' outside bottom right
% 'SouthWestOutside' outside bottom left
% 'Best' least conflict with data in plot
% 'BestOutside' least unused space outside plot
% Example:
% d.plot('nodes','yes','links','yes','highlightnode',{'10','11'},
% 'highlightlink',{'10'},'fontsize',8);
% d.plot('line','no');
% d.plot('point','no','linksindex','yes');
% d.plot('linksindex','yes','fontsize',8);
% d.plot('nodesindex','yes','fontsize',14);
% f=figure()
% d.plot('axes', h) % d.plot('axes', handles.axes) #gui
% d.plot('legend','hide')
% d.plot('legendposition','northwest')
% d = epanet('Net1.inp');
% nodeSet1={'10','11','22'};
% nodeSet2={'21','23','31'};
% colorNodeSet1={'r','r','r'};
% colorNodeSet2={'g','g','g'};
% linkSet1={'111','122','121'};
% linkSet2={'110','12','113'};
% colorLinkSet1={'k','k','k'};
% colorLinkSet2={'y','y','y'};
% d.plot('nodes','yes','links','yes','highlightnode',[nodeSet1 nodeSet2],'colornode',[colorNodeSet1 colorNodeSet2],...
% 'highlightlink',[linkSet1 linkSet2],'colorlink',[colorLinkSet1 colorLinkSet2])
[value] = plotnet(obj,'bin',0,varargin{:});
end
function value = getControls(obj, varargin)
%Retrieves the parameters of all control statements
indices = getControlIndices(obj,varargin);j=1;
value=struct();
obj.ControlTypes={};
for i=indices
[obj.Errcode, obj.ControlTypesIndex(j),...
obj.ControlLinkIndex(j), obj.ControlSettings(j),...
obj.ControlNodeIndex(j),obj.ControlLevelValues(j)]...
= ENgetcontrol(i,obj.LibEPANET);
if obj.Errcode, error(obj.getError(obj.Errcode)), return; end
obj.ControlTypes(j)=obj.TYPECONTROL(obj.ControlTypesIndex(j)+1);
value(j).Type = obj.ControlTypes{j};
%value{i}.TypeIndex = obj.ControlTypesIndex(i);
value(j).LinkID = obj.getLinkNameID{obj.ControlLinkIndex(j)};
if all(obj.ControlSettings(j) ~= [0, 1])
value(j).Setting = obj.ControlSettings(j);
else
value(j).Setting = obj.TYPESTATUS{obj.ControlSettings(j)+1};
end
if obj.ControlNodeIndex(j)
value(j).NodeID = obj.getNodeNameID{obj.ControlNodeIndex(j)};
else
value(j).NodeID = NaN;
end
value(j).Value = obj.ControlLevelValues(j);
switch obj.ControlTypes{j}
case 'LOWLEVEL'
value(j).Control = ['LINK ',value(j).LinkID,' ',...
value(j).Setting,' IF NODE ',value(j).NodeID,...
' BELOW ',num2str(value(j).Value)];
case 'HIGHLEVEL'
value(j).Control = ['LINK ',value(j).LinkID,' ',...
value(j).Setting,' IF NODE ',value(j).NodeID,...
' ABOVE ',num2str(value(j).Value)];
case 'TIMER'
value(j).Control = ['LINK ',value(j).LinkID,' ',...
num2str(value(j).Setting),' AT TIME ',num2str(value(j).Value)];
case 'TIMEOFDAY'
value(j).Control = ['LINK ',value(j).LinkID,' ',...
num2str(value(j).Setting),' AT CLOCKTIME ',num2str(value(j).Value)];
end
j=j+1;
end
end
% function value = getRules(obj)
% value={};
% cnt=obj.getRuleCount;
% if cnt
% obj.RulePremises(cnt)=NaN;
% obj.RuleTrueActions(cnt)=NaN;
% obj.RuleFalseActions(cnt)=NaN;
% obj.RulePriority(cnt)=NaN;
% for i=1:cnt
% [obj.Errcode, obj.RulePremises(i), obj.RuleTrueActions(i), obj.RuleFalseActions(i), obj.RulePriority(i)] = ENgetrule(i, obj.LibEPANET);
% value{i}={obj.RulePremises(i), obj.RuleTrueActions(i),obj.RuleFalseActions(i),obj.RulePriority(i)};
% end
% end
% end
function value = getNodeCount(obj)
% Retrieves the number of nodes
[obj.Errcode, value] = ENgetcount(obj.ToolkitConstants.EN_NODECOUNT,obj.LibEPANET);
end
function value = getNodeTankReservoirCount(obj)
% Retrieves the number of tanks
[obj.Errcode, value] = ENgetcount(obj.ToolkitConstants.EN_TANKCOUNT,obj.LibEPANET);
end
function value = getLinkCount(obj)
%Retrieves the number of links
[obj.Errcode, value] = ENgetcount(obj.ToolkitConstants.EN_LINKCOUNT,obj.LibEPANET);
end
function value = getPatternCount(obj)
%Retrieves the number of patterns
[obj.Errcode, value] = ENgetcount(obj.ToolkitConstants.EN_PATCOUNT,obj.LibEPANET);
end
function value = getCurveCount(obj)
%Retrieves the number of curves
[obj.Errcode, value] = ENgetcount(obj.ToolkitConstants.EN_CURVECOUNT,obj.LibEPANET);
end
function value = getControlRulesCount(obj)
%Retrieves the number of controls
[obj.Errcode, value] = ENgetcount(obj.ToolkitConstants.EN_CONTROLCOUNT,obj.LibEPANET);
end
% function value = getRuleCount(obj)
% %Retrieves the number of rules
% [obj.Errcode, value] = ENgetcount(obj.ToolkitConstants.EN_RULECOUNT,obj.LibEPANET);
% end
function value = getNodeTankCount(obj)
%Retrieves the number of Tanks
value = sum(strcmp(obj.getNodeType,'TANK'));
end
function value = getNodeReservoirCount(obj)
%Retrieves the number of Reservoirs
value = sum(strcmp(obj.getNodeType,'RESERVOIR'));
end
function value = getNodeJunctionCount(obj)
%Retrieves the number of junction nodes
value = obj.getNodeCount - obj.getNodeTankReservoirCount;
end
function value = getLinkPipeCount(obj)
%Retrieves the number of pipes
LinkType1=obj.getLinkType;
value = sum(strcmp(LinkType1,'PIPE')+strcmp(LinkType1,'CVPIPE'));
end
function value = getLinkPumpCount(obj)
%Retrieves the number of pumps
value = sum(strcmp(obj.getLinkType,'PUMP'));
end
function value = getLinkValveCount(obj)
%Retrieves the number of valves
LinkType1=obj.getLinkType;
pipepump = sum(strcmp(LinkType1,'PIPE')+strcmp(LinkType1,'CVPIPE')+strcmp(LinkType1,'PUMP'));
value = obj.getLinkCount - pipepump;
end
function [errmssg, Errcode] = getError(obj,Errcode)
%Retrieves the text of the message associated with a particular error or warning code.
[errmssg , Errcode] = ENgeterror(Errcode,obj.LibEPANET);
end
function value = getFlowUnits(obj)
%Retrieves flow units used to express all flow rates.
[obj.Errcode, flowunitsindex] = ENgetflowunits(obj.LibEPANET);
value=obj.TYPEUNITS(flowunitsindex+1);
end
function value = getLinkNameID(obj,varargin)
%Retrieves the ID label(s) of all links, or the IDs of an index set of links
if isempty(varargin)
value=cell(1, obj.getLinkCount);
for i=1:obj.getLinkCount
[obj.Errcode, value{i}]=ENgetlinkid(i,obj.LibEPANET);
end
else
k=1;
value = cell(1, length(varargin{1}));
if isempty(varargin{1}), varargin{1}=0; end
for i=varargin{1}
[obj.Errcode, value{k}]=ENgetlinkid(i,obj.LibEPANET);
if obj.Errcode==204, value=[]; return; end
k=k+1;
end
end
end
function value = getLinkPipeNameID(obj)
%Retrieves the pipe id
value=obj.getLinkNameID(obj.getLinkPipeIndex);
end
function value = getLinkPumpNameID(obj)
%Retrieves the pump id
value=obj.getLinkNameID(obj.getLinkPumpIndex);
end
function value = getLinkValveNameID(obj)
%Retrieves the valve id
value=obj.getLinkNameID(obj.getLinkValveIndex);
end
function value = getLinkIndex(obj,varargin)
%Retrieves the indices of all links, or the indices of an ID set of links
if isempty(varargin)
value=1:obj.getLinkCount;
elseif isa(varargin{1},'cell')
k=1;
value = zeros(1, length(varargin{1}));
for j=1:length(varargin{1})
[obj.Errcode, value(k)] = ENgetlinkindex(varargin{1}{j},obj.LibEPANET);
k=k+1;
end
elseif isa(varargin{1},'char')
[obj.Errcode, value] = ENgetlinkindex(varargin{1},obj.LibEPANET);
else
disp('Run function: getLinkIndex({''linkID''})) or getLinkIndex(''linkID''))');
end
end
function value = getLinkPipeIndex(obj)
%Retrieves the pipe indices
tmpLinkTypes=obj.getLinkType;
value = find(strcmp(tmpLinkTypes,'PIPE'));
end
function value = getLinkPumpIndex(obj, varargin)
%Retrieves the pump indices
tmpLinkTypes=obj.getLinkType;
value = find(strcmp(tmpLinkTypes,'PUMP'));
if ~isempty(varargin)
value = value(varargin{1});
end
end
function value = getLinkValveIndex(obj)
%Retrieves the valve indices
value = obj.getLinkPipeCount+obj.getLinkPumpCount+1:obj.getLinkCount;
end
function value = getLinkNodesIndex(obj)
%Retrieves the indexes of the from/to nodes of all links.
value(obj.getLinkCount,1:2)=[nan nan];
for i=1:obj.getLinkCount
[obj.Errcode,linkFromNode,linkToNode] = ENgetlinknodes(i,obj.LibEPANET);
value(i,:)= [linkFromNode,linkToNode];
end
end
function value = getNodesConnectingLinksID(obj)
%Retrieves the id of the from/to nodes of all links.
value={};
obj.NodesConnectingLinksIndex=obj.getLinkNodesIndex;
if obj.getLinkCount
value(:,1)=obj.getNodeNameID(obj.NodesConnectingLinksIndex(:,1)');
value(:,2)=obj.getNodeNameID(obj.NodesConnectingLinksIndex(:,2)');
end
end
function value = getLinkType(obj, varargin)
%Retrieves the link-type code for all links.
if ~isempty(varargin), varargin=varargin{1}; end
value=obj.TYPELINK(obj.getLinkTypeIndex(varargin)+1);
end
function value = getLinkTypeIndex(obj, varargin)
%Retrieves the link-type code for all links.
[indices, value] = getLinkIndices(obj,varargin);j=1;
for i=indices
[obj.Errcode,value(j)] = ENgetlinktype(i,obj.LibEPANET);
if obj.Errcode, error(obj.getError(obj.Errcode)), return; end
j=j+1;
end
end
function [value] = getLinksInfo(obj)
%Retrieves all link info
value = struct();
for i=1:obj.getLinkCount
[~, value.LinkDiameter(i)] = ENgetlinkvalue(i,obj.ToolkitConstants.EN_DIAMETER,obj.LibEPANET);
[~, value.LinkLength(i)] = ENgetlinkvalue(i,obj.ToolkitConstants.EN_LENGTH,obj.LibEPANET);
[~, value.LinkRoughnessCoeff(i)] = ENgetlinkvalue(i,obj.ToolkitConstants.EN_ROUGHNESS,obj.LibEPANET);
[~, value.LinkMinorLossCoeff(i)] = ENgetlinkvalue(i,obj.ToolkitConstants.EN_MINORLOSS,obj.LibEPANET);
[~, value.LinkInitialStatus(i)] = ENgetlinkvalue(i,obj.ToolkitConstants.EN_INITSTATUS,obj.LibEPANET);
[~, value.LinkInitialSetting(i)] = ENgetlinkvalue(i,obj.ToolkitConstants.EN_INITSETTING,obj.LibEPANET);
[~, value.LinkBulkReactionCoeff(i)] = ENgetlinkvalue(i,obj.ToolkitConstants.EN_KBULK,obj.LibEPANET);
[~, value.LinkWallReactionCoeff(i)] = ENgetlinkvalue(i,obj.ToolkitConstants.EN_KWALL,obj.LibEPANET);
[~,value.NodesConnectingLinksIndex(i,1),value.NodesConnectingLinksIndex(i,2)] = ENgetlinknodes(i,obj.LibEPANET);
[~,value.LinkTypeIndex(i)] = ENgetlinktype(i,obj.LibEPANET);
end
end
function value = getLinkDiameter(obj, varargin)
[indices, value] = getLinkIndices(obj,varargin);j=1;
%Retrieves the value of all link diameters
for i=indices
[obj.Errcode, value(j)] = ENgetlinkvalue(i,obj.ToolkitConstants.EN_DIAMETER,obj.LibEPANET);
if obj.Errcode, error(obj.getError(obj.Errcode)), return; end
j=j+1;