Merge pull request #372 from LRossman/lrossman-dev

New updates to address compiler warnings (issue #370)
This commit is contained in:
Lew Rossman
2019-01-22 10:50:07 -05:00
committed by GitHub
16 changed files with 1034 additions and 754 deletions

View File

@@ -261,7 +261,7 @@ Public Const EN_R_IS_ACTIVE = 3
Declare Function ENsetstatusreport Lib "epanet2.dll" (ByVal level As Int32) As Int32 Declare Function ENsetstatusreport Lib "epanet2.dll" (ByVal level As Int32) As Int32
Declare Function ENgetcount Lib "epanet2.dll" (ByVal object As Int32, count As Int32) As Int32 Declare Function ENgetcount Lib "epanet2.dll" (ByVal object As Int32, count As Int32) As Int32
Declare Function ENgeterror Lib "epanet2.dll" (ByVal errcode As Int32, ByVal errmsg As String, ByVal maxLen As Int32) As Int32 Declare Function ENgeterror Lib "epanet2.dll" (ByVal errcode As Int32, ByVal errmsg As String, ByVal maxLen As Int32) As Int32
Declare Function ENgetstatistic Lib "epanet2.dll" (ByVal type As Int32, ByRef value As Single) As Int32 Declare Function ENgetstatistic Lib "epanet2.dll" (ByVal type_ As Int32, ByRef value As Single) As Int32
'Analysis Options Functions 'Analysis Options Functions
Declare Function ENgetoption Lib "epanet2.dll" (ByVal option As Int32, value As Single) As Int32 Declare Function ENgetoption Lib "epanet2.dll" (ByVal option As Int32, value As Single) As Int32
@@ -289,8 +289,8 @@ Public Const EN_R_IS_ACTIVE = 3
Declare Function ENsetcoord Lib "epanet2.dll" (ByVal index As Int32, ByVal x As Single, ByVal y As Single) As Int32 Declare Function ENsetcoord Lib "epanet2.dll" (ByVal index As Int32, ByVal x As Single, ByVal y As Single) As Int32
'Nodal Demand Functions 'Nodal Demand Functions
Declare Function ENgetdemandmodel Lib "epanet2.dll" (type As Int32, pmin As Single, preq As Single, pexp As Single) As Int32 Declare Function ENgetdemandmodel Lib "epanet2.dll" (type_ As Int32, pmin As Single, preq As Single, pexp As Single) As Int32
Declare Function ENsetdemandmodel Lib "epanet2.dll" (ByVal type As Int32, ByVal pmin As Single, ByVal preq As Single, ByVal pexp As Single) As Int32 Declare Function ENsetdemandmodel Lib "epanet2.dll" (ByVal type_ As Int32, ByVal pmin As Single, ByVal preq As Single, ByVal pexp As Single) As Int32
Declare Function ENgetnumdemands Lib "epanet2.dll" (ByVal nodeIndex As Int32, numDemands As Int32) As Int32 Declare Function ENgetnumdemands Lib "epanet2.dll" (ByVal nodeIndex As Int32, numDemands As Int32) As Int32
Declare Function ENgetbasedemand Lib "epanet2.dll" (ByVal nodeIndex As Int32, ByVal demandIndex As Int32, value As Single) As Int32 Declare Function ENgetbasedemand Lib "epanet2.dll" (ByVal nodeIndex As Int32, ByVal demandIndex As Int32, value As Single) As Int32
Declare Function ENsetbasedemand Lib "epanet2.dll" (ByVal nodeIndex As Int32, ByVal demandIndex As Int32, ByVal BaseDemand As Single) As Int32 Declare Function ENsetbasedemand Lib "epanet2.dll" (ByVal nodeIndex As Int32, ByVal demandIndex As Int32, ByVal BaseDemand As Single) As Int32
@@ -322,28 +322,28 @@ Public Const EN_R_IS_ACTIVE = 3
Declare Function ENaddpattern Lib "epanet2.dll" (ByVal id As String) As Int32 Declare Function ENaddpattern Lib "epanet2.dll" (ByVal id As String) As Int32
Declare Function ENgetpatternindex Lib "epanet2.dll" (ByVal id As String, index As Int32) As Int32 Declare Function ENgetpatternindex Lib "epanet2.dll" (ByVal id As String, index As Int32) As Int32
Declare Function ENgetpatternid Lib "epanet2.dll" (ByVal index As Int32, ByVal id As String) As Int32 Declare Function ENgetpatternid Lib "epanet2.dll" (ByVal index As Int32, ByVal id As String) As Int32
Declare Function ENgetpatternlen Lib "epanet2.dll" (ByVal index As Int32, len As Int32) As Int32 Declare Function ENgetpatternlen Lib "epanet2.dll" (ByVal index As Int32, len_ As Int32) As Int32
Declare Function ENgetpatternvalue Lib "epanet2.dll" (ByVal index As Int32, ByVal period As Int32, value As Single) As Int32 Declare Function ENgetpatternvalue Lib "epanet2.dll" (ByVal index As Int32, ByVal period As Int32, value As Single) As Int32
Declare Function ENsetpatternvalue Lib "epanet2.dll" (ByVal index As Int32, ByVal period As Int32, ByVal value As Single) As Int32 Declare Function ENsetpatternvalue Lib "epanet2.dll" (ByVal index As Int32, ByVal period As Int32, ByVal value As Single) As Int32
Declare Function ENgetaveragepatternvalue Lib "epanet2.dll" (ByVal index As Int32, value As Single) As Int32 Declare Function ENgetaveragepatternvalue Lib "epanet2.dll" (ByVal index As Int32, value As Single) As Int32
Declare Function ENsetpattern Lib "epanet2.dll" (ByVal index As Int32, values As Any, ByVal len As Int32) As Int32 Declare Function ENsetpattern Lib "epanet2.dll" (ByVal index As Int32, values As Any, ByVal len_ As Int32) As Int32
'Data Curve Functions 'Data Curve Functions
Declare Function ENaddcurve Lib "epanet2.dll" (ByVal id As String) As Int32 Declare Function ENaddcurve Lib "epanet2.dll" (ByVal id As String) As Int32
Declare Function ENgetcurveindex Lib "epanet2.dll" (ByVal id As String, index As Int32) As Int32 Declare Function ENgetcurveindex Lib "epanet2.dll" (ByVal id As String, index As Int32) As Int32
Declare Function ENgetcurveid Lib "epanet2.dll" (ByVal index As Int32, ByVal id As String) As Int32 Declare Function ENgetcurveid Lib "epanet2.dll" (ByVal index As Int32, ByVal id As String) As Int32
Declare Function ENgetcurvelen Lib "epanet2.dll" (ByVal index As Int32, len As Int32) As Int32 Declare Function ENgetcurvelen Lib "epanet2.dll" (ByVal index As Int32, len_ As Int32) As Int32
Declare Function ENgetcurvetype Lib "epanet2.dll" (ByVal index As Int32, type As Int32) As Int32 Declare Function ENgetcurvetype Lib "epanet2.dll" (ByVal index As Int32, type_ As Int32) As Int32
Declare Function ENgetcurvevalue Lib "epanet2.dll" (ByVal curveIndex As Int32, ByVal pointIndex As Int32, x As Single, y As Single) As Int32 Declare Function ENgetcurvevalue Lib "epanet2.dll" (ByVal curveIndex As Int32, ByVal pointIndex As Int32, x As Single, y As Single) As Int32
Declare Function ENsetcurvevalue Lib "epanet2.dll" (ByVal curveIndex As Int32, ByVal pointIndex As Int32, ByVal x As Single, ByVal y As Single) As Int32 Declare Function ENsetcurvevalue Lib "epanet2.dll" (ByVal curveIndex As Int32, ByVal pointIndex As Int32, ByVal x As Single, ByVal y As Single) As Int32
Declare Function ENgetcurve Lib "epanet2.dll" (ByVal index As Int32, ByVal id As String, nPoints As Int32, xValues As Any, yValues As Any) As Int32 Declare Function ENgetcurve Lib "epanet2.dll" (ByVal index As Int32, ByVal id As String, nPoints As Int32, xValues As Any, yValues As Any) As Int32
Declare Function ENsetcurve Lib "epanet2.dll" (ByVal index As Int32, xValues As Any, yValues As Any, ByVal nPoints As Int32) As Int32 Declare Function ENsetcurve Lib "epanet2.dll" (ByVal index As Int32, xValues As Any, yValues As Any, ByVal nPoints As Int32) As Int32
'Simple Control Functions 'Simple Control Functions
Declare Function ENaddcontrol Lib "epanet2.dll" (ByVal type As Int32, ByVal linkIndex As Int32, ByVal setting As Single, ByVal nodeIndex As Int32, ByVal level As Single, index As Int32) As Int32 Declare Function ENaddcontrol Lib "epanet2.dll" (ByVal type_ As Int32, ByVal linkIndex As Int32, ByVal setting As Single, ByVal nodeIndex As Int32, ByVal level As Single, index As Int32) As Int32
Declare Function ENdeletecontrol Lib "epanet2.dll" (ByVal index As Int32) As Int32 Declare Function ENdeletecontrol Lib "epanet2.dll" (ByVal index As Int32) As Int32
Declare Function ENgetcontrol Lib "epanet2.dll" (ByVal index As Int32, type As Int32, linkIndex As Int32, setting As Single, nodeIndex As Int32, level As Single) As Int32 Declare Function ENgetcontrol Lib "epanet2.dll" (ByVal index As Int32, type_ As Int32, linkIndex As Int32, setting As Single, nodeIndex As Int32, level As Single) As Int32
Declare Function ENsetcontrol Lib "epanet2.dll" (ByVal index As Int32, ByVal type As Int32, ByVal linkIndex As Int32, ByVal setting As Single, ByVal nodeIndex As Int32, ByVal level As Single) As Int32 Declare Function ENsetcontrol Lib "epanet2.dll" (ByVal index As Int32, ByVal type_ As Int32, ByVal linkIndex As Int32, ByVal setting As Single, ByVal nodeIndex As Int32, ByVal level As Single) As Int32
'Rule-Based Control Functions 'Rule-Based Control Functions
Declare Function ENaddrule Lib "epanet2.dll" (ByVal rule As String) As Int32 Declare Function ENaddrule Lib "epanet2.dll" (ByVal rule As String) As Int32

File diff suppressed because it is too large Load Diff

View File

@@ -1,15 +1,15 @@
/** @file epanet2_enums.h /** @file epanet2_enums.h
*/ */
/* /*
****************************************************************************** ******************************************************************************
Project: OWA EPANET Project: OWA EPANET
Version: 2.2 Version: 2.2
Module: epanet2_enums.h Module: epanet2_enums.h
Description: enumerations of symbolic constants used by the API Description: enumerations of symbolic constants used by the API functions
Authors: see AUTHORS Authors: see AUTHORS
Copyright: see AUTHORS Copyright: see AUTHORS
License: see LICENSE License: see LICENSE
Last Updated: 01/08/2019 Last Updated: 01/14/2019
****************************************************************************** ******************************************************************************
*/ */
@@ -23,65 +23,78 @@
#define EN_MAXID 31 //!< Max. # characters in ID name #define EN_MAXID 31 //!< Max. # characters in ID name
#define EN_MAXMSG 255 //!< Max. # characters in message text #define EN_MAXMSG 255 //!< Max. # characters in message text
/// Node property codes /// Node properties
/**
These node properties can be accessed with @ref EN_getnodevalue and
@ref EN_setnodevalue. Those marked as read only are computed values that can
only be retrieved.
*/
typedef enum { typedef enum {
EN_ELEVATION = 0, //!< Elevation EN_ELEVATION = 0, //!< Elevation
EN_BASEDEMAND = 1, //!< Junction baseline demand, from last demand category EN_BASEDEMAND = 1, //!< Primary demand baseline value
EN_PATTERN = 2, //!< Junction baseline demand pattern EN_PATTERN = 2, //!< Primary demand time pattern index
EN_EMITTER = 3, //!< Junction emitter coefficient EN_EMITTER = 3, //!< Emitter flow coefficient
EN_INITQUAL = 4, //!< Initial quality EN_INITQUAL = 4, //!< Initial quality
EN_SOURCEQUAL = 5, //!< Quality source strength EN_SOURCEQUAL = 5, //!< Quality source strength
EN_SOURCEPAT = 6, //!< Quality source pattern EN_SOURCEPAT = 6, //!< Quality source pattern index
EN_SOURCETYPE = 7, //!< Qualiy source type EN_SOURCETYPE = 7, //!< Quality source type (see @ref EN_SourceType)
EN_TANKLEVEL = 8, //!< Current computed tank water level EN_TANKLEVEL = 8, //!< Current computed tank water level (read only)
EN_DEMAND = 9, //!< Current computed demand EN_DEMAND = 9, //!< Current computed demand (read only)
EN_HEAD = 10, //!< Current computed hydraulic head EN_HEAD = 10, //!< Current computed hydraulic head (read only)
EN_PRESSURE = 11, //!< Current computed pressure EN_PRESSURE = 11, //!< Current computed pressure (read only)
EN_QUALITY = 12, //!< Current computed quality EN_QUALITY = 12, //!< Current computed quality (read only)
EN_SOURCEMASS = 13, //!< Current computed quality source mass inflow EN_SOURCEMASS = 13, //!< Current computed quality source mass inflow (read only)
EN_INITVOLUME = 14, //!< Tank initial volume EN_INITVOLUME = 14, //!< Tank initial volume (read only)
EN_MIXMODEL = 15, //!< Tank mixing model EN_MIXMODEL = 15, //!< Tank mixing model (see @ref EN_MixingModel)
EN_MIXZONEVOL = 16, //!< Tank mixing zone volume EN_MIXZONEVOL = 16, //!< Tank mixing zone volume (read only)
EN_TANKDIAM = 17, //!< Tank diameter EN_TANKDIAM = 17, //!< Tank diameter
EN_MINVOLUME = 18, //!< Tank minimum volume EN_MINVOLUME = 18, //!< Tank minimum volume
EN_VOLCURVE = 19, //!< Tank volume curve EN_VOLCURVE = 19, //!< Tank volume curve index
EN_MINLEVEL = 20, //!< Tank minimum level EN_MINLEVEL = 20, //!< Tank minimum level
EN_MAXLEVEL = 21, //!< Tank maximum level EN_MAXLEVEL = 21, //!< Tank maximum level
EN_MIXFRACTION = 22, //!< Tank mixing fraction EN_MIXFRACTION = 22, //!< Tank mixing fraction
EN_TANK_KBULK = 23, //!< Tank bulk decay coefficient EN_TANK_KBULK = 23, //!< Tank bulk decay coefficient
EN_TANKVOLUME = 24, //!< Current computed tank volume EN_TANKVOLUME = 24, //!< Current computed tank volume (read only)
EN_MAXVOLUME = 25 //!< Tank maximum volume EN_MAXVOLUME = 25 //!< Tank maximum volume (read only)
} EN_NodeProperty; } EN_NodeProperty;
/// Link property codes /// Link properties
/**
These link properties can be accessed with @ref EN_getlinkvalue and @ref EN_setlinkvalue.
Those marked as read only are computed values that can only be retrieved.
*/
typedef enum { typedef enum {
EN_DIAMETER = 0, //!< Pipe/valve diameter EN_DIAMETER = 0, //!< Pipe/valve diameter
EN_LENGTH = 1, //!< Pipe length EN_LENGTH = 1, //!< Pipe length
EN_ROUGHNESS = 2, //!< Pipe roughness coefficient EN_ROUGHNESS = 2, //!< Pipe roughness coefficient
EN_MINORLOSS = 3, //!< Pipe/valve minor loss coefficient EN_MINORLOSS = 3, //!< Pipe/valve minor loss coefficient
EN_INITSTATUS = 4, //!< Initial status (e.g., OPEN/CLOSED) EN_INITSTATUS = 4, //!< Initial status (see @ref EN_LinkStatusType)
EN_INITSETTING = 5, //!< Initial pump speed or valve setting EN_INITSETTING = 5, //!< Initial pump speed or valve setting
EN_KBULK = 6, //!< Bulk chemical reaction coefficient EN_KBULK = 6, //!< Bulk chemical reaction coefficient
EN_KWALL = 7, //!< Pipe wall chemical reaction coefficient EN_KWALL = 7, //!< Pipe wall chemical reaction coefficient
EN_FLOW = 8, //!< Current computed flow rate EN_FLOW = 8, //!< Current computed flow rate (read only)
EN_VELOCITY = 9, //!< Current computed flow velocity EN_VELOCITY = 9, //!< Current computed flow velocity (read only)
EN_HEADLOSS = 10, //!< Current computed head loss EN_HEADLOSS = 10, //!< Current computed head loss (read only)
EN_STATUS = 11, //!< Current link status EN_STATUS = 11, //!< Current link status (see @ref EN_LinkStatusType)
EN_SETTING = 12, //!< Current link setting EN_SETTING = 12, //!< Current link setting
EN_ENERGY = 13, //!< Current computed pump energy usage EN_ENERGY = 13, //!< Current computed pump energy usage (read only)
EN_LINKQUAL = 14, //!< Current computed link quality EN_LINKQUAL = 14, //!< Current computed link quality (read only)
EN_LINKPATTERN = 15, //!< Pump speed time pattern EN_LINKPATTERN = 15, //!< Pump speed time pattern index
EN_PUMP_STATE = 16, //!< Current computed pump state (read only) (see @ref EN_PumpStateType)
EN_PUMP_STATE = 16, //!< Current computed pump state EN_PUMP_EFFIC = 17, //!< Current computed pump efficiency (read only)
EN_PUMP_EFFIC = 17, //!< Current computed pump efficiency
EN_PUMP_POWER = 18, //!< Pump constant power rating EN_PUMP_POWER = 18, //!< Pump constant power rating
EN_PUMP_HCURVE = 19, //!< Pump head v. flow curve EN_PUMP_HCURVE = 19, //!< Pump head v. flow curve index
EN_PUMP_ECURVE = 20, //!< Pump efficiency v. flow curve EN_PUMP_ECURVE = 20, //!< Pump efficiency v. flow curve index
EN_PUMP_ECOST = 21, //!< Pump average energy price EN_PUMP_ECOST = 21, //!< Pump average energy price
EN_PUMP_EPAT = 22 //!< Pump energy price time pattern EN_PUMP_EPAT = 22 //!< Pump energy price time pattern index
} EN_LinkProperty; } EN_LinkProperty;
/// Time parameter codes (all in seconds) /// Time parameters
/**
These time parameters are accessed using @ref EN_gettimeparam and@ref EN_settimeparam.
All times are expressed in seconds The parameters marked as read only are
computed values that can only be retrieved.
*/
typedef enum { typedef enum {
EN_DURATION = 0, //!< Total simulation duration EN_DURATION = 0, //!< Total simulation duration
EN_HYDSTEP = 1, //!< Hydraulic time step EN_HYDSTEP = 1, //!< Hydraulic time step
@@ -90,18 +103,23 @@ typedef enum {
EN_PATTERNSTART = 4, //!< Time when time patterns begin EN_PATTERNSTART = 4, //!< Time when time patterns begin
EN_REPORTSTEP = 5, //!< Reporting time step EN_REPORTSTEP = 5, //!< Reporting time step
EN_REPORTSTART = 6, //!< Time when reporting starts EN_REPORTSTART = 6, //!< Time when reporting starts
EN_RULESTEP = 7, //!< Rule evaluation time step EN_RULESTEP = 7, //!< Rule-based control evaluation time step
EN_STATISTIC = 8, //!< Reporting statistic code EN_STATISTIC = 8, //!< Reporting statistic code (see @ref EN_StatisticType)
EN_PERIODS = 9, //!< Number of reporting time periods EN_PERIODS = 9, //!< Number of reporting time periods (read only)
EN_STARTTIME = 10, //!< Simulation starting time of day EN_STARTTIME = 10, //!< Simulation starting time of day
EN_HTIME = 11, //!< Elapsed time of current hydraulic solution EN_HTIME = 11, //!< Elapsed time of current hydraulic solution (read only)
EN_QTIME = 12, //!< Elapsed time of current quality solution EN_QTIME = 12, //!< Elapsed time of current quality solution (read only)
EN_HALTFLAG = 13, //!< Flag indicating if the simulation was halted EN_HALTFLAG = 13, //!< Flag indicating if the simulation was halted (read only)
EN_NEXTEVENT = 14, //!< Next time until a tank becomes empty or full EN_NEXTEVENT = 14, //!< Shortest time until a tank becomes empty or full (read only)
EN_NEXTEVENTIDX = 15 //!< Index of next tank that becomes empty or full EN_NEXTEVENTTANK = 15 //!< Index of tank with shortest time to become empty or full (read only)
} EN_TimeProperty; } EN_TimeParameter;
/// Statistics for the most current hydraulic/quality analysis made /// Analysis convergence statistics
/**
These statistics report the convergence criteria for the most current hydraulic analysis
and the cumulative water quality mass balance error at the current simulation time. They
can be retrieved with @ref EN_getstatistic.
*/
typedef enum { typedef enum {
EN_ITERATIONS = 0, //!< Number of hydraulic iterations taken EN_ITERATIONS = 0, //!< Number of hydraulic iterations taken
EN_RELATIVEERROR = 1, //!< Sum of link flow changes / sum of link flows EN_RELATIVEERROR = 1, //!< Sum of link flow changes / sum of link flows
@@ -110,7 +128,10 @@ typedef enum {
EN_MASSBALANCE = 4 //!< Cumulative water quality mass balance ratio EN_MASSBALANCE = 4 //!< Cumulative water quality mass balance ratio
} EN_AnalysisStatistic; } EN_AnalysisStatistic;
/// Object count codes /// Types of objects to count
/**
These options tell @ref EN_getcount which type of object to count.
*/
typedef enum { typedef enum {
EN_NODECOUNT = 0, //!< Number of nodes (junctions + tanks + reservoirs) EN_NODECOUNT = 0, //!< Number of nodes (junctions + tanks + reservoirs)
EN_TANKCOUNT = 1, //!< Number of tanks and reservoirs EN_TANKCOUNT = 1, //!< Number of tanks and reservoirs
@@ -121,14 +142,20 @@ typedef enum {
EN_RULECOUNT = 6 //!< Number of rule-based controls EN_RULECOUNT = 6 //!< Number of rule-based controls
} EN_CountType; } EN_CountType;
/// Node type codes /// Types of nodes
/**
These are the different types of nodes that can be returned by calling @ref EN_getnodetype.
*/
typedef enum { typedef enum {
EN_JUNCTION = 0, //!< Junction node EN_JUNCTION = 0, //!< Junction node
EN_RESERVOIR = 1, //!< Reservoir node EN_RESERVOIR = 1, //!< Reservoir node
EN_TANK = 2 //!< Storage tank node EN_TANK = 2 //!< Storage tank node
} EN_NodeType; } EN_NodeType;
/// Link type codes /// Types of links
/**
These are the different types of links that can be returned by calling @ref EN_getlinktype.
*/
typedef enum { typedef enum {
EN_CVPIPE = 0, //!< Pipe with check valve EN_CVPIPE = 0, //!< Pipe with check valve
EN_PIPE = 1, //!< Pipe EN_PIPE = 1, //!< Pipe
@@ -141,7 +168,36 @@ typedef enum {
EN_GPV = 8 //!< General purpose valve EN_GPV = 8 //!< General purpose valve
} EN_LinkType; } EN_LinkType;
/// Water quality analysis types /// Link status
/**
One of these values is returned when @ref EN_getlinkvalue is used to retrieve a link's
initial status (EN_INITSTATUS) or its current status (EN_STATUS). These options are
also used with @ref EN_setlinkvalue to set values for these same properties.
*/
typedef enum {
EN_CLOSED = 0,
EN_OPEN = 1
} EN_LinkStatusType;
/// Pump states
/**
One of these codes is returned when @ref EN_getlinkvalue is used to retrieve a pump's
current operating state (EN_PUMP_STATE). EN_PUMP_XHEAD indicates that the pump has been
shut down because it is being asked to deliver more than its shutoff head. EN_PUMP_XFLOW
indicates that the pump is being asked to deliver more than its maximum flow.
*/
typedef enum {
EN_PUMP_XHEAD = 0, //!< Pump closed - cannot supply head
EN_PUMP_CLOSED = 2, //!< Pump closed
EN_PUMP_OPEN = 3, //!< Pump open
EN_PUMP_XFLOW = 5 //!< Pump open - cannot supply flow
} EN_PumpStateType;
/// Types of water quality analyses
/**
These are the different types of water quality analyses that EPANET can run. They
are used with @ref EN_getqualinfo, @ref EN_getqualtype, and @ref EN_setqualtype.
*/
typedef enum { typedef enum {
EN_NONE = 0, //!< No quality analysis EN_NONE = 0, //!< No quality analysis
EN_CHEM = 1, //!< Chemical fate and transport EN_CHEM = 1, //!< Chemical fate and transport
@@ -149,22 +205,40 @@ typedef enum {
EN_TRACE = 3 //!< Source tracing analysis EN_TRACE = 3 //!< Source tracing analysis
} EN_QualityType; } EN_QualityType;
/// Water quality source types /// Types of water quality sources
/**
These are the options for EN_SOURCETYPE, the type of external water quality
source assigned to a node. They are used in @ref EN_getnodevalue and @ref EN_setnodevalue.
The EN_SOURCEQUAL property is used in these functions to access a source's strength
and EN_SOURCEPATTERN to access a time pattern applied to the source.
*/
typedef enum { typedef enum {
EN_CONCEN = 0, //!< Concentration inflow source EN_CONCEN = 0, //!< Concentration of any external inflow entering a node
EN_MASS = 1, //!< Mass inflow source EN_MASS = 1, //!< Injects a given mass/minute into a node
EN_SETPOINT = 2, //!< Concentration setpoint source EN_SETPOINT = 2, //!< Sets the concentration leaving a node to a given value
EN_FLOWPACED = 3 //!< Concentration flow paced source EN_FLOWPACED = 3 //!< Adds a given value to the concentration leaving a node
} EN_SourceType; } EN_SourceType;
/// Head loss formulas /// Head loss formula choices
/**
These are the choices for the EN_HEADLOSSFORM option in @ref EN_getoption and
@ref EN_setoption. They are also used for the head loss type argument in @ref EN_init.
Each head loss formula uses a different type of roughness coefficient (EN_ROUGHNESS)
that can be set with @ref EN_setlinkvalue.
*/
typedef enum { typedef enum {
EN_HW = 0, //!< Hazen-Williams EN_HW = 0, //!< Hazen-Williams
EN_DW = 1, //!< Darcy-Weisbach EN_DW = 1, //!< Darcy-Weisbach
EN_CM = 2 //!< Chezy-Manning EN_CM = 2 //!< Chezy-Manning
} EN_HeadLossType; } EN_HeadLossType;
/// Flow units types /// Flow units choices
/**
These choices for flow units are used with @ref EN_getflowunits and @ref EN_setflowunits.
They are also used for the flow units type argument in @ref EN_init. If flow units are
expressed in US Customary units (EN_CFS through EN_AFD) then all other quantities are
in US Customary units. Otherwise they are in metric units.
*/
typedef enum { typedef enum {
EN_CFS = 0, //!< Cubic feet per second EN_CFS = 0, //!< Cubic feet per second
EN_GPM = 1, //!< Gallons per minute EN_GPM = 1, //!< Gallons per minute
@@ -178,39 +252,65 @@ typedef enum {
EN_CMD = 9 //!< Cubic meters per day EN_CMD = 9 //!< Cubic meters per day
} EN_FlowUnits; } EN_FlowUnits;
/// Demand model types /// Types of demand models
/**
These choices for representing consumer demands are used with @ref EN_getdemandmodel
and @ref EN_setdemandmodel.
A demand driven analysis requires that a junction's full demand be supplied
in each time period independent of how much pressure is available. A pressure
driven analysis makes demand be a power function of pressure, up to the point
where the full demand is met.
*/
typedef enum { typedef enum {
EN_DDA = 0, //!< Demand driven analysis EN_DDA = 0, //!< Demand driven analysis
EN_PDA = 1 //!< Pressure driven analysis EN_PDA = 1 //!< Pressure driven analysis
} EN_DemandModel; } EN_DemandModel;
/// Simulation option codes /// Simulation options
/**
These options specify hydraulic convergence criteria, choice of head loss formula, and
several other parameters applied on a network-wide basis. They are accessed using the
@ref EN_getoption and @ref EN_setoption functions.
*/
typedef enum { typedef enum {
EN_TRIALS = 0, //!< Maximum hydraulic trials allowed EN_TRIALS = 0, //!< Maximum hydraulic trials allowed
EN_ACCURACY = 1, //!< Hydraulic convergence accuracy EN_ACCURACY = 1, //!< Maximum total relative flow change for hydraulic convergence
EN_TOLERANCE = 2, //!< Water quality tolerance EN_TOLERANCE = 2, //!< Water quality tolerance
EN_EMITEXPON = 3, //!< Exponent for emitter head loss formula EN_EMITEXPON = 3, //!< Exponent in emitter discharge formula
EN_DEMANDMULT = 4, //!< Global demand multiplier EN_DEMANDMULT = 4, //!< Global demand multiplier
EN_HEADERROR = 5, //!< Maximum allowable head loss error EN_HEADERROR = 5, //!< Maximum head loss error for hydraulic convergence
EN_FLOWCHANGE = 6, //!< Maximum allowable flow change EN_FLOWCHANGE = 6, //!< Maximum flow change for hydraulic convergence
EN_DEFDEMANDPAT = 7, //!< Default demand time pattern EN_DEFDEMANDPAT = 7, //!< Index of the default demand time pattern
EN_HEADLOSSFORM = 8, //!< Head loss formula EN_HEADLOSSFORM = 8, //!< Head loss formula (see @ref EN_HeadLossType)
EN_GLOBALEFFIC = 9, //!< Global pump efficiency EN_GLOBALEFFIC = 9, //!< Global pump efficiency (percent)
EN_GLOBALPRICE = 10, //!< Global energy price per KWH EN_GLOBALPRICE = 10, //!< Global energy price per KWH
EN_GLOBALPATTERN = 11, //!< Global energy price pattern EN_GLOBALPATTERN = 11, //!< Index of a global energy price pattern
EN_DEMANDCHARGE = 12 //!< Energy charge per max. KW usage EN_DEMANDCHARGE = 12 //!< Energy charge per max. KW usage
} EN_Option; } EN_Option;
/// Simple control types /// Types of simple controls
/**
These are the different types of simple (single statement) controls that can be applied
to network links. They are used as an argument to @ref EN_addcontrol,@ref EN_getcontrol,
and @ref EN_setcontrol.
*/
typedef enum { typedef enum {
EN_LOWLEVEL = 0, //!< Act when level drops below a setpoint EN_LOWLEVEL = 0, //!< Act when pressure or tank level drops below a setpoint
EN_HILEVEL = 1, //!< Act when level rises above a setpoint EN_HILEVEL = 1, //!< Act when pressure or tank level rises above a setpoint
EN_TIMER = 2, //!< Act at a prescribed elapsed amount of time EN_TIMER = 2, //!< Act at a prescribed elapsed amount of time
EN_TIMEOFDAY = 3 //!< Act at a particular time of day EN_TIMEOFDAY = 3 //!< Act at a particular time of day
} EN_ControlType; } EN_ControlType;
/// Reporting statistic types /// Reporting statistic choices
/**
These options determine what kind of statistical post-processing should be done on
the time series of simulation results generated before they are reported using
@ref EN_report. An option can be chosen by using `STATISTIC option` as the argument
to @ref EN_setreport.
*/
typedef enum { typedef enum {
EN_SERIES = 0, //!< Report all time series points
EN_AVERAGE = 1, //!< Report average value over simulation period EN_AVERAGE = 1, //!< Report average value over simulation period
EN_MINIMUM = 2, //!< Report minimum value over simulation period EN_MINIMUM = 2, //!< Report minimum value over simulation period
EN_MAXIMUM = 3, //!< Report maximum value over simulation period EN_MAXIMUM = 3, //!< Report maximum value over simulation period
@@ -218,6 +318,11 @@ typedef enum {
} EN_StatisticType; } EN_StatisticType;
/// Tank mixing models /// Tank mixing models
/**
These are the different types of models that describe water quality mixing in storage tanks.
The choice of model is accessed with the EN_MIXMODEL property of a Tank node using
@ref EN_getnodevalue and @ref EN_setnodevalue.
*/
typedef enum { typedef enum {
EN_MIX1 = 0, //!< Complete mix model EN_MIX1 = 0, //!< Complete mix model
EN_MIX2 = 1, //!< 2-compartment model EN_MIX2 = 1, //!< 2-compartment model
@@ -226,14 +331,20 @@ typedef enum {
} EN_MixingModel; } EN_MixingModel;
/// Hydraulic initialization options /// Hydraulic initialization options
/**
These options are used to initialize a new hydraulic analysis when @ref EN_initH is called.
*/
typedef enum { typedef enum {
EN_NOSAVE = 0, //!< Don't save hydraulics; don't re-initialize flows EN_NOSAVE = 0, //!< Don't save hydraulics; don't re-initialize flows
EN_SAVE = 1, //!< Save hydraulics to file, don't re-initialize flows EN_SAVE = 1, //!< Save hydraulics to file, don't re-initialize flows
EN_INITFLOW = 10, //!< Don't save hydraulics; re-initialize flows EN_INITFLOW = 10, //!< Don't save hydraulics; re-initialize flows
EN_SAVE_AND_INIT = 11 //!< Save hydraulics; re-initialize flows EN_SAVE_AND_INIT = 11 //!< Save hydraulics; re-initialize flows
} EN_SaveOption; } EN_InitHydOption;
/// Pump curve types /// Types of pump curves
/**
@ref EN_getpumptype returns one of these values when it is called.
*/
typedef enum { typedef enum {
EN_CONST_HP = 0, //!< Constant horsepower EN_CONST_HP = 0, //!< Constant horsepower
EN_POWER_FUNC = 1, //!< Power function EN_POWER_FUNC = 1, //!< Power function
@@ -241,36 +352,49 @@ typedef enum {
EN_NOCURVE = 3 //!< No curve EN_NOCURVE = 3 //!< No curve
} EN_PumpType; } EN_PumpType;
/// Data curve types /// Types of data curves
/**
These are the different types of physical relationships that a data curve could
represent as returned by calling @ref EN_getcurvetype.
*/
typedef enum { typedef enum {
EN_VOLUME_CURVE = 0, //!< Tank volume curve EN_VOLUME_CURVE = 0, //!< Tank volume v. depth curve
EN_PUMP_CURVE = 1, //!< Pump head curve EN_PUMP_CURVE = 1, //!< Pump head v. flow curve
EN_EFFIC_CURVE = 2, //!< Pump efficiency curve EN_EFFIC_CURVE = 2, //!< Pump efficiency v. flow curve
EN_HLOSS_CURVE = 3, //!< Valve head loss curve EN_HLOSS_CURVE = 3, //!< Valve head loss v. flow curve
EN_GENERIC_CURVE = 4 //!< Generic curve EN_GENERIC_CURVE = 4 //!< Generic curve
} EN_CurveType; } EN_CurveType;
/// Deletion action codes /// Deletion action codes
/**
These codes are used in @ref EN_deletenode and @ref EN_deletelink to indicate what action
should be taken if the node or link being deleted appears in any simple or rule-based
controls.
*/
typedef enum { typedef enum {
EN_UNCONDITIONAL = 0, //!< Delete all controls that contain object EN_UNCONDITIONAL = 0, //!< Delete all controls that contain object
EN_CONDITIONAL = 1 //!< Cancel object deletion if contained in controls EN_CONDITIONAL = 1 //!< Cancel object deletion if contained in controls
} EN_ActionCodeType; } EN_ActionCodeType;
/// Options for reporting on the status of the hydraulic solver at each time period /// Status reporting levels
/**
These choices specify the level of status reporting written to a project's report
file during a hydraulic analysis. The level is set using the @ref EN_setstatusreport function.
*/
typedef enum { typedef enum {
EN_NO_REPORT = 0, //!< No status reporting EN_NO_REPORT = 0, //!< No status reporting
EN_NORMAL_REPORT = 1, //!< Normal level of status reporting EN_NORMAL_REPORT = 1, //!< Normal level of status reporting
EN_FULL_REPORT = 2 //!< Full level of status reporting EN_FULL_REPORT = 2 //!< Full level of status reporting
} EN_StatusReport; } EN_StatusReport;
/// Codes for objects referred to in the clauses of rule-based controls /// Network objects used in rule-based controls
typedef enum { typedef enum {
EN_R_NODE = 6, //!< Clause refers to a node EN_R_NODE = 6, //!< Clause refers to a node
EN_R_LINK = 7, //!< Clause refers to a link EN_R_LINK = 7, //!< Clause refers to a link
EN_R_SYSTEM = 8 //!< Clause refers to a system parameter (e.g., time) EN_R_SYSTEM = 8 //!< Clause refers to a system parameter (e.g., time)
} EN_RuleObject; } EN_RuleObject;
/// Codes for variables used in the clauses of rule-based controls /// Object variables used in rule-based controls
typedef enum { typedef enum {
EN_R_DEMAND = 0, //!< Nodal demand EN_R_DEMAND = 0, //!< Nodal demand
EN_R_HEAD = 1, //!< Nodal hydraulic head EN_R_HEAD = 1, //!< Nodal hydraulic head
@@ -287,7 +411,7 @@ typedef enum {
EN_R_DRAINTIME = 12 //!< Time to drain a tank EN_R_DRAINTIME = 12 //!< Time to drain a tank
} EN_RuleVariable; } EN_RuleVariable;
/// Comparison operators used in the premises of rule-based controls /// Comparison operators used in rule-based controls
typedef enum { typedef enum {
EN_R_EQ = 0, //!< Equal to EN_R_EQ = 0, //!< Equal to
EN_R_NE = 1, //!< Not equal EN_R_NE = 1, //!< Not equal
@@ -301,7 +425,7 @@ typedef enum {
EN_R_ABOVE = 9 //!< Is above EN_R_ABOVE = 9 //!< Is above
} EN_RuleOperator; } EN_RuleOperator;
/// Status codes used in the clauses of rule-based controls /// Link status codes used in rule-based controls
typedef enum { typedef enum {
EN_R_IS_OPEN = 1, //!< Link is open EN_R_IS_OPEN = 1, //!< Link is open
EN_R_IS_CLOSED = 2, //!< Link is closed EN_R_IS_CLOSED = 2, //!< Link is closed

View File

@@ -123,8 +123,8 @@ int DLLEXPORT EN_init(EN_Project p, const char *rptFile, const char *outFile,
/*---------------------------------------------------------------- /*----------------------------------------------------------------
** Input: rptFile = name of report file ** Input: rptFile = name of report file
** outFile = name of binary output file ** outFile = name of binary output file
** unitsType = type of flow units (see EN_FlowUnits) ** unitsType = type of flow units (see FlowUnitsType)
** headLossType = type of head loss formula (see EN_HeadLossType) ** headLossType = type of head loss formula (see HeadLossType)
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: initializes an EPANET project that isn't opened with ** Purpose: initializes an EPANET project that isn't opened with
@@ -255,7 +255,7 @@ int DLLEXPORT EN_close(EN_Project p)
** Input: none ** Input: none
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: frees all memory & files used by EPANET ** Purpose: frees all memory & files used by a project
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -367,7 +367,7 @@ int DLLEXPORT EN_saveH(EN_Project p)
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
char tmpflag; int tmpflag;
int errcode; int errcode;
// Check if hydraulic results exist // Check if hydraulic results exist
@@ -392,7 +392,7 @@ int DLLEXPORT EN_openH(EN_Project p)
** Input: none ** Input: none
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: opens EPANET's hydraulic solver ** Purpose: opens a project's hydraulic solver
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -421,7 +421,7 @@ int DLLEXPORT EN_initH(EN_Project p, int initFlag)
** results should be saved to file (1) or not (0) ** results should be saved to file (1) or not (0)
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: initializes EPANET's hydraulic solver ** Purpose: initializes a project's hydraulic solver
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -500,7 +500,7 @@ int DLLEXPORT EN_closeH(EN_Project p)
** Input: none ** Input: none
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: closes EPANET's hydraulic solver ** Purpose: closes a project's hydraulic solver
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -516,7 +516,7 @@ int DLLEXPORT EN_savehydfile(EN_Project p, char *filename)
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: saves results from a scratch hydraulics file to a ** Purpose: saves results from a scratch hydraulics file to a
** permanent one. ** permanent one
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -543,8 +543,8 @@ int DLLEXPORT EN_usehydfile(EN_Project p, char *filename)
** Input: filename = name of previously saved hydraulics file ** Input: filename = name of previously saved hydraulics file
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: uses contents of a previous saved hydraulics file to ** Purpose: uses contents of a previously saved hydraulics file to
** run a water quality analysis. ** run a water quality analysis
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -626,7 +626,7 @@ int DLLEXPORT EN_openQ(EN_Project p)
** Input: none ** Input: none
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: opens EPANET's water quality solver ** Purpose: opens a project's water quality solver
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -694,7 +694,7 @@ int DLLEXPORT EN_nextQ(EN_Project p, long *tStep)
** Output: tStep = time step over which water quality is updated (sec) ** Output: tStep = time step over which water quality is updated (sec)
** Returns: error code ** Returns: error code
** Purpose: updates water quality throughout the network until ** Purpose: updates water quality throughout the network until
** next hydraulic event occurs. ** next hydraulic event occurs
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -717,7 +717,7 @@ int DLLEXPORT EN_stepQ(EN_Project p, long *timeLeft)
** Output: timeLeft = amount of simulation time remaining (sec) ** Output: timeLeft = amount of simulation time remaining (sec)
** Returns: error code ** Returns: error code
** Purpose: updates water quality throughout the network over ** Purpose: updates water quality throughout the network over
** fixed time step. ** fixed time step
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -739,7 +739,7 @@ int DLLEXPORT EN_closeQ(EN_Project p)
** Input: none ** Input: none
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: closes EPANET's water quality solver ** Purpose: closes a project's water quality solver
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -760,7 +760,7 @@ int DLLEXPORT EN_writeline(EN_Project p, char *line)
** Input: line = line of text ** Input: line = line of text
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: write a line of text to the project's report file ** Purpose: write a line of text to a project's report file
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -774,7 +774,7 @@ int DLLEXPORT EN_report(EN_Project p)
** Input: none ** Input: none
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: writes formatted simulation results to the project's ** Purpose: writes formatted simulation results to a project's
** report file ** report file
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
@@ -858,11 +858,11 @@ int DLLEXPORT EN_getversion(int *version)
** Input: none ** Input: none
** Output: version = version number of the source code ** Output: version = version number of the source code
** Returns: error code (should always be 0) ** Returns: error code (should always be 0)
** Purpose: retrieves a number assigned to the most recent ** Purpose: retrieves the toolkit API version number
** update of the source code. This number, set by the **
** constant CODEVERSION found in TYPES.H, is to be ** The version number is set by the constant CODEVERSION found in
** interpreted with implied decimals, i.e., ** TYPES.H and is to be interpreted with implied decimals, i.e.,
** "20100" == "2(.)01(.)00" ** "20100" == "2(.)01(.)00".
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -875,7 +875,7 @@ int DLLEXPORT EN_getcount(EN_Project p, int object, int *count)
** Input: object = type of object to count (see EN_CountType) ** Input: object = type of object to count (see EN_CountType)
** Output: count = number of objects of the specified type ** Output: count = number of objects of the specified type
** Returns: error code ** Returns: error code
** Purpose: Retrieves number of network objects of a given type. ** Purpose: Retrieves number of network objects of a given type
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -1283,7 +1283,7 @@ int DLLEXPORT EN_setflowunits(EN_Project p, int units)
int DLLEXPORT EN_gettimeparam(EN_Project p, int param, long *value) int DLLEXPORT EN_gettimeparam(EN_Project p, int param, long *value)
/*---------------------------------------------------------------- /*----------------------------------------------------------------
** Input: param = time parameter code (see EN_TimeProperty) ** Input: param = time parameter code (see EN_TimeParameter)
** Output: value = time parameter value ** Output: value = time parameter value
** Returns: error code ** Returns: error code
** Purpose: retrieves the value of a time parameter ** Purpose: retrieves the value of a time parameter
@@ -1297,7 +1297,7 @@ int DLLEXPORT EN_gettimeparam(EN_Project p, int param, long *value)
*value = 0; *value = 0;
if (!p->Openflag) return 102; if (!p->Openflag) return 102;
if (param < EN_DURATION || param > EN_NEXTEVENTIDX) return 251; if (param < EN_DURATION || param > EN_NEXTEVENTTANK) return 251;
switch (param) switch (param)
{ {
case EN_DURATION: case EN_DURATION:
@@ -1341,7 +1341,7 @@ int DLLEXPORT EN_gettimeparam(EN_Project p, int param, long *value)
// or the time to next full/empty tank // or the time to next full/empty tank
tanktimestep(p, value); tanktimestep(p, value);
break; break;
case EN_NEXTEVENTIDX: case EN_NEXTEVENTTANK:
*value = time->Hstep; *value = time->Hstep;
i = tanktimestep(p, value); i = tanktimestep(p, value);
*value = i; *value = i;
@@ -1352,7 +1352,7 @@ int DLLEXPORT EN_gettimeparam(EN_Project p, int param, long *value)
int DLLEXPORT EN_settimeparam(EN_Project p, int param, long value) int DLLEXPORT EN_settimeparam(EN_Project p, int param, long value)
/*---------------------------------------------------------------- /*----------------------------------------------------------------
** Input: param = time parameter code (see EN_TimeProperty) ** Input: param = time parameter code (see EN_TimeParameter)
** value = time parameter value ** value = time parameter value
** Output: none ** Output: none
** Returns: error code ** Returns: error code
@@ -1493,7 +1493,7 @@ int DLLEXPORT EN_setqualtype(EN_Project p, int qualType, char *chemName,
** Input: qualType = type of quality analysis to run (see EN_QualityType) ** Input: qualType = type of quality analysis to run (see EN_QualityType)
** chemname = name of chemical constituent ** chemname = name of chemical constituent
** chemunits = concentration units of constituent ** chemunits = concentration units of constituent
** tracenode = index of node being traced (if applicable) ** tracenode = ID name of node being traced (if applicable)
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: sets water quality analysis options ** Purpose: sets water quality analysis options
@@ -1701,13 +1701,13 @@ int DLLEXPORT EN_deletenode(EN_Project p, int index, int actionCode)
** its links appear in a control and returns an error code ** its links appear in a control and returns an error code
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: deletes a node from a project. ** Purpose: deletes a node from a project
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
Network *net = &p->network; Network *net = &p->network;
int i, nodeType, tankindex, numControls = 0; int i, nodeType, tankindex;
Snode *node; Snode *node;
Pdemand demand, nextdemand; Pdemand demand, nextdemand;
Psource source; Psource source;
@@ -2350,7 +2350,7 @@ int DLLEXPORT EN_setjuncdata(EN_Project p, int index, double elev,
** dmndpat = name of primary demand time pattern ** dmndpat = name of primary demand time pattern
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: sets several properties for a junction node. ** Purpose: sets several properties for a junction node
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -2406,7 +2406,7 @@ int DLLEXPORT EN_settankdata(EN_Project p, int index, double elev,
** volCurve = name of curve for volume v. level ** volCurve = name of curve for volume v. level
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: sets several properties for a tank node. ** Purpose: sets several properties for a tank node
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -2415,7 +2415,6 @@ int DLLEXPORT EN_settankdata(EN_Project p, int index, double elev,
int i, j, n, curveIndex = 0; int i, j, n, curveIndex = 0;
double area, elevation = elev; double area, elevation = elev;
double *Ucf = p->Ucf; double *Ucf = p->Ucf;
Snode *Node = net->Node;
Stank *Tank = net->Tank; Stank *Tank = net->Tank;
Scurve *curve; Scurve *curve;
@@ -2823,8 +2822,8 @@ int DLLEXPORT EN_addlink(EN_Project p, char *id, int linkType,
link = &net->Link[n]; link = &net->Link[n];
strncpy(link->ID, id, MAXID); strncpy(link->ID, id, MAXID);
if (linkType <= EN_PIPE) net->Npipes++; if (linkType <= PIPE) net->Npipes++;
else if (linkType == EN_PUMP) else if (linkType == PUMP)
{ {
// Grow pump array to accomodate the new link // Grow pump array to accomodate the new link
net->Npumps++; net->Npumps++;
@@ -2860,13 +2859,13 @@ int DLLEXPORT EN_addlink(EN_Project p, char *id, int linkType,
link->N2 = n2; link->N2 = n2;
link->Status = OPEN; link->Status = OPEN;
if (linkType == EN_PUMP) if (linkType == PUMP)
{ {
link->Kc = 1.0; // Speed factor link->Kc = 1.0; // Speed factor
link->Km = 0.0; // Horsepower link->Km = 0.0; // Horsepower
link->Len = 0.0; link->Len = 0.0;
} }
else if (linkType <= EN_PIPE) // pipe or cvpipe else if (linkType <= PIPE) // pipe or cvpipe
{ {
link->Diam = 10 / p->Ucf[DIAM]; link->Diam = 10 / p->Ucf[DIAM];
link->Kc = 100; // Rough. coeff link->Kc = 100; // Rough. coeff
@@ -2901,7 +2900,7 @@ int DLLEXPORT EN_deletelink(EN_Project p, int index, int actionCode)
** in a control and returns an error code ** in a control and returns an error code
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: deletes a link from a project. ** Purpose: deletes a link from a project
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -2918,7 +2917,7 @@ int DLLEXPORT EN_deletelink(EN_Project p, int index, int actionCode)
if (p->hydraul.OpenHflag || p->quality.OpenQflag) return 262; if (p->hydraul.OpenHflag || p->quality.OpenQflag) return 262;
// Check that link exists // Check that link exists
if (index <= 0 || index > net->Nlinks) 204; if (index <= 0 || index > net->Nlinks) return 204;
if (actionCode < EN_UNCONDITIONAL || actionCode > EN_CONDITIONAL) return 251; if (actionCode < EN_UNCONDITIONAL || actionCode > EN_CONDITIONAL) return 251;
// Deletion will be cancelled if link appears in any controls // Deletion will be cancelled if link appears in any controls
@@ -2964,7 +2963,7 @@ int DLLEXPORT EN_deletelink(EN_Project p, int index, int actionCode)
net->Npumps--; net->Npumps--;
} }
// Delete any valve (linkType > EN_PUMP) associated with the deleted link // Delete any valve (linkType > PUMP) associated with the deleted link
if (linkType > PUMP) if (linkType > PUMP)
{ {
valveindex = findvalve(net, index); valveindex = findvalve(net, index);
@@ -3235,7 +3234,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
switch (property) switch (property)
{ {
case EN_DIAMETER: case EN_DIAMETER:
if (Link[index].Type == EN_PUMP) v = 0.0; if (Link[index].Type == PUMP) v = 0.0;
else v = Link[index].Diam * Ucf[DIAM]; else v = Link[index].Diam * Ucf[DIAM];
break; break;
@@ -3244,7 +3243,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
break; break;
case EN_ROUGHNESS: case EN_ROUGHNESS:
if (Link[index].Type <= EN_PIPE) if (Link[index].Type <= PIPE)
{ {
if (hyd->Formflag == DW) v = Link[index].Kc * (1000.0 * Ucf[ELEV]); if (hyd->Formflag == DW) v = Link[index].Kc * (1000.0 * Ucf[ELEV]);
else v = Link[index].Kc; else v = Link[index].Kc;
@@ -3253,7 +3252,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
break; break;
case EN_MINORLOSS: case EN_MINORLOSS:
if (Link[index].Type != EN_PUMP) if (Link[index].Type != PUMP)
{ {
v = Link[index].Km; v = Link[index].Km;
v *= (SQR(Link[index].Diam) * SQR(Link[index].Diam) / 0.02517); v *= (SQR(Link[index].Diam) * SQR(Link[index].Diam) / 0.02517);
@@ -3267,19 +3266,19 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
break; break;
case EN_INITSETTING: case EN_INITSETTING:
if (Link[index].Type == EN_PIPE || Link[index].Type == EN_CVPIPE) if (Link[index].Type == PIPE || Link[index].Type == CVPIPE)
{ {
return EN_getlinkvalue(p, index, EN_ROUGHNESS, value); return EN_getlinkvalue(p, index, EN_ROUGHNESS, value);
} }
v = Link[index].Kc; v = Link[index].Kc;
switch (Link[index].Type) switch (Link[index].Type)
{ {
case EN_PRV: case PRV:
case EN_PSV: case PSV:
case EN_PBV: case PBV:
v *= Ucf[PRESSURE]; v *= Ucf[PRESSURE];
break; break;
case EN_FCV: case FCV:
v *= Ucf[FLOW]; v *= Ucf[FLOW];
default: default:
break; break;
@@ -3300,7 +3299,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
break; break;
case EN_VELOCITY: case EN_VELOCITY:
if (Link[index].Type == EN_PUMP) v = 0.0; if (Link[index].Type == PUMP) v = 0.0;
else if (hyd->LinkStatus[index] <= CLOSED) v = 0.0; else if (hyd->LinkStatus[index] <= CLOSED) v = 0.0;
else else
{ {
@@ -3315,7 +3314,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
else else
{ {
h = hyd->NodeHead[Link[index].N1] - hyd->NodeHead[Link[index].N2]; h = hyd->NodeHead[Link[index].N1] - hyd->NodeHead[Link[index].N2];
if (Link[index].Type != EN_PUMP) h = ABS(h); if (Link[index].Type != PUMP) h = ABS(h);
v = h * Ucf[HEADLOSS]; v = h * Ucf[HEADLOSS];
} }
break; break;
@@ -3326,7 +3325,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
break; break;
case EN_SETTING: case EN_SETTING:
if (Link[index].Type == EN_PIPE || Link[index].Type == EN_CVPIPE) if (Link[index].Type == PIPE || Link[index].Type == CVPIPE)
{ {
return EN_getlinkvalue(p, index, EN_ROUGHNESS, value); return EN_getlinkvalue(p, index, EN_ROUGHNESS, value);
} }
@@ -3334,12 +3333,12 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
else v = LinkSetting[index]; else v = LinkSetting[index];
switch (Link[index].Type) switch (Link[index].Type)
{ {
case EN_PRV: case PRV:
case EN_PSV: case PSV:
case EN_PBV: case PBV:
v *= Ucf[PRESSURE]; v *= Ucf[PRESSURE];
break; break;
case EN_FCV: case FCV:
v *= Ucf[FLOW]; v *= Ucf[FLOW];
default: default:
break; break;
@@ -3355,7 +3354,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
break; break;
case EN_LINKPATTERN: case EN_LINKPATTERN:
if (Link[index].Type == EN_PUMP) if (Link[index].Type == PUMP)
{ {
v = (double)Pump[findpump(&p->network, index)].Upat; v = (double)Pump[findpump(&p->network, index)].Upat;
} }
@@ -3364,7 +3363,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
case EN_PUMP_STATE: case EN_PUMP_STATE:
v = hyd->LinkStatus[index]; v = hyd->LinkStatus[index];
if (Link[index].Type == EN_PUMP) if (Link[index].Type == PUMP)
{ {
pmp = findpump(net, index); pmp = findpump(net, index);
if (hyd->LinkStatus[index] >= OPEN) if (hyd->LinkStatus[index] >= OPEN)
@@ -3384,7 +3383,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
case EN_PUMP_POWER: case EN_PUMP_POWER:
v = 0; v = 0;
if (Link[index].Type == EN_PUMP) if (Link[index].Type == PUMP)
{ {
pmp = findpump(net, index); pmp = findpump(net, index);
if (Pump[pmp].Ptype == CONST_HP) v = Link[index].Km; // Power in HP or KW if (Pump[pmp].Ptype == CONST_HP) v = Link[index].Km; // Power in HP or KW
@@ -3392,28 +3391,28 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val
break; break;
case EN_PUMP_HCURVE: case EN_PUMP_HCURVE:
if (Link[index].Type == EN_PUMP) if (Link[index].Type == PUMP)
{ {
v = (double)Pump[findpump(&p->network, index)].Hcurve; v = (double)Pump[findpump(&p->network, index)].Hcurve;
} }
break; break;
case EN_PUMP_ECURVE: case EN_PUMP_ECURVE:
if (Link[index].Type == EN_PUMP) if (Link[index].Type == PUMP)
{ {
v = (double)Pump[findpump(&p->network, index)].Ecurve; v = (double)Pump[findpump(&p->network, index)].Ecurve;
} }
break; break;
case EN_PUMP_ECOST: case EN_PUMP_ECOST:
if (Link[index].Type == EN_PUMP) if (Link[index].Type == PUMP)
{ {
v = (double)Pump[findpump(&p->network, index)].Ecost; v = (double)Pump[findpump(&p->network, index)].Ecost;
} }
break; break;
case EN_PUMP_EPAT: case EN_PUMP_EPAT:
if (Link[index].Type == EN_PUMP) if (Link[index].Type == PUMP)
{ {
v = (double)Pump[findpump(&p->network, index)].Epat; v = (double)Pump[findpump(&p->network, index)].Epat;
} }
@@ -3453,7 +3452,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
switch (property) switch (property)
{ {
case EN_DIAMETER: case EN_DIAMETER:
if (Link[index].Type != EN_PUMP) if (Link[index].Type != PUMP)
{ {
if (value <= 0.0) return 211; if (value <= 0.0) return 211;
value /= Ucf[DIAM]; // Convert to feet value /= Ucf[DIAM]; // Convert to feet
@@ -3465,7 +3464,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
break; break;
case EN_LENGTH: case EN_LENGTH:
if (Link[index].Type <= EN_PIPE) if (Link[index].Type <= PIPE)
{ {
if (value <= 0.0) return 211; if (value <= 0.0) return 211;
Link[index].Len = value / Ucf[ELEV]; Link[index].Len = value / Ucf[ELEV];
@@ -3474,7 +3473,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
break; break;
case EN_ROUGHNESS: case EN_ROUGHNESS:
if (Link[index].Type <= EN_PIPE) if (Link[index].Type <= PIPE)
{ {
if (value <= 0.0) return 211; if (value <= 0.0) return 211;
Link[index].Kc = value; Link[index].Kc = value;
@@ -3484,7 +3483,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
break; break;
case EN_MINORLOSS: case EN_MINORLOSS:
if (Link[index].Type != EN_PUMP) if (Link[index].Type != PUMP)
{ {
if (value <= 0.0) return 211; if (value <= 0.0) return 211;
Link[index].Km = 0.02517 * value / SQR(Link[index].Diam) / Link[index].Km = 0.02517 * value / SQR(Link[index].Diam) /
@@ -3495,7 +3494,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
case EN_INITSTATUS: case EN_INITSTATUS:
case EN_STATUS: case EN_STATUS:
// Cannot set status for a check valve // Cannot set status for a check valve
if (Link[index].Type == EN_CVPIPE) return 207; if (Link[index].Type == CVPIPE) return 207;
s = (char)ROUND(value); s = (char)ROUND(value);
if (s < 0 || s > 1) return 211; if (s < 0 || s > 1) return 211;
if (property == EN_INITSTATUS) if (property == EN_INITSTATUS)
@@ -3511,7 +3510,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
case EN_INITSETTING: case EN_INITSETTING:
case EN_SETTING: case EN_SETTING:
if (value < 0.0) return 211; if (value < 0.0) return 211;
if (Link[index].Type == EN_PIPE || Link[index].Type == EN_CVPIPE) if (Link[index].Type == PIPE || Link[index].Type == CVPIPE)
{ {
return EN_setlinkvalue(p, index, EN_ROUGHNESS, value); return EN_setlinkvalue(p, index, EN_ROUGHNESS, value);
} }
@@ -3519,19 +3518,19 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
{ {
switch (Link[index].Type) switch (Link[index].Type)
{ {
case EN_PUMP: case PUMP:
break; break;
case EN_PRV: case PRV:
case EN_PSV: case PSV:
case EN_PBV: case PBV:
value /= Ucf[PRESSURE]; value /= Ucf[PRESSURE];
break; break;
case EN_FCV: case FCV:
value /= Ucf[FLOW]; value /= Ucf[FLOW];
break; break;
case EN_TCV: case TCV:
break; break;
case EN_GPV: case GPV:
return 207; // Cannot modify setting for GPV return 207; // Cannot modify setting for GPV
default: default:
return 0; return 0;
@@ -3549,7 +3548,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
break; break;
case EN_KBULK: case EN_KBULK:
if (Link[index].Type <= EN_PIPE) if (Link[index].Type <= PIPE)
{ {
Link[index].Kb = value / SECperDAY; Link[index].Kb = value / SECperDAY;
qual->Reactflag = 1; qual->Reactflag = 1;
@@ -3557,7 +3556,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
break; break;
case EN_KWALL: case EN_KWALL:
if (Link[index].Type <= EN_PIPE) if (Link[index].Type <= PIPE)
{ {
Link[index].Kw = value / SECperDAY; Link[index].Kw = value / SECperDAY;
qual->Reactflag = 1; qual->Reactflag = 1;
@@ -3565,7 +3564,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
break; break;
case EN_LINKPATTERN: case EN_LINKPATTERN:
if (Link[index].Type == EN_PUMP) if (Link[index].Type == PUMP)
{ {
patIndex = ROUND(value); patIndex = ROUND(value);
if (patIndex <= 0 || patIndex > net->Npats) return 205; if (patIndex <= 0 || patIndex > net->Npats) return 205;
@@ -3575,7 +3574,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
break; break;
case EN_PUMP_POWER: case EN_PUMP_POWER:
if (Link[index].Type == EN_PUMP) if (Link[index].Type == PUMP)
{ {
if (value <= 0.0) return 211; if (value <= 0.0) return 211;
pumpIndex = findpump(&p->network, index); pumpIndex = findpump(&p->network, index);
@@ -3591,14 +3590,14 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
break; break;
case EN_PUMP_HCURVE: case EN_PUMP_HCURVE:
if (Link[index].Type == EN_PUMP) if (Link[index].Type == PUMP)
{ {
return EN_setheadcurveindex(p, index, ROUND(value)); return EN_setheadcurveindex(p, index, ROUND(value));
} }
break; break;
case EN_PUMP_ECURVE: case EN_PUMP_ECURVE:
if (Link[index].Type == EN_PUMP) if (Link[index].Type == PUMP)
{ {
curveIndex = ROUND(value); curveIndex = ROUND(value);
if (curveIndex <= 0 || curveIndex > net->Ncurves) return 205; if (curveIndex <= 0 || curveIndex > net->Ncurves) return 205;
@@ -3608,7 +3607,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
break; break;
case EN_PUMP_ECOST: case EN_PUMP_ECOST:
if (Link[index].Type == EN_PUMP) if (Link[index].Type == PUMP)
{ {
if (value < 0.0) return 211; if (value < 0.0) return 211;
pumpIndex = findpump(&p->network, index); pumpIndex = findpump(&p->network, index);
@@ -3617,7 +3616,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
break; break;
case EN_PUMP_EPAT: case EN_PUMP_EPAT:
if (Link[index].Type == EN_PUMP) if (Link[index].Type == PUMP)
{ {
patIndex = ROUND(value); patIndex = ROUND(value);
if (patIndex <= 0 || patIndex > net->Npats) return 205; if (patIndex <= 0 || patIndex > net->Npats) return 205;
@@ -3642,7 +3641,7 @@ int DLLEXPORT EN_setpipedata(EN_Project p, int index, double length,
** mloss = minor loss coefficient ** mloss = minor loss coefficient
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: sets several properties for a pipe link. ** Purpose: sets several properties for a pipe link
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -3655,7 +3654,7 @@ int DLLEXPORT EN_setpipedata(EN_Project p, int index, double length,
// Check that pipe exists // Check that pipe exists
if (!p->Openflag) return 102; if (!p->Openflag) return 102;
if (index <= 0 || index > net->Nlinks) return 204; if (index <= 0 || index > net->Nlinks) return 204;
if (Link[index].Type > EN_PIPE) return 0; if (Link[index].Type > PIPE) return 0;
// Check for valid parameters // Check for valid parameters
if (length <= 0.0 || diam <= 0.0 || rough <= 0.0 || mloss < 0.0) return 211; if (length <= 0.0 || diam <= 0.0 || rough <= 0.0 || mloss < 0.0) return 211;
@@ -3698,7 +3697,7 @@ int DLLEXPORT EN_getpumptype(EN_Project p, int linkIndex, int *pumpType)
*pumpType = -1; *pumpType = -1;
if (!p->Openflag) return 102; if (!p->Openflag) return 102;
if (linkIndex < 1 || linkIndex > Nlinks) return 204; if (linkIndex < 1 || linkIndex > Nlinks) return 204;
if (EN_PUMP != Link[linkIndex].Type) return 216; if (PUMP != Link[linkIndex].Type) return 216;
*pumpType = Pump[findpump(&p->network, linkIndex)].Ptype; *pumpType = Pump[findpump(&p->network, linkIndex)].Ptype;
return 0; return 0;
} }
@@ -3721,7 +3720,7 @@ int DLLEXPORT EN_getheadcurveindex(EN_Project p, int linkIndex, int *curveIndex)
*curveIndex = 0; *curveIndex = 0;
if (!p->Openflag) return 102; if (!p->Openflag) return 102;
if (linkIndex < 1 || linkIndex > Nlinks) return 204; if (linkIndex < 1 || linkIndex > Nlinks) return 204;
if (EN_PUMP != Link[linkIndex].Type) return 216; if (PUMP != Link[linkIndex].Type) return 216;
*curveIndex = Pump[findpump(net, linkIndex)].Hcurve; *curveIndex = Pump[findpump(net, linkIndex)].Hcurve;
return 0; return 0;
} }
@@ -3738,9 +3737,6 @@ int DLLEXPORT EN_setheadcurveindex(EN_Project p, int linkIndex, int curveIndex)
{ {
Network *net = &p->network; Network *net = &p->network;
Slink *Link = net->Link;
const int Nlinks = net->Nlinks;
const int Ncurves = net->Ncurves;
double *Ucf = p->Ucf; double *Ucf = p->Ucf;
int pumpIndex; int pumpIndex;
Spump *pump; Spump *pump;
@@ -3748,7 +3744,7 @@ int DLLEXPORT EN_setheadcurveindex(EN_Project p, int linkIndex, int curveIndex)
// Check for valid parameters // Check for valid parameters
if (!p->Openflag) return 102; if (!p->Openflag) return 102;
if (linkIndex < 1 || linkIndex > net->Nlinks) return 204; if (linkIndex < 1 || linkIndex > net->Nlinks) return 204;
if (EN_PUMP != net->Link[linkIndex].Type) return 0; if (PUMP != net->Link[linkIndex].Type) return 0;
if (curveIndex <= 0 || curveIndex > net->Ncurves) return 206; if (curveIndex <= 0 || curveIndex > net->Ncurves) return 206;
// Assign the new curve to the pump // Assign the new curve to the pump
@@ -4275,7 +4271,7 @@ int DLLEXPORT EN_addcontrol(EN_Project p, int type, int linkIndex, double settin
if (linkIndex <= 0 || linkIndex > net->Nlinks) return 204; if (linkIndex <= 0 || linkIndex > net->Nlinks) return 204;
// Cannot control check valve // Cannot control check valve
if (net->Link[linkIndex].Type == EN_CVPIPE) return 207; if (net->Link[linkIndex].Type == CVPIPE) return 207;
// Check for valid parameters // Check for valid parameters
if (type < 0 || type > EN_TIMEOFDAY) return 251; if (type < 0 || type > EN_TIMEOFDAY) return 251;
@@ -4289,22 +4285,22 @@ int DLLEXPORT EN_addcontrol(EN_Project p, int type, int linkIndex, double settin
// Adjust units of control parameters // Adjust units of control parameters
switch (net->Link[linkIndex].Type) switch (net->Link[linkIndex].Type)
{ {
case EN_PRV: case PRV:
case EN_PSV: case PSV:
case EN_PBV: case PBV:
s /= Ucf[PRESSURE]; s /= Ucf[PRESSURE];
break; break;
case EN_FCV: case FCV:
s /= Ucf[FLOW]; s /= Ucf[FLOW];
break; break;
case EN_GPV: case GPV:
if (s == 0.0) status = CLOSED; if (s == 0.0) status = CLOSED;
else if (s == 1.0) status = OPEN; else if (s == 1.0) status = OPEN;
else return 202; else return 202;
s = net->Link[linkIndex].Kc; s = net->Link[linkIndex].Kc;
break; break;
case EN_PIPE: case PIPE:
case EN_PUMP: case PUMP:
status = OPEN; status = OPEN;
if (s == 0.0) status = CLOSED; if (s == 0.0) status = CLOSED;
default: default:
@@ -4407,12 +4403,12 @@ int DLLEXPORT EN_getcontrol(EN_Project p, int index, int *type, int *linkIndex,
{ {
switch (net->Link[*linkIndex].Type) switch (net->Link[*linkIndex].Type)
{ {
case EN_PRV: case PRV:
case EN_PSV: case PSV:
case EN_PBV: case PBV:
s *= Ucf[PRESSURE]; s *= Ucf[PRESSURE];
break; break;
case EN_FCV: case FCV:
s *= Ucf[FLOW]; s *= Ucf[FLOW];
default: default:
break; break;
@@ -4487,7 +4483,7 @@ int DLLEXPORT EN_setcontrol(EN_Project p, int index, int type, int linkIndex,
if (linkIndex < 0 || linkIndex > net->Nlinks) return 204; if (linkIndex < 0 || linkIndex > net->Nlinks) return 204;
// Cannot control check valve // Cannot control check valve
if (net->Link[linkIndex].Type == EN_CVPIPE) return 207; if (net->Link[linkIndex].Type == CVPIPE) return 207;
// Check for valid control properties // Check for valid control properties
if (type < 0 || type > EN_TIMEOFDAY) return 251; if (type < 0 || type > EN_TIMEOFDAY) return 251;
@@ -4502,22 +4498,22 @@ int DLLEXPORT EN_setcontrol(EN_Project p, int index, int type, int linkIndex,
link = &net->Link[linkIndex]; link = &net->Link[linkIndex];
switch (link->Type) switch (link->Type)
{ {
case EN_PRV: case PRV:
case EN_PSV: case PSV:
case EN_PBV: case PBV:
s /= Ucf[PRESSURE]; s /= Ucf[PRESSURE];
break; break;
case EN_FCV: case FCV:
s /= Ucf[FLOW]; s /= Ucf[FLOW];
break; break;
case EN_GPV: case GPV:
if (s == 0.0) status = CLOSED; if (s == 0.0) status = CLOSED;
else if (s == 1.0) status = OPEN; else if (s == 1.0) status = OPEN;
else return 202; else return 202;
s = link->Kc; s = link->Kc;
break; break;
case EN_PIPE: case PIPE:
case EN_PUMP: case PUMP:
status = OPEN; status = OPEN;
if (s == 0.0) status = CLOSED; if (s == 0.0) status = CLOSED;
default: default:
@@ -4609,7 +4605,7 @@ int DLLEXPORT EN_deleterule(EN_Project p, int index)
** Input: index = rule index ** Input: index = rule index
** Output: none ** Output: none
** Returns: error code ** Returns: error code
** Purpose: deletes a rule from a project. ** Purpose: deletes a rule from a project
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
@@ -4810,7 +4806,7 @@ int DLLEXPORT EN_setpremisestatus(EN_Project p, int ruleIndex, int premiseIndex,
if (ruleIndex < 1 || ruleIndex > p->network.Nrules) return 257; if (ruleIndex < 1 || ruleIndex > p->network.Nrules) return 257;
premises = p->network.Rule[ruleIndex].Premises; premises = p->network.Rule[ruleIndex].Premises;
premise = getpremise(premises, ruleIndex); premise = getpremise(premises, premiseIndex);
if (premise == NULL) return 258; if (premise == NULL) return 258;
premise->status = status; premise->status = status;

View File

@@ -100,6 +100,8 @@ int hydsolve(Project *pr, int *iter, double *relerr)
// Initialize status checking & relaxation factor // Initialize status checking & relaxation factor
nextcheck = hyd->CheckFreq; nextcheck = hyd->CheckFreq;
hyd->RelaxFactor = 1.0; hyd->RelaxFactor = 1.0;
hydbal.maxheaderror = 0.0;
hydbal.maxflowchange = 0.0;
// Repeat iterations until convergence or trial limit is exceeded. // Repeat iterations until convergence or trial limit is exceeded.
// (ExtraIter used to increase trials in case of status cycling.) // (ExtraIter used to increase trials in case of status cycling.)
@@ -121,7 +123,7 @@ int hydsolve(Project *pr, int *iter, double *relerr)
// Matrix ill-conditioning problem - if control valve causing problem, // Matrix ill-conditioning problem - if control valve causing problem,
// fix its status & continue, otherwise quit with no solution. // fix its status & continue, otherwise quit with no solution.
if (errcode > 0) if (errcode > 0)
{ {
if (badvalve(pr, sm->Order[errcode])) continue; if (badvalve(pr, sm->Order[errcode])) continue;
else break; else break;
} }
@@ -360,7 +362,6 @@ double newflows(Project *pr, Hydbalance *hbal)
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
Network *net = &pr->network;
Hydraul *hyd = &pr->hydraul; Hydraul *hyd = &pr->hydraul;
double dqsum, // Network flow change double dqsum, // Network flow change

View File

@@ -102,7 +102,6 @@ int saveinpfile(Project *pr, const char *fname)
Times *time = &pr->times; Times *time = &pr->times;
int i, j, n; int i, j, n;
int errcode;
double d, kc, ke, km, ucf; double d, kc, ke, km, ucf;
char s[MAXLINE + 1], s1[MAXLINE + 1], s2[MAXLINE + 1]; char s[MAXLINE + 1], s1[MAXLINE + 1], s2[MAXLINE + 1];
Pdemand demand; Pdemand demand;
@@ -451,7 +450,7 @@ int saveinpfile(Project *pr, const char *fname)
for (i = 1; i <= net->Nrules; i++) for (i = 1; i <= net->Nrules; i++)
{ {
fprintf(f, "\nRULE %s", pr->network.Rule[i].label); fprintf(f, "\nRULE %s", pr->network.Rule[i].label);
errcode = writerule(pr, f, i); // see RULES.C writerule(pr, f, i); // see RULES.C
fprintf(f, "\n"); fprintf(f, "\n");
} }
@@ -489,7 +488,7 @@ int saveinpfile(Project *pr, const char *fname)
fprintf(f, s_MIXING); fprintf(f, s_MIXING);
for (i = 1; i <= net->Ntanks; i++) for (i = 1; i <= net->Ntanks; i++)
{ {
Stank *tank = &net->Tank[i]; tank = &net->Tank[i];
if (tank->A == 0.0) continue; if (tank->A == 0.0) continue;
fprintf(f, "\n %-31s %-8s %12.4f", net->Node[tank->Node].ID, fprintf(f, "\n %-31s %-8s %12.4f", net->Node[tank->Node].ID,
MixTxt[tank->MixModel], (tank->V1max / tank->Vmax)); MixTxt[tank->MixModel], (tank->V1max / tank->Vmax));
@@ -719,7 +718,7 @@ int saveinpfile(Project *pr, const char *fname)
j = 0; j = 0;
for (i = 1; i <= net->Nlinks; i++) for (i = 1; i <= net->Nlinks; i++)
{ {
Slink *link = &net->Link[i]; link = &net->Link[i];
if (link->Rpt == 1) if (link->Rpt == 1)
{ {
if (j % 5 == 0) fprintf(f, "\n LINKS "); if (j % 5 == 0) fprintf(f, "\n LINKS ");

View File

@@ -45,7 +45,7 @@ static int getpumpcurve(Project *, int);
static void changestatus(Network *, int, StatusType, double); static void changestatus(Network *, int, StatusType, double);
static int setError(Parser *, int, int); static int setError(Parser *, int, int);
int setError(Parser *parser, int tokindex, int errcode) int setError(Parser *parser, int tokindex, int errcode)
/* /*
**-------------------------------------------------------------- **--------------------------------------------------------------
@@ -85,7 +85,7 @@ int juncdata(Project *pr)
Pdemand demand; // demand record Pdemand demand; // demand record
STmplist *patlist; // list of demands STmplist *patlist; // list of demands
Snode *node; Snode *node;
// Add new junction to data base // Add new junction to data base
n = parser->Ntokens; n = parser->Ntokens;
if (net->Nnodes == parser->MaxNodes) return 200; if (net->Nnodes == parser->MaxNodes) return 200;
@@ -117,7 +117,7 @@ int juncdata(Project *pr)
node->Type = JUNCTION; node->Type = JUNCTION;
strcpy(node->Comment, parser->Comment); strcpy(node->Comment, parser->Comment);
// create a demand record, even if no demand is specified here. // create a demand record, even if no demand is specified here.
demand = (struct Sdemand *) malloc(sizeof(struct Sdemand)); demand = (struct Sdemand *) malloc(sizeof(struct Sdemand));
if (demand == NULL) return 101; if (demand == NULL) return 101;
@@ -162,7 +162,7 @@ int tankdata(Project *pr)
STmplist *tmplist; STmplist *tmplist;
Snode *node; Snode *node;
Stank *tank; Stank *tank;
// Add new tank to data base // Add new tank to data base
n = parser->Ntokens; n = parser->Ntokens;
if (net->Ntanks == parser->MaxTanks || if (net->Ntanks == parser->MaxTanks ||
@@ -189,7 +189,7 @@ int tankdata(Project *pr)
} }
} }
else if (n < 6) return 201; else if (n < 6) return 201;
// Tank is a storage tank // Tank is a storage tank
else else
{ {
@@ -232,7 +232,7 @@ int tankdata(Project *pr)
tank->A = diam; tank->A = diam;
tank->Pat = pattern; tank->Pat = pattern;
tank->Kb = MISSING; tank->Kb = MISSING;
//******************************************************************* //*******************************************************************
// NOTE: The min, max, & initial volumes set here are based on a // NOTE: The min, max, & initial volumes set here are based on a
// nominal tank diameter. They will be modified in INPUT1.C if // nominal tank diameter. They will be modified in INPUT1.C if
@@ -275,7 +275,7 @@ int pipedata(Project *pr)
LinkType type = PIPE; // Link type LinkType type = PIPE; // Link type
StatusType status = OPEN; // Link status StatusType status = OPEN; // Link status
Slink *link; Slink *link;
// Add new pipe to data base // Add new pipe to data base
n = parser->Ntokens; n = parser->Ntokens;
if (net->Nlinks == parser->MaxLinks) return 200; if (net->Nlinks == parser->MaxLinks) return 200;
@@ -354,10 +354,10 @@ int pumpdata(Project *pr)
Network *net = &pr->network; Network *net = &pr->network;
Parser *parser = &pr->parser; Parser *parser = &pr->parser;
int j, int j,
j1, // Start-node index j1, // Start-node index
j2, // End-node index j2, // End-node index
m, n; // # data items m, n; // # data items
double y; double y;
STmplist *tmplist; // Temporary list STmplist *tmplist; // Temporary list
Slink *link; Slink *link;
@@ -380,7 +380,7 @@ int pumpdata(Project *pr)
// Save pump data // Save pump data
link = &net->Link[net->Nlinks]; link = &net->Link[net->Nlinks];
pump = &net->Pump[net->Npumps]; pump = &net->Pump[net->Npumps];
link->N1 = j1; link->N1 = j1;
link->N2 = j2; link->N2 = j2;
link->Diam = 0; link->Diam = 0;
@@ -426,25 +426,25 @@ int pumpdata(Project *pr)
if (y <= 0.0) return setError(parser, m, 202); if (y <= 0.0) return setError(parser, m, 202);
pump->Ptype = CONST_HP; pump->Ptype = CONST_HP;
link->Km = y; link->Km = y;
} }
else if (match(parser->Tok[m - 1], w_HEAD)) // Custom pump curve else if (match(parser->Tok[m - 1], w_HEAD)) // Custom pump curve
{ {
tmplist = getlistitem(parser->Tok[m], parser->Curvelist); tmplist = getlistitem(parser->Tok[m], parser->Curvelist);
if (tmplist == NULL) return setError(parser, m, 206); if (tmplist == NULL) return setError(parser, m, 206);
pump->Hcurve = tmplist->i; pump->Hcurve = tmplist->i;
} }
else if (match(parser->Tok[m - 1], w_PATTERN)) // Speed/status pattern else if (match(parser->Tok[m - 1], w_PATTERN)) // Speed/status pattern
{ {
tmplist = getlistitem(parser->Tok[m], parser->Patlist); tmplist = getlistitem(parser->Tok[m], parser->Patlist);
if (tmplist == NULL) return setError(parser, m, 205); if (tmplist == NULL) return setError(parser, m, 205);
pump->Upat = tmplist->i; pump->Upat = tmplist->i;
} }
else if (match(parser->Tok[m - 1], w_SPEED)) // Speed setting else if (match(parser->Tok[m - 1], w_SPEED)) // Speed setting
{ {
if (!getfloat(parser->Tok[m], &y)) return setError(parser, m, 202); if (!getfloat(parser->Tok[m], &y)) return setError(parser, m, 202);
if (y < 0.0) return setError(parser, m, 211); if (y < 0.0) return setError(parser, m, 211);
link->Kc = y; link->Kc = y;
} }
else return 201; else return 201;
m = m + 2; // Move to next keyword token m = m + 2; // Move to next keyword token
} }
@@ -476,7 +476,7 @@ int valvedata(Project *pr)
lcoeff = 0.0; // Minor loss coeff. lcoeff = 0.0; // Minor loss coeff.
STmplist *tmplist; // Temporary list STmplist *tmplist; // Temporary list
Slink *link; Slink *link;
// Add new valve to data base // Add new valve to data base
n = parser->Ntokens; n = parser->Ntokens;
if (net->Nlinks == parser->MaxLinks || if (net->Nlinks == parser->MaxLinks ||
@@ -499,12 +499,12 @@ int valvedata(Project *pr)
else if (match(parser->Tok[4], w_GPV)) type = GPV; else if (match(parser->Tok[4], w_GPV)) type = GPV;
else return setError(parser, 4, 213); else return setError(parser, 4, 213);
if (!getfloat(parser->Tok[3], &diam)) return setError(parser, 3, 202); 202; if (!getfloat(parser->Tok[3], &diam)) return setError(parser, 3, 202);
if (diam <= 0.0) return setError(parser, 3, 211); if (diam <= 0.0) return setError(parser, 3, 211);
// Find headloss curve for GPV // Find headloss curve for GPV
if (type == GPV) if (type == GPV)
{ {
tmplist = getlistitem(parser->Tok[5], parser->Curvelist); tmplist = getlistitem(parser->Tok[5], parser->Curvelist);
if (tmplist == NULL) return setError(parser, 5, 206); if (tmplist == NULL) return setError(parser, 5, 206);
setting = tmplist->i; setting = tmplist->i;
@@ -532,7 +532,7 @@ int valvedata(Project *pr)
link->Km = lcoeff; link->Km = lcoeff;
link->Kb = 0.0; link->Kb = 0.0;
link->Kw = 0.0; link->Kw = 0.0;
link->Type = type; link->Type = type;
link->Status = status; link->Status = status;
link->Rpt = 0; link->Rpt = 0;
strcpy(link->Comment, parser->Comment); strcpy(link->Comment, parser->Comment);
@@ -658,11 +658,11 @@ int coordata(Project *pr)
int j; int j;
double x, y; double x, y;
Snode *node; Snode *node;
// Check for valid node ID // Check for valid node ID
if (parser->Ntokens < 3) return 201; if (parser->Ntokens < 3) return 201;
if ((j = findnode(net, parser->Tok[0])) == 0) return setError(parser, 0, 203); if ((j = findnode(net, parser->Tok[0])) == 0) return setError(parser, 0, 203);
// Check for valid data // Check for valid data
if (!getfloat(parser->Tok[1], &x)) return setError(parser, 1, 202); if (!getfloat(parser->Tok[1], &x)) return setError(parser, 1, 202);
if (!getfloat(parser->Tok[2], &y)) return setError(parser, 2, 202); if (!getfloat(parser->Tok[2], &y)) return setError(parser, 2, 202);
@@ -768,7 +768,7 @@ int controldata(Project *pr)
{ {
Network *net = &pr->network; Network *net = &pr->network;
Parser *parser = &pr->parser; Parser *parser = &pr->parser;
int i = 0, // Node index int i = 0, // Node index
k, // Link index k, // Link index
n; // # data items n; // # data items
@@ -779,7 +779,7 @@ int controldata(Project *pr)
ControlType ctltype; // Control type ControlType ctltype; // Control type
LinkType linktype; // Link type LinkType linktype; // Link type
Scontrol *control; Scontrol *control;
// Check for sufficient number of input tokens // Check for sufficient number of input tokens
n = parser->Ntokens; n = parser->Ntokens;
if (n < 6) return 201; if (n < 6) return 201;
@@ -878,7 +878,7 @@ int sourcedata(Project *pr)
{ {
Network *net = &pr->network; Network *net = &pr->network;
Parser *parser = &pr->parser; Parser *parser = &pr->parser;
int i, // Token with quality value int i, // Token with quality value
j, // Node index j, // Node index
n, // # data items n, // # data items
@@ -912,7 +912,7 @@ int sourcedata(Project *pr)
// Parse optional source time pattern // Parse optional source time pattern
if (n > i + 1 && strlen(parser->Tok[i + 1]) > 0 && if (n > i + 1 && strlen(parser->Tok[i + 1]) > 0 &&
strcmp(parser->Tok[i + 1], "*") != 0) strcmp(parser->Tok[i + 1], "*") != 0)
{ {
patlist = getlistitem(parser->Tok[i + 1], parser->Patlist); patlist = getlistitem(parser->Tok[i + 1], parser->Patlist);
if (patlist == NULL) return setError(parser, i+1, 205); if (patlist == NULL) return setError(parser, i+1, 205);
@@ -921,7 +921,7 @@ int sourcedata(Project *pr)
// Destroy any existing source assigned to node // Destroy any existing source assigned to node
if (net->Node[j].S != NULL) free(net->Node[j].S); if (net->Node[j].S != NULL) free(net->Node[j].S);
// Create a new source & assign it to the node // Create a new source & assign it to the node
source = (struct Ssource *)malloc(sizeof(struct Ssource)); source = (struct Ssource *)malloc(sizeof(struct Ssource));
if (source == NULL) return 101; if (source == NULL) return 101;
@@ -946,7 +946,7 @@ int emitterdata(Project *pr)
{ {
Network *net = &pr->network; Network *net = &pr->network;
Parser *parser = &pr->parser; Parser *parser = &pr->parser;
int j, // Node index int j, // Node index
n; // # data items n; // # data items
double k; // Flow coeff. double k; // Flow coeff.
@@ -984,7 +984,7 @@ int qualdata(Project *pr)
long i, i1, i2; long i, i1, i2;
double c0; double c0;
Snode *Node = net->Node; Snode *Node = net->Node;
if (net->Nnodes == 0) return setError(parser, 0, 203); // No nodes defined yet if (net->Nnodes == 0) return setError(parser, 0, 203); // No nodes defined yet
n = parser->Ntokens; n = parser->Ntokens;
if (n < 2) return 0; if (n < 2) return 0;
@@ -1016,7 +1016,7 @@ int qualdata(Project *pr)
if (i >= i1 && i <= i2) Node[j].C0 = c0; if (i >= i1 && i <= i2) Node[j].C0 = c0;
} }
} }
// Otherwise use lexicographic comparison // Otherwise use lexicographic comparison
else else
{ {
@@ -1058,7 +1058,7 @@ int reactdata(Project *pr)
long i, i1, i2; long i, i1, i2;
double y; double y;
// Skip line if insufficient data // Skip line if insufficient data
n = parser->Ntokens; n = parser->Ntokens;
if (n < 3) return 0; if (n < 3) return 0;
@@ -1093,7 +1093,7 @@ int reactdata(Project *pr)
qual->Climit = y; qual->Climit = y;
return 0; return 0;
} }
// Keyword is GLOBAL // Keyword is GLOBAL
if (match(parser->Tok[0], w_GLOBAL)) if (match(parser->Tok[0], w_GLOBAL))
{ {
@@ -1125,7 +1125,7 @@ int reactdata(Project *pr)
if ((j = findnode(net,parser->Tok[1])) <= net->Njuncs) return 0; if ((j = findnode(net,parser->Tok[1])) <= net->Njuncs) return 0;
net->Tank[j - net->Njuncs].Kb = y; net->Tank[j - net->Njuncs].Kb = y;
} }
// Case where a numerical range of tank IDs is specified // Case where a numerical range of tank IDs is specified
else if ((i1 = atol(parser->Tok[1])) > 0 && else if ((i1 = atol(parser->Tok[1])) > 0 &&
(i2 = atol(parser->Tok[2])) > 0) (i2 = atol(parser->Tok[2])) > 0)
@@ -1160,7 +1160,7 @@ int reactdata(Project *pr)
if (item == 1) net->Link[j].Kb = y; if (item == 1) net->Link[j].Kb = y;
else net->Link[j].Kw = y; else net->Link[j].Kw = y;
} }
// Case where a numerical range of link IDs is specified // Case where a numerical range of link IDs is specified
else if ((i1 = atol(parser->Tok[1])) > 0 && else if ((i1 = atol(parser->Tok[1])) > 0 &&
(i2 = atol(parser->Tok[2])) > 0) (i2 = atol(parser->Tok[2])) > 0)
@@ -1168,14 +1168,14 @@ int reactdata(Project *pr)
for (j = 1; j <= net->Nlinks; j++) for (j = 1; j <= net->Nlinks; j++)
{ {
i = atol(net->Link[j].ID); i = atol(net->Link[j].ID);
if (i >= i1 && i <= i2) if (i >= i1 && i <= i2)
{ {
if (item == 1) net->Link[j].Kb = y; if (item == 1) net->Link[j].Kb = y;
else net->Link[j].Kw = y; else net->Link[j].Kw = y;
} }
} }
} }
// Case where a general range of link IDs is specified // Case where a general range of link IDs is specified
else for (j = 1; j <= net->Nlinks; j++) else for (j = 1; j <= net->Nlinks; j++)
{ {
@@ -1210,7 +1210,7 @@ int mixingdata(Project *pr)
m, // Type of mixing model m, // Type of mixing model
n; // Number of data items n; // Number of data items
double v; // Mixing zone volume fraction double v; // Mixing zone volume fraction
// Check for valid data // Check for valid data
if (net->Nnodes == 0) return setError(parser, 0, 203); if (net->Nnodes == 0) return setError(parser, 0, 203);
n = parser->Ntokens; n = parser->Ntokens;
@@ -1254,7 +1254,7 @@ int statusdata(Project *pr)
long i, i1, i2; long i, i1, i2;
double y = 0.0; double y = 0.0;
char status = ACTIVE; char status = ACTIVE;
if (net->Nlinks == 0) return setError(parser, 0, 204); if (net->Nlinks == 0) return setError(parser, 0, 204);
n = parser->Ntokens - 1; n = parser->Ntokens - 1;
if (n < 1) return 201; if (n < 1) return 201;
@@ -1272,7 +1272,7 @@ int statusdata(Project *pr)
if (n == 1) if (n == 1)
{ {
if ((j = findlink(net, parser->Tok[0])) == 0) return setError(parser, 0, 204); if ((j = findlink(net, parser->Tok[0])) == 0) return setError(parser, 0, 204);
// Cannot change status of a Check Valve // Cannot change status of a Check Valve
if (net->Link[j].Type == CVPIPE) return setError(parser, 0, 207); if (net->Link[j].Type == CVPIPE) return setError(parser, 0, 207);
@@ -1291,7 +1291,7 @@ int statusdata(Project *pr)
if (i >= i1 && i <= i2) changestatus(net, j, status, y); if (i >= i1 && i <= i2) changestatus(net, j, status, y);
} }
} }
// A range of general link ID's was supplied // A range of general link ID's was supplied
else for (j = 1; j <= net->Nlinks; j++) else for (j = 1; j <= net->Nlinks; j++)
{ {
@@ -1319,14 +1319,14 @@ int energydata(Project *pr)
Network *net = &pr->network; Network *net = &pr->network;
Hydraul *hyd = &pr->hydraul; Hydraul *hyd = &pr->hydraul;
Parser *parser = &pr->parser; Parser *parser = &pr->parser;
int j, k, n; int j, k, n;
double y; double y;
STmplist *listitem; STmplist *listitem;
Slink *Link = net->Link; Slink *Link = net->Link;
Spump *Pump = net->Pump; Spump *Pump = net->Pump;
// Check for sufficient data // Check for sufficient data
n = parser->Ntokens; n = parser->Ntokens;
if (n < 3) return 201; if (n < 3) return 201;
@@ -1345,7 +1345,7 @@ int energydata(Project *pr)
{ {
j = 0; j = 0;
} }
// First keyword is PUMP (remaining data refer to a specific pump) // First keyword is PUMP (remaining data refer to a specific pump)
else if (match(parser->Tok[0], w_PUMP)) else if (match(parser->Tok[0], w_PUMP))
{ {
@@ -1366,7 +1366,7 @@ int energydata(Project *pr)
else Pump[j].Ecost = y; else Pump[j].Ecost = y;
return 0; return 0;
} }
// Price PATTERN being set // Price PATTERN being set
else if (match(parser->Tok[n - 2], w_PATTERN)) else if (match(parser->Tok[n - 2], w_PATTERN))
{ {
@@ -1376,7 +1376,7 @@ int energydata(Project *pr)
else Pump[j].Epat = listitem->i; else Pump[j].Epat = listitem->i;
return 0; return 0;
} }
// Pump EFFIC being set // Pump EFFIC being set
else if (match(parser->Tok[n - 2], w_EFFIC)) else if (match(parser->Tok[n - 2], w_EFFIC))
{ {
@@ -1389,7 +1389,7 @@ int energydata(Project *pr)
else else
{ {
listitem = getlistitem(parser->Tok[n - 1], parser->Curvelist); listitem = getlistitem(parser->Tok[n - 1], parser->Curvelist);
if (listitem == NULL) return setError(parser, n - 1, 206); if (listitem == NULL) return setError(parser, n - 1, 206);
Pump[j].Ecurve = listitem->i; Pump[j].Ecurve = listitem->i;
net->Curve[listitem->i].Type = EFFIC_CURVE; net->Curve[listitem->i].Type = EFFIC_CURVE;
} }
@@ -1423,10 +1423,10 @@ int reportdata(Project *pr)
Network *net = &pr->network; Network *net = &pr->network;
Report *rpt = &pr->report; Report *rpt = &pr->report;
Parser *parser = &pr->parser; Parser *parser = &pr->parser;
int i, j, n; int i, j, n;
double y; double y;
n = parser->Ntokens - 1; n = parser->Ntokens - 1;
if (n < 1) return 201; if (n < 1) return 201;
@@ -1511,8 +1511,8 @@ int reportdata(Project *pr)
// Report fields specified // Report fields specified
// Special case needed to distinguish "HEAD" from "HEADLOSS" // Special case needed to distinguish "HEAD" from "HEADLOSS"
if (strcomp(parser->Tok[0], t_HEADLOSS)) i = HEADLOSS; if (strcomp(parser->Tok[0], t_HEADLOSS)) i = HEADLOSS;
else i = findmatch(parser->Tok[0], Fldname); else i = findmatch(parser->Tok[0], Fldname);
if (i >= 0) if (i >= 0)
{ {
if (i > FRICTION) return setError(parser, 0, 213); if (i > FRICTION) return setError(parser, 0, 213);
if (parser->Ntokens == 1 || match(parser->Tok[1], w_YES)) if (parser->Ntokens == 1 || match(parser->Tok[1], w_YES))
@@ -1552,7 +1552,7 @@ int reportdata(Project *pr)
return 0; return 0;
} }
// If get to here then return error condition // If get to here then return error condition
return 201; return 201;
} }
@@ -1690,10 +1690,10 @@ int optionchoice(Project *pr, int n)
Quality *qual = &pr->quality; Quality *qual = &pr->quality;
Parser *parser = &pr->parser; Parser *parser = &pr->parser;
Outfile *out = &pr->outfile; Outfile *out = &pr->outfile;
int choice; int choice;
// Check if 1st token matches a parameter name and // Check if 1st token matches a parameter name and
// process the input for the matched parameter // process the input for the matched parameter
if (n < 0) return 201; if (n < 0) return 201;
@@ -1725,7 +1725,7 @@ int optionchoice(Project *pr, int n)
else if (match(parser->Tok[1], w_METERS)) parser->Pressflag = METERS; else if (match(parser->Tok[1], w_METERS)) parser->Pressflag = METERS;
else return setError(parser, 1, 213); else return setError(parser, 1, 213);
} }
// HEADLOSS formula // HEADLOSS formula
else if (match(parser->Tok[0], w_HEADLOSS)) else if (match(parser->Tok[0], w_HEADLOSS))
{ {
@@ -1735,7 +1735,7 @@ int optionchoice(Project *pr, int n)
else if (match(parser->Tok[1], w_CM)) hyd->Formflag = CM; else if (match(parser->Tok[1], w_CM)) hyd->Formflag = CM;
else return setError(parser, 1, 213); else return setError(parser, 1, 213);
} }
// HYDRUALICS USE/SAVE file option // HYDRUALICS USE/SAVE file option
else if (match(parser->Tok[0], w_HYDRAULIC)) else if (match(parser->Tok[0], w_HYDRAULIC))
{ {
@@ -1777,19 +1777,19 @@ int optionchoice(Project *pr, int n)
strncpy(qual->ChemUnits, u_HOURS, MAXID); strncpy(qual->ChemUnits, u_HOURS, MAXID);
} }
} }
// MAP file name // MAP file name
else if (match(parser->Tok[0], w_MAP)) else if (match(parser->Tok[0], w_MAP))
{ {
if (n < 1) return 0; if (n < 1) return 0;
strncpy(pr->MapFname, parser->Tok[1], MAXFNAME); strncpy(pr->MapFname, parser->Tok[1], MAXFNAME);
} }
else if (match(parser->Tok[0], w_VERIFY)) else if (match(parser->Tok[0], w_VERIFY))
{ {
// Deprecated // Deprecated
} }
// Hydraulics UNBALANCED option // Hydraulics UNBALANCED option
else if (match(parser->Tok[0], w_UNBALANCED)) else if (match(parser->Tok[0], w_UNBALANCED))
{ {
@@ -1802,7 +1802,7 @@ int optionchoice(Project *pr, int n)
} }
else return setError(parser, 1, 213); else return setError(parser, 1, 213);
} }
// Default demand PATTERN // Default demand PATTERN
else if (match(parser->Tok[0], w_PATTERN)) else if (match(parser->Tok[0], w_PATTERN))
{ {
@@ -1854,7 +1854,7 @@ int optionvalue(Project *pr, int n)
** RQTOL value ** RQTOL value
** CHECKFREQ value ** CHECKFREQ value
** MAXCHECK value ** MAXCHECK value
** DAMPLIMIT value ** DAMPLIMIT value
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
@@ -1890,19 +1890,19 @@ int optionvalue(Project *pr, int n)
// Diffusivity // Diffusivity
if (match(tok0, w_DIFFUSIVITY)) if (match(tok0, w_DIFFUSIVITY))
{ {
if (y < 0.0) return setError(parser, nvalue, 213); if (y < 0.0) return setError(parser, nvalue, 213);
qual->Diffus = y; qual->Diffus = y;
return 0; return 0;
} }
// Hydraulic damping limit option */ // Hydraulic damping limit option */
if (match(tok0, w_DAMPLIMIT)) if (match(tok0, w_DAMPLIMIT))
{ {
hyd->DampLimit = y; hyd->DampLimit = y;
return 0; return 0;
} }
// Flow change limit // Flow change limit
else if (match(tok0, w_FLOWCHANGE)) else if (match(tok0, w_FLOWCHANGE))
{ {
@@ -1989,7 +1989,7 @@ int getpumpcurve(Project *pr, int n)
double a, b, c, h0, h1, h2, q1, q2; double a, b, c, h0, h1, h2, q1, q2;
Spump *pump = &net->Pump[net->Npumps]; Spump *pump = &net->Pump[net->Npumps];
// Constant HP curve // Constant HP curve
if (n == 1) if (n == 1)
{ {
@@ -1997,7 +1997,7 @@ int getpumpcurve(Project *pr, int n)
pump->Ptype = CONST_HP; pump->Ptype = CONST_HP;
net->Link[net->Nlinks].Km = parser->X[0]; net->Link[net->Nlinks].Km = parser->X[0];
} }
// Power function curve // Power function curve
else else
{ {
@@ -2080,7 +2080,7 @@ void changestatus(Network *net, int j, StatusType status, double y)
*/ */
{ {
Slink *link = &net->Link[j]; Slink *link = &net->Link[j];
if (link->Type == PIPE || link->Type == GPV) if (link->Type == PIPE || link->Type == GPV)
{ {
if (status != ACTIVE) link->Status = status; if (status != ACTIVE) link->Status = status;

View File

@@ -151,7 +151,7 @@ int openhydfile(Project *pr)
if (version != ENGINE_VERSION) return 306; if (version != ENGINE_VERSION) return 306;
if (fread(nsize, sizeof(INT4), 6, pr->outfile.HydFile) < 6) return 306; if (fread(nsize, sizeof(INT4), 6, pr->outfile.HydFile) < 6) return 306;
if (nsize[0] != Nnodes || nsize[1] != Nlinks || nsize[2] != Ntanks || if (nsize[0] != Nnodes || nsize[1] != Nlinks || nsize[2] != Ntanks ||
nsize[3] != Npumps || nsize[4] != Nvalves || nsize[3] != Npumps || nsize[4] != Nvalves ||
nsize[5] != pr->times.Dur nsize[5] != pr->times.Dur
) return 306; ) return 306;
pr->outfile.SaveHflag = TRUE; pr->outfile.SaveHflag = TRUE;
@@ -187,7 +187,7 @@ int openoutfile(Project *pr)
} }
// If output file name was supplied, then attempt to // If output file name was supplied, then attempt to
// open it. Otherwise open a temporary output file. // open it. Otherwise open a temporary output file.
if (pr->outfile.Outflag == SAVE) if (pr->outfile.Outflag == SAVE)
{ {
pr->outfile.OutFile = fopen(pr->outfile.OutFname, "w+b"); pr->outfile.OutFile = fopen(pr->outfile.OutFname, "w+b");
@@ -305,7 +305,7 @@ int allocdata(Project *pr)
ERRCODE(MEMCHECK(pr->quality.NodeQual)); ERRCODE(MEMCHECK(pr->quality.NodeQual));
} }
// Allocate memory for network links // Allocate memory for network links
if (!errcode) if (!errcode)
{ {
n = pr->parser.MaxLinks + 1; n = pr->parser.MaxLinks + 1;
@@ -442,7 +442,7 @@ void freedata(Project *pr)
free(demand); free(demand);
demand = nextdemand; demand = nextdemand;
} }
// Free memory used for WQ source data // Free memory used for WQ source data
source = pr->network.Node[j].S; source = pr->network.Node[j].S;
if (source != NULL) free(source); if (source != NULL) free(source);
} }
@@ -579,7 +579,6 @@ int incontrols(Project *pr, int objType, int index)
*/ */
{ {
Network *net = &pr->network; Network *net = &pr->network;
Rules *rules = &pr->rules;
int i, ruleObject; int i, ruleObject;
Spremise *premise; Spremise *premise;
@@ -652,7 +651,7 @@ int valvecheck(Project *pr, int type, int j1, int j2)
{ {
// Can't be connected to a fixed grade node // Can't be connected to a fixed grade node
if (j1 > net->Njuncs || j2 > net->Njuncs) return 219; if (j1 > net->Njuncs || j2 > net->Njuncs) return 219;
// Examine each existing valve // Examine each existing valve
for (k = 1; k <= net->Nvalves; k++) for (k = 1; k <= net->Nvalves; k++)
{ {
@@ -832,7 +831,7 @@ double interp(int n, double x[], double y[], double xx)
double dx, dy; double dx, dy;
m = n - 1; // Highest data index m = n - 1; // Highest data index
if (xx <= x[0]) return (y[0]); // xx off low end of curve if (xx <= x[0]) return (y[0]); // xx off low end of curve
for (k = 1; k <= m; k++) // Bracket xx on curve for (k = 1; k <= m; k++) // Bracket xx on curve
{ {
if (x[k] >= xx) // Interp. over interval if (x[k] >= xx) // Interp. over interval

View File

@@ -35,7 +35,7 @@ const double Q_STAGNANT = 0.005 / GPMperCFS; // 0.005 gpm = 1.114e-5 cfs
//int stepqual(Project *, long *); //int stepqual(Project *, long *);
//int closequal(Project *); //int closequal(Project *);
//double avgqual(Project *, int); //double avgqual(Project *, int);
double findsourcequal(Project *, int, double, double, long); double findsourcequal(Project *, int, double, long);
// Imported functions // Imported functions
extern char setreactflag(Project *); extern char setreactflag(Project *);
@@ -78,21 +78,21 @@ int openqual(Project *pr)
// Create a memory pool for water quality segments // Create a memory pool for water quality segments
qual->OutOfMemory = FALSE; qual->OutOfMemory = FALSE;
qual->SegPool = mempool_create(); qual->SegPool = mempool_create();
if (qual->SegPool == NULL) errcode = 101; if (qual->SegPool == NULL) errcode = 101;
// Allocate arrays for link flow direction & reaction rates // Allocate arrays for link flow direction & reaction rates
n = net->Nlinks + 1; n = net->Nlinks + 1;
qual->FlowDir = (FlowDirection *)calloc(n, sizeof(FlowDirection)); qual->FlowDir = (FlowDirection *)calloc(n, sizeof(FlowDirection));
qual->PipeRateCoeff = (double *)calloc(n, sizeof(double)); qual->PipeRateCoeff = (double *)calloc(n, sizeof(double));
// Allocate arrays used for volume segments in links & tanks // Allocate arrays used for volume segments in links & tanks
n = net->Nlinks + net->Ntanks + 1; n = net->Nlinks + net->Ntanks + 1;
qual->FirstSeg = (Pseg *)calloc(n, sizeof(Pseg)); qual->FirstSeg = (Pseg *)calloc(n, sizeof(Pseg));
qual->LastSeg = (Pseg *)calloc(n, sizeof(Pseg)); qual->LastSeg = (Pseg *)calloc(n, sizeof(Pseg));
// Allocate memory for topologically sorted nodes // Allocate memory for topologically sorted nodes
qual->SortedNodes = (int *)calloc(n, sizeof(int)); qual->SortedNodes = (int *)calloc(n, sizeof(int));
ERRCODE(MEMCHECK(qual->FlowDir)); ERRCODE(MEMCHECK(qual->FlowDir));
ERRCODE(MEMCHECK(qual->PipeRateCoeff)); ERRCODE(MEMCHECK(qual->PipeRateCoeff));
ERRCODE(MEMCHECK(qual->FirstSeg)); ERRCODE(MEMCHECK(qual->FirstSeg));
@@ -119,7 +119,7 @@ int initqual(Project *pr)
int i; int i;
int errcode = 0; int errcode = 0;
// Re-position hydraulics file // Re-position hydraulics file
if (!hyd->OpenHflag) if (!hyd->OpenHflag)
{ {
fseek(pr->outfile.HydFile, pr->outfile.HydOffset, SEEK_SET); fseek(pr->outfile.HydFile, pr->outfile.HydOffset, SEEK_SET);
@@ -148,7 +148,7 @@ int initqual(Project *pr)
// Initialize quality at trace node (if applicable) // Initialize quality at trace node (if applicable)
if (qual->Qualflag == TRACE) qual->NodeQual[qual->TraceNode] = 100.0; if (qual->Qualflag == TRACE) qual->NodeQual[qual->TraceNode] = 100.0;
// Compute Schmidt number // Compute Schmidt number
if (qual->Diffus > 0.0) qual->Sc = hyd->Viscos / qual->Diffus; if (qual->Diffus > 0.0) qual->Sc = hyd->Viscos / qual->Diffus;
else qual->Sc = 0.0; else qual->Sc = 0.0;
@@ -202,17 +202,17 @@ int runqual(Project *pr, long *t)
Quality *qual = &pr->quality; Quality *qual = &pr->quality;
Times *time = &pr->times; Times *time = &pr->times;
long hydtime; // Hydraulic solution time long hydtime = 0; // Hydraulic solution time
long hydstep; // Hydraulic time step long hydstep = 0; // Hydraulic time step
int errcode = 0; int errcode = 0;
// Update reported simulation time // Update reported simulation time
*t = time->Qtime; *t = time->Qtime;
// Read hydraulic solution from hydraulics file // Read hydraulic solution from hydraulics file
if (time->Qtime == time->Htime) if (time->Qtime == time->Htime)
{ {
// Read hydraulic results from file // Read hydraulic results from file
if (!hyd->OpenHflag) if (!hyd->OpenHflag)
{ {
if (!readhyd(pr, &hydtime)) return 307; if (!readhyd(pr, &hydtime)) return 307;
@@ -220,7 +220,7 @@ int runqual(Project *pr, long *t)
time->Htime = hydtime; time->Htime = hydtime;
} }
// Save current results to output file // Save current results to output file
if (time->Htime >= time->Rtime) if (time->Htime >= time->Rtime)
{ {
if (pr->outfile.Saveflag) if (pr->outfile.Saveflag)
@@ -263,7 +263,7 @@ int nextqual(Project *pr, long *tstep)
{ {
Quality *qual = &pr->quality; Quality *qual = &pr->quality;
Times *time = &pr->times; Times *time = &pr->times;
long hydstep; // Time step until next hydraulic event long hydstep; // Time step until next hydraulic event
long dt, qtime; long dt, qtime;
int errcode = 0; int errcode = 0;
@@ -316,7 +316,7 @@ int stepqual(Project *pr, long *tleft)
** Input: none ** Input: none
** Output: tleft = time left in simulation ** Output: tleft = time left in simulation
** Returns: error code ** Returns: error code
** Purpose: updates quality conditions over a single ** Purpose: updates quality conditions over a single
** quality time step ** quality time step
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
@@ -402,7 +402,7 @@ int closequal(Project *pr)
int errcode = 0; int errcode = 0;
if (qual->SegPool) mempool_delete(qual->SegPool); if (qual->SegPool) mempool_delete(qual->SegPool);
FREE(qual->FirstSeg); FREE(qual->FirstSeg);
FREE(qual->LastSeg); FREE(qual->LastSeg);
FREE(qual->PipeRateCoeff); FREE(qual->PipeRateCoeff);
FREE(qual->FlowDir); FREE(qual->FlowDir);
@@ -452,11 +452,10 @@ double avgqual(Project *pr, int k)
} }
double findsourcequal(Project *pr, int n, double volin, double volout, long tstep) double findsourcequal(Project *pr, int n, double volout, long tstep)
/* /*
**--------------------------------------------------------------------- **---------------------------------------------------------------------
** Input: n = node index ** Input: n = node index
** volin = volume of node inflow over time step
** volout = volume of node outflow over time step ** volout = volume of node outflow over time step
** tstep = current quality time step ** tstep = current quality time step
** Output: returns concentration added by an external quality source. ** Output: returns concentration added by an external quality source.
@@ -543,7 +542,6 @@ double sourcequal(Project *pr, Psource source)
*/ */
{ {
Network *net = &pr->network; Network *net = &pr->network;
Quality *qual = &pr->quality;
Times *time = &pr->times; Times *time = &pr->times;
int i; int i;

View File

@@ -222,7 +222,7 @@ double piperate(Project *pr, int k)
d = net->Link[k].Diam; // Pipe diameter, ft d = net->Link[k].Diam; // Pipe diameter, ft
// Ignore mass transfer if Schmidt No. is 0 // Ignore mass transfer if Schmidt No. is 0
if (qual->Sc == 0.0) if (qual->Sc == 0.0)
{ {
if (qual->WallOrder == 0.0) return BIG; if (qual->WallOrder == 0.0) return BIG;
@@ -445,7 +445,6 @@ double mixtank(Project *pr, int n, double volin, double massin, double volout)
*/ */
{ {
Network *net = &pr->network; Network *net = &pr->network;
Quality *qual = &pr->quality;
int i; int i;
double vnet; double vnet;
@@ -475,7 +474,6 @@ void tankmix1(Project *pr, int i, double vin, double win, double vnet)
*/ */
{ {
Network *net = &pr->network; Network *net = &pr->network;
Hydraul *hyd = &pr->hydraul;
Quality *qual = &pr->quality; Quality *qual = &pr->quality;
int k; int k;
@@ -544,7 +542,7 @@ void tankmix2(Project *pr, int i, double vin, double win, double vnet)
} }
} }
// Tank is emptying // Tank is emptying
else if (vnet < 0.0) else if (vnet < 0.0)
{ {
if (stagzone->v > 0.0) vt = MIN(stagzone->v, (-vnet)); if (stagzone->v > 0.0) vt = MIN(stagzone->v, (-vnet));
@@ -555,7 +553,7 @@ void tankmix2(Project *pr, int i, double vin, double win, double vnet)
} }
} }
// Update segment volumes // Update segment volumes
if (vt > 0.0) if (vt > 0.0)
{ {
mixzone->v = vmz; mixzone->v = vmz;
@@ -589,7 +587,6 @@ void tankmix3(Project *pr, int i, double vin, double win, double vnet)
*/ */
{ {
Network *net = &pr->network; Network *net = &pr->network;
Hydraul *hyd = &pr->hydraul;
Quality *qual = &pr->quality; Quality *qual = &pr->quality;
int k; int k;
@@ -640,7 +637,7 @@ void tankmix3(Project *pr, int i, double vin, double win, double vnet)
} }
// Use quality withdrawn from 1st segment // Use quality withdrawn from 1st segment
// to represent overall quality of tank // to represent overall quality of tank
if (vsum > 0.0) tank->C = wsum / vsum; if (vsum > 0.0) tank->C = wsum / vsum;
else if (qual->FirstSeg[k] == NULL) tank->C = 0.0; else if (qual->FirstSeg[k] == NULL) tank->C = 0.0;
else tank->C = qual->FirstSeg[k]->c; else tank->C = qual->FirstSeg[k]->c;
@@ -662,7 +659,7 @@ void tankmix4(Project *pr, int i, double vin, double win, double vnet)
Network *net = &pr->network; Network *net = &pr->network;
Quality *qual = &pr->quality; Quality *qual = &pr->quality;
int k, n; int k;
double cin, vsum, wsum, vseg; double cin, vsum, wsum, vseg;
Pseg seg; Pseg seg;
Stank *tank = &pr->network.Tank[i]; Stank *tank = &pr->network.Tank[i];
@@ -671,7 +668,6 @@ void tankmix4(Project *pr, int i, double vin, double win, double vnet)
if (qual->LastSeg[k] == NULL || qual->FirstSeg[k] == NULL) return; if (qual->LastSeg[k] == NULL || qual->FirstSeg[k] == NULL) return;
// Find inflows & outflows // Find inflows & outflows
n = tank->Node;
if (vin > 0.0) cin = win / vin; if (vin > 0.0) cin = win / vin;
else cin = 0.0; else cin = 0.0;
@@ -691,7 +687,7 @@ void tankmix4(Project *pr, int i, double vin, double win, double vnet)
qual->LastSeg[k]->prev = seg; qual->LastSeg[k]->prev = seg;
} }
// ... update reported tank quality // ... update reported tank quality
tank->C = qual->LastSeg[k]->c; tank->C = qual->LastSeg[k]->c;
} }

View File

@@ -35,7 +35,7 @@ void reversesegs(Project *, int);
void addseg(Project *, int, double, double); void addseg(Project *, int, double, double);
// Imported functions // Imported functions
extern double findsourcequal(Project *, int, double, double, long); extern double findsourcequal(Project *, int, double, long);
extern void reactpipes(Project *, long); extern void reactpipes(Project *, long);
extern void reacttanks(Project *, long); extern void reacttanks(Project *, long);
extern double mixtank(Project *, int, double, double, double); extern double mixtank(Project *, int, double, double, double);
@@ -147,7 +147,6 @@ void evalnodeinflow(Project *pr, int k, long tstep, double *volin,
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
Network *net = &pr->network;
Hydraul *hyd = &pr->hydraul; Hydraul *hyd = &pr->hydraul;
Quality *qual = &pr->quality; Quality *qual = &pr->quality;
@@ -251,7 +250,7 @@ double findnodequal(Project *pr, int n, double volin,
} }
// Find quality contribued by any external chemical source // Find quality contribued by any external chemical source
else qual->SourceQual = findsourcequal(pr, n, volin, volout, tstep); else qual->SourceQual = findsourcequal(pr, n, volout, tstep);
if (qual->SourceQual == 0.0) return qual->NodeQual[n]; if (qual->SourceQual == 0.0) return qual->NodeQual[n];
// Combine source quality with node quality // Combine source quality with node quality
@@ -285,7 +284,6 @@ double noflowqual(Project *pr, int n)
*/ */
{ {
Network *net = &pr->network; Network *net = &pr->network;
Hydraul *hyd = &pr->hydraul;
Quality *qual = &pr->quality; Quality *qual = &pr->quality;
int k, inflow, kount = 0; int k, inflow, kount = 0;
@@ -300,7 +298,7 @@ double noflowqual(Project *pr, int n)
k = alink->link; k = alink->link;
dir = qual->FlowDir[k]; dir = qual->FlowDir[k];
// Node n is link's downstream node - add quality // Node n is link's downstream node - add quality
// of link's first segment to average // of link's first segment to average
if (net->Link[k].N2 == n && dir >= 0) inflow = TRUE; if (net->Link[k].N2 == n && dir >= 0) inflow = TRUE;
else if (net->Link[k].N1 == n && dir < 0) inflow = TRUE; else if (net->Link[k].N1 == n && dir < 0) inflow = TRUE;
@@ -311,7 +309,7 @@ double noflowqual(Project *pr, int n)
kount++; kount++;
} }
// Node n is link's upstream node - add quality // Node n is link's upstream node - add quality
// of link's last segment to average // of link's last segment to average
else if (inflow == FALSE && qual->LastSeg[k] != NULL) else if (inflow == FALSE && qual->LastSeg[k] != NULL)
{ {
@@ -428,7 +426,6 @@ int sortnodes(Project *pr)
*/ */
{ {
Network *net = &pr->network; Network *net = &pr->network;
Hydraul *hyd = &pr->hydraul;
Quality *qual = &pr->quality; Quality *qual = &pr->quality;
int i, j, k, n; int i, j, k, n;
@@ -578,7 +575,6 @@ void initsegs(Project *pr)
*/ */
{ {
Network *net = &pr->network; Network *net = &pr->network;
Hydraul *hyd = &pr->hydraul;
Quality *qual = &pr->quality; Quality *qual = &pr->quality;
int j, k; int j, k;

View File

@@ -69,8 +69,8 @@ int writereport(Project *pr)
{ {
Report *rpt = &pr->report; Report *rpt = &pr->report;
Parser *parser = &pr->parser; Parser *parser = &pr->parser;
char tflag; int tflag;
FILE *tfile; FILE *tfile;
int errcode = 0; int errcode = 0;
@@ -82,7 +82,7 @@ int writereport(Project *pr)
if (rpt->Energyflag) writeenergy(pr); if (rpt->Energyflag) writeenergy(pr);
errcode = writeresults(pr); errcode = writeresults(pr);
} }
// A secondary report file was specified // A secondary report file was specified
else if (strlen(rpt->Rpt2Fname) > 0) else if (strlen(rpt->Rpt2Fname) > 0)
{ {
@@ -145,7 +145,7 @@ void writelogo(Project *pr)
char s[80]; char s[80];
time_t timer; // time_t structure & functions time() & time_t timer; // time_t structure & functions time() &
// ctime() are defined in time.h // ctime() are defined in time.h
version = CODEVERSION; version = CODEVERSION;
major = version / 10000; major = version / 10000;
minor = (version % 10000) / 100; minor = (version % 10000) / 100;
@@ -230,12 +230,12 @@ void writesummary(Project *pr)
writeline(pr, s); writeline(pr, s);
} }
sprintf(s, FMT27a, hyd->CheckFreq); sprintf(s, FMT27a, hyd->CheckFreq);
writeline(pr, s); writeline(pr, s);
sprintf(s, FMT27b, hyd->MaxCheck); sprintf(s, FMT27b, hyd->MaxCheck);
writeline(pr, s); writeline(pr, s);
sprintf(s, FMT27c, hyd->DampLimit); sprintf(s, FMT27c, hyd->DampLimit);
writeline(pr, s); writeline(pr, s);
sprintf(s, FMT28, hyd->MaxIter); sprintf(s, FMT28, hyd->MaxIter);
writeline(pr, s); writeline(pr, s);
@@ -341,7 +341,7 @@ void writehydstat(Project *pr, int iter, double relerr)
} }
} }
// Display status changes for links // Display status changes for links
for (i = 1; i <= net->Nlinks; i++) for (i = 1; i <= net->Nlinks; i++)
{ {
if (hyd->LinkStatus[i] != hyd->OldStatus[i]) if (hyd->LinkStatus[i] != hyd->OldStatus[i])
@@ -399,7 +399,7 @@ void writemassbalance(Project *pr)
writeline(pr, s1); writeline(pr, s1);
snprintf(s1, MAXMSG, "Final Mass: %12.5e", qual->MassBalance.final); snprintf(s1, MAXMSG, "Final Mass: %12.5e", qual->MassBalance.final);
writeline(pr, s1); writeline(pr, s1);
snprintf(s1, MAXMSG, "Mass Ratio: %-0.5f", qual->MassBalance.ratio); snprintf(s1, MAXMSG, "Mass Ratio: %-.5f", qual->MassBalance.ratio);
writeline(pr, s1); writeline(pr, s1);
snprintf(s1, MAXMSG, "================================\n"); snprintf(s1, MAXMSG, "================================\n");
writeline(pr, s1); writeline(pr, s1);
@@ -426,7 +426,7 @@ void writeenergy(Project *pr)
if (net->Npumps == 0) return; if (net->Npumps == 0) return;
writeline(pr, " "); writeline(pr, " ");
writeheader(pr,ENERHDR, 0); writeheader(pr,ENERHDR, 0);
csum = 0.0; csum = 0.0;
for (j = 1; j <= net->Npumps; j++) for (j = 1; j <= net->Npumps; j++)
{ {
@@ -534,7 +534,7 @@ int writeresults(Project *pr)
} }
} }
// Free allocated memory // Free allocated memory
for (j = 0; j < m; j++) free(x[j]); for (j = 0; j < m; j++) free(x[j]);
free(x); free(x);
return errcode; return errcode;
@@ -572,7 +572,7 @@ void writenodetable(Project *pr, Pfloat *x)
if ((rpt->Nodeflag == 1 || node->Rpt) && if ((rpt->Nodeflag == 1 || node->Rpt) &&
checklimits(rpt, y, ELEV, QUALITY)) checklimits(rpt, y, ELEV, QUALITY))
{ {
// Check if new page needed // Check if new page needed
if (rpt->LineNum == (long)rpt->PageSize) writeheader(pr, NODEHDR, 1); if (rpt->LineNum == (long)rpt->PageSize) writeheader(pr, NODEHDR, 1);
// Add node ID and each reported field to string s // Add node ID and each reported field to string s
@@ -618,7 +618,7 @@ void writelinktable(Project *pr, Pfloat *x)
double y[MAXVAR]; double y[MAXVAR];
double *Ucf = pr->Ucf; double *Ucf = pr->Ucf;
Slink *Link = net->Link; Slink *Link = net->Link;
// Write table header // Write table header
writeheader(pr, LINKHDR, 0); writeheader(pr, LINKHDR, 0);
@@ -686,7 +686,7 @@ void writeheader(Project *pr, int type, int contin)
Quality *qual = &pr->quality; Quality *qual = &pr->quality;
Parser *parser = &pr->parser; Parser *parser = &pr->parser;
Times *time = &pr->times; Times *time = &pr->times;
char s[MAXLINE + 1], s1[MAXLINE + 1], s2[MAXLINE + 1], s3[MAXLINE + 1]; char s[MAXLINE + 1], s1[MAXLINE + 1], s2[MAXLINE + 1], s3[MAXLINE + 1];
int i, n; int i, n;
@@ -697,7 +697,7 @@ void writeheader(Project *pr, int type, int contin)
} }
writeline(pr, " "); writeline(pr, " ");
// Hydraulic Status Table // Hydraulic Status Table
if (type == STATHDR) if (type == STATHDR)
{ {
sprintf(s, FMT49); sprintf(s, FMT49);
@@ -737,12 +737,12 @@ void writeheader(Project *pr, int type, int contin)
else sprintf(s, FMT78, clocktime(rpt->Atime, time->Htime)); else sprintf(s, FMT78, clocktime(rpt->Atime, time->Htime));
if (contin) strcat(s, t_CONTINUED); if (contin) strcat(s, t_CONTINUED);
writeline(pr, s); writeline(pr, s);
n = 15; n = 15;
sprintf(s2, "%15s", ""); sprintf(s2, "%15s", "");
strcpy(s, t_NODEID); strcpy(s, t_NODEID);
sprintf(s3, "%-15s", s); sprintf(s3, "%-15s", s);
for (i = ELEV; i < QUALITY; i++) for (i = ELEV; i < QUALITY; i++)
{ {
if (rpt->Field[i].Enabled == TRUE) if (rpt->Field[i].Enabled == TRUE)
@@ -846,7 +846,7 @@ void writerelerr(Project *pr, int iter, double relerr)
{ {
Report *rpt = &pr->report; Report *rpt = &pr->report;
Times *time = &pr->times; Times *time = &pr->times;
if (iter == 0) if (iter == 0)
{ {
sprintf(pr->Msg, FMT64, clocktime(rpt->Atime, time->Htime)); sprintf(pr->Msg, FMT64, clocktime(rpt->Atime, time->Htime));
@@ -878,7 +878,7 @@ void writestatchange(Project *pr, int k, char s1, char s2)
double *Ucf = pr->Ucf; double *Ucf = pr->Ucf;
double *LinkSetting = hyd->LinkSetting; double *LinkSetting = hyd->LinkSetting;
Slink *Link = net->Link; Slink *Link = net->Link;
// We have a pump/valve setting change instead of a status change // We have a pump/valve setting change instead of a status change
if (s1 == s2) if (s1 == s2)
{ {
@@ -934,7 +934,7 @@ void writecontrolaction(Project *pr, int k, int i)
Snode *Node = net->Node; Snode *Node = net->Node;
Slink *Link = net->Link; Slink *Link = net->Link;
Scontrol *Control = net->Control; Scontrol *Control = net->Control;
switch (Control[i].Type) switch (Control[i].Type)
{ {
case LOWLEVEL: case LOWLEVEL:
@@ -944,7 +944,7 @@ void writecontrolaction(Project *pr, int k, int i)
LinkTxt[Link[k].Type], Link[k].ID, LinkTxt[Link[k].Type], Link[k].ID,
NodeTxt[getnodetype(net, n)], Node[n].ID); NodeTxt[getnodetype(net, n)], Node[n].ID);
break; break;
case TIMER: case TIMER:
case TIMEOFDAY: case TIMEOFDAY:
sprintf(pr->Msg, FMT55, clocktime(rpt->Atime, time->Htime), sprintf(pr->Msg, FMT55, clocktime(rpt->Atime, time->Htime),
@@ -1001,7 +1001,7 @@ int writehydwarn(Project *pr, int iter, double relerr)
int i, j; int i, j;
char flag = 0; char flag = 0;
char s; int s;
Snode *Node = net->Node; Snode *Node = net->Node;
Slink *Link = net->Link; Slink *Link = net->Link;
Spump *Pump = net->Pump; Spump *Pump = net->Pump;
@@ -1010,7 +1010,7 @@ int writehydwarn(Project *pr, int iter, double relerr)
double *NodeDemand = hyd->NodeDemand; double *NodeDemand = hyd->NodeDemand;
double *LinkFlow = hyd->LinkFlow; double *LinkFlow = hyd->LinkFlow;
double *LinkSetting = hyd->LinkSetting; double *LinkSetting = hyd->LinkSetting;
// Check if system unstable // Check if system unstable
if (iter > hyd->MaxIter && relerr <= hyd->Hacc) if (iter > hyd->MaxIter && relerr <= hyd->Hacc)
{ {
@@ -1046,19 +1046,19 @@ int writehydwarn(Project *pr, int iter, double relerr)
} }
} }
// Check for abnormal pump condition // Check for abnormal pump condition
for (i = 1; i <= net->Npumps; i++) for (i = 1; i <= net->Npumps; i++)
{ {
j = Pump[i].Link; j = Pump[i].Link;
s = hyd->LinkStatus[j]; s = hyd->LinkStatus[j];
if (hyd->LinkStatus[j] >= OPEN) if (hyd->LinkStatus[j] >= OPEN)
{
if (LinkFlow[j] > LinkSetting[j] * Pump[i].Qmax) s = XFLOW;
if (LinkFlow[j] < 0.0) s = XHEAD;
}
if (s == XHEAD || s == XFLOW)
{ {
sprintf(pr->Msg, WARN04, Link[j].ID, StatTxt[s], if (LinkFlow[j] > LinkSetting[j] * Pump[i].Qmax) s = XFLOW;
if (LinkFlow[j] < 0.0) s = XHEAD;
}
if (s == XHEAD || s == XFLOW)
{
sprintf(pr->Msg, WARN04, Link[j].ID, StatTxt[s],
clocktime(rpt->Atime, time->Htime)); clocktime(rpt->Atime, time->Htime));
if (rpt->Messageflag) writeline(pr, pr->Msg); if (rpt->Messageflag) writeline(pr, pr->Msg);
flag = 4; flag = 4;
@@ -1098,7 +1098,7 @@ void writehyderr(Project *pr, int errnode)
Times *time = &pr->times; Times *time = &pr->times;
Snode *Node = net->Node; Snode *Node = net->Node;
sprintf(pr->Msg, FMT62, clocktime(rpt->Atime, time->Htime), sprintf(pr->Msg, FMT62, clocktime(rpt->Atime, time->Htime),
Node[errnode].ID); Node[errnode].ID);
if (rpt->Messageflag) writeline(pr, pr->Msg); if (rpt->Messageflag) writeline(pr, pr->Msg);
@@ -1218,7 +1218,7 @@ void marknodes(Project *pr, int m, int *nodelist, char *marked)
int i, j, k, n; int i, j, k, n;
Padjlist alink; Padjlist alink;
// Scan each successive entry of node list // Scan each successive entry of node list
n = 1; n = 1;
while (n <= m) while (n <= m)
@@ -1232,7 +1232,7 @@ void marknodes(Project *pr, int m, int *nodelist, char *marked)
j = alink->node; j = alink->node;
if (marked[j]) continue; if (marked[j]) continue;
// Check if valve connection is in correct direction // Check if valve connection is in correct direction
switch (net->Link[k].Type) switch (net->Link[k].Type)
{ {
case CVPIPE: case CVPIPE:
@@ -1299,7 +1299,7 @@ void writelimits(Project *pr, int j1, int j2)
{ {
Report *rpt = &pr->report; Report *rpt = &pr->report;
int j; int j;
for (j = j1; j <= j2; j++) for (j = j1; j <= j2; j++)
{ {
if (rpt->Field[j].RptLim[LOW] < BIG) if (rpt->Field[j].RptLim[LOW] < BIG)

View File

@@ -193,7 +193,7 @@ int ruledata(Project *pr)
switch (key) switch (key)
{ {
case -1: case -1:
err = 201; // Unrecognized keyword err = 201; // Unrecognized keyword
break; break;
case r_RULE: case r_RULE:
@@ -328,7 +328,6 @@ void adjustrules(Project *pr, int objtype, int index)
//----------------------------------------------------------- //-----------------------------------------------------------
{ {
Network *net = &pr->network; Network *net = &pr->network;
Rules *rules = &pr->rules;
int i, delete; int i, delete;
Spremise *p; Spremise *p;
@@ -453,7 +452,6 @@ int writerule(Project *pr, FILE *f, int ruleIndex)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
{ {
Network *net = &pr->network; Network *net = &pr->network;
Rules *rules = &pr->rules;
Srule *rule = &net->Rule[ruleIndex]; Srule *rule = &net->Rule[ruleIndex];
Spremise *p; Spremise *p;
@@ -678,7 +676,7 @@ int newpremise(Project *pr, int logop)
{ {
if (!getfloat(Tok[parser->Ntokens - 1], &x)) if (!getfloat(Tok[parser->Ntokens - 1], &x))
return (202); return (202);
if (v == r_FILLTIME || v == r_DRAINTIME) x = x * 3600.0; if (v == r_FILLTIME || v == r_DRAINTIME) x = x * 3600.0;
} }
// Create new premise structure // Create new premise structure
@@ -715,7 +713,7 @@ int newaction(Project *pr)
double x; double x;
Saction *a; Saction *a;
char **Tok = parser->Tok; char **Tok = parser->Tok;
// Check for correct number of tokens // Check for correct number of tokens
if (parser->Ntokens != 6) return 201; if (parser->Ntokens != 6) return 201;
@@ -848,7 +846,7 @@ int checktime(Project *pr, Spremise *p)
{ {
t1 = rules->Time1; t1 = rules->Time1;
t2 = time->Htime; t2 = time->Htime;
} }
else if (p->variable == r_CLOCKTIME) else if (p->variable == r_CLOCKTIME)
{ {
t1 = (rules->Time1 + time->Tstart) % SECperDAY; t1 = (rules->Time1 + time->Tstart) % SECperDAY;
@@ -878,7 +876,7 @@ int checktime(Project *pr, Spremise *p)
case EQ: case EQ:
case NE: case NE:
flag = FALSE; flag = FALSE;
if (t2 < t1) // E.g., 11:00 am to 1:00 am if (t2 < t1) // E.g., 11:00 am to 1:00 am
{ {
if (x >= t1 || x <= t2) if (x >= t1 || x <= t2)
flag = TRUE; flag = TRUE;
@@ -893,7 +891,7 @@ int checktime(Project *pr, Spremise *p)
break; break;
} }
// If we get to here then premise was satisfied // If we get to here then premise was satisfied
return 1; return 1;
} }
@@ -906,7 +904,7 @@ int checkstatus(Project *pr, Spremise *p)
char i; char i;
int j; int j;
switch (p->status) switch (p->status)
{ {
case IS_OPEN: case IS_OPEN:
@@ -930,7 +928,7 @@ int checkvalue(Project *pr, Spremise *p)
{ {
Network *net = &pr->network; Network *net = &pr->network;
Hydraul *hyd = &pr->hydraul; Hydraul *hyd = &pr->hydraul;
int i, j, v; int i, j, v;
double x, // A variable's value double x, // A variable's value
tol = 1.e-3; // Equality tolerance tol = 1.e-3; // Equality tolerance
@@ -942,7 +940,7 @@ int checkvalue(Project *pr, Spremise *p)
Snode *Node = net->Node; Snode *Node = net->Node;
Slink *Link = net->Link; Slink *Link = net->Link;
Stank *Tank = net->Tank; Stank *Tank = net->Tank;
// Find the value being checked // Find the value being checked
i = p->index; i = p->index;
v = p->variable; v = p->variable;
@@ -1099,13 +1097,13 @@ int takeactions(Project *pr)
Hydraul *hyd = &pr->hydraul; Hydraul *hyd = &pr->hydraul;
Report *rpt = &pr->report; Report *rpt = &pr->report;
Rules *rules = &pr->rules; Rules *rules = &pr->rules;
char flag; char flag;
int k, s, n; int k, s, n;
double tol = 1.e-3, v, x; double tol = 1.e-3, v, x;
Saction *a; Saction *a;
SactionList *actionItem; SactionList *actionItem;
n = 0; n = 0;
actionItem = rules->ActionList; actionItem = rules->ActionList;
while (actionItem != NULL) while (actionItem != NULL)

View File

@@ -81,9 +81,9 @@ static void transpose(int, int *, int *, int *, int *,
int createsparse(Project *pr) int createsparse(Project *pr)
/* /*
**-------------------------------------------------------------- **--------------------------------------------------------------
** Input: none ** Input: none
** Output: returns error code ** Output: returns error code
** Purpose: creates sparse representation of coeff. matrix ** Purpose: creates sparse representation of coeff. matrix
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
@@ -104,7 +104,7 @@ int createsparse(Project *pr)
errcode = localadjlists(net, sm); errcode = localadjlists(net, sm);
if (errcode) return errcode; if (errcode) return errcode;
// Re-order nodes to minimize number of non-zero coeffs. // Re-order nodes to minimize number of non-zero coeffs.
// in factorized solution matrix // in factorized solution matrix
ERRCODE(reordernodes(pr)); ERRCODE(reordernodes(pr));
@@ -134,9 +134,9 @@ int createsparse(Project *pr)
int allocsmatrix(Smatrix *sm, int Nnodes, int Nlinks) int allocsmatrix(Smatrix *sm, int Nnodes, int Nlinks)
/* /*
**-------------------------------------------------------------- **--------------------------------------------------------------
** Input: none ** Input: none
** Output: returns error code ** Output: returns error code
** Purpose: allocates memory for representing a sparse matrix ** Purpose: allocates memory for representing a sparse matrix
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
@@ -192,20 +192,19 @@ int alloclinsolve(Smatrix *sm, int n)
void freesparse(Project *pr) void freesparse(Project *pr)
/* /*
**---------------------------------------------------------------- **----------------------------------------------------------------
** Input: None ** Input: None
** Output: None ** Output: None
** Purpose: Frees memory used for sparse matrix storage ** Purpose: Frees memory used for sparse matrix storage
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
Network *net = &pr->network;
Smatrix *sm = &pr->hydraul.smatrix; Smatrix *sm = &pr->hydraul.smatrix;
// stoptimer(SmatrixTimer); // stoptimer(SmatrixTimer);
// printf("\n"); // printf("\n");
// printf("\n Processing Time = %7.3f s", gettimer(SmatrixTimer)); // printf("\n Processing Time = %7.3f s", gettimer(SmatrixTimer));
// printf("\n"); // printf("\n");
FREE(sm->Order); FREE(sm->Order);
FREE(sm->Row); FREE(sm->Row);
FREE(sm->Ndx); FREE(sm->Ndx);
@@ -247,7 +246,7 @@ int localadjlists(Network *net, Smatrix *sm)
i = net->Link[k].N1; i = net->Link[k].N1;
j = net->Link[k].N2; j = net->Link[k].N2;
pmark = paralink(net, sm, i, j, k); // Parallel link check pmark = paralink(net, sm, i, j, k); // Parallel link check
// Include link in start node i's list // Include link in start node i's list
alink = (struct Sadjlist *) malloc(sizeof(struct Sadjlist)); alink = (struct Sadjlist *) malloc(sizeof(struct Sadjlist));
if (alink == NULL) return(101); if (alink == NULL) return(101);
@@ -261,7 +260,7 @@ int localadjlists(Network *net, Smatrix *sm)
alink = (struct Sadjlist *) malloc(sizeof(struct Sadjlist)); alink = (struct Sadjlist *) malloc(sizeof(struct Sadjlist));
if (alink == NULL) return(101); if (alink == NULL) return(101);
if (!pmark) alink->node = i; if (!pmark) alink->node = i;
else alink->node = 0; // Parallel link marker else alink->node = 0; // Parallel link marker
alink->link = k; alink->link = k;
alink->next = net->Adjlist[j]; alink->next = net->Adjlist[j];
net->Adjlist[j] = alink; net->Adjlist[j] = alink;
@@ -276,7 +275,7 @@ int localadjlists(Network *net, Smatrix *sm)
int paralink(Network *net, Smatrix *sm, int i, int j, int k) int paralink(Network *net, Smatrix *sm, int i, int j, int k)
/* /*
**-------------------------------------------------------------- **--------------------------------------------------------------
** Input: i = index of start node of link ** Input: i = index of start node of link
** j = index of end node of link ** j = index of end node of link
** k = link index ** k = link index
** Output: returns 1 if link k parallels another link, else 0 ** Output: returns 1 if link k parallels another link, else 0
@@ -350,10 +349,10 @@ void xparalinks(Network *net)
int reordernodes(Project *pr) int reordernodes(Project *pr)
/* /*
**-------------------------------------------------------------- **--------------------------------------------------------------
** Input: none ** Input: none
** Output: returns 1 if successful, 0 if not ** Output: returns 1 if successful, 0 if not
** Purpose: re-orders nodes to minimize # of non-zeros that ** Purpose: re-orders nodes to minimize # of non-zeros that
** will appear in factorized solution matrix ** will appear in factorized solution matrix
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
@@ -376,7 +375,7 @@ int reordernodes(Project *pr)
int *qsize = NULL; int *qsize = NULL;
int *llist = NULL; int *llist = NULL;
int *marker = NULL; int *marker = NULL;
// Default ordering // Default ordering
for (k = 1; k <= net->Nnodes; k++) for (k = 1; k <= net->Nnodes; k++)
{ {
@@ -483,17 +482,17 @@ int factorize(Project *pr)
int growlist(Project *pr, int knode) int growlist(Project *pr, int knode)
/* /*
**-------------------------------------------------------------- **--------------------------------------------------------------
** Input: knode = node index ** Input: knode = node index
** Output: returns 1 if successful, 0 if not ** Output: returns 1 if successful, 0 if not
** Purpose: creates new entries in knode's adjacency list for ** Purpose: creates new entries in knode's adjacency list for
** all unlinked pairs of active nodes that are ** all unlinked pairs of active nodes that are
** adjacent to knode ** adjacent to knode
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
Network *net = &pr->network; Network *net = &pr->network;
Smatrix *sm = &pr->hydraul.smatrix; Smatrix *sm = &pr->hydraul.smatrix;
int node; int node;
Padjlist alink; Padjlist alink;
@@ -517,16 +516,16 @@ int growlist(Project *pr, int knode)
int newlink(Project *pr, Padjlist alink) int newlink(Project *pr, Padjlist alink)
/* /*
**-------------------------------------------------------------- **--------------------------------------------------------------
** Input: alink = element of node's adjacency list ** Input: alink = element of node's adjacency list
** Output: returns 1 if successful, 0 if not ** Output: returns 1 if successful, 0 if not
** Purpose: links end of current adjacent link to end nodes of ** Purpose: links end of current adjacent link to end nodes of
** all links that follow it on adjacency list ** all links that follow it on adjacency list
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
Network *net = &pr->network; Network *net = &pr->network;
Smatrix *sm = &pr->hydraul.smatrix; Smatrix *sm = &pr->hydraul.smatrix;
int inode, jnode; int inode, jnode;
Padjlist blink; Padjlist blink;
@@ -535,7 +534,7 @@ int newlink(Project *pr, Padjlist alink)
for (blink = alink->next; blink != NULL; blink = blink->next) for (blink = alink->next; blink != NULL; blink = blink->next)
{ {
jnode = blink->node; // End node of next connection jnode = blink->node; // End node of next connection
// If jnode still active, and inode not connected to jnode, // If jnode still active, and inode not connected to jnode,
// then add a new connection between inode and jnode. // then add a new connection between inode and jnode.
if (jnode > 0 && sm->Degree[jnode] > 0) // jnode still active if (jnode > 0 && sm->Degree[jnode] > 0) // jnode still active
@@ -545,7 +544,7 @@ int newlink(Project *pr, Padjlist alink)
// Since new connection represents a non-zero coeff. // Since new connection represents a non-zero coeff.
// in the solution matrix, update the coeff. count. // in the solution matrix, update the coeff. count.
sm->Ncoeffs++; sm->Ncoeffs++;
// Update adjacency lists for inode & jnode to // Update adjacency lists for inode & jnode to
// reflect the new connection. // reflect the new connection.
if (!addlink(net, inode, jnode, sm->Ncoeffs)) return 0; if (!addlink(net, inode, jnode, sm->Ncoeffs)) return 0;
@@ -562,10 +561,10 @@ int newlink(Project *pr, Padjlist alink)
int linked(Network *net, int i, int j) int linked(Network *net, int i, int j)
/* /*
**-------------------------------------------------------------- **--------------------------------------------------------------
** Input: i = node index ** Input: i = node index
** j = node index ** j = node index
** Output: returns 1 if nodes i and j are linked, 0 if not ** Output: returns 1 if nodes i and j are linked, 0 if not
** Purpose: checks if nodes i and j are already linked. ** Purpose: checks if nodes i and j are already linked.
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
@@ -581,11 +580,11 @@ int linked(Network *net, int i, int j)
int addlink(Network *net, int i, int j, int n) int addlink(Network *net, int i, int j, int n)
/* /*
**-------------------------------------------------------------- **--------------------------------------------------------------
** Input: i = node index ** Input: i = node index
** j = node index ** j = node index
** n = link index ** n = link index
** Output: returns 1 if successful, 0 if not ** Output: returns 1 if successful, 0 if not
** Purpose: augments node i's adjacency list with node j ** Purpose: augments node i's adjacency list with node j
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
@@ -603,20 +602,20 @@ int addlink(Network *net, int i, int j, int n)
int storesparse(Project *pr, int n) int storesparse(Project *pr, int n)
/* /*
**-------------------------------------------------------------- **--------------------------------------------------------------
** Input: n = number of rows in solution matrix ** Input: n = number of rows in solution matrix
** Output: returns error code ** Output: returns error code
** Purpose: stores row indexes of non-zeros of each column of ** Purpose: stores row indexes of non-zeros of each column of
** lower triangular portion of factorized matrix ** lower triangular portion of factorized matrix
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
Network *net = &pr->network; Network *net = &pr->network;
Smatrix *sm = &pr->hydraul.smatrix; Smatrix *sm = &pr->hydraul.smatrix;
int i, ii, j, k, l, m; int i, ii, j, k, l, m;
int errcode = 0; int errcode = 0;
Padjlist alink; Padjlist alink;
// Allocate sparse matrix storage // Allocate sparse matrix storage
sm->XLNZ = (int *) calloc(n+2, sizeof(int)); sm->XLNZ = (int *) calloc(n+2, sizeof(int));
sm->NZSUB = (int *) calloc(sm->Ncoeffs+2, sizeof(int)); sm->NZSUB = (int *) calloc(sm->Ncoeffs+2, sizeof(int));
@@ -625,7 +624,7 @@ int storesparse(Project *pr, int n)
ERRCODE(MEMCHECK(sm->NZSUB)); ERRCODE(MEMCHECK(sm->NZSUB));
ERRCODE(MEMCHECK(sm->LNZ)); ERRCODE(MEMCHECK(sm->LNZ));
if (errcode) return errcode; if (errcode) return errcode;
// Generate row index pointers for each column of matrix // Generate row index pointers for each column of matrix
k = 0; k = 0;
sm->XLNZ[1] = 1; sm->XLNZ[1] = 1;
@@ -655,20 +654,20 @@ int storesparse(Project *pr, int n)
int sortsparse(Smatrix *sm, int n) int sortsparse(Smatrix *sm, int n)
/* /*
**-------------------------------------------------------------- **--------------------------------------------------------------
** Input: n = number of rows in solution matrix ** Input: n = number of rows in solution matrix
** Output: returns eror code ** Output: returns eror code
** Purpose: puts row indexes in ascending order in NZSUB ** Purpose: puts row indexes in ascending order in NZSUB
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
int i, k; int i, k;
int *xlnzt, *nzsubt, *lnzt, *nzt; int *xlnzt, *nzsubt, *lnzt, *nzt;
int errcode = 0; int errcode = 0;
int *LNZ = sm->LNZ; int *LNZ = sm->LNZ;
int *XLNZ = sm->XLNZ; int *XLNZ = sm->XLNZ;
int *NZSUB = sm->NZSUB; int *NZSUB = sm->NZSUB;
xlnzt = (int *) calloc(n+2, sizeof(int)); xlnzt = (int *) calloc(n+2, sizeof(int));
nzsubt = (int *) calloc(sm->Ncoeffs+2, sizeof(int)); nzsubt = (int *) calloc(sm->Ncoeffs+2, sizeof(int));
lnzt = (int *) calloc(sm->Ncoeffs+2, sizeof(int)); lnzt = (int *) calloc(sm->Ncoeffs+2, sizeof(int));
@@ -687,12 +686,12 @@ int sortsparse(Smatrix *sm, int n)
} }
xlnzt[1] = 1; xlnzt[1] = 1;
for (i = 1; i <= n; i++) xlnzt[i+1] = xlnzt[i] + nzt[i]; for (i = 1; i <= n; i++) xlnzt[i+1] = xlnzt[i] + nzt[i];
// Transpose matrix twice to order column indexes // Transpose matrix twice to order column indexes
transpose(n, XLNZ, NZSUB, LNZ, xlnzt, nzsubt, lnzt, nzt); transpose(n, XLNZ, NZSUB, LNZ, xlnzt, nzsubt, lnzt, nzt);
transpose(n, xlnzt, nzsubt, lnzt, XLNZ, NZSUB, LNZ, nzt); transpose(n, xlnzt, nzsubt, lnzt, XLNZ, NZSUB, LNZ, nzt);
} }
// Reclaim memory // Reclaim memory
free(xlnzt); free(xlnzt);
free(nzsubt); free(nzsubt);
@@ -706,11 +705,11 @@ void transpose(int n, int *il, int *jl, int *xl, int *ilt, int *jlt,
int *xlt, int *nzt) int *xlt, int *nzt)
/* /*
**--------------------------------------------------------------------- **---------------------------------------------------------------------
** Input: n = matrix order ** Input: n = matrix order
** il,jl,xl = sparse storage scheme for original matrix ** il,jl,xl = sparse storage scheme for original matrix
** nzt = work array ** nzt = work array
** Output: ilt,jlt,xlt = sparse storage scheme for transposed matrix ** Output: ilt,jlt,xlt = sparse storage scheme for transposed matrix
** Purpose: Determines sparse storage scheme for transpose of a matrix ** Purpose: Determines sparse storage scheme for transpose of a matrix
**--------------------------------------------------------------------- **---------------------------------------------------------------------
*/ */
{ {
@@ -735,25 +734,25 @@ int linsolve(Smatrix *sm, int n)
/* /*
**-------------------------------------------------------------- **--------------------------------------------------------------
** Input: sm = sparse matrix struct ** Input: sm = sparse matrix struct
n = number of equations n = number of equations
** Output: sm->F = solution values ** Output: sm->F = solution values
** returns 0 if solution found, or index of ** returns 0 if solution found, or index of
** equation causing system to be ill-conditioned ** equation causing system to be ill-conditioned
** Purpose: solves sparse symmetric system of linear ** Purpose: solves sparse symmetric system of linear
** equations using Cholesky factorization ** equations using Cholesky factorization
** **
** NOTE: This procedure assumes that the solution matrix has ** NOTE: This procedure assumes that the solution matrix has
** been symbolically factorized with the positions of ** been symbolically factorized with the positions of
** the lower triangular, off-diagonal, non-zero coeffs. ** the lower triangular, off-diagonal, non-zero coeffs.
** stored in the following integer arrays: ** stored in the following integer arrays:
** XLNZ (start position of each column in NZSUB) ** XLNZ (start position of each column in NZSUB)
** NZSUB (row index of each non-zero in each column) ** NZSUB (row index of each non-zero in each column)
** LNZ (position of each NZSUB entry in Aij array) ** LNZ (position of each NZSUB entry in Aij array)
** **
** This procedure has been adapted from subroutines GSFCT and ** This procedure has been adapted from subroutines GSFCT and
** GSSLV in the book "Computer Solution of Large Sparse ** GSSLV in the book "Computer Solution of Large Sparse
** Positive Definite Systems" by A. George and J. W-H Liu ** Positive Definite Systems" by A. George and J. W-H Liu
** (Prentice-Hall, 1981). ** (Prentice-Hall, 1981).
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
@@ -766,7 +765,7 @@ int linsolve(Smatrix *sm, int n)
int *NZSUB = sm->NZSUB; int *NZSUB = sm->NZSUB;
int *link = sm->link; int *link = sm->link;
int *first = sm->first; int *first = sm->first;
int i, istop, istrt, isub, j, k, kfirst, newk; int i, istop, istrt, isub, j, k, kfirst, newk;
double bj, diagj, ljk; double bj, diagj, ljk;

View File

@@ -384,7 +384,7 @@ typedef struct // Node Object
Psource S; // source pointer Psource S; // source pointer
double C0; // initial quality double C0; // initial quality
double Ke; // emitter coeff. double Ke; // emitter coeff.
char Rpt; // reporting flag int Rpt; // reporting flag
NodeType Type; // node type NodeType Type; // node type
char Comment[MAXMSG+1]; // node comment char Comment[MAXMSG+1]; // node comment
} Snode; } Snode;
@@ -405,7 +405,7 @@ typedef struct // Link Object
double Qa; // low flow limit double Qa; // low flow limit
LinkType Type; // link type LinkType Type; // link type
StatusType Status; // initial status StatusType Status; // initial status
char Rpt; // reporting flag int Rpt; // reporting flag
char Comment[MAXMSG+1]; // link Comment char Comment[MAXMSG+1]; // link Comment
} Slink; } Slink;
@@ -466,7 +466,7 @@ typedef struct // Field Object of Report Table
{ {
char Name[MAXID+1]; // name of reported variable char Name[MAXID+1]; // name of reported variable
char Units[MAXID+1]; // units of reported variable char Units[MAXID+1]; // units of reported variable
char Enabled; // enabled if in table int Enabled; // enabled if in table
int Precision; // number of decimal places int Precision; // number of decimal places
double RptLim[2]; // lower/upper report limits double RptLim[2]; // lower/upper report limits
} SField; } SField;
@@ -544,9 +544,6 @@ typedef struct {
FILE *InFile; // Input file handle FILE *InFile; // Input file handle
char char
Unitsflag, // Unit system flag
Flowflag, // Flow units flag
Pressflag, // Pressure units flag
DefPatID[MAXID+1], // Default demand pattern ID DefPatID[MAXID+1], // Default demand pattern ID
InpFname[MAXFNAME+1], // Input file name InpFname[MAXFNAME+1], // Input file name
*Tok[MAXTOKS], // Array of token strings *Tok[MAXTOKS], // Array of token strings
@@ -566,7 +563,10 @@ typedef struct {
MaxCurves, // Curve count " " " MaxCurves, // Curve count " " "
Ntokens, // Number of tokens in line of input Ntokens, // Number of tokens in line of input
Ntitle, // Number of title lines Ntitle, // Number of title lines
ErrTok; // Index of error-producing token ErrTok, // Index of error-producing token
Unitsflag, // Unit system flag
Flowflag, // Flow units flag
Pressflag; // Pressure units flag
STmplist STmplist
*Patlist, // Temporary time pattern list *Patlist, // Temporary time pattern list
@@ -605,13 +605,7 @@ typedef struct {
int int
Nperiods, // Number of reporting periods Nperiods, // Number of reporting periods
PageSize; // Lines/page in output report/ PageSize, // Lines/page in output report/
long
LineNum, // Current line number
PageNum; // Current page number
char
Rptflag, // Report flag Rptflag, // Report flag
Tstatflag, // Report time series statistic flag Tstatflag, // Report time series statistic flag
Summaryflag, // Report summary flag Summaryflag, // Report summary flag
@@ -620,11 +614,17 @@ typedef struct {
Energyflag, // Energy report flag Energyflag, // Energy report flag
Nodeflag, // Node report flag Nodeflag, // Node report flag
Linkflag, // Link report flag Linkflag, // Link report flag
Fprinterr; // File write error flag
long
LineNum, // Current line number
PageNum; // Current page number
char
Atime[13], // Clock time (hrs:min:sec) Atime[13], // Clock time (hrs:min:sec)
Rpt1Fname[MAXFNAME+1], // Primary report file name Rpt1Fname[MAXFNAME+1], // Primary report file name
Rpt2Fname[MAXFNAME+1], // Secondary report file name Rpt2Fname[MAXFNAME+1], // Secondary report file name
DateStamp[26], // Current date & time DateStamp[26]; // Current date & time
Fprinterr; // File write error flag
SField Field[MAXVAR]; // Output reporting fields SField Field[MAXVAR]; // Output reporting fields
@@ -635,7 +635,9 @@ typedef struct {
char char
HydFname[MAXFNAME+1], // Hydraulics file name HydFname[MAXFNAME+1], // Hydraulics file name
OutFname[MAXFNAME+1], // Binary output file name OutFname[MAXFNAME+1]; // Binary output file name
int
Outflag, // Output file flag Outflag, // Output file flag
Hydflag, // Hydraulics flag Hydflag, // Hydraulics flag
SaveHflag, // Hydraulic results saved flag SaveHflag, // Hydraulic results saved flag
@@ -732,22 +734,20 @@ typedef struct {
DefPat, // Default demand pattern DefPat, // Default demand pattern
Epat, // Energy cost time pattern Epat, // Energy cost time pattern
DemandModel, // Fixed or pressure dependent DemandModel, // Fixed or pressure dependent
Formflag, // Head loss formula flag
Iterations, // Number of hydraulic trials taken Iterations, // Number of hydraulic trials taken
MaxIter, // Max. hydraulic trials allowed MaxIter, // Max. hydraulic trials allowed
ExtraIter, // Extra hydraulic trials ExtraIter, // Extra hydraulic trials
CheckFreq, // Hydraulic trials between status checks CheckFreq, // Hydraulic trials between status checks
MaxCheck, // Hydraulic trials limit on status checks MaxCheck, // Hydraulic trials limit on status checks
OpenHflag, // Hydraulic system opened flag
Haltflag; // Flag to halt simulation Haltflag; // Flag to halt simulation
StatusType StatusType
*LinkStatus, // Link status *LinkStatus, // Link status
*OldStatus; // Previous link/tank status *OldStatus; // Previous link/tank status
char Smatrix smatrix; // Sparse matrix storage
OpenHflag, // Hydraulic system opened flag
Formflag; // Head loss formula flag
Smatrix smatrix; // Sparse matrix storage
} Hydraul; } Hydraul;
@@ -757,20 +757,18 @@ struct Mempool;
// Water Quality Solver Wrapper // Water Quality Solver Wrapper
typedef struct { typedef struct {
char int
Qualflag, // Water quality analysis flag Qualflag, // Water quality analysis flag
OpenQflag, // Quality system opened flag OpenQflag, // Quality system opened flag
Reactflag, // Reaction indicator Reactflag, // Reaction indicator
OutOfMemory; // Out of memory indicator OutOfMemory, // Out of memory indicator
TraceNode, // Source node for flow tracing
*SortedNodes; // Topologically sorted node indexes
char char
ChemName[MAXID + 1], // Name of chemical ChemName[MAXID + 1], // Name of chemical
ChemUnits[MAXID + 1]; // Units of chemical ChemUnits[MAXID + 1]; // Units of chemical
int
TraceNode, // Source node for flow tracing
*SortedNodes; // Topologically sorted node indexes
double double
Ctol, // Water quality tolerance Ctol, // Water quality tolerance
Diffus, // Diffusivity (sq ft/sec) Diffus, // Diffusivity (sq ft/sec)
@@ -854,9 +852,11 @@ typedef struct Project {
double Ucf[MAXVAR]; // Unit conversion factors double Ucf[MAXVAR]; // Unit conversion factors
char int
Openflag, // Project open flag Openflag, // Project open flag
Warnflag, // Warning flag Warnflag; // Warning flag
char
Msg[MAXMSG+1], // General-purpose string: errors, messages Msg[MAXMSG+1], // General-purpose string: errors, messages
Title[MAXTITLE][TITLELEN+1], // Project title Title[MAXTITLE][TITLELEN+1], // Project title
MapFname[MAXFNAME+1], // Map file name MapFname[MAXFNAME+1], // Map file name

View File

@@ -45,14 +45,14 @@ int main(int argc, char *argv[])
EN_init(ph, "", "", EN_GPM, EN_HW); EN_init(ph, "", "", EN_GPM, EN_HW);
// Build a network // Build a network
EN_addnode(ph, "N1", EN_JUNCTION); EN_addnode(ph, (char *)"N1", EN_JUNCTION);
EN_addnode(ph, "N2", EN_JUNCTION); EN_addnode(ph, (char *)"N2", EN_JUNCTION);
EN_addnode(ph, "N3", EN_RESERVOIR); EN_addnode(ph, (char *)"N3", EN_RESERVOIR);
EN_addnode(ph, "N4", EN_TANK); EN_addnode(ph, (char *)"N4", EN_TANK);
EN_addlink(ph, "L1", EN_PUMP, "N3", "N1"); EN_addlink(ph, (char *)"L1", EN_PUMP, (char *)"N3", (char *)"N1");
EN_addlink(ph, "L2", EN_PIPE, "N1", "N3"); EN_addlink(ph, (char *)"L2", EN_PIPE, (char *)"N1", (char *)"N3");
EN_addlink(ph, "L3", EN_PIPE, "N1", "N2"); EN_addlink(ph, (char *)"L3", EN_PIPE, (char *)"N1", (char *)"N2");
EN_addcurve(ph, "C1"); EN_addcurve(ph, (char *)"C1");
// Set network data using the new helper functions // Set network data using the new helper functions
EN_setcurvevalue(ph, 1, 1, 1500, 250); EN_setcurvevalue(ph, 1, 1, 1500, 250);
@@ -88,9 +88,9 @@ int main(int argc, char *argv[])
// Save these new results // Save these new results
EN_getnodevalue(ph, 1, EN_PRESSURE, &p1_2); EN_getnodevalue(ph, 1, EN_PRESSURE, &p1_2);
EN_getnodevalue(ph, 2, EN_PRESSURE, &p2_2); EN_getnodevalue(ph, 2, EN_PRESSURE, &p2_2);
EN_getlinkindex(ph, "L1", &index); EN_getlinkindex(ph, (char *)"L1", &index);
EN_getlinkvalue(ph, index, EN_FLOW, &q1_2); EN_getlinkvalue(ph, index, EN_FLOW, &q1_2);
EN_getlinkindex(ph, "L2", &index); EN_getlinkindex(ph, (char *)"L2", &index);
EN_getlinkvalue(ph, index, EN_FLOW, &q2_2); EN_getlinkvalue(ph, index, EN_FLOW, &q2_2);
// Display old & new results // Display old & new results