diff --git a/include/epanet2.vb b/include/epanet2.vb index d6a31c6..3ada541 100644 --- a/include/epanet2.vb +++ b/include/epanet2.vb @@ -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 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 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 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 '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 ENsetdemandmodel Lib "epanet2.dll" (ByVal type As Int32, ByVal pmin As Single, ByVal preq As Single, ByVal 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 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 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 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 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 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 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 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 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 ENgetcurvetype Lib "epanet2.dll" (ByVal index As Int32, type 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 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 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 '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 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 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 'Rule-Based Control Functions Declare Function ENaddrule Lib "epanet2.dll" (ByVal rule As String) As Int32 diff --git a/include/epanet2_2.h b/include/epanet2_2.h index ed2213b..ae21a60 100644 --- a/include/epanet2_2.h +++ b/include/epanet2_2.h @@ -6,12 +6,12 @@ ****************************************************************************** Project: OWA EPANET Version: 2.2 - Module: epanet2_2.h - Description: declarations of the new thread-safe EPANET 2 API functions + Module: epanet2.h + Description: API function declarations Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE - Last Updated: 01/09/2019 + Last Updated: 01/08/2019 ****************************************************************************** */ @@ -64,14 +64,15 @@ typedef struct Project *EN_Project; ********************************************************************/ -/** + /** @brief Creates an EPANET project. @param[out] ph an EPANET project handle that is passed into all other API functions. @return an error code. + + EN_createproject must be called before any other API functions are used. */ int DLLEXPORT EN_createproject(EN_Project *ph); - /** @brief Deletes a currently opened EPANET project. @param[in,out] ph an EPANET project handle which is returned as NULL. @@ -93,13 +94,13 @@ typedef struct Project *EN_Project; The callback function should reside in and be used by the calling code to display the progress messages that EPANET generates as it carries out its computations. Here is an example of a such a function that displays progress messages to stdout: - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + \code {.c} void writeConsole(char *s) { fprintf(stdout, "\n%s", s); } - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - It would be passed into EN_runproject as &writeConsole. If this feature is not needed then + \endcode + It would be passed into EN_runproject as `&writeConsole`. If this feature is not needed then the pviewprog argument should be NULL. */ int DLLEXPORT EN_runproject(EN_Project ph, const char *inpFile, const char *rptFile, @@ -110,11 +111,11 @@ typedef struct Project *EN_Project; @param ph an EPANET project handle. @param rptFile the name of a report file to be created (or "" if not needed). @param outFile the name of a binary output file to be created (or "" if not needed). - @param unitsType the choice of flow units (see ::EN_FlowUnits). - @param headLossType the choice of head loss formula (see ::EN_HeadLossType). + @param unitsType the choice of flow units (see @ref EN_FlowUnits). + @param headLossType the choice of head loss formula (see @ref EN_HeadLossType). @return an error code. - This function should be called immediately after EN_open if an EPANET-formatted input + This function should be called immediately after ::EN_createproject if an EPANET-formatted input file will not be used to supply network data. If the project receives it's network data from an input file then there is no need to call this function. */ @@ -128,11 +129,13 @@ typedef struct Project *EN_Project; @param rptFile the name of a report file to be created (or "" if not needed). @param outFile the name of a binary output file to be created (or "" if not needed). @return an error code. + + This function should be called immediately after ::EN_createproject if an EPANET-formatted + input file will be used to supply network data. */ int DLLEXPORT EN_open(EN_Project ph, const char *inpFile, const char *rptFile, const char *outFile); - /** @brief Saves a project's data to an EPANET-formatted text file. @param ph an EPANET project handle. @@ -141,14 +144,13 @@ typedef struct Project *EN_Project; */ int DLLEXPORT EN_saveinpfile(EN_Project ph, const char *filename); - /** @brief Closes a project and frees all of its memory. @param ph an EPANET project handle. @return Error code This function clears all existing data from a project but does not delete the - project, so it can be re-used with another set of network data. Use \ref EN_deleteProject + project, so it can be re-used with another set of network data. Use ::EN_deleteproject to actually delete a project from memory. */ int DLLEXPORT EN_close(EN_Project ph); @@ -165,7 +167,7 @@ typedef struct Project *EN_Project; @param ph an EPANET project handle. @return an error code. - Use EN_solveH to generate a complete hydraulic solution which can stand alone + Use ::EN_solveH to generate a complete hydraulic solution which can stand alone or be used as input to a water quality analysis. This function will not allow one to examine intermediate hydraulic results as they are generated. It can also be followed by calls to ::EN_saveH and ::EN_report to write hydraulic results to the report file. @@ -173,10 +175,20 @@ typedef struct Project *EN_Project; The sequence ::EN_openH - ::EN_initH - ::EN_runH - ::EN_nextH - ::EN_closeH can be used instead to gain access to results at intermediate time periods and directly adjust link status and control settings as a simulation proceeds. + + Example: + \code {.c} + EN_Project ph; + EN_createproject(&ph); + EN_open(ph, "net1.inp", "net1.rpt", ""); + EN_solveH(ph); + EN_solveQ(ph); + EN_report(ph); + EN_deleteproject(&ph); + \endcode */ int DLLEXPORT EN_solveH(EN_Project ph); - /** @brief Uses a previously saved binary hydraulics file to supply a project's hydraulics. @param ph an EPANET project handle. @@ -191,92 +203,111 @@ typedef struct Project *EN_Project; */ int DLLEXPORT EN_usehydfile(EN_Project ph, char *filename); - /** @brief Opens a project's hydraulic solver. @param ph an EPANET project handle. @return an error code. - Call EN_openH prior to running the first hydraulic analysis using the EN_initH - EN_runH - EN_nextH - sequence. Multiple analyses can be made before calling ::EN_closeH to close the hydraulic solver. + Call ::EN_openH prior to running the first hydraulic analysis using the + ::EN_initH - ::EN_runH - ::EN_nextH sequence. Multiple analyses can be made before + calling ::EN_closeH to close the hydraulic solver. - Do not call this function if ::EN_solveH is being used to run a complete hydraulic analysis or if - hydraulics are being supplied by a previously saved hydraulics file using ::EN_usehydfile. + Do not call this function if ::EN_solveH is being used to run a complete hydraulic + analysis or if hydraulics are being supplied by a previously saved hydraulics file + using ::EN_usehydfile. */ int DLLEXPORT EN_openH(EN_Project ph); - /** @brief Initializes a network prior to running a hydraulic analysis. @param ph an EPANET project handle. - @param initFlag a 2-digit initialization flag (see ::EN_SaveOption). + @param initFlag a 2-digit initialization flag (see @ref EN_InitHydOption). @return an error code. + This function initializes storage tank levels, link status and settings, and + the simulation time clock prior to running a hydraulic analysis. + The initialization flag is a two digit number where the 1st (left) digit indicates if link flows should be re-initialized (1) or not (0), and the 2nd digit indicates if hydraulic results should be saved to a temporary binary hydraulics file (1) or not (0). - Be sure to call EN_initH prior to running a hydraulic analysis using a ::EN_runH - ::EN_nextH loop. + Be sure to call ::EN_initH prior to running a hydraulic analysis using a + ::EN_runH - ::EN_nextH loop. Choose to save hydraulics results if you will be: - making a subsequent water quality run, - using ::EN_report to generate a report - - or using ::EN_savehydfile to save the binary hydraulics file. - There is no need to save hydraulics if you will be writing custom code to process hydraulic - results as they are generated, using functions like ::EN_getnodevalue and ::EN_getlinkvalue. + - using ::EN_savehydfile to save the binary hydraulics file. + + There is no need to save hydraulics if you will be writing custom code to + process hydraulic results as they are generated using the functions ::EN_getnodevalue + and ::EN_getlinkvalue. */ int DLLEXPORT EN_initH(EN_Project ph, int initFlag); - /** @brief Computes a hydraulic solution for the current point in time. @param ph an EPANET project handle. @param[out] currentTime the current simulation time in seconds. @return an error or warning code. - This function is used in a loop with ::EN_nextH() to run an extended period hydraulic simulation. - This process automatically updates the simulation clock time so currentTime should be treated as a - read-only variable. + This function is used in a loop with ::EN_nextH to run an extended period hydraulic + simulation. This process automatically updates the simulation clock time so currentTime + should be treated as a read-only variable. - ::EN_initH must have been called prior to running the EN_runH - EN_nextH loop. + ::EN_initH must have been called prior to running the ::EN_runH - ::EN_nextH loop. + + See ::EN_nextH for an example of using this function. */ int DLLEXPORT EN_runH(EN_Project ph, long *currentTime); - /** - @brief Determines the length of time until the next hydraulic event occurs in an extended period - simulation. + @brief Determines the length of time until the next hydraulic event occurs in an + extended period simulation. @param ph an EPANET project handle. - @param[out] tStep the time (in seconds) until the next hydraulic event or 0 if at the end of the - full simulation duration. + @param[out] tStep the time (in seconds) until the next hydraulic event or 0 if at + the end of the full simulation duration. @return an error code. - This function is used in a loop with ::EN_runH() to run an extended period hydraulic simulation. + This function is used in a loop with ::EN_runH to run an extended period hydraulic + simulation. - The value of tstep should be treated as a read-only variable. It is automatically computed as - the smaller of: + The value of tstep should be treated as a read-only variable. It is automatically + computed as the smaller of: - the time interval until the next hydraulic time step begins - the time interval until the next reporting time step begins - the time interval until the next change in demands occurs - the time interval until a tank becomes full or empty - the time interval until a control or rule fires. + + Example: + \code {.c} + long t, tstep; + EN_openH(ph); + EN_initH(ph, EN_NOSAVE); + do { + EN_runH(ph, &t); + // Retrieve hydraulic results for time t + EN_nextH(ph, &tstep); + } while (tstep > 0); + EN_closeH(ph); + \endcode */ int DLLEXPORT EN_nextH(EN_Project ph, long *tStep); /** - @brief Transfers a project's hydraulics results from its temporary hydraulics file to its - binary output file, where results are only reported at uniform reporting intervals. + @brief Transfers a project's hydraulics results from its temporary hydraulics file + to its binary output file, where results are only reported at uniform reporting intervals. @param ph an EPANET project handle. @return an error code. - EN_saveH is used when only a hydraulic analysis is run and results at uniform reporting intervals - need to be transferred to EPANET's binary output file. Such would be the case when an output - report to EPANET's report file will be written using ::EN_report. + ::EN_saveH is used when only a hydraulic analysis is run and results at uniform reporting + intervals need to be transferred to a project's binary output file. Such would be the case + when results are to be written in formatted fashion to the project's report file using ::EN_report. */ int DLLEXPORT EN_saveH(EN_Project ph); - /** @brief Saves a project's temporary hydraulics file to disk. @param ph an EPANET project handle. @@ -288,13 +319,19 @@ typedef struct Project *EN_Project; The hydraulics file contains nodal demands and heads and link flows, status, and settings for all hydraulic time steps, even intermediate ones. + + Before calling this function hydraulic results must have been generated and saved by having + called ::EN_solveH or the ::EN_initH - ::EN_runH - ::EN_nextH sequence with the initflag + argument of ::EN_initH set to `EN_SAVE` or `EN_SAVE_AND_INIT`. */ int DLLEXPORT EN_savehydfile(EN_Project ph, char *filename); - /** @brief Closes the hydraulic solver freeing all of its allocated memory. @return an error code. + + Call ::EN_closeH after all hydraulics analyses have been made using + ::EN_initH - ::EN_runH - ::EN_nextH. Do not call this function if ::EN_solveH is being used. */ int DLLEXPORT EN_closeH(EN_Project ph); @@ -311,23 +348,24 @@ typedef struct Project *EN_Project; @return an error code. A hydraulic analysis must have been run and saved to a hydraulics file before - calling EN_solveQ. This function will not allow one to examine intermediate water + calling ::EN_solveQ. This function will not allow one to examine intermediate water quality results as they are generated. It can be followed by a call to ::EN_report to write all hydraulic and water quality results to a formatted report file. One can instead use the ::EN_openQ - ::EN_initQ - ::EN_runQ - ::EN_nextQ - ::EN_closeQ sequence to gain access to gain access to water quality results at intermediate time periods. + + Example: see ::EN_solveH. */ int DLLEXPORT EN_solveQ(EN_Project ph); - /** @brief Opens a project's water quality solver. @param ph n EPANET project handle. @return an error code. - Call EN_openQ prior to running the first water quality analysis using an + Call ::EN_openQ prior to running the first water quality analysis using an ::EN_initQ - ::EN_runQ - ::EN_nextQ (or ::EN_stepQ) sequence. Multiple water quality analyses can be made before calling ::EN_closeQ to close the water quality solver. @@ -337,24 +375,22 @@ typedef struct Project *EN_Project; */ int DLLEXPORT EN_openQ(EN_Project ph); - /** @brief Initializes a network prior to running a water quality analysis. @param ph n EPANET project handle. - @param saveFlag set to EN_SAVE (1) if results are to be saved to the project's - binary output file, or to EN_NOSAVE (0) if not. + @param saveFlag set to `EN_SAVE` (1) if results are to be saved to the project's + binary output file, or to `EN_NOSAVE` (0) if not. @return an error code. - Call EN_initQ prior to running a water quality analysis using ::EN_runQ in conjunction with - either ::EN_nextQ or ::EN_stepQ. + Call ::EN_initQ prior to running a water quality analysis using ::EN_runQ in + conjunction with either ::EN_nextQ or ::EN_stepQ. ::EN_openQ must have been called prior to calling EN_initQ. - Do not call EN_initQ if a complete water quality analysis will be made using ::EN_solveQ. + Do not call ::EN_initQ if a complete water quality analysis will be made using ::EN_solveQ. */ int DLLEXPORT EN_initQ(EN_Project ph, int saveFlag); - /** @brief Makes hydraulic and water quality results at the start of the current time period available to a project's water quality solver. @@ -362,57 +398,77 @@ typedef struct Project *EN_Project; @param[out] currentTime current simulation time in seconds. @return an error code. - Use EN_runQ along with ::EN_nextQ in a loop to access water quality results at the start - of each hydraulic period in an extended period simulation. Or use it in a loop with ::EN_stepQ - to access results at the start of each water quality time step. See each of these functions - for examples of how to code such loops. + Use ::EN_runQ along with ::EN_nextQ in a loop to access water quality results at the + start of each hydraulic period in an extended period simulation. Or use it in a loop + with ::EN_stepQ to access results at the start of each water quality time step. See + each of these functions for examples of how to code such loops. - ::EN_initQ must have been called prior to running an EN_runQ - EN_nextQ (or EN_stepQ) loop. + ::EN_initQ must have been called prior to running an ::EN_runQ - ::EN_nextQ + (or ::EN_stepQ) loop. - The current time of the simulation is determined from information saved with the hydraulic - analysis that preceded the water quality analysis. Treat it as a read-only variable. + The current time of the simulation is determined from information saved with the + hydraulic analysis that preceded the water quality analysis. Treat it as a read-only + variable. */ int DLLEXPORT EN_runQ(EN_Project ph, long *currentTime); - /** @brief Advances a water quality simulation over the time until the next hydraulic event. @param ph an EPANET project handle. - @param[out] tStep time (in seconds) until the next hydraulic event or 0 if at the end of the - full simulation duration. + @param[out] tStep time (in seconds) until the next hydraulic event or 0 if at the end + of the full simulation duration. @return an error code. - This function is used in a loop with ::EN_runQ to perform an extended period water quality analysis. - It reacts and routes a project's water quality constituent over a time step determined by when - the next hydraulic event occurs. Use ::EN_stepQ instead if you wish to generate results over each - water quality time step. + This function is used in a loop with ::EN_runQ to perform an extended period water + quality analysis. It reacts and routes a project's water quality constituent over a + time step determined by when the next hydraulic event occurs. Use ::EN_stepQ instead + if you wish to generate results over each water quality time step. - The value of tstep is determined from information produced by the hydraulic analysis that - preceded the water quality analysis. Treat it as a read-only variable. + The value of `tStep` is determined from information produced by the hydraulic analysis + that preceded the water quality analysis. Treat it as a read-only variable. + + Example: + \code {.c} + long t, tStep; + EN_solveH(ph); // Generate & save hydraulics + EN_openQ(ph); + EN_initQ(ph, EN_NOSAVE); + do { + EN_runQ(ph, &t); + // Monitor results at time t, which + // begins a new hydraulic time period + EN_nextQ(ph, &tStep); + } while (tStep > 0); + EN_closeQ(ph); + \endcode */ int DLLEXPORT EN_nextQ(EN_Project ph, long *tStep); - /** @brief Advances a water quality simulation by a single water quality time step. @param ph an EPANET project handle. @param[out] timeLeft time left (in seconds) to the overall simulation duration. @return an error code. - This function is used in a loop with ::EN_runQ to perform an extended period water quality - simulation. It allows one to generate water quality results at each water quality time step - of the simulation, rather than over each hydraulic event period as with ::EN_nextQ. + This function is used in a loop with ::EN_runQ to perform an extended period water + quality simulation. It allows one to generate water quality results at each water + quality time step of the simulation, rather than over each hydraulic event period + as with ::EN_nextQ. - Use the argument timeLeft to determine when no more calls to EN_runQ are needed because - the end of the simulation period has been reached (i.e., when tleft = 0). + Use the argument `timeLeft` to determine when no more calls to ::EN_runQ are needed + because the end of the simulation period has been reached (i.e., when `timeLeft = 0`). */ int DLLEXPORT EN_stepQ(EN_Project ph, long *timeLeft); - /** @brief Closes the water quality solver, freeing all of its allocated memory. @param ph an EPANET project handle. @return an error code. + + Call ::EN_closeQ after all water quality analyses have been made using the + ::EN_initQ - ::EN_runQ - ::EN_nextQ (or ::EN_stepQ) sequence of function calls. + + Do not call this function if ::EN_solveQ is being used. */ int DLLEXPORT EN_closeQ(EN_Project ph); @@ -434,6 +490,13 @@ typedef struct Project *EN_Project; @brief Writes simulation results in a tabular format to a project's report file. @param ph an EPANET project handle. @return an error code + + Either a full hydraulic analysis or full hydraulic and water quality analysis must + have been run, with results saved to file, before ::EN_report is called. In the + former case, ::EN_saveH must also be called first to transfer results from the + project's intermediate hydraulics file to its output file. + + The format of the report is controlled by commands issued with ::EN_setreport. */ int DLLEXPORT EN_report(EN_Project ph); @@ -441,6 +504,16 @@ typedef struct Project *EN_Project; @brief Resets a project's report options to their default values. @param ph an EPANET project handle. @return an error code + + After calling this function the default reporting options are in effect. These are: + - no status report + - no energy report + - no nodes reported on + - no links reported on + - node variables reported to 2 decimal places + - link variables reported to 2 decimal places (3 for friction factor) + - node variables reported are elevation, head, pressure, and quality + - link variables reported are flow, velocity, and head loss. */ int DLLEXPORT EN_resetreport(EN_Project ph); @@ -452,20 +525,35 @@ typedef struct Project *EN_Project; Acceptable report formatting commands are described in Appendix C of the EPANET 2 Users Manual. + + Formatted results of a simulation can be written to a project's report file + using the ::EN_report function. */ int DLLEXPORT EN_setreport(EN_Project ph, char *format); /** @brief Sets the level of hydraulic status reporting. @param ph an EPANET project handle. - @param level a status reporting level code (see ::EN_StatusReport). + @param level a status reporting level code (see @ref EN_StatusReport). @return an error code. + + Status reporting writes changes in the hydraulics status of network elements to a + project's report file as a hydraulic simulation unfolds. There are three levels + of reporting: `EN_NO_REPORT` (no status reporting), `EN_NORMAL_REPORT` (normal + reporting) `EN_FULL_REPORT` (full status reporting). + + The full status report contains information at each trial of the solution to the + system hydraulic equations at each time step of a simulation. It is useful mainly + for debugging purposes. + + If many hydraulic analyses will be run in the application it is recommended that + status reporting be turned off (`level = EN_NO_REPORT`). */ int DLLEXPORT EN_setstatusreport(EN_Project ph, int level); /** @brief Retrieves the toolkit API version number. - @param[out] version the version of the OWA-EPANET toolkit + @param[out] version the version of the OWA-EPANET toolkit. @return an error code. The version number is to be interpreted with implied decimals, i.e., @@ -474,9 +562,9 @@ typedef struct Project *EN_Project; int DLLEXPORT EN_getversion(int *version); /** - @brief Retrieves the number of objects of a given type in the network. + @brief Retrieves the number of objects of a given type in a project. @param ph an EPANET project handle. - @param object a type of object to count (see ::EN_CountType) + @param object a type of object to count (see @ref EN_CountType) @param[out] count number of objects of the specified type @return an error code */ @@ -488,13 +576,15 @@ typedef struct Project *EN_Project; @param[out] errmsg the error message generated by the error code @param maxLen maximum number of characters that errmsg can hold @return an error code + + Error message strings should be at least @ref EN_MAXMSG characters in length. */ int DLLEXPORT EN_geterror(int errcode, char *errmsg, int maxLen); /** - @brief Retrieves a particular simulation statistic + @brief Retrieves a particular simulation statistic. @param ph an EPANET project handle. - @param type the type of statistic to retrieve (see ::EN_AnalysisStatistic). + @param type the type of statistic to retrieve (see @ref EN_AnalysisStatistic). @param[out] value the value of the statistic. @return an error code */ @@ -509,7 +599,7 @@ typedef struct Project *EN_Project; /** @brief Retrieves the value of an analysis option. @param ph an EPANET project handle. - @param option a type of analysis option (see ::EN_Option). + @param option a type of analysis option (see @ref EN_Option). @param[out] value the current value of the option. @return an error code */ @@ -518,7 +608,7 @@ typedef struct Project *EN_Project; /** @brief Sets the value for an anlysis option. @param ph an EPANET project handle. - @param option a type of analysis option (see ::EN_Option). + @param option a type of analysis option (see @ref EN_Option). @param value the new value assigned to the option. @return an error code. @see EN_Option @@ -528,23 +618,29 @@ typedef struct Project *EN_Project; /** @brief Retrieves a project's flow units. @param ph an EPANET project handle. - @param[out] units a flow units code (see ::EN_FlowUnits) + @param[out] units a flow units code (see @ref EN_FlowUnits) @return an error code. + + Flow units in liters or cubic meters implies that SI metric units are used for all + other quantities in addition to flow. Otherwise US Customary units are employed. */ int DLLEXPORT EN_getflowunits(EN_Project ph, int *units); /** @brief Sets a project's flow units. @param ph an EPANET project handle. - @param units a flow units code (see ::EN_FlowUnits) + @param units a flow units code (see @ref EN_FlowUnits) @return an error code. + + Flow units in liters or cubic meters implies that SI metric units are used for all + other quantities in addition to flow. Otherwise US Customary units are employed. */ int DLLEXPORT EN_setflowunits(EN_Project ph, int units); /** @brief Retrieves the value of a time parameter. @param ph an EPANET project handle. - @param param a time parameter code (see ::EN_TimeProperty). + @param param a time parameter code (see @ref EN_TimeParameter). @param[out] value the current value of the time parameter (in seconds). @return an error code. */ @@ -553,7 +649,7 @@ typedef struct Project *EN_Project; /** @brief Sets the value of a time parameter. @param ph an EPANET project handle. - @param param a time parameter code (see ::EN_TimeProperty). + @param param a time parameter code (see @ref EN_TimeParameter). @param value the new value of the time parameter (in seconds) @return an error code. */ @@ -562,7 +658,7 @@ typedef struct Project *EN_Project; /** @brief Gets information about the type of water quality analysis requested. @param ph an EPANET project handle. - @param[out] qualType type of analysis to run (see ::EN_QualityType). + @param[out] qualType type of analysis to run (see @ref EN_QualityType). @param[out] chemName name of chemical constituent. @param[out] chemUnits concentration units of the constituent. @param[out] traceNode index of the node being traced (if applicable). @@ -574,8 +670,8 @@ typedef struct Project *EN_Project; /** @brief Retrieves the type of water quality analysis to be run. @param ph an EPANET project handle. - @param[out] qualType the type of analysis to run (see ::EN_QualityType). - @param[out] traceNode the index of node being traced, if qualType is EN_TRACE. + @param[out] qualType the type of analysis to run (see @ref EN_QualityType). + @param[out] traceNode the index of node being traced, if `qualType = EN_TRACE`. @return an error code. */ int DLLEXPORT EN_getqualtype(EN_Project ph, int *qualType, int *traceNode); @@ -583,14 +679,16 @@ typedef struct Project *EN_Project; /** @brief Sets the type of water quality analysis to run. @param ph an EPANET project handle. - @param qualType the type of analysis to run (see ::EN_QualityType). + @param qualType the type of analysis to run (see @ref EN_QualityType). @param chemName the name of the quality constituent. @param chemUnits the concentration units of the constituent. - @param traceNode the index of the node being traced if qualType is EN_TRACE. + @param traceNode the ID name of the node being traced if `qualType = EN_TRACE`. @return an error code. - - _chemName_ and _chemUnits_ only apply when _qualType_ is EN_CHEM. - _traceNode_ only applies when _qualType_ is EN_TRACE. + + Chemical name and units can be an empty string if the analysis is not for a chemical. + The same holds for the trace node if the analysis is not for source tracing. + + Note that the trace node is specified by ID name and not by index. */ int DLLEXPORT EN_setqualtype(EN_Project ph, int qualType, char *chemName, char *chemUnits, char *traceNode); @@ -605,8 +703,10 @@ typedef struct Project *EN_Project; @brief Adds a new node to a project. @param ph an EPANET project handle. @param id the ID name of the node to be added. - @param nodeType the type of node being added (see ::EN_NodeType) + @param nodeType the type of node being added (see @ref EN_NodeType) @return an error code. + + When a new node is created all of it's properties (see @ref EN_NodeProperty) are set to 0. */ int DLLEXPORT EN_addnode(EN_Project ph, char *id, int nodeType); @@ -617,19 +717,19 @@ typedef struct Project *EN_Project; @param actionCode the action taken if any control contains the node and its links. @return an error code. - If _actionCode_ is EN_UNCONDITIONAL then the node, its incident links and all + If `actionCode` is `EN_UNCONDITIONAL` then the node, its incident links and all simple and rule-based controls that contain them are deleted. If set to - EN_CONDITIONAL then the node is not deleted if it or its incident links appear + `EN_CONDITIONAL` then the node is not deleted if it or its incident links appear in any controls and error code 261 is returned. */ int DLLEXPORT EN_deletenode(EN_Project ph, int index, int actionCode); /** - @brief Gets the index of node given its ID name. + @brief Gets the index of a node given its ID name. @param ph an EPANET project handle. @param id a node ID name. - @param[out] index the node's index. + @param[out] index the node's index (starting from 1). @return an error code */ int DLLEXPORT EN_getnodeindex(EN_Project ph, char *id, int *index); @@ -637,28 +737,30 @@ typedef struct Project *EN_Project; /** @brief Gets the ID name of a node given its index. @param ph an EPANET project handle. - @param index a node's index. + @param index a node's index (starting from 1). @param[out] id the node's ID name. @return an error code - The ID name must be sized to hold at least ::MAXID characters. + The ID name must be sized to hold at least @ref EN_MAXID characters. */ int DLLEXPORT EN_getnodeid(EN_Project ph, int index, char *id); /** @brief Changes the ID name of a node. @param ph an EPANET project handle. - @param index a node's index. + @param index a node's index (starting from 1). @param newid the new ID name for the node. @return an error code. + + The ID name must not be longer than @ref EN_MAXID characters. */ int DLLEXPORT EN_setnodeid(EN_Project ph, int index, char *newid); /** @brief Retrieves a node's type given its index. @param ph an EPANET project handle. - @param index a node's index. - @param[out] nodeType the node's type (see ::EN_NodeType). + @param index a node's index (starting from 1). + @param[out] nodeType the node's type (see @ref EN_NodeType). @return an error code. */ int DLLEXPORT EN_getnodetype(EN_Project ph, int index, int *nodeType); @@ -667,30 +769,37 @@ typedef struct Project *EN_Project; @brief Retrieves a property value for a node. @param ph an EPANET project handle. @param index a node's index. - @param property the property to retrieve (see ::EN_NodeProperty). + @param property the property to retrieve (see @ref EN_NodeProperty). @param[out] value the current value of the property. @return an error code. + + Values are returned in units that depend on the units used for flow rate + (see @ref Units). */ int DLLEXPORT EN_getnodevalue(EN_Project ph, int index, int property, double *value); /** @brief Sets a property value for a node. @param ph an EPANET project handle. - @param index a node's index. - @param property the property to set (see ::EN_NodeProperty). + @param index a node's index (starting from 1). + @param property the property to set (see @ref EN_NodeProperty). @param value the new value for the property. @return an error code. + + Values are in units that depend on the units used for flow rate (see @ref Units). */ int DLLEXPORT EN_setnodevalue(EN_Project ph, int index, int property, double value); /** @brief Sets a group of properties for a junction node. @param ph an EPANET project handle. - @param index a junction node's index. + @param index a junction node's index (starting from 1). @param elev the value of the junction's elevation. @param dmnd the value of the junction's primary base demand. - @param dmndpat the name of the demand's time pattern ("" for no pattern) + @param dmndpat the ID name of the demand's time pattern ("" for no pattern) @return an error code. + + These properties have units that depend on the units used for flow rate (see @ref Units). */ int DLLEXPORT EN_setjuncdata(EN_Project ph, int index, double elev, double dmnd, char *dmndpat); @@ -698,7 +807,7 @@ typedef struct Project *EN_Project; /** @brief Sets a group of properties for a tank node. @param ph an EPANET project handle. - @param index a tank node's index. + @param index a tank node's index (starting from 1). @param elev the tank's bottom elevation. @param initlvl the initial water level in the tank. @param minlvl the minimum water level for the tank. @@ -707,6 +816,8 @@ typedef struct Project *EN_Project; @param minvol the volume of the tank at its minimum water level. @param volcurve the name of the tank's volume curve ("" for no curve) @return an error code. + + These properties have units that depend on the units used for flow rate (see @ref Units). */ int DLLEXPORT EN_settankdata(EN_Project ph, int index, double elev, double initlvl, double minlvl, double maxlvl, double diam, double minvol, char *volcurve); @@ -714,7 +825,7 @@ typedef struct Project *EN_Project; /** @brief Gets the (x,y) coordinates of a node. @param ph an EPANET project handle. - @param index a node index. + @param index a node index (starting from 1). @param[out] x the node's X-coordinate value. @param[out] y the node's Y-coordinate value. @return an error code. @@ -724,7 +835,7 @@ typedef struct Project *EN_Project; /** @brief Sets the (x,y) coordinates of a node. @param ph an EPANET project handle. - @param index a node index. + @param index a node index (starting from 1). @param x the node's X-coordinate value. @param y the node's Y-coordinate value. @return an error code. @@ -740,11 +851,13 @@ typedef struct Project *EN_Project; /** @brief Retrieves the type of demand model in use and its parameters. @param ph an EPANET project handle. - @param[out] type Type of demand model (see ::EN_DemandModel). + @param[out] type Type of demand model (see @ref EN_DemandModel). @param[out] pmin Pressure below which there is no demand. @param[out] preq Pressure required to deliver full demand. @param[out] pexp Pressure exponent in demand function. @return an error code. + + Parameters `pmin`, `preq`, and `pexp` are only used when the demand model is `EN_PDA`. */ int DLLEXPORT EN_getdemandmodel(EN_Project ph, int *type, double *pmin, double *preq, double *pexp); @@ -752,27 +865,29 @@ typedef struct Project *EN_Project; /** @brief Sets the type of demand model to use and its parameters. @param ph an EPANET project handle. - @param type Type of demand model (see ::EN_DemandModel). + @param type Type of demand model (see @ref EN_DemandModel). @param pmin Pressure below which there is no demand. @param preq Pressure required to deliver full demand. @param pexp Pressure exponent in demand function. @return an error code. - Set _type_ to __EN_DDA__ for a traditional demand driven analysis (in which case the - remaining three parameter values are ignored) or to __EN_PDA__ for a pressure driven + Set `type` to `EN_DDA` for a traditional demand driven analysis (in which case the + remaining three parameter values are ignored) or to `EN_PDA` for a pressure driven analysis. In the latter case a node's demand is computed as: - > Dfull * [ (P - pmin) / (preq - pmin) ] ^ pexp - where Dfull is the full demand and P is the current pressure. + > `Dfull * [ (P - pmin) / (preq - pmin) ] ^ pexp` + where `Dfull` is the full demand and `P` is the current pressure. - Setting _preq_ equal to _pmin_ will result in a solution with the smallest amount of demand reductions needed to insure that no node delivers positive demand at a pressure below _pmin_. + Setting `preq` equal to `pmin` will result in a solution with the smallest amount of + demand reductions needed to insure that no node delivers positive demand at a pressure + below `pmin`. */ int DLLEXPORT EN_setdemandmodel(EN_Project ph, int type, double pmin, double preq, double pexp); /** - @brief Retrieves the number of demand categories for a node. + @brief Retrieves the number of demand categories for a junction node. @param ph an EPANET project handle. - @param nodeIndex the index of a node. + @param nodeIndex the index of a node (starting from 1). @param[out] numDemands the number of demand categories assigned to the node. @return an error code. */ @@ -781,8 +896,8 @@ typedef struct Project *EN_Project; /** @brief Gets the base demand for one of a node's demand categories. @param ph an EPANET project handle. - @param nodeIndex a node's index. - @param demandIndex the index of a demand category for the node. + @param nodeIndex a node's index (starting from 1). + @param demandIndex the index of a demand category for the node (starting from 1). @param[out] baseDemand the category's base demand. @return an error code. */ @@ -792,8 +907,8 @@ typedef struct Project *EN_Project; /** @brief Sets the base demand for one of a node's demand categories. @param ph an EPANET project handle. - @param nodeIndex a node's index. - @param demandIndex the index of a demand category for the node. + @param nodeIndex a node's index (starting from 1). + @param demandIndex the index of a demand category for the node (starting from 1). @param baseDemand the new base demand for the category. @return an error code. */ @@ -803,10 +918,13 @@ typedef struct Project *EN_Project; /** @brief Retrieves the index of a time pattern assigned to one of a node's demand categories. @param ph an EPANET project handle. - @param nodeIndex the node's index. - @param demandIndex the index of a demand category for the node. + @param nodeIndex the node's index (starting from 1). + @param demandIndex the index of a demand category for the node (starting from 1). @param[out] patIndex the index of the category's time pattern. @return an error code. + + A returned pattern index of 0 indicates that no time pattern has been assigned to the + demand category. */ int DLLEXPORT EN_getdemandpattern(EN_Project ph, int nodeIndex, int demandIndex, int *patIndex); @@ -814,30 +932,37 @@ typedef struct Project *EN_Project; /** @brief Sets the index of a time pattern used for one of a node's demand categories. @param ph an EPANET project handle. - @param nodeIndex a node's index. - @param demandIndex the index of one of the node's demand categories. + @param nodeIndex a node's index (starting from 1). + @param demandIndex the index of one of the node's demand categories (starting from 1). @param patIndex the index of the time pattern assigned to the category. @return an error code. + + Specifying a pattern index of 0 indicates that no time pattern is assigned to the + demand category. */ int DLLEXPORT EN_setdemandpattern(EN_Project ph, int nodeIndex, int demandIndex, int patIndex); /** @brief Retrieves the name of a node's demand category. @param ph an EPANET project handle. - @param nodeIndex a node's index. - @param demandIndex the index of one of the node's demand categories. + @param nodeIndex a node's index (starting from 1). + @param demandIndex the index of one of the node's demand categories (starting from 1). @param[out] demandName The name of the selected category. @return an error code. + + `demandName` must be sized to contain at least @ref EN_MAXID characters. */ int DLLEXPORT EN_getdemandname(EN_Project ph, int nodeIndex, int demandIndex, char *demandName); /** - @brief Sets the name of a node's demand category. + @brief Assigns a name to a node's demand category. @param ph an EPANET project handle. - @param nodeIndex a node's index. - @param demandIdx the index of one of the node's demand categories. + @param nodeIndex a node's index (starting from 1). + @param demandIdx the index of one of the node's demand categories (starting from 1). @param demandName the new name assigned to the category. @return Error code. + + The category name must contain no more than @ref EN_MAXID characters. */ int DLLEXPORT EN_setdemandname(EN_Project ph, int nodeIndex, int demandIdx, char *demandName); @@ -851,10 +976,20 @@ typedef struct Project *EN_Project; @brief Adds a new link to a project. @param ph an EPANET project handle. @param id the ID name of the link to be added. - @param linkType The type of link being added (see ::EN_LinkType) + @param linkType The type of link being added (see @ref EN_LinkType) @param fromNode The ID name of the link's starting node. @param toNode The ID name of the link's ending node. @return an error code. + + A new pipe is assigned a diameter of 10 inches (or 254 mm), a length of 100 + feet (or meters), a roughness coefficient of 100 and 0 for all other properties. + + A new pump has a status of `EN_OPEN`, a speed setting of 1, and has no pump + curve or power rating assigned to it. + + A new valve has a diameter of 10 inches (or 254 mm) and all other properties set to 0. + + See @ref EN_LinkProperty. */ int DLLEXPORT EN_addlink(EN_Project ph, char *id, int linkType, char *fromNode, char *toNode); @@ -865,10 +1000,9 @@ typedef struct Project *EN_Project; @param actionCode The action taken if any control contains the link. @return an error code. - If _actionCode_ is __EN_UNCONDITIONAL__ then the link and all simple and rule-based - controls that contain it are deleted. If set to __EN_CONDITIONAL__ then the link + If `actionCode` is `EN_UNCONDITIONAL` then the link and all simple and rule-based + controls that contain it are deleted. If set to `EN_CONDITIONAL` then the link is not deleted if it appears in any control and error 261 is returned. - */ int DLLEXPORT EN_deletelink(EN_Project ph, int index, int actionCode); @@ -876,7 +1010,7 @@ typedef struct Project *EN_Project; @brief Gets the index of a link given its ID name. @param ph an EPANET project handle. @param id a link's ID name. - @param[out] index the link's index. + @param[out] index the link's index (starting from 1). @return an error code. */ int DLLEXPORT EN_getlinkindex(EN_Project ph, char *id, int *index); @@ -884,28 +1018,30 @@ typedef struct Project *EN_Project; /** @brief Gets the ID name of a link given its index. @param ph an EPANET project handle. - @param index a link's index. + @param index a link's index (starting from 1). @param[out] id The link's ID name. @return an error code. - The _id_ string must be sized to hold at least ::MAXID characters. + The ID name must be sized to hold at least @ref EN_MAXID characters. */ int DLLEXPORT EN_getlinkid(EN_Project ph, int index, char *id); /** @brief Changes the ID name of a link. @param ph an EPANET project handle. - @param index a link's index. + @param index a link's index (starting from 1). @param newid the new ID name for the link. @return Error code. + + The ID name must not be longer than @ref EN_MAXID characters. */ int DLLEXPORT EN_setlinkid(EN_Project ph, int index, char *newid); /** - @brief Retrieves a link's type given its index. + @brief Retrieves a link's type. @param ph an EPANET project handle. - @param index a link's index. - @param[out] linkType the link's type (see ::EN_LinkType). + @param index a link's index (starting from 1). + @param[out] linkType the link's type (see @ref EN_LinkType). @return an error code. */ int DLLEXPORT EN_getlinktype(EN_Project ph, int index, int *linkType); @@ -914,13 +1050,13 @@ typedef struct Project *EN_Project; @brief Changes a link's type. @param ph an EPANET project handle. @param[in,out] index the link's index before [in] and after [out] the type change. - @param linkType the new type to change the link to (see ::EN_LinkType). + @param linkType the new type to change the link to (see @ref EN_LinkType). @param actionCode the action taken if any controls contain the link. @return an error code. - If _actionCode_ is __EN_UNCONDITIONAL__ then all simple and rule-based controls that + If `actionCode` is `EN_UNCONDITIONAL` then all simple and rule-based controls that contain the link are deleted when the link's type is changed. If set to - __EN_CONDITIONAL__ then the type change is cancelled if the link appears in any + `EN_CONDITIONAL` then the type change is cancelled if the link appears in any control and error 261 is returned. */ int DLLEXPORT EN_setlinktype(EN_Project ph, int *index, int linkType, int actionCode); @@ -928,9 +1064,9 @@ typedef struct Project *EN_Project; /** @brief Gets the indexes of a link's start- and end-nodes. @param ph an EPANET project handle. - @param index a link's index. - @param[out] node1 the index of the link's start node. - @param[out] node2 the index of the link's end node. + @param index a link's index (starting from 1). + @param[out] node1 the index of the link's start node (starting from 1). + @param[out] node2 the index of the link's end node (starting from 1). @return an error code. */ int DLLEXPORT EN_getlinknodes(EN_Project ph, int index, int *node1, int *node2); @@ -938,9 +1074,9 @@ typedef struct Project *EN_Project; /** @brief Sets the indexes of a link's start- and end-nodes. @param ph an EPANET project handle. - @param index a link's index. - @param node1 The index of the link's start node. - @param node2 The index of the link's end node. + @param index a link's index (starting from 1). + @param node1 The index of the link's start node (starting from 1). + @param node2 The index of the link's end node (starting from 1). @return an error code. */ int DLLEXPORT EN_setlinknodes(EN_Project ph, int index, int node1, int node2); @@ -948,10 +1084,12 @@ typedef struct Project *EN_Project; /** @brief Retrieves a property value for a link. @param ph an EPANET project handle. - @param index a link's index. - @param property the property to retrieve (see ::EN_LinkProperty). + @param index a link's index (starting from 1). + @param property the property to retrieve (see @ref EN_LinkProperty). @param[out] value the current value of the property. @return an error code. + + Values are returned in units that depend on the units used for flow rate (see @ref Units). */ int DLLEXPORT EN_getlinkvalue(EN_Project ph, int index, int property, double *value); @@ -959,21 +1097,25 @@ typedef struct Project *EN_Project; @brief Sets a property value for a link. @param ph an EPANET project handle. @param index a link's index. - @param property the property to set (see ::EN_LinkProperty). + @param property the property to set (see @ref EN_LinkProperty). @param value the new value for the property. @return an error code. + + Values are in units that depend on the units used for flow rate (see @ref Units). */ int DLLEXPORT EN_setlinkvalue(EN_Project ph, int index, int property, double value); /** @brief Sets a group of properties for a pipe link. @param ph an EPANET project handle. - @param index the index of a pipe link. + @param index the index of a pipe link (starting from 1). @param length the pipe's length. @param diam the pipe's diameter. @param rough the pipe's roughness coefficient. @param mloss the pipe's minor loss coefficient. @return an error code. + + These properties have units that depend on the units used for flow rate (see @ref Units). */ int DLLEXPORT EN_setpipedata(EN_Project ph, int index, double length, double diam, double rough, double mloss); @@ -988,8 +1130,8 @@ typedef struct Project *EN_Project; /** @brief Retrieves the type of head curve used by a pump. @param ph an EPANET project handle. - @param linkIndex the index of a pump link. - @param[out] pumpType the type of head curve used by the pump (see ::EN_PumpType). + @param linkIndex the index of a pump link (starting from 1). + @param[out] pumpType the type of head curve used by the pump (see @ref EN_PumpType). @return an error code. */ int DLLEXPORT EN_getpumptype(EN_Project ph, int linkIndex, int *pumpType); @@ -997,7 +1139,7 @@ typedef struct Project *EN_Project; /** @brief Retrieves the curve assigned to a pump's head curve. @param ph an EPANET project handle. - @param linkIndex the index of a pump link. + @param linkIndex the index of a pump link (starting from 1). @param[out] curveIndex the index of the curve assigned to the pump's head curve. @return an error code. */ @@ -1006,7 +1148,7 @@ typedef struct Project *EN_Project; /** @brief Assigns a curve to a pump's head curve. @param ph an EPANET project handle. - @param linkIndex the index of a pump link. + @param linkIndex the index of a pump link (starting from 1). @param curveIndex the index of a curve to be assigned as the pump's head curve. @return an error code. */ @@ -1023,6 +1165,8 @@ typedef struct Project *EN_Project; @param ph an EPANET project handle. @param id the ID name of the pattern to add. @return an error code. + + The new pattern contains a single time period whose factor is 1.0. */ int DLLEXPORT EN_addpattern(EN_Project ph, char *id); @@ -1030,24 +1174,26 @@ typedef struct Project *EN_Project; @brief Retrieves the index of a time pattern given its ID name. @param ph an EPANET project handle. @param id the ID name of a time pattern. - @param[out] index the time pattern's index. + @param[out] index the time pattern's index (starting from 1). @return an error code. */ int DLLEXPORT EN_getpatternindex(EN_Project ph, char *id, int *index); /** - @brief Retrieves ID name of a time pattern given its index. + @brief Retrieves the ID name of a time pattern given its index. @param ph an EPANET project handle. - @param index a time pattern index. + @param index a time pattern index (starting from 1). @param[out] id the time pattern's ID name. @return an error code. + + The ID name must be sized to hold at least @ref EN_MAXID characters. */ int DLLEXPORT EN_getpatternid(EN_Project ph, int index, char *id); /** - @brief Retrieves the number time periods in a time pattern. + @brief Retrieves the number of time periods in a time pattern. @param ph an EPANET project handle. - @param index a time pattern index. + @param index a time pattern index (starting from 1). @param[out] len the number of time periods in the pattern. @return an error code. */ @@ -1056,8 +1202,8 @@ typedef struct Project *EN_Project; /** @brief Retrieves a time pattern's factor for a given time period. @param ph an EPANET project handle. - @param index a time pattern index. - @param period a time period in the pattern. + @param index a time pattern index (starting from 1). + @param period a time period in the pattern (starting from 1). @param[out] value the pattern factor for the given time period. @return an error code. */ @@ -1066,8 +1212,8 @@ typedef struct Project *EN_Project; /** @brief Sets a time pattern's factor for a given time period. @param ph an EPANET project handle. - @param index a time pattern index. - @param period a time period in the pattern. + @param index a time pattern index (starting from 1). + @param period a time period in the pattern (starting from 1). @param value the new value of the pattern factor for the given time period. @return an error code. */ @@ -1076,7 +1222,7 @@ typedef struct Project *EN_Project; /** @brief Retrieves the average of all pattern factors in a time pattern. @param ph an EPANET project handle. - @param index a time pattern index. + @param index a time pattern index (starting from 1). @param[out] value The average of all of the time pattern's factors. @return an error code. */ @@ -1085,12 +1231,17 @@ typedef struct Project *EN_Project; /** @brief Sets the pattern factors for a given time pattern. @param ph an EPANET project handle. - @param index a time pattern index. - @param f an array of new pattern factors. - @param len the number of time periods contained in the factor array f. + @param index a time pattern index (starting from 1). + @param values an array of new pattern factor values. + @param len the number of factor values supplied. @return an error code. + + `values` is a zero-based array that contains `len` elements. + + Use this function to redefine (and resize) a time pattern all at once; + use @ref EN_setpatternvalue to revise pattern factors one at a time. */ - int DLLEXPORT EN_setpattern(EN_Project ph, int index, double *f, int len); + int DLLEXPORT EN_setpattern(EN_Project ph, int index, double *values, int len); /******************************************************************** @@ -1103,6 +1254,8 @@ typedef struct Project *EN_Project; @param ph an EPANET project handle. @param id The ID name of the curve to be added. @return an error code. + + The new curve contains a single data point (1.0, 1.0). */ int DLLEXPORT EN_addcurve(EN_Project ph, char *id); @@ -1110,7 +1263,7 @@ typedef struct Project *EN_Project; @brief Retrieves the index of a curve given its ID name. @param ph an EPANET project handle. @param id the ID name of a curve. - @param[out] index The curve's index. + @param[out] index The curve's index (starting from 1). @return an error code. */ int DLLEXPORT EN_getcurveindex(EN_Project ph, char *id, int *index); @@ -1118,16 +1271,18 @@ typedef struct Project *EN_Project; /** @brief Retrieves the ID name of a curve given its index. @param ph an EPANET project handle. - @param index a curve's index. + @param index a curve's index (starting from 1). @param[out] id the curve's ID name. @return an error code. + + The ID name must be sized to hold at least @ref EN_MAXID characters. */ int DLLEXPORT EN_getcurveid(EN_Project ph, int index, char *id); /** @brief Retrieves the number of points in a curve. @param ph an EPANET project handle. - @param index a curve's index. + @param index a curve's index (starting from 1). @param[out] len The number of data points assigned to the curve. @return an error code. */ @@ -1136,8 +1291,8 @@ typedef struct Project *EN_Project; /** @brief Retrieves a curve's type. @param ph an EPANET project handle. - @param index a curve's index. - @param[out] type the curve's type (see EN_CurveType). + @param index a curve's index (starting from 1). + @param[out] type the curve's type (see @ref EN_CurveType). @return an error code. */ int DLLEXPORT EN_getcurvetype(EN_Project ph, int index, int *type); @@ -1145,8 +1300,8 @@ typedef struct Project *EN_Project; /** @brief Retrieves the value of a single data point for a curve. @param ph an EPANET project handle. - @param curveIndex a curve's index. - @param pointIndex the index of a point on the curve. + @param curveIndex a curve's index (starting from 1). + @param pointIndex the index of a point on the curve (starting from 1). @param[out] x the point's x-value. @param[out] y the point's y-value. @return an error code. @@ -1157,39 +1312,45 @@ typedef struct Project *EN_Project; /** @brief Sets the value of a single data point for a curve. @param ph an EPANET project handle. - @param curveIndex a curve's index. - @param pointIndex the index of a point on the curve. - @param x the point's x-value. - @param y the point's y-value. + @param curveIndex a curve's index (starting from 1). + @param pointIndex the index of a point on the curve (starting from 1). + @param x the point's new x-value. + @param y the point's new y-value. @return an error code. */ int DLLEXPORT EN_setcurvevalue(EN_Project ph, int curveIndex, int pointIndex, double x, double y); /** - @brief Retrieves a curve's data. + @brief Retrieves all of a curve's data. @param ph an EPANET project handle. - @param curveIndex a curve's index. + @param index a curve's index (starting from 1). @param[out] id the curve's ID name. @param[out] nPoints the number of data points on the curve. @param[out] xValues the curve's x-values. @param[out] yValues the curve's y-values. @return an error code. - The calling program is responsible for making _xValues_ and _yValues_ large enough - to hold nPoints number of data points and sizing _id_ to hold at least MAXID characters. + The calling program is responsible for making `xValues` and `yValues` large enough + to hold `nPoints` number of data points and for sizing `id` to hold at least + @ref EN_MAXID characters. */ - int DLLEXPORT EN_getcurve(EN_Project ph, int curveIndex, char* id, int *nPoints, + int DLLEXPORT EN_getcurve(EN_Project ph, int index, char* id, int *nPoints, double **xValues, double **yValues); /** - @brief Sets a curve's data points. + @brief assigns a set of data points to a curve. @param ph an EPANET project handle. - @param index a curve's index. + @param index a curve's index (starting from 1). @param xValues an array of new x-values for the curve. @param yValues an array of new y-values for the curve. - @param nPoints a new number of data points for the curve. + @param nPoints the new number of data points for the curve. @return an error code. + + `xValues` and `yValues` are zero-based arrays that contains `nPoints` elements. + + Use this function to redefine (and resize) a curve all at once; + use @ref EN_setcurvevalue to revise a curve's data points one at a time. */ int DLLEXPORT EN_setcurve(EN_Project ph, int index, double *xValues, double *yValues, int nPoints); @@ -1203,11 +1364,13 @@ typedef struct Project *EN_Project; /** @brief Adds a new simple control to a project. @param ph an EPANET project handle. - @param type the type of control to add (see EN_ControlType). - @param linkIndex the index of a link to control. + @param type the type of control to add (see @ref EN_ControlType). + @param linkIndex the index of a link to control (starting from 1). @param setting control setting applied to the link. - @param nodeIndex index of the node used to control the link, or 0 for TIMER / TIMEOFDAY control. - @param level action level (tank level, junction pressure, or time in seconds) that triggers the control. + @param nodeIndex index of the node used to control the link + (0 for `EN_TIMER` and `EN_TIMEOFDAY` controls). + @param level action level (tank level, junction pressure, or time in seconds) + that triggers the control. @param[out] index index of the new control. @return an error code. */ @@ -1217,7 +1380,7 @@ typedef struct Project *EN_Project; /** @brief Deletes an existing simple control. @param ph an EPANET project handle. - @param index the index of the control to delete. + @param index the index of the control to delete (starting from 1). @return an error code. */ int DLLEXPORT EN_deletecontrol(EN_Project ph, int index); @@ -1225,12 +1388,14 @@ typedef struct Project *EN_Project; /** @brief Retrieves the properties of a simple control. @param ph an EPANET project handle. - @param index the control's index. - @param[out] type the type of control (see EN_ControlType). + @param index the control's index (starting from 1). + @param[out] type the type of control (see @ref EN_ControlType). @param[out] linkIndex the index of the link being controlled. @param[out] setting the control setting applied to the link. - @param[out] nodeIndex the index of the node used to trigger the control (0 for TIMER / TIMEOFDAY control). - @param[out] level the action level (tank level, junction pressure, or time in seconds) that triggers the control. + @param[out] nodeIndex the index of the node used to trigger the control + (0 for `EN_TIMER` and `EN_TIMEOFDAY` controls). + @param[out] level the action level (tank level, junction pressure, or time in seconds) + that triggers the control. @return an error code. */ int DLLEXPORT EN_getcontrol(EN_Project ph, int index, int *type, int *linkIndex, @@ -1239,12 +1404,14 @@ typedef struct Project *EN_Project; /** @brief Sets the properties of an existing simple control. @param ph an EPANET project handle. - @param index the control's index. - @param type the type of control (see EN_ControlType). + @param index the control's index (starting from 1). + @param type the type of control (see @ref EN_ControlType). @param linkIndex the index of the link being controlled. @param setting the control setting applied to the link. - @param nodeIndex the index of the node used to trigger the control (0 for TIMER / TIMEOFDAY control). - @param level the action level (tank level, junction pressure, or time in seconds) that triggers the control. + @param nodeIndex the index of the node used to trigger the control + (0 for `EN_TIMER` and `EN_TIMEOFDAY` controls). + @param level the action level (tank level, junction pressure, or time in seconds) + that triggers the control. @return an error code. */ int DLLEXPORT EN_setcontrol(EN_Project ph, int index, int type, int linkIndex, @@ -1263,14 +1430,15 @@ typedef struct Project *EN_Project; @param rule text of the rule following the format used in an EPANET input file. @return an error code. - Consult Appendix C of the EPANET 2 Users Manual to learn about a rule's format. + Consult Appendix C of the EPANET 2 Users Manual + to learn about a rule's format. Each clause of the rule must end with a newline character `\n`. */ int DLLEXPORT EN_addrule(EN_Project ph, char *rule); /** @brief Deletes an existing rule-based control. @param ph an EPANET project handle. - @param index the index of the rule to be deleted. + @param index the index of the rule to be deleted (starting from 1). @return an error code. */ int DLLEXPORT EN_deleterule(EN_Project ph, int index); @@ -1278,11 +1446,11 @@ typedef struct Project *EN_Project; /** @brief Retrieves summary information about a rule-based control. @param ph an EPANET project handle. - @param index the rule's index. + @param index the rule's index (starting from 1). @param[out] nPremises number of premises in the rule's IF section. @param[out] nThenActions number of actions in the rule's THEN section. @param[out] nElseActions number of actions in the rule's ELSE section. - @param[out] priority the rule's priority. + @param[out] priority the rule's priority value. @return an error code. */ int DLLEXPORT EN_getrule(EN_Project ph, int index, int *nPremises, @@ -1291,23 +1459,27 @@ typedef struct Project *EN_Project; /** @brief Gets the ID name of a rule-based control given its index. @param ph an EPANET project handle. - @param index the rule's index. + @param index the rule's index (starting from 1). @param[out] id the rule's ID name. @return Error code. + + The ID name must be sized to hold at least @ref EN_MAXID characters. */ int DLLEXPORT EN_getruleID(EN_Project ph, int index, char* id); /** @brief Gets the properties of a premise in a rule-based control. @param ph an EPANET project handle. - @param ruleIndex the rule's index. - @param premiseIndex the position of the premise in the rule's list of premises. - @param[out] logop the premise's logical operator (IF = 1, AND = 2, OR = 3). - @param[out] object the type of object the premise refers to (see EN_RuleObject). - @param[out] objIndex the index of the object (e.g. the index of the tank). - @param[out] variable the object's variable being compared (see EN_RuleVariable). - @param[out] relop the premise's comparison operator (see EN_RuleOperator). - @param[out] status the status that the object's status is compared to (see EN_RuleStatus). + @param ruleIndex the rule's index (starting from 1). + @param premiseIndex the position of the premise in the rule's list of premises + (starting from 1). + @param[out] logop the premise's logical operator (`IF` = 1, `AND` = 2, `OR` = 3). + @param[out] object the type of object the premise refers to (see @ref EN_RuleObject). + @param[out] objIndex the index of the object (e.g. the index of a tank). + @param[out] variable the object's variable being compared (see @ref EN_RuleVariable). + @param[out] relop the premise's comparison operator (see @ref EN_RuleOperator). + @param[out] status the status that the object's status is compared to + (see @ref EN_RuleStatus). @param[out] value the value that the object's variable is compared to. @return an error code. */ @@ -1318,14 +1490,15 @@ typedef struct Project *EN_Project; /** @brief Sets the properties of a premise in a rule-based control. @param ph an EPANET project handle. - @param ruleIndex the rule's index. + @param ruleIndex the rule's index (starting from 1). @param premiseIndex the position of the premise in the rule's list of premises. - @param logop the premise's logical operator (IF = 1, AND = 2, OR = 3). - @param object the type of object the premise refers to (see EN_RuleObject). - @param objIndex the index of the object (e.g. the index of the tank). - @param variable the object's variable being compared (see EN_RuleVariable). - @param relop the premise's comparison operator (see EN_RuleOperator). - @param status the status that the object's status is compared to (see ::EN_RuleStatus). + @param logop the premise's logical operator (`IF` = 1, `AND` = 2, `OR` = 3). + @param object the type of object the premise refers to (see @ref EN_RuleObject). + @param objIndex the index of the object (e.g. the index of a tank). + @param variable the object's variable being compared (see @ref EN_RuleVariable). + @param relop the premise's comparison operator (see @ref EN_RuleOperator). + @param status the status that the object's status is compared to + (see @ref EN_RuleStatus). @param value the value that the object's variable is compared to. @return an error code. */ @@ -1336,9 +1509,9 @@ typedef struct Project *EN_Project; /** @brief Sets the index of an object in a premise of a rule-based control. @param ph an EPANET project handle. - @param ruleIndex the rule's index. - @param premiseIndex the premise's index. - @param objIndex the index of the premise's object (e.g. the index of the tank). + @param ruleIndex the rule's index (starting from 1). + @param premiseIndex the premise's index (starting from 1). + @param objIndex the index of the premise's object (e.g. the index of a tank). @return an error code. */ int DLLEXPORT EN_setpremiseindex(EN_Project ph, int ruleIndex, int premiseIndex, @@ -1347,9 +1520,10 @@ typedef struct Project *EN_Project; /** @brief Sets the status being compared to in a premise of a rule-based control. @param ph an EPANET project handle. - @param ruleIndex the rule's index. - @param premiseIndex the premise's index. - @param status the status that the premise's object status is compared to (see ::EN_RuleStatus). + @param ruleIndex the rule's index (starting from 1). + @param premiseIndex the premise's index (starting from 1). + @param status the status that the premise's object status is compared to + (see @ref EN_RuleStatus). @return an error code. */ int DLLEXPORT EN_setpremisestatus(EN_Project ph, int ruleIndex, int premiseIndex, @@ -1358,8 +1532,8 @@ typedef struct Project *EN_Project; /** @brief Sets the value in a premise of a rule-based control. @param ph an EPANET project handle. - @param ruleIndex the rule's index. - @param premiseIndex the premise's index. + @param ruleIndex the rule's index (staring from 1). + @param premiseIndex the premise's index (starting from 1). @param value The value that the premise's variable is compared to. @return an error code. */ @@ -1369,10 +1543,10 @@ typedef struct Project *EN_Project; /** @brief Gets the properties of a THEN action in a rule-based control. @param ph an EPANET project handle. - @param ruleIndex the rule's index. - @param actionIndex the index of the THEN action to retrieve. - @param[out] linkIndex the index of the link in the action. - @param[out] status the status assigned to the link (see ::EN_RuleStatus) + @param ruleIndex the rule's index (starting from 1). + @param actionIndex the index of the THEN action to retrieve (starting from 1). + @param[out] linkIndex the index of the link in the action (starting from 1). + @param[out] status the status assigned to the link (see @ref EN_RuleStatus) @param[out] setting the value assigned to the link's setting. @return an error code. */ @@ -1382,11 +1556,11 @@ typedef struct Project *EN_Project; /** @brief Sets the properties of a THEN action in a rule-based control. @param ph an EPANET project handle. - @param ruleIndex the rule's index. - @param actionIndex the index of the THEN action to modify. - @param[out] linkIndex the index of the link in the action. - @param[out] status the new status assigned to the link (see ::EN_RuleStatus). - @param[out] setting the new value assigned to the link's setting. + @param ruleIndex the rule's index (starting from 1). + @param actionIndex the index of the THEN action to modify (starting from 1). + @param linkIndex the index of the link in the action. + @param status the new status assigned to the link (see @ref EN_RuleStatus). + @param setting the new value assigned to the link's setting. @return an error code. */ int DLLEXPORT EN_setthenaction(EN_Project ph, int ruleIndex, int actionIndex, @@ -1395,10 +1569,10 @@ typedef struct Project *EN_Project; /** @brief Gets the properties of an ELSE action in a rule-based control. @param ph an EPANET project handle. - @param ruleIndex the rule's index. - @param actionIndex the index of the ELSE action to retrieve. + @param ruleIndex the rule's index (starting from 1). + @param actionIndex the index of the ELSE action to retrieve (starting from 1). @param[out] linkIndex the index of the link in the action. - @param[out] status the status assigned to the link (see ::EN_RuleStatus). + @param[out] status the status assigned to the link (see @ref EN_RuleStatus). @param[out] setting the value assigned to the link's setting. @return an error code. */ @@ -1408,11 +1582,11 @@ typedef struct Project *EN_Project; /** @brief Sets the properties of an ELSE action in a rule-based control. @param ph an EPANET project handle. - @param ruleIndex the rule's index. - @param actionIndex the index of the ELSE action being modified. - @param[out] linkIndex the index of the link in the action. - @param[out] status the new status assigned to the link (see ::EN_RuleStatus) - @param[out] setting the new value assigned to the link's setting. + @param ruleIndex the rule's index (starting from 1). + @param actionIndex the index of the ELSE action being modified (starting from 1). + @param linkIndex the index of the link in the action (starting from 1). + @param status the new status assigned to the link (see @ref EN_RuleStatus) + @param setting the new value assigned to the link's setting. @return an error code. */ int DLLEXPORT EN_setelseaction(EN_Project ph, int ruleIndex, int actionIndex, @@ -1421,8 +1595,8 @@ typedef struct Project *EN_Project; /** @brief Sets the priority of a rule-based control. @param ph an EPANET project handle. - @param index the rule's index. - @param priority the priority assigned to the rule. + @param index the rule's index (starting from 1). + @param priority the priority value assigned to the rule. @return an error code. */ int DLLEXPORT EN_setrulepriority(EN_Project ph, int index, double priority); diff --git a/include/epanet2_enums.h b/include/epanet2_enums.h index cd63cac..656386c 100644 --- a/include/epanet2_enums.h +++ b/include/epanet2_enums.h @@ -1,15 +1,15 @@ /** @file epanet2_enums.h - */ +*/ /* ****************************************************************************** Project: OWA EPANET Version: 2.2 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 Copyright: see AUTHORS 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_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 { EN_ELEVATION = 0, //!< Elevation - EN_BASEDEMAND = 1, //!< Junction baseline demand, from last demand category - EN_PATTERN = 2, //!< Junction baseline demand pattern - EN_EMITTER = 3, //!< Junction emitter coefficient + EN_BASEDEMAND = 1, //!< Primary demand baseline value + EN_PATTERN = 2, //!< Primary demand time pattern index + EN_EMITTER = 3, //!< Emitter flow coefficient EN_INITQUAL = 4, //!< Initial quality EN_SOURCEQUAL = 5, //!< Quality source strength - EN_SOURCEPAT = 6, //!< Quality source pattern - EN_SOURCETYPE = 7, //!< Qualiy source type - EN_TANKLEVEL = 8, //!< Current computed tank water level - EN_DEMAND = 9, //!< Current computed demand - EN_HEAD = 10, //!< Current computed hydraulic head - EN_PRESSURE = 11, //!< Current computed pressure - EN_QUALITY = 12, //!< Current computed quality - EN_SOURCEMASS = 13, //!< Current computed quality source mass inflow - EN_INITVOLUME = 14, //!< Tank initial volume - EN_MIXMODEL = 15, //!< Tank mixing model - EN_MIXZONEVOL = 16, //!< Tank mixing zone volume + EN_SOURCEPAT = 6, //!< Quality source pattern index + EN_SOURCETYPE = 7, //!< Quality source type (see @ref EN_SourceType) + EN_TANKLEVEL = 8, //!< Current computed tank water level (read only) + EN_DEMAND = 9, //!< Current computed demand (read only) + EN_HEAD = 10, //!< Current computed hydraulic head (read only) + EN_PRESSURE = 11, //!< Current computed pressure (read only) + EN_QUALITY = 12, //!< Current computed quality (read only) + EN_SOURCEMASS = 13, //!< Current computed quality source mass inflow (read only) + EN_INITVOLUME = 14, //!< Tank initial volume (read only) + EN_MIXMODEL = 15, //!< Tank mixing model (see @ref EN_MixingModel) + EN_MIXZONEVOL = 16, //!< Tank mixing zone volume (read only) EN_TANKDIAM = 17, //!< Tank diameter 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_MAXLEVEL = 21, //!< Tank maximum level EN_MIXFRACTION = 22, //!< Tank mixing fraction EN_TANK_KBULK = 23, //!< Tank bulk decay coefficient - EN_TANKVOLUME = 24, //!< Current computed tank volume - EN_MAXVOLUME = 25 //!< Tank maximum volume + EN_TANKVOLUME = 24, //!< Current computed tank volume (read only) + EN_MAXVOLUME = 25 //!< Tank maximum volume (read only) } 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 { EN_DIAMETER = 0, //!< Pipe/valve diameter EN_LENGTH = 1, //!< Pipe length EN_ROUGHNESS = 2, //!< Pipe roughness 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_KBULK = 6, //!< Bulk chemical reaction coefficient EN_KWALL = 7, //!< Pipe wall chemical reaction coefficient - EN_FLOW = 8, //!< Current computed flow rate - EN_VELOCITY = 9, //!< Current computed flow velocity - EN_HEADLOSS = 10, //!< Current computed head loss - EN_STATUS = 11, //!< Current link status + EN_FLOW = 8, //!< Current computed flow rate (read only) + EN_VELOCITY = 9, //!< Current computed flow velocity (read only) + EN_HEADLOSS = 10, //!< Current computed head loss (read only) + EN_STATUS = 11, //!< Current link status (see @ref EN_LinkStatusType) EN_SETTING = 12, //!< Current link setting - EN_ENERGY = 13, //!< Current computed pump energy usage - EN_LINKQUAL = 14, //!< Current computed link quality - EN_LINKPATTERN = 15, //!< Pump speed time pattern - - EN_PUMP_STATE = 16, //!< Current computed pump state - EN_PUMP_EFFIC = 17, //!< Current computed pump efficiency + EN_ENERGY = 13, //!< Current computed pump energy usage (read only) + EN_LINKQUAL = 14, //!< Current computed link quality (read only) + EN_LINKPATTERN = 15, //!< Pump speed time pattern index + EN_PUMP_STATE = 16, //!< Current computed pump state (read only) (see @ref EN_PumpStateType) + EN_PUMP_EFFIC = 17, //!< Current computed pump efficiency (read only) EN_PUMP_POWER = 18, //!< Pump constant power rating - EN_PUMP_HCURVE = 19, //!< Pump head v. flow curve - EN_PUMP_ECURVE = 20, //!< Pump efficiency v. flow curve + EN_PUMP_HCURVE = 19, //!< Pump head v. flow curve index + EN_PUMP_ECURVE = 20, //!< Pump efficiency v. flow curve index 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; -/// 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 { EN_DURATION = 0, //!< Total simulation duration EN_HYDSTEP = 1, //!< Hydraulic time step @@ -90,18 +103,23 @@ typedef enum { EN_PATTERNSTART = 4, //!< Time when time patterns begin EN_REPORTSTEP = 5, //!< Reporting time step EN_REPORTSTART = 6, //!< Time when reporting starts - EN_RULESTEP = 7, //!< Rule evaluation time step - EN_STATISTIC = 8, //!< Reporting statistic code - EN_PERIODS = 9, //!< Number of reporting time periods + EN_RULESTEP = 7, //!< Rule-based control evaluation time step + EN_STATISTIC = 8, //!< Reporting statistic code (see @ref EN_StatisticType) + EN_PERIODS = 9, //!< Number of reporting time periods (read only) EN_STARTTIME = 10, //!< Simulation starting time of day - EN_HTIME = 11, //!< Elapsed time of current hydraulic solution - EN_QTIME = 12, //!< Elapsed time of current quality solution - EN_HALTFLAG = 13, //!< Flag indicating if the simulation was halted - EN_NEXTEVENT = 14, //!< Next time until a tank becomes empty or full - EN_NEXTEVENTIDX = 15 //!< Index of next tank that becomes empty or full -} EN_TimeProperty; + EN_HTIME = 11, //!< Elapsed time of current hydraulic solution (read only) + EN_QTIME = 12, //!< Elapsed time of current quality solution (read only) + EN_HALTFLAG = 13, //!< Flag indicating if the simulation was halted (read only) + EN_NEXTEVENT = 14, //!< Shortest time until a tank becomes empty or full (read only) + EN_NEXTEVENTTANK = 15 //!< Index of tank with shortest time to become empty or full (read only) +} 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 { EN_ITERATIONS = 0, //!< Number of hydraulic iterations taken 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_AnalysisStatistic; -/// Object count codes +/// Types of objects to count +/** +These options tell @ref EN_getcount which type of object to count. +*/ typedef enum { EN_NODECOUNT = 0, //!< Number of nodes (junctions + tanks + reservoirs) EN_TANKCOUNT = 1, //!< Number of tanks and reservoirs @@ -121,14 +142,20 @@ typedef enum { EN_RULECOUNT = 6 //!< Number of rule-based controls } 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 { EN_JUNCTION = 0, //!< Junction node EN_RESERVOIR = 1, //!< Reservoir node EN_TANK = 2 //!< Storage tank node } 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 { EN_CVPIPE = 0, //!< Pipe with check valve EN_PIPE = 1, //!< Pipe @@ -141,7 +168,36 @@ typedef enum { EN_GPV = 8 //!< General purpose valve } 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 { EN_NONE = 0, //!< No quality analysis EN_CHEM = 1, //!< Chemical fate and transport @@ -149,22 +205,40 @@ typedef enum { EN_TRACE = 3 //!< Source tracing analysis } 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 { - EN_CONCEN = 0, //!< Concentration inflow source - EN_MASS = 1, //!< Mass inflow source - EN_SETPOINT = 2, //!< Concentration setpoint source - EN_FLOWPACED = 3 //!< Concentration flow paced source + EN_CONCEN = 0, //!< Concentration of any external inflow entering a node + EN_MASS = 1, //!< Injects a given mass/minute into a node + EN_SETPOINT = 2, //!< Sets the concentration leaving a node to a given value + EN_FLOWPACED = 3 //!< Adds a given value to the concentration leaving a node } 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 { EN_HW = 0, //!< Hazen-Williams EN_DW = 1, //!< Darcy-Weisbach EN_CM = 2 //!< Chezy-Manning } 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 { EN_CFS = 0, //!< Cubic feet per second EN_GPM = 1, //!< Gallons per minute @@ -178,39 +252,65 @@ typedef enum { EN_CMD = 9 //!< Cubic meters per day } 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 { EN_DDA = 0, //!< Demand driven analysis EN_PDA = 1 //!< Pressure driven analysis } 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 { 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_EMITEXPON = 3, //!< Exponent for emitter head loss formula + EN_EMITEXPON = 3, //!< Exponent in emitter discharge formula EN_DEMANDMULT = 4, //!< Global demand multiplier - EN_HEADERROR = 5, //!< Maximum allowable head loss error - EN_FLOWCHANGE = 6, //!< Maximum allowable flow change - EN_DEFDEMANDPAT = 7, //!< Default demand time pattern - EN_HEADLOSSFORM = 8, //!< Head loss formula - EN_GLOBALEFFIC = 9, //!< Global pump efficiency + EN_HEADERROR = 5, //!< Maximum head loss error for hydraulic convergence + EN_FLOWCHANGE = 6, //!< Maximum flow change for hydraulic convergence + EN_DEFDEMANDPAT = 7, //!< Index of the default demand time pattern + EN_HEADLOSSFORM = 8, //!< Head loss formula (see @ref EN_HeadLossType) + EN_GLOBALEFFIC = 9, //!< Global pump efficiency (percent) 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_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 { - EN_LOWLEVEL = 0, //!< Act when level drops below a setpoint - EN_HILEVEL = 1, //!< Act when level rises above a setpoint + EN_LOWLEVEL = 0, //!< Act when pressure or tank level drops below 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_TIMEOFDAY = 3 //!< Act at a particular time of day } 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 { + EN_SERIES = 0, //!< Report all time series points EN_AVERAGE = 1, //!< Report average value over simulation period EN_MINIMUM = 2, //!< Report minimum value over simulation period EN_MAXIMUM = 3, //!< Report maximum value over simulation period @@ -218,6 +318,11 @@ typedef enum { } EN_StatisticType; /// 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 { EN_MIX1 = 0, //!< Complete mix model EN_MIX2 = 1, //!< 2-compartment model @@ -226,14 +331,20 @@ typedef enum { } EN_MixingModel; /// Hydraulic initialization options +/** +These options are used to initialize a new hydraulic analysis when @ref EN_initH is called. +*/ typedef enum { 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_INITFLOW = 10, //!< Don't 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 { EN_CONST_HP = 0, //!< Constant horsepower EN_POWER_FUNC = 1, //!< Power function @@ -241,36 +352,49 @@ typedef enum { EN_NOCURVE = 3 //!< No curve } 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 { - EN_VOLUME_CURVE = 0, //!< Tank volume curve - EN_PUMP_CURVE = 1, //!< Pump head curve - EN_EFFIC_CURVE = 2, //!< Pump efficiency curve - EN_HLOSS_CURVE = 3, //!< Valve head loss curve + EN_VOLUME_CURVE = 0, //!< Tank volume v. depth curve + EN_PUMP_CURVE = 1, //!< Pump head v. flow curve + EN_EFFIC_CURVE = 2, //!< Pump efficiency v. flow curve + EN_HLOSS_CURVE = 3, //!< Valve head loss v. flow curve EN_GENERIC_CURVE = 4 //!< Generic curve } EN_CurveType; /// 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 { EN_UNCONDITIONAL = 0, //!< Delete all controls that contain object EN_CONDITIONAL = 1 //!< Cancel object deletion if contained in controls } 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 { EN_NO_REPORT = 0, //!< No status reporting EN_NORMAL_REPORT = 1, //!< Normal level of status reporting EN_FULL_REPORT = 2 //!< Full level of status reporting } EN_StatusReport; -/// Codes for objects referred to in the clauses of rule-based controls +/// Network objects used in rule-based controls typedef enum { EN_R_NODE = 6, //!< Clause refers to a node EN_R_LINK = 7, //!< Clause refers to a link EN_R_SYSTEM = 8 //!< Clause refers to a system parameter (e.g., time) } EN_RuleObject; -/// Codes for variables used in the clauses of rule-based controls +/// Object variables used in rule-based controls typedef enum { EN_R_DEMAND = 0, //!< Nodal demand EN_R_HEAD = 1, //!< Nodal hydraulic head @@ -287,7 +411,7 @@ typedef enum { EN_R_DRAINTIME = 12 //!< Time to drain a tank } EN_RuleVariable; -/// Comparison operators used in the premises of rule-based controls +/// Comparison operators used in rule-based controls typedef enum { EN_R_EQ = 0, //!< Equal to EN_R_NE = 1, //!< Not equal @@ -301,7 +425,7 @@ typedef enum { EN_R_ABOVE = 9 //!< Is above } EN_RuleOperator; -/// Status codes used in the clauses of rule-based controls +/// Link status codes used in rule-based controls typedef enum { EN_R_IS_OPEN = 1, //!< Link is open EN_R_IS_CLOSED = 2, //!< Link is closed diff --git a/src/epanet.c b/src/epanet.c index e5e0135..7735578 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -123,8 +123,8 @@ int DLLEXPORT EN_init(EN_Project p, const char *rptFile, const char *outFile, /*---------------------------------------------------------------- ** Input: rptFile = name of report file ** outFile = name of binary output file - ** unitsType = type of flow units (see EN_FlowUnits) - ** headLossType = type of head loss formula (see EN_HeadLossType) + ** unitsType = type of flow units (see FlowUnitsType) + ** headLossType = type of head loss formula (see HeadLossType) ** Output: none ** Returns: error code ** Purpose: initializes an EPANET project that isn't opened with @@ -255,7 +255,7 @@ int DLLEXPORT EN_close(EN_Project p) ** Input: none ** Output: none ** 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; // Check if hydraulic results exist @@ -392,7 +392,7 @@ int DLLEXPORT EN_openH(EN_Project p) ** Input: none ** Output: none ** 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) ** Output: none ** 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 ** Output: none ** 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 ** Returns: error code ** 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 ** Output: none ** Returns: error code -** Purpose: uses contents of a previous saved hydraulics file to -** run a water quality analysis. +** Purpose: uses contents of a previously saved hydraulics file to +** run a water quality analysis **---------------------------------------------------------------- */ { @@ -626,7 +626,7 @@ int DLLEXPORT EN_openQ(EN_Project p) ** Input: none ** Output: none ** 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) ** Returns: error code ** 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) ** Returns: error code ** 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 ** Output: none ** 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 ** Output: none ** 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 ** Output: none ** Returns: error code -** Purpose: writes formatted simulation results to the project's +** Purpose: writes formatted simulation results to a project's ** report file **---------------------------------------------------------------- */ @@ -858,11 +858,11 @@ int DLLEXPORT EN_getversion(int *version) ** Input: none ** Output: version = version number of the source code ** Returns: error code (should always be 0) -** Purpose: retrieves a number assigned to the most recent -** update of the source code. This number, set by the -** constant CODEVERSION found in TYPES.H, is to be -** interpreted with implied decimals, i.e., -** "20100" == "2(.)01(.)00" +** Purpose: retrieves the toolkit API version number +** +** The version number is set by the constant CODEVERSION found in +** TYPES.H and is to be interpreted with implied decimals, i.e., +** "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) ** Output: count = number of objects of the specified type ** 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) /*---------------------------------------------------------------- -** Input: param = time parameter code (see EN_TimeProperty) +** Input: param = time parameter code (see EN_TimeParameter) ** Output: value = time parameter value ** Returns: error code ** 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; 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) { 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 tanktimestep(p, value); break; - case EN_NEXTEVENTIDX: + case EN_NEXTEVENTTANK: *value = time->Hstep; i = tanktimestep(p, value); *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) /*---------------------------------------------------------------- -** Input: param = time parameter code (see EN_TimeProperty) +** Input: param = time parameter code (see EN_TimeParameter) ** value = time parameter value ** Output: none ** 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) ** chemname = name of chemical 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 ** Returns: error code ** 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 ** Output: none ** Returns: error code -** Purpose: deletes a node from a project. +** Purpose: deletes a node from a project **---------------------------------------------------------------- */ { Network *net = &p->network; - int i, nodeType, tankindex, numControls = 0; + int i, nodeType, tankindex; Snode *node; Pdemand demand, nextdemand; Psource source; @@ -2350,7 +2350,7 @@ int DLLEXPORT EN_setjuncdata(EN_Project p, int index, double elev, ** dmndpat = name of primary demand time pattern ** Output: none ** 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 ** Output: none ** 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; double area, elevation = elev; double *Ucf = p->Ucf; - Snode *Node = net->Node; Stank *Tank = net->Tank; Scurve *curve; @@ -2823,8 +2822,8 @@ int DLLEXPORT EN_addlink(EN_Project p, char *id, int linkType, link = &net->Link[n]; strncpy(link->ID, id, MAXID); - if (linkType <= EN_PIPE) net->Npipes++; - else if (linkType == EN_PUMP) + if (linkType <= PIPE) net->Npipes++; + else if (linkType == PUMP) { // Grow pump array to accomodate the new link net->Npumps++; @@ -2860,13 +2859,13 @@ int DLLEXPORT EN_addlink(EN_Project p, char *id, int linkType, link->N2 = n2; link->Status = OPEN; - if (linkType == EN_PUMP) + if (linkType == PUMP) { link->Kc = 1.0; // Speed factor link->Km = 0.0; // Horsepower 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->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 ** Output: none ** 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; // 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; // 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--; } - // Delete any valve (linkType > EN_PUMP) associated with the deleted link + // Delete any valve (linkType > PUMP) associated with the deleted link if (linkType > PUMP) { valveindex = findvalve(net, index); @@ -3235,7 +3234,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val switch (property) { 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]; break; @@ -3244,7 +3243,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val break; 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]); else v = Link[index].Kc; @@ -3253,7 +3252,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val break; case EN_MINORLOSS: - if (Link[index].Type != EN_PUMP) + if (Link[index].Type != PUMP) { v = Link[index].Km; 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; 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); } v = Link[index].Kc; switch (Link[index].Type) { - case EN_PRV: - case EN_PSV: - case EN_PBV: + case PRV: + case PSV: + case PBV: v *= Ucf[PRESSURE]; break; - case EN_FCV: + case FCV: v *= Ucf[FLOW]; default: break; @@ -3300,7 +3299,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val break; 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 { @@ -3315,7 +3314,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val else { 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]; } break; @@ -3326,7 +3325,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val break; 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); } @@ -3334,12 +3333,12 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val else v = LinkSetting[index]; switch (Link[index].Type) { - case EN_PRV: - case EN_PSV: - case EN_PBV: + case PRV: + case PSV: + case PBV: v *= Ucf[PRESSURE]; break; - case EN_FCV: + case FCV: v *= Ucf[FLOW]; default: break; @@ -3355,7 +3354,7 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val break; case EN_LINKPATTERN: - if (Link[index].Type == EN_PUMP) + if (Link[index].Type == PUMP) { 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: v = hyd->LinkStatus[index]; - if (Link[index].Type == EN_PUMP) + if (Link[index].Type == PUMP) { pmp = findpump(net, index); 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: v = 0; - if (Link[index].Type == EN_PUMP) + if (Link[index].Type == PUMP) { pmp = findpump(net, index); 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; case EN_PUMP_HCURVE: - if (Link[index].Type == EN_PUMP) + if (Link[index].Type == PUMP) { v = (double)Pump[findpump(&p->network, index)].Hcurve; } break; case EN_PUMP_ECURVE: - if (Link[index].Type == EN_PUMP) + if (Link[index].Type == PUMP) { v = (double)Pump[findpump(&p->network, index)].Ecurve; } break; case EN_PUMP_ECOST: - if (Link[index].Type == EN_PUMP) + if (Link[index].Type == PUMP) { v = (double)Pump[findpump(&p->network, index)].Ecost; } break; case EN_PUMP_EPAT: - if (Link[index].Type == EN_PUMP) + if (Link[index].Type == PUMP) { 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) { case EN_DIAMETER: - if (Link[index].Type != EN_PUMP) + if (Link[index].Type != PUMP) { if (value <= 0.0) return 211; value /= Ucf[DIAM]; // Convert to feet @@ -3465,7 +3464,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu break; case EN_LENGTH: - if (Link[index].Type <= EN_PIPE) + if (Link[index].Type <= PIPE) { if (value <= 0.0) return 211; Link[index].Len = value / Ucf[ELEV]; @@ -3474,7 +3473,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu break; case EN_ROUGHNESS: - if (Link[index].Type <= EN_PIPE) + if (Link[index].Type <= PIPE) { if (value <= 0.0) return 211; Link[index].Kc = value; @@ -3484,7 +3483,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu break; case EN_MINORLOSS: - if (Link[index].Type != EN_PUMP) + if (Link[index].Type != PUMP) { if (value <= 0.0) return 211; 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_STATUS: // 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); if (s < 0 || s > 1) return 211; 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_SETTING: 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); } @@ -3519,19 +3518,19 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu { switch (Link[index].Type) { - case EN_PUMP: + case PUMP: break; - case EN_PRV: - case EN_PSV: - case EN_PBV: + case PRV: + case PSV: + case PBV: value /= Ucf[PRESSURE]; break; - case EN_FCV: + case FCV: value /= Ucf[FLOW]; break; - case EN_TCV: + case TCV: break; - case EN_GPV: + case GPV: return 207; // Cannot modify setting for GPV default: return 0; @@ -3549,7 +3548,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu break; case EN_KBULK: - if (Link[index].Type <= EN_PIPE) + if (Link[index].Type <= PIPE) { Link[index].Kb = value / SECperDAY; qual->Reactflag = 1; @@ -3557,7 +3556,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu break; case EN_KWALL: - if (Link[index].Type <= EN_PIPE) + if (Link[index].Type <= PIPE) { Link[index].Kw = value / SECperDAY; qual->Reactflag = 1; @@ -3565,7 +3564,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu break; case EN_LINKPATTERN: - if (Link[index].Type == EN_PUMP) + if (Link[index].Type == PUMP) { patIndex = ROUND(value); 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; case EN_PUMP_POWER: - if (Link[index].Type == EN_PUMP) + if (Link[index].Type == PUMP) { if (value <= 0.0) return 211; pumpIndex = findpump(&p->network, index); @@ -3591,14 +3590,14 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu break; case EN_PUMP_HCURVE: - if (Link[index].Type == EN_PUMP) + if (Link[index].Type == PUMP) { return EN_setheadcurveindex(p, index, ROUND(value)); } break; case EN_PUMP_ECURVE: - if (Link[index].Type == EN_PUMP) + if (Link[index].Type == PUMP) { curveIndex = ROUND(value); 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; case EN_PUMP_ECOST: - if (Link[index].Type == EN_PUMP) + if (Link[index].Type == PUMP) { if (value < 0.0) return 211; pumpIndex = findpump(&p->network, index); @@ -3617,7 +3616,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu break; case EN_PUMP_EPAT: - if (Link[index].Type == EN_PUMP) + if (Link[index].Type == PUMP) { patIndex = ROUND(value); 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 ** Output: none ** 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 if (!p->Openflag) return 102; 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 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; if (!p->Openflag) return 102; 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; return 0; } @@ -3721,7 +3720,7 @@ int DLLEXPORT EN_getheadcurveindex(EN_Project p, int linkIndex, int *curveIndex) *curveIndex = 0; if (!p->Openflag) return 102; 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; return 0; } @@ -3738,9 +3737,6 @@ int DLLEXPORT EN_setheadcurveindex(EN_Project p, int linkIndex, int curveIndex) { Network *net = &p->network; - Slink *Link = net->Link; - const int Nlinks = net->Nlinks; - const int Ncurves = net->Ncurves; double *Ucf = p->Ucf; int pumpIndex; Spump *pump; @@ -3748,7 +3744,7 @@ int DLLEXPORT EN_setheadcurveindex(EN_Project p, int linkIndex, int curveIndex) // Check for valid parameters if (!p->Openflag) return 102; 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; // 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; // 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 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 switch (net->Link[linkIndex].Type) { - case EN_PRV: - case EN_PSV: - case EN_PBV: + case PRV: + case PSV: + case PBV: s /= Ucf[PRESSURE]; break; - case EN_FCV: + case FCV: s /= Ucf[FLOW]; break; - case EN_GPV: + case GPV: if (s == 0.0) status = CLOSED; else if (s == 1.0) status = OPEN; else return 202; s = net->Link[linkIndex].Kc; break; - case EN_PIPE: - case EN_PUMP: + case PIPE: + case PUMP: status = OPEN; if (s == 0.0) status = CLOSED; default: @@ -4407,12 +4403,12 @@ int DLLEXPORT EN_getcontrol(EN_Project p, int index, int *type, int *linkIndex, { switch (net->Link[*linkIndex].Type) { - case EN_PRV: - case EN_PSV: - case EN_PBV: + case PRV: + case PSV: + case PBV: s *= Ucf[PRESSURE]; break; - case EN_FCV: + case FCV: s *= Ucf[FLOW]; default: 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; // 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 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]; switch (link->Type) { - case EN_PRV: - case EN_PSV: - case EN_PBV: + case PRV: + case PSV: + case PBV: s /= Ucf[PRESSURE]; break; - case EN_FCV: + case FCV: s /= Ucf[FLOW]; break; - case EN_GPV: + case GPV: if (s == 0.0) status = CLOSED; else if (s == 1.0) status = OPEN; else return 202; s = link->Kc; break; - case EN_PIPE: - case EN_PUMP: + case PIPE: + case PUMP: status = OPEN; if (s == 0.0) status = CLOSED; default: @@ -4609,7 +4605,7 @@ int DLLEXPORT EN_deleterule(EN_Project p, int index) ** Input: index = rule index ** Output: none ** 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; premises = p->network.Rule[ruleIndex].Premises; - premise = getpremise(premises, ruleIndex); + premise = getpremise(premises, premiseIndex); if (premise == NULL) return 258; premise->status = status; diff --git a/src/hydsolver.c b/src/hydsolver.c index 021d776..3c0694a 100644 --- a/src/hydsolver.c +++ b/src/hydsolver.c @@ -100,6 +100,8 @@ int hydsolve(Project *pr, int *iter, double *relerr) // Initialize status checking & relaxation factor nextcheck = hyd->CheckFreq; hyd->RelaxFactor = 1.0; + hydbal.maxheaderror = 0.0; + hydbal.maxflowchange = 0.0; // Repeat iterations until convergence or trial limit is exceeded. // (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, // fix its status & continue, otherwise quit with no solution. if (errcode > 0) - { + { if (badvalve(pr, sm->Order[errcode])) continue; else break; } @@ -360,7 +362,6 @@ double newflows(Project *pr, Hydbalance *hbal) **---------------------------------------------------------------- */ { - Network *net = &pr->network; Hydraul *hyd = &pr->hydraul; double dqsum, // Network flow change diff --git a/src/inpfile.c b/src/inpfile.c index 18f4a1c..bc110dd 100644 --- a/src/inpfile.c +++ b/src/inpfile.c @@ -102,7 +102,6 @@ int saveinpfile(Project *pr, const char *fname) Times *time = &pr->times; int i, j, n; - int errcode; double d, kc, ke, km, ucf; char s[MAXLINE + 1], s1[MAXLINE + 1], s2[MAXLINE + 1]; Pdemand demand; @@ -451,7 +450,7 @@ int saveinpfile(Project *pr, const char *fname) for (i = 1; i <= net->Nrules; i++) { 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"); } @@ -489,7 +488,7 @@ int saveinpfile(Project *pr, const char *fname) fprintf(f, s_MIXING); for (i = 1; i <= net->Ntanks; i++) { - Stank *tank = &net->Tank[i]; + tank = &net->Tank[i]; if (tank->A == 0.0) continue; fprintf(f, "\n %-31s %-8s %12.4f", net->Node[tank->Node].ID, MixTxt[tank->MixModel], (tank->V1max / tank->Vmax)); @@ -719,7 +718,7 @@ int saveinpfile(Project *pr, const char *fname) j = 0; for (i = 1; i <= net->Nlinks; i++) { - Slink *link = &net->Link[i]; + link = &net->Link[i]; if (link->Rpt == 1) { if (j % 5 == 0) fprintf(f, "\n LINKS "); diff --git a/src/input3.c b/src/input3.c index 0acc72e..ef5211c 100644 --- a/src/input3.c +++ b/src/input3.c @@ -45,7 +45,7 @@ static int getpumpcurve(Project *, int); static void changestatus(Network *, int, StatusType, double); static int setError(Parser *, int, int); - + int setError(Parser *parser, int tokindex, int errcode) /* **-------------------------------------------------------------- @@ -85,7 +85,7 @@ int juncdata(Project *pr) Pdemand demand; // demand record STmplist *patlist; // list of demands Snode *node; - + // Add new junction to data base n = parser->Ntokens; if (net->Nnodes == parser->MaxNodes) return 200; @@ -117,7 +117,7 @@ int juncdata(Project *pr) node->Type = JUNCTION; strcpy(node->Comment, parser->Comment); - + // create a demand record, even if no demand is specified here. demand = (struct Sdemand *) malloc(sizeof(struct Sdemand)); if (demand == NULL) return 101; @@ -162,7 +162,7 @@ int tankdata(Project *pr) STmplist *tmplist; Snode *node; Stank *tank; - + // Add new tank to data base n = parser->Ntokens; if (net->Ntanks == parser->MaxTanks || @@ -189,7 +189,7 @@ int tankdata(Project *pr) } } else if (n < 6) return 201; - + // Tank is a storage tank else { @@ -232,7 +232,7 @@ int tankdata(Project *pr) tank->A = diam; tank->Pat = pattern; tank->Kb = MISSING; - + //******************************************************************* // NOTE: The min, max, & initial volumes set here are based on a // nominal tank diameter. They will be modified in INPUT1.C if @@ -275,7 +275,7 @@ int pipedata(Project *pr) LinkType type = PIPE; // Link type StatusType status = OPEN; // Link status Slink *link; - + // Add new pipe to data base n = parser->Ntokens; if (net->Nlinks == parser->MaxLinks) return 200; @@ -354,10 +354,10 @@ int pumpdata(Project *pr) Network *net = &pr->network; Parser *parser = &pr->parser; - int j, + int j, j1, // Start-node index j2, // End-node index - m, n; // # data items + m, n; // # data items double y; STmplist *tmplist; // Temporary list Slink *link; @@ -380,7 +380,7 @@ int pumpdata(Project *pr) // Save pump data link = &net->Link[net->Nlinks]; pump = &net->Pump[net->Npumps]; - + link->N1 = j1; link->N2 = j2; link->Diam = 0; @@ -426,25 +426,25 @@ int pumpdata(Project *pr) if (y <= 0.0) return setError(parser, m, 202); pump->Ptype = CONST_HP; link->Km = y; - } + } else if (match(parser->Tok[m - 1], w_HEAD)) // Custom pump curve { tmplist = getlistitem(parser->Tok[m], parser->Curvelist); if (tmplist == NULL) return setError(parser, m, 206); pump->Hcurve = tmplist->i; - } + } else if (match(parser->Tok[m - 1], w_PATTERN)) // Speed/status pattern { tmplist = getlistitem(parser->Tok[m], parser->Patlist); if (tmplist == NULL) return setError(parser, m, 205); pump->Upat = tmplist->i; - } + } else if (match(parser->Tok[m - 1], w_SPEED)) // Speed setting { if (!getfloat(parser->Tok[m], &y)) return setError(parser, m, 202); if (y < 0.0) return setError(parser, m, 211); link->Kc = y; - } + } else return 201; m = m + 2; // Move to next keyword token } @@ -476,7 +476,7 @@ int valvedata(Project *pr) lcoeff = 0.0; // Minor loss coeff. STmplist *tmplist; // Temporary list Slink *link; - + // Add new valve to data base n = parser->Ntokens; if (net->Nlinks == parser->MaxLinks || @@ -499,12 +499,12 @@ int valvedata(Project *pr) else if (match(parser->Tok[4], w_GPV)) type = GPV; 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); - // Find headloss curve for GPV + // Find headloss curve for GPV if (type == GPV) - { + { tmplist = getlistitem(parser->Tok[5], parser->Curvelist); if (tmplist == NULL) return setError(parser, 5, 206); setting = tmplist->i; @@ -532,7 +532,7 @@ int valvedata(Project *pr) link->Km = lcoeff; link->Kb = 0.0; link->Kw = 0.0; - link->Type = type; + link->Type = type; link->Status = status; link->Rpt = 0; strcpy(link->Comment, parser->Comment); @@ -658,11 +658,11 @@ int coordata(Project *pr) int j; double x, y; Snode *node; - + // Check for valid node ID if (parser->Ntokens < 3) return 201; if ((j = findnode(net, parser->Tok[0])) == 0) return setError(parser, 0, 203); - + // Check for valid data if (!getfloat(parser->Tok[1], &x)) return setError(parser, 1, 202); if (!getfloat(parser->Tok[2], &y)) return setError(parser, 2, 202); @@ -768,7 +768,7 @@ int controldata(Project *pr) { Network *net = &pr->network; Parser *parser = &pr->parser; - + int i = 0, // Node index k, // Link index n; // # data items @@ -779,7 +779,7 @@ int controldata(Project *pr) ControlType ctltype; // Control type LinkType linktype; // Link type Scontrol *control; - + // Check for sufficient number of input tokens n = parser->Ntokens; if (n < 6) return 201; @@ -878,7 +878,7 @@ int sourcedata(Project *pr) { Network *net = &pr->network; Parser *parser = &pr->parser; - + int i, // Token with quality value j, // Node index n, // # data items @@ -912,7 +912,7 @@ int sourcedata(Project *pr) // Parse optional source time pattern 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); if (patlist == NULL) return setError(parser, i+1, 205); @@ -921,7 +921,7 @@ int sourcedata(Project *pr) // Destroy any existing source assigned to node if (net->Node[j].S != NULL) free(net->Node[j].S); - + // Create a new source & assign it to the node source = (struct Ssource *)malloc(sizeof(struct Ssource)); if (source == NULL) return 101; @@ -946,7 +946,7 @@ int emitterdata(Project *pr) { Network *net = &pr->network; Parser *parser = &pr->parser; - + int j, // Node index n; // # data items double k; // Flow coeff. @@ -984,7 +984,7 @@ int qualdata(Project *pr) long i, i1, i2; double c0; Snode *Node = net->Node; - + if (net->Nnodes == 0) return setError(parser, 0, 203); // No nodes defined yet n = parser->Ntokens; if (n < 2) return 0; @@ -1016,7 +1016,7 @@ int qualdata(Project *pr) if (i >= i1 && i <= i2) Node[j].C0 = c0; } } - + // Otherwise use lexicographic comparison else { @@ -1058,7 +1058,7 @@ int reactdata(Project *pr) long i, i1, i2; double y; - // Skip line if insufficient data + // Skip line if insufficient data n = parser->Ntokens; if (n < 3) return 0; @@ -1093,7 +1093,7 @@ int reactdata(Project *pr) qual->Climit = y; return 0; } - + // Keyword is 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; net->Tank[j - net->Njuncs].Kb = y; } - + // Case where a numerical range of tank IDs is specified else if ((i1 = atol(parser->Tok[1])) > 0 && (i2 = atol(parser->Tok[2])) > 0) @@ -1160,7 +1160,7 @@ int reactdata(Project *pr) if (item == 1) net->Link[j].Kb = y; else net->Link[j].Kw = y; } - + // Case where a numerical range of link IDs is specified else if ((i1 = atol(parser->Tok[1])) > 0 && (i2 = atol(parser->Tok[2])) > 0) @@ -1168,14 +1168,14 @@ int reactdata(Project *pr) for (j = 1; j <= net->Nlinks; j++) { i = atol(net->Link[j].ID); - if (i >= i1 && i <= i2) + if (i >= i1 && i <= i2) { if (item == 1) net->Link[j].Kb = y; else net->Link[j].Kw = y; } } } - + // Case where a general range of link IDs is specified else for (j = 1; j <= net->Nlinks; j++) { @@ -1210,7 +1210,7 @@ int mixingdata(Project *pr) m, // Type of mixing model n; // Number of data items double v; // Mixing zone volume fraction - + // Check for valid data if (net->Nnodes == 0) return setError(parser, 0, 203); n = parser->Ntokens; @@ -1254,7 +1254,7 @@ int statusdata(Project *pr) long i, i1, i2; double y = 0.0; char status = ACTIVE; - + if (net->Nlinks == 0) return setError(parser, 0, 204); n = parser->Ntokens - 1; if (n < 1) return 201; @@ -1272,7 +1272,7 @@ int statusdata(Project *pr) if (n == 1) { if ((j = findlink(net, parser->Tok[0])) == 0) return setError(parser, 0, 204); - + // Cannot change status of a Check Valve 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); } } - + // A range of general link ID's was supplied else for (j = 1; j <= net->Nlinks; j++) { @@ -1319,14 +1319,14 @@ int energydata(Project *pr) Network *net = &pr->network; Hydraul *hyd = &pr->hydraul; Parser *parser = &pr->parser; - + int j, k, n; double y; STmplist *listitem; Slink *Link = net->Link; Spump *Pump = net->Pump; - + // Check for sufficient data n = parser->Ntokens; if (n < 3) return 201; @@ -1345,7 +1345,7 @@ int energydata(Project *pr) { j = 0; } - + // First keyword is PUMP (remaining data refer to a specific pump) else if (match(parser->Tok[0], w_PUMP)) { @@ -1366,7 +1366,7 @@ int energydata(Project *pr) else Pump[j].Ecost = y; return 0; } - + // Price PATTERN being set else if (match(parser->Tok[n - 2], w_PATTERN)) { @@ -1376,7 +1376,7 @@ int energydata(Project *pr) else Pump[j].Epat = listitem->i; return 0; } - + // Pump EFFIC being set else if (match(parser->Tok[n - 2], w_EFFIC)) { @@ -1389,7 +1389,7 @@ int energydata(Project *pr) else { 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; net->Curve[listitem->i].Type = EFFIC_CURVE; } @@ -1423,10 +1423,10 @@ int reportdata(Project *pr) Network *net = &pr->network; Report *rpt = &pr->report; Parser *parser = &pr->parser; - + int i, j, n; double y; - + n = parser->Ntokens - 1; if (n < 1) return 201; @@ -1511,8 +1511,8 @@ int reportdata(Project *pr) // Report fields specified // Special case needed to distinguish "HEAD" from "HEADLOSS" if (strcomp(parser->Tok[0], t_HEADLOSS)) i = HEADLOSS; - else i = findmatch(parser->Tok[0], Fldname); - if (i >= 0) + else i = findmatch(parser->Tok[0], Fldname); + if (i >= 0) { if (i > FRICTION) return setError(parser, 0, 213); if (parser->Ntokens == 1 || match(parser->Tok[1], w_YES)) @@ -1552,7 +1552,7 @@ int reportdata(Project *pr) return 0; } - // If get to here then return error condition + // If get to here then return error condition return 201; } @@ -1690,10 +1690,10 @@ int optionchoice(Project *pr, int n) Quality *qual = &pr->quality; Parser *parser = &pr->parser; Outfile *out = &pr->outfile; - + 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 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 return setError(parser, 1, 213); } - + // HEADLOSS formula 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 return setError(parser, 1, 213); } - + // HYDRUALICS USE/SAVE file option else if (match(parser->Tok[0], w_HYDRAULIC)) { @@ -1777,19 +1777,19 @@ int optionchoice(Project *pr, int n) strncpy(qual->ChemUnits, u_HOURS, MAXID); } } - + // MAP file name else if (match(parser->Tok[0], w_MAP)) { if (n < 1) return 0; strncpy(pr->MapFname, parser->Tok[1], MAXFNAME); } - + else if (match(parser->Tok[0], w_VERIFY)) { // Deprecated } - + // Hydraulics UNBALANCED option else if (match(parser->Tok[0], w_UNBALANCED)) { @@ -1802,7 +1802,7 @@ int optionchoice(Project *pr, int n) } else return setError(parser, 1, 213); } - + // Default demand PATTERN else if (match(parser->Tok[0], w_PATTERN)) { @@ -1854,7 +1854,7 @@ int optionvalue(Project *pr, int n) ** RQTOL value ** CHECKFREQ value ** MAXCHECK value -** DAMPLIMIT value +** DAMPLIMIT value **-------------------------------------------------------------- */ { @@ -1890,19 +1890,19 @@ int optionvalue(Project *pr, int n) // Diffusivity if (match(tok0, w_DIFFUSIVITY)) - { + { if (y < 0.0) return setError(parser, nvalue, 213); qual->Diffus = y; return 0; } - // Hydraulic damping limit option */ + // Hydraulic damping limit option */ if (match(tok0, w_DAMPLIMIT)) { hyd->DampLimit = y; return 0; } - + // Flow change limit 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; Spump *pump = &net->Pump[net->Npumps]; - + // Constant HP curve if (n == 1) { @@ -1997,7 +1997,7 @@ int getpumpcurve(Project *pr, int n) pump->Ptype = CONST_HP; net->Link[net->Nlinks].Km = parser->X[0]; } - + // Power function curve else { @@ -2080,7 +2080,7 @@ void changestatus(Network *net, int j, StatusType status, double y) */ { Slink *link = &net->Link[j]; - + if (link->Type == PIPE || link->Type == GPV) { if (status != ACTIVE) link->Status = status; diff --git a/src/project.c b/src/project.c index 93d6935..1e34602 100644 --- a/src/project.c +++ b/src/project.c @@ -151,7 +151,7 @@ int openhydfile(Project *pr) if (version != ENGINE_VERSION) return 306; if (fread(nsize, sizeof(INT4), 6, pr->outfile.HydFile) < 6) return 306; 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 ) return 306; pr->outfile.SaveHflag = TRUE; @@ -187,7 +187,7 @@ int openoutfile(Project *pr) } // 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) { pr->outfile.OutFile = fopen(pr->outfile.OutFname, "w+b"); @@ -305,7 +305,7 @@ int allocdata(Project *pr) ERRCODE(MEMCHECK(pr->quality.NodeQual)); } - // Allocate memory for network links + // Allocate memory for network links if (!errcode) { n = pr->parser.MaxLinks + 1; @@ -442,7 +442,7 @@ void freedata(Project *pr) free(demand); demand = nextdemand; } - // Free memory used for WQ source data + // Free memory used for WQ source data source = pr->network.Node[j].S; if (source != NULL) free(source); } @@ -579,7 +579,6 @@ int incontrols(Project *pr, int objType, int index) */ { Network *net = &pr->network; - Rules *rules = &pr->rules; int i, ruleObject; 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 if (j1 > net->Njuncs || j2 > net->Njuncs) return 219; - + // Examine each existing valve for (k = 1; k <= net->Nvalves; k++) { @@ -832,7 +831,7 @@ double interp(int n, double x[], double y[], double xx) double dx, dy; 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 { if (x[k] >= xx) // Interp. over interval diff --git a/src/quality.c b/src/quality.c index ad05246..f9ede48 100644 --- a/src/quality.c +++ b/src/quality.c @@ -35,7 +35,7 @@ const double Q_STAGNANT = 0.005 / GPMperCFS; // 0.005 gpm = 1.114e-5 cfs //int stepqual(Project *, long *); //int closequal(Project *); //double avgqual(Project *, int); -double findsourcequal(Project *, int, double, double, long); +double findsourcequal(Project *, int, double, long); // Imported functions extern char setreactflag(Project *); @@ -78,21 +78,21 @@ int openqual(Project *pr) // Create a memory pool for water quality segments qual->OutOfMemory = FALSE; qual->SegPool = mempool_create(); - if (qual->SegPool == NULL) errcode = 101; + if (qual->SegPool == NULL) errcode = 101; // Allocate arrays for link flow direction & reaction rates n = net->Nlinks + 1; qual->FlowDir = (FlowDirection *)calloc(n, sizeof(FlowDirection)); 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; qual->FirstSeg = (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)); - + ERRCODE(MEMCHECK(qual->FlowDir)); ERRCODE(MEMCHECK(qual->PipeRateCoeff)); ERRCODE(MEMCHECK(qual->FirstSeg)); @@ -119,7 +119,7 @@ int initqual(Project *pr) int i; int errcode = 0; - // Re-position hydraulics file + // Re-position hydraulics file if (!hyd->OpenHflag) { fseek(pr->outfile.HydFile, pr->outfile.HydOffset, SEEK_SET); @@ -148,7 +148,7 @@ int initqual(Project *pr) // Initialize quality at trace node (if applicable) if (qual->Qualflag == TRACE) qual->NodeQual[qual->TraceNode] = 100.0; - + // Compute Schmidt number if (qual->Diffus > 0.0) qual->Sc = hyd->Viscos / qual->Diffus; else qual->Sc = 0.0; @@ -202,17 +202,17 @@ int runqual(Project *pr, long *t) Quality *qual = &pr->quality; Times *time = &pr->times; - long hydtime; // Hydraulic solution time - long hydstep; // Hydraulic time step + long hydtime = 0; // Hydraulic solution time + long hydstep = 0; // Hydraulic time step int errcode = 0; // Update reported simulation time *t = time->Qtime; - // Read hydraulic solution from hydraulics file + // Read hydraulic solution from hydraulics file if (time->Qtime == time->Htime) { - // Read hydraulic results from file + // Read hydraulic results from file if (!hyd->OpenHflag) { if (!readhyd(pr, &hydtime)) return 307; @@ -220,7 +220,7 @@ int runqual(Project *pr, long *t) time->Htime = hydtime; } - // Save current results to output file + // Save current results to output file if (time->Htime >= time->Rtime) { if (pr->outfile.Saveflag) @@ -263,7 +263,7 @@ int nextqual(Project *pr, long *tstep) { Quality *qual = &pr->quality; Times *time = &pr->times; - + long hydstep; // Time step until next hydraulic event long dt, qtime; int errcode = 0; @@ -316,7 +316,7 @@ int stepqual(Project *pr, long *tleft) ** Input: none ** Output: tleft = time left in simulation ** Returns: error code -** Purpose: updates quality conditions over a single +** Purpose: updates quality conditions over a single ** quality time step **-------------------------------------------------------------- */ @@ -402,7 +402,7 @@ int closequal(Project *pr) int errcode = 0; if (qual->SegPool) mempool_delete(qual->SegPool); - FREE(qual->FirstSeg); + FREE(qual->FirstSeg); FREE(qual->LastSeg); FREE(qual->PipeRateCoeff); 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 -** volin = volume of node inflow over time step ** volout = volume of node outflow over time step ** tstep = current quality time step ** Output: returns concentration added by an external quality source. @@ -543,7 +542,6 @@ double sourcequal(Project *pr, Psource source) */ { Network *net = &pr->network; - Quality *qual = &pr->quality; Times *time = &pr->times; int i; diff --git a/src/qualreact.c b/src/qualreact.c index f728ea7..0805a21 100644 --- a/src/qualreact.c +++ b/src/qualreact.c @@ -222,7 +222,7 @@ double piperate(Project *pr, int k) 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->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; - Quality *qual = &pr->quality; int i; double vnet; @@ -475,7 +474,6 @@ void tankmix1(Project *pr, int i, double vin, double win, double vnet) */ { Network *net = &pr->network; - Hydraul *hyd = &pr->hydraul; Quality *qual = &pr->quality; 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) { 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) { mixzone->v = vmz; @@ -589,7 +587,6 @@ void tankmix3(Project *pr, int i, double vin, double win, double vnet) */ { Network *net = &pr->network; - Hydraul *hyd = &pr->hydraul; Quality *qual = &pr->quality; int k; @@ -640,7 +637,7 @@ void tankmix3(Project *pr, int i, double vin, double win, double vnet) } // 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; else if (qual->FirstSeg[k] == NULL) tank->C = 0.0; 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; Quality *qual = &pr->quality; - int k, n; + int k; double cin, vsum, wsum, vseg; Pseg seg; 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; // Find inflows & outflows - n = tank->Node; if (vin > 0.0) cin = win / vin; 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; } - // ... update reported tank quality + // ... update reported tank quality tank->C = qual->LastSeg[k]->c; } diff --git a/src/qualroute.c b/src/qualroute.c index 8ee2d5d..72bb66f 100644 --- a/src/qualroute.c +++ b/src/qualroute.c @@ -35,7 +35,7 @@ void reversesegs(Project *, int); void addseg(Project *, int, double, double); // Imported functions -extern double findsourcequal(Project *, int, double, double, long); +extern double findsourcequal(Project *, int, double, long); extern void reactpipes(Project *, long); extern void reacttanks(Project *, long); 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; Quality *qual = &pr->quality; @@ -251,7 +250,7 @@ double findnodequal(Project *pr, int n, double volin, } // 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]; // Combine source quality with node quality @@ -285,7 +284,6 @@ double noflowqual(Project *pr, int n) */ { Network *net = &pr->network; - Hydraul *hyd = &pr->hydraul; Quality *qual = &pr->quality; int k, inflow, kount = 0; @@ -300,7 +298,7 @@ double noflowqual(Project *pr, int n) k = alink->link; 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 if (net->Link[k].N2 == 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++; } - // 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 else if (inflow == FALSE && qual->LastSeg[k] != NULL) { @@ -428,7 +426,6 @@ int sortnodes(Project *pr) */ { Network *net = &pr->network; - Hydraul *hyd = &pr->hydraul; Quality *qual = &pr->quality; int i, j, k, n; @@ -578,7 +575,6 @@ void initsegs(Project *pr) */ { Network *net = &pr->network; - Hydraul *hyd = &pr->hydraul; Quality *qual = &pr->quality; int j, k; diff --git a/src/report.c b/src/report.c index 817ccce..885e0b2 100644 --- a/src/report.c +++ b/src/report.c @@ -69,8 +69,8 @@ int writereport(Project *pr) { Report *rpt = &pr->report; Parser *parser = &pr->parser; - - char tflag; + + int tflag; FILE *tfile; int errcode = 0; @@ -82,7 +82,7 @@ int writereport(Project *pr) if (rpt->Energyflag) writeenergy(pr); errcode = writeresults(pr); } - + // A secondary report file was specified else if (strlen(rpt->Rpt2Fname) > 0) { @@ -145,7 +145,7 @@ void writelogo(Project *pr) char s[80]; time_t timer; // time_t structure & functions time() & // ctime() are defined in time.h - + version = CODEVERSION; major = version / 10000; minor = (version % 10000) / 100; @@ -230,12 +230,12 @@ void writesummary(Project *pr) writeline(pr, s); } - sprintf(s, FMT27a, hyd->CheckFreq); - writeline(pr, s); - sprintf(s, FMT27b, hyd->MaxCheck); - writeline(pr, s); - sprintf(s, FMT27c, hyd->DampLimit); - writeline(pr, s); + sprintf(s, FMT27a, hyd->CheckFreq); + writeline(pr, s); + sprintf(s, FMT27b, hyd->MaxCheck); + writeline(pr, s); + sprintf(s, FMT27c, hyd->DampLimit); + writeline(pr, s); sprintf(s, FMT28, hyd->MaxIter); 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++) { if (hyd->LinkStatus[i] != hyd->OldStatus[i]) @@ -399,7 +399,7 @@ void writemassbalance(Project *pr) writeline(pr, s1); snprintf(s1, MAXMSG, "Final Mass: %12.5e", qual->MassBalance.final); 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); snprintf(s1, MAXMSG, "================================\n"); writeline(pr, s1); @@ -426,7 +426,7 @@ void writeenergy(Project *pr) if (net->Npumps == 0) return; writeline(pr, " "); writeheader(pr,ENERHDR, 0); - + csum = 0.0; 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]); free(x); return errcode; @@ -572,7 +572,7 @@ void writenodetable(Project *pr, Pfloat *x) if ((rpt->Nodeflag == 1 || node->Rpt) && 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); // Add node ID and each reported field to string s @@ -618,7 +618,7 @@ void writelinktable(Project *pr, Pfloat *x) double y[MAXVAR]; double *Ucf = pr->Ucf; Slink *Link = net->Link; - + // Write table header writeheader(pr, LINKHDR, 0); @@ -686,7 +686,7 @@ void writeheader(Project *pr, int type, int contin) Quality *qual = &pr->quality; Parser *parser = &pr->parser; Times *time = &pr->times; - + char s[MAXLINE + 1], s1[MAXLINE + 1], s2[MAXLINE + 1], s3[MAXLINE + 1]; int i, n; @@ -697,7 +697,7 @@ void writeheader(Project *pr, int type, int contin) } writeline(pr, " "); - // Hydraulic Status Table + // Hydraulic Status Table if (type == STATHDR) { sprintf(s, FMT49); @@ -737,12 +737,12 @@ void writeheader(Project *pr, int type, int contin) else sprintf(s, FMT78, clocktime(rpt->Atime, time->Htime)); if (contin) strcat(s, t_CONTINUED); writeline(pr, s); - + n = 15; sprintf(s2, "%15s", ""); strcpy(s, t_NODEID); sprintf(s3, "%-15s", s); - + for (i = ELEV; i < QUALITY; i++) { if (rpt->Field[i].Enabled == TRUE) @@ -846,7 +846,7 @@ void writerelerr(Project *pr, int iter, double relerr) { Report *rpt = &pr->report; Times *time = &pr->times; - + if (iter == 0) { 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 *LinkSetting = hyd->LinkSetting; Slink *Link = net->Link; - + // We have a pump/valve setting change instead of a status change if (s1 == s2) { @@ -934,7 +934,7 @@ void writecontrolaction(Project *pr, int k, int i) Snode *Node = net->Node; Slink *Link = net->Link; Scontrol *Control = net->Control; - + switch (Control[i].Type) { case LOWLEVEL: @@ -944,7 +944,7 @@ void writecontrolaction(Project *pr, int k, int i) LinkTxt[Link[k].Type], Link[k].ID, NodeTxt[getnodetype(net, n)], Node[n].ID); break; - + case TIMER: case TIMEOFDAY: sprintf(pr->Msg, FMT55, clocktime(rpt->Atime, time->Htime), @@ -1001,7 +1001,7 @@ int writehydwarn(Project *pr, int iter, double relerr) int i, j; char flag = 0; - char s; + int s; Snode *Node = net->Node; Slink *Link = net->Link; Spump *Pump = net->Pump; @@ -1010,7 +1010,7 @@ int writehydwarn(Project *pr, int iter, double relerr) double *NodeDemand = hyd->NodeDemand; double *LinkFlow = hyd->LinkFlow; double *LinkSetting = hyd->LinkSetting; - + // Check if system unstable 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++) { j = Pump[i].Link; - s = hyd->LinkStatus[j]; - 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) + s = hyd->LinkStatus[j]; + if (hyd->LinkStatus[j] >= OPEN) { - 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)); if (rpt->Messageflag) writeline(pr, pr->Msg); flag = 4; @@ -1098,7 +1098,7 @@ void writehyderr(Project *pr, int errnode) Times *time = &pr->times; Snode *Node = net->Node; - + sprintf(pr->Msg, FMT62, clocktime(rpt->Atime, time->Htime), Node[errnode].ID); 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; Padjlist alink; - + // Scan each successive entry of node list n = 1; while (n <= m) @@ -1232,7 +1232,7 @@ void marknodes(Project *pr, int m, int *nodelist, char *marked) j = alink->node; 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) { case CVPIPE: @@ -1299,7 +1299,7 @@ void writelimits(Project *pr, int j1, int j2) { Report *rpt = &pr->report; int j; - + for (j = j1; j <= j2; j++) { if (rpt->Field[j].RptLim[LOW] < BIG) diff --git a/src/rules.c b/src/rules.c index eb93fc1..7e9945f 100644 --- a/src/rules.c +++ b/src/rules.c @@ -193,7 +193,7 @@ int ruledata(Project *pr) switch (key) { case -1: - err = 201; // Unrecognized keyword + err = 201; // Unrecognized keyword break; case r_RULE: @@ -328,7 +328,6 @@ void adjustrules(Project *pr, int objtype, int index) //----------------------------------------------------------- { Network *net = &pr->network; - Rules *rules = &pr->rules; int i, delete; Spremise *p; @@ -453,7 +452,6 @@ int writerule(Project *pr, FILE *f, int ruleIndex) //----------------------------------------------------------------------------- { Network *net = &pr->network; - Rules *rules = &pr->rules; Srule *rule = &net->Rule[ruleIndex]; Spremise *p; @@ -678,7 +676,7 @@ int newpremise(Project *pr, int logop) { if (!getfloat(Tok[parser->Ntokens - 1], &x)) 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 @@ -715,7 +713,7 @@ int newaction(Project *pr) double x; Saction *a; char **Tok = parser->Tok; - + // Check for correct number of tokens if (parser->Ntokens != 6) return 201; @@ -848,7 +846,7 @@ int checktime(Project *pr, Spremise *p) { t1 = rules->Time1; t2 = time->Htime; - } + } else if (p->variable == r_CLOCKTIME) { t1 = (rules->Time1 + time->Tstart) % SECperDAY; @@ -878,7 +876,7 @@ int checktime(Project *pr, Spremise *p) case EQ: case NE: 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) flag = TRUE; @@ -893,7 +891,7 @@ int checktime(Project *pr, Spremise *p) break; } - // If we get to here then premise was satisfied + // If we get to here then premise was satisfied return 1; } @@ -906,7 +904,7 @@ int checkstatus(Project *pr, Spremise *p) char i; int j; - + switch (p->status) { case IS_OPEN: @@ -930,7 +928,7 @@ int checkvalue(Project *pr, Spremise *p) { Network *net = &pr->network; Hydraul *hyd = &pr->hydraul; - + int i, j, v; double x, // A variable's value tol = 1.e-3; // Equality tolerance @@ -942,7 +940,7 @@ int checkvalue(Project *pr, Spremise *p) Snode *Node = net->Node; Slink *Link = net->Link; Stank *Tank = net->Tank; - + // Find the value being checked i = p->index; v = p->variable; @@ -1099,13 +1097,13 @@ int takeactions(Project *pr) Hydraul *hyd = &pr->hydraul; Report *rpt = &pr->report; Rules *rules = &pr->rules; - + char flag; int k, s, n; double tol = 1.e-3, v, x; Saction *a; SactionList *actionItem; - + n = 0; actionItem = rules->ActionList; while (actionItem != NULL) diff --git a/src/smatrix.c b/src/smatrix.c index f81f3dc..510bb3e 100755 --- a/src/smatrix.c +++ b/src/smatrix.c @@ -81,9 +81,9 @@ static void transpose(int, int *, int *, int *, int *, int createsparse(Project *pr) /* **-------------------------------------------------------------- -** Input: none -** Output: returns error code -** Purpose: creates sparse representation of coeff. matrix +** Input: none +** Output: returns error code +** Purpose: creates sparse representation of coeff. matrix **-------------------------------------------------------------- */ { @@ -104,7 +104,7 @@ int createsparse(Project *pr) errcode = localadjlists(net, sm); 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 ERRCODE(reordernodes(pr)); @@ -134,9 +134,9 @@ int createsparse(Project *pr) int allocsmatrix(Smatrix *sm, int Nnodes, int Nlinks) /* **-------------------------------------------------------------- -** Input: none -** Output: returns error code -** Purpose: allocates memory for representing a sparse matrix +** Input: none +** Output: returns error code +** Purpose: allocates memory for representing a sparse matrix **-------------------------------------------------------------- */ { @@ -192,20 +192,19 @@ int alloclinsolve(Smatrix *sm, int n) void freesparse(Project *pr) /* **---------------------------------------------------------------- -** Input: None -** Output: None -** Purpose: Frees memory used for sparse matrix storage +** Input: None +** Output: None +** Purpose: Frees memory used for sparse matrix storage **---------------------------------------------------------------- */ { - Network *net = &pr->network; Smatrix *sm = &pr->hydraul.smatrix; // stoptimer(SmatrixTimer); // printf("\n"); // printf("\n Processing Time = %7.3f s", gettimer(SmatrixTimer)); // printf("\n"); - + FREE(sm->Order); FREE(sm->Row); FREE(sm->Ndx); @@ -247,7 +246,7 @@ int localadjlists(Network *net, Smatrix *sm) i = net->Link[k].N1; j = net->Link[k].N2; pmark = paralink(net, sm, i, j, k); // Parallel link check - + // Include link in start node i's list alink = (struct Sadjlist *) malloc(sizeof(struct Sadjlist)); if (alink == NULL) return(101); @@ -261,7 +260,7 @@ int localadjlists(Network *net, Smatrix *sm) alink = (struct Sadjlist *) malloc(sizeof(struct Sadjlist)); if (alink == NULL) return(101); if (!pmark) alink->node = i; - else alink->node = 0; // Parallel link marker + else alink->node = 0; // Parallel link marker alink->link = k; alink->next = net->Adjlist[j]; 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) /* **-------------------------------------------------------------- -** Input: i = index of start node of link +** Input: i = index of start node of link ** j = index of end node of link ** k = link index ** Output: returns 1 if link k parallels another link, else 0 @@ -350,10 +349,10 @@ void xparalinks(Network *net) int reordernodes(Project *pr) /* **-------------------------------------------------------------- -** Input: none -** Output: returns 1 if successful, 0 if not -** Purpose: re-orders nodes to minimize # of non-zeros that -** will appear in factorized solution matrix +** Input: none +** Output: returns 1 if successful, 0 if not +** Purpose: re-orders nodes to minimize # of non-zeros that +** will appear in factorized solution matrix **-------------------------------------------------------------- */ { @@ -376,7 +375,7 @@ int reordernodes(Project *pr) int *qsize = NULL; int *llist = NULL; int *marker = NULL; - + // Default ordering for (k = 1; k <= net->Nnodes; k++) { @@ -483,17 +482,17 @@ int factorize(Project *pr) int growlist(Project *pr, int knode) /* **-------------------------------------------------------------- -** Input: knode = node index -** Output: returns 1 if successful, 0 if not -** Purpose: creates new entries in knode's adjacency list for -** all unlinked pairs of active nodes that are -** adjacent to knode +** Input: knode = node index +** Output: returns 1 if successful, 0 if not +** Purpose: creates new entries in knode's adjacency list for +** all unlinked pairs of active nodes that are +** adjacent to knode **-------------------------------------------------------------- */ { Network *net = &pr->network; Smatrix *sm = &pr->hydraul.smatrix; - + int node; Padjlist alink; @@ -517,16 +516,16 @@ int growlist(Project *pr, int knode) int newlink(Project *pr, Padjlist alink) /* **-------------------------------------------------------------- -** Input: alink = element of node's adjacency list -** Output: returns 1 if successful, 0 if not -** Purpose: links end of current adjacent link to end nodes of -** all links that follow it on adjacency list +** Input: alink = element of node's adjacency list +** Output: returns 1 if successful, 0 if not +** Purpose: links end of current adjacent link to end nodes of +** all links that follow it on adjacency list **-------------------------------------------------------------- */ { Network *net = &pr->network; Smatrix *sm = &pr->hydraul.smatrix; - + int inode, jnode; Padjlist blink; @@ -535,7 +534,7 @@ int newlink(Project *pr, Padjlist alink) for (blink = alink->next; blink != NULL; blink = blink->next) { jnode = blink->node; // End node of next connection - + // If jnode still active, and inode not connected to jnode, // then add a new connection between inode and jnode. 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. // in the solution matrix, update the coeff. count. sm->Ncoeffs++; - + // Update adjacency lists for inode & jnode to // reflect the new connection. 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) /* **-------------------------------------------------------------- -** Input: i = node index -** j = node index -** Output: returns 1 if nodes i and j are linked, 0 if not -** Purpose: checks if nodes i and j are already linked. +** Input: i = node index +** j = node index +** Output: returns 1 if nodes i and j are linked, 0 if not +** 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) /* **-------------------------------------------------------------- -** Input: i = node index -** j = node index -** n = link index -** Output: returns 1 if successful, 0 if not -** Purpose: augments node i's adjacency list with node j +** Input: i = node index +** j = node index +** n = link index +** Output: returns 1 if successful, 0 if not +** 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) /* **-------------------------------------------------------------- -** Input: n = number of rows in solution matrix -** Output: returns error code -** Purpose: stores row indexes of non-zeros of each column of -** lower triangular portion of factorized matrix +** Input: n = number of rows in solution matrix +** Output: returns error code +** Purpose: stores row indexes of non-zeros of each column of +** lower triangular portion of factorized matrix **-------------------------------------------------------------- */ { Network *net = &pr->network; Smatrix *sm = &pr->hydraul.smatrix; - + int i, ii, j, k, l, m; int errcode = 0; Padjlist alink; - + // Allocate sparse matrix storage sm->XLNZ = (int *) calloc(n+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->LNZ)); if (errcode) return errcode; - + // Generate row index pointers for each column of matrix k = 0; sm->XLNZ[1] = 1; @@ -655,20 +654,20 @@ int storesparse(Project *pr, int n) int sortsparse(Smatrix *sm, int n) /* **-------------------------------------------------------------- -** Input: n = number of rows in solution matrix -** Output: returns eror code -** Purpose: puts row indexes in ascending order in NZSUB +** Input: n = number of rows in solution matrix +** Output: returns eror code +** Purpose: puts row indexes in ascending order in NZSUB **-------------------------------------------------------------- */ { int i, k; int *xlnzt, *nzsubt, *lnzt, *nzt; int errcode = 0; - + int *LNZ = sm->LNZ; int *XLNZ = sm->XLNZ; int *NZSUB = sm->NZSUB; - + xlnzt = (int *) calloc(n+2, sizeof(int)); nzsubt = (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; for (i = 1; i <= n; i++) xlnzt[i+1] = xlnzt[i] + nzt[i]; - + // Transpose matrix twice to order column indexes transpose(n, XLNZ, NZSUB, LNZ, xlnzt, nzsubt, lnzt, nzt); transpose(n, xlnzt, nzsubt, lnzt, XLNZ, NZSUB, LNZ, nzt); } - + // Reclaim memory free(xlnzt); free(nzsubt); @@ -706,11 +705,11 @@ void transpose(int n, int *il, int *jl, int *xl, int *ilt, int *jlt, int *xlt, int *nzt) /* **--------------------------------------------------------------------- -** Input: n = matrix order -** il,jl,xl = sparse storage scheme for original matrix -** nzt = work array -** Output: ilt,jlt,xlt = sparse storage scheme for transposed matrix -** Purpose: Determines sparse storage scheme for transpose of a matrix +** Input: n = matrix order +** il,jl,xl = sparse storage scheme for original matrix +** nzt = work array +** Output: ilt,jlt,xlt = sparse storage scheme for transposed 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 - n = number of equations -** Output: sm->F = solution values -** returns 0 if solution found, or index of -** equation causing system to be ill-conditioned -** Purpose: solves sparse symmetric system of linear -** equations using Cholesky factorization -** -** NOTE: This procedure assumes that the solution matrix has -** been symbolically factorized with the positions of -** the lower triangular, off-diagonal, non-zero coeffs. -** stored in the following integer arrays: -** XLNZ (start position of each column in NZSUB) -** NZSUB (row index of each non-zero in each column) -** LNZ (position of each NZSUB entry in Aij array) -** -** This procedure has been adapted from subroutines GSFCT and -** GSSLV in the book "Computer Solution of Large Sparse -** Positive Definite Systems" by A. George and J. W-H Liu -** (Prentice-Hall, 1981). + n = number of equations +** Output: sm->F = solution values +** returns 0 if solution found, or index of +** equation causing system to be ill-conditioned +** Purpose: solves sparse symmetric system of linear +** equations using Cholesky factorization +** +** NOTE: This procedure assumes that the solution matrix has +** been symbolically factorized with the positions of +** the lower triangular, off-diagonal, non-zero coeffs. +** stored in the following integer arrays: +** XLNZ (start position of each column in NZSUB) +** NZSUB (row index of each non-zero in each column) +** LNZ (position of each NZSUB entry in Aij array) +** +** This procedure has been adapted from subroutines GSFCT and +** GSSLV in the book "Computer Solution of Large Sparse +** Positive Definite Systems" by A. George and J. W-H Liu +** (Prentice-Hall, 1981). **-------------------------------------------------------------- */ { @@ -766,7 +765,7 @@ int linsolve(Smatrix *sm, int n) int *NZSUB = sm->NZSUB; int *link = sm->link; int *first = sm->first; - + int i, istop, istrt, isub, j, k, kfirst, newk; double bj, diagj, ljk; diff --git a/src/types.h b/src/types.h index f8b125c..027bb61 100755 --- a/src/types.h +++ b/src/types.h @@ -384,7 +384,7 @@ typedef struct // Node Object Psource S; // source pointer double C0; // initial quality double Ke; // emitter coeff. - char Rpt; // reporting flag + int Rpt; // reporting flag NodeType Type; // node type char Comment[MAXMSG+1]; // node comment } Snode; @@ -405,7 +405,7 @@ typedef struct // Link Object double Qa; // low flow limit LinkType Type; // link type StatusType Status; // initial status - char Rpt; // reporting flag + int Rpt; // reporting flag char Comment[MAXMSG+1]; // link Comment } Slink; @@ -466,7 +466,7 @@ typedef struct // Field Object of Report Table { char Name[MAXID+1]; // name 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 double RptLim[2]; // lower/upper report limits } SField; @@ -544,9 +544,6 @@ typedef struct { FILE *InFile; // Input file handle char - Unitsflag, // Unit system flag - Flowflag, // Flow units flag - Pressflag, // Pressure units flag DefPatID[MAXID+1], // Default demand pattern ID InpFname[MAXFNAME+1], // Input file name *Tok[MAXTOKS], // Array of token strings @@ -566,7 +563,10 @@ typedef struct { MaxCurves, // Curve count " " " Ntokens, // Number of tokens in line of input 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 *Patlist, // Temporary time pattern list @@ -605,13 +605,7 @@ typedef struct { int Nperiods, // Number of reporting periods - PageSize; // Lines/page in output report/ - - long - LineNum, // Current line number - PageNum; // Current page number - - char + PageSize, // Lines/page in output report/ Rptflag, // Report flag Tstatflag, // Report time series statistic flag Summaryflag, // Report summary flag @@ -620,11 +614,17 @@ typedef struct { Energyflag, // Energy report flag Nodeflag, // Node 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) Rpt1Fname[MAXFNAME+1], // Primary report file name Rpt2Fname[MAXFNAME+1], // Secondary report file name - DateStamp[26], // Current date & time - Fprinterr; // File write error flag + DateStamp[26]; // Current date & time SField Field[MAXVAR]; // Output reporting fields @@ -635,7 +635,9 @@ typedef struct { char 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 Hydflag, // Hydraulics flag SaveHflag, // Hydraulic results saved flag @@ -732,22 +734,20 @@ typedef struct { DefPat, // Default demand pattern Epat, // Energy cost time pattern DemandModel, // Fixed or pressure dependent + Formflag, // Head loss formula flag Iterations, // Number of hydraulic trials taken MaxIter, // Max. hydraulic trials allowed ExtraIter, // Extra hydraulic trials CheckFreq, // Hydraulic trials between status checks MaxCheck, // Hydraulic trials limit on status checks + OpenHflag, // Hydraulic system opened flag Haltflag; // Flag to halt simulation StatusType *LinkStatus, // Link status *OldStatus; // Previous link/tank status - char - OpenHflag, // Hydraulic system opened flag - Formflag; // Head loss formula flag - - Smatrix smatrix; // Sparse matrix storage + Smatrix smatrix; // Sparse matrix storage } Hydraul; @@ -757,20 +757,18 @@ struct Mempool; // Water Quality Solver Wrapper typedef struct { - char + int Qualflag, // Water quality analysis flag OpenQflag, // Quality system opened flag 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 ChemName[MAXID + 1], // Name of chemical ChemUnits[MAXID + 1]; // Units of chemical - int - TraceNode, // Source node for flow tracing - *SortedNodes; // Topologically sorted node indexes - double Ctol, // Water quality tolerance Diffus, // Diffusivity (sq ft/sec) @@ -854,9 +852,11 @@ typedef struct Project { double Ucf[MAXVAR]; // Unit conversion factors - char + int Openflag, // Project open flag - Warnflag, // Warning flag + Warnflag; // Warning flag + + char Msg[MAXMSG+1], // General-purpose string: errors, messages Title[MAXTITLE][TITLELEN+1], // Project title MapFname[MAXFNAME+1], // Map file name diff --git a/tests/test_net_builder_2.cpp b/tests/test_net_builder_2.cpp index 8002b4a..23cc421 100644 --- a/tests/test_net_builder_2.cpp +++ b/tests/test_net_builder_2.cpp @@ -45,14 +45,14 @@ int main(int argc, char *argv[]) EN_init(ph, "", "", EN_GPM, EN_HW); // Build a network - EN_addnode(ph, "N1", EN_JUNCTION); - EN_addnode(ph, "N2", EN_JUNCTION); - EN_addnode(ph, "N3", EN_RESERVOIR); - EN_addnode(ph, "N4", EN_TANK); - EN_addlink(ph, "L1", EN_PUMP, "N3", "N1"); - EN_addlink(ph, "L2", EN_PIPE, "N1", "N3"); - EN_addlink(ph, "L3", EN_PIPE, "N1", "N2"); - EN_addcurve(ph, "C1"); + EN_addnode(ph, (char *)"N1", EN_JUNCTION); + EN_addnode(ph, (char *)"N2", EN_JUNCTION); + EN_addnode(ph, (char *)"N3", EN_RESERVOIR); + EN_addnode(ph, (char *)"N4", EN_TANK); + EN_addlink(ph, (char *)"L1", EN_PUMP, (char *)"N3", (char *)"N1"); + EN_addlink(ph, (char *)"L2", EN_PIPE, (char *)"N1", (char *)"N3"); + EN_addlink(ph, (char *)"L3", EN_PIPE, (char *)"N1", (char *)"N2"); + EN_addcurve(ph, (char *)"C1"); // Set network data using the new helper functions EN_setcurvevalue(ph, 1, 1, 1500, 250); @@ -88,9 +88,9 @@ int main(int argc, char *argv[]) // Save these new results EN_getnodevalue(ph, 1, EN_PRESSURE, &p1_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_getlinkindex(ph, "L2", &index); + EN_getlinkindex(ph, (char *)"L2", &index); EN_getlinkvalue(ph, index, EN_FLOW, &q2_2); // Display old & new results