Skip to content

Commit

Permalink
Merge pull request #390 from OpenWaterAnalytics/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
karosc authored Mar 28, 2023
2 parents 1ea204b + 2e5b21d commit 8266e44
Show file tree
Hide file tree
Showing 36 changed files with 1,155 additions and 283 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ jobs:
- name: Before reg test
env:
NRTESTS_URL: https://github.com/OpenWaterAnalytics/swmm-nrtestsuite
BENCHMARK_TAG: v3.0.0
BENCHMARK_TAG: v3.0.1
run: ./${{ matrix.before_reg_test }} ${{ env.BENCHMARK_TAG }}

- name: Run reg test
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# CMakeLists.txt - CMake configuration file for swmm-solver
#
# Created: July 11, 2019
# Updated: May 19, 2021
# Modified: Aug 16, 2022
#
# Authors: Michael E. Tryby
# US EPA ORD/CESER
Expand All @@ -22,7 +22,7 @@ endif()


project(swmm-solver
VERSION 5.2.1
VERSION 5.2.3
LANGUAGES C CXX
)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Stormwater-Management-Model

ORD Stormwater Management Model (aka "SWMM")
Stormwater Management Model (aka "SWMM") solver only

## Introduction
This is the open source SWMM source code repository maintained by the Open
Expand Down
4 changes: 2 additions & 2 deletions src/solver/consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// Project: EPA SWMM5
// Version: 5.2
// Date: 06/01/22 (Build 5.2.1)
// Date: 02/12/23 (Build 5.2.3)
// Author: L. Rossman
//
// Various Constants
Expand All @@ -17,7 +17,7 @@
//------------------

// OWA Version string stored in version.h
// #define VERSION 52001
// #define VERSION 52003
#define MAGICNUMBER 516114522
#define EOFMARK 0x1A // Use 0x04 for UNIX systems
#define MAXTITLE 3 // Max. # title lines
Expand Down
4 changes: 2 additions & 2 deletions src/solver/controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1198,8 +1198,8 @@ void updateActionList(struct TAction* a)
listItem->next = ActionList;
ActionList = listItem;
}
listItem->action = a;
}
listItem->action = a;
}

//=============================================================================

Expand Down
18 changes: 9 additions & 9 deletions src/solver/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,18 @@
// Cross section shape types
//-------------------------------------
enum XsectType {
DUMMY, // 0
DUMMY, // 0
CIRCULAR, // 1 closed
FILLED_CIRCULAR, // 2 closed
RECT_CLOSED, // 3 closed
RECT_OPEN, // 4
TRAPEZOIDAL, // 5
TRIANGULAR, // 6
RECT_OPEN, // 4
TRAPEZOIDAL, // 5
TRIANGULAR, // 6
PARABOLIC, // 7
POWERFUNC, // 8
RECT_TRIANG, // 9
POWERFUNC, // 8
RECT_TRIANG, // 9
RECT_ROUND, // 10
MOD_BASKET, // 11
MOD_BASKET, // 11
HORIZ_ELLIPSE, // 12 closed
VERT_ELLIPSE, // 13 closed
ARCH, // 14 closed
Expand Down Expand Up @@ -197,7 +197,7 @@
//-------------------------------------
// Computed node quantities
//-------------------------------------
#define MAX_NODE_RESULTS 7
#define MAX_NODE_RESULTS 7
enum NodeResultType {
NODE_DEPTH, // water depth above invert
NODE_HEAD, // hydraulic head
Expand Down Expand Up @@ -418,7 +418,7 @@ enum CompatibilityType {

enum PumpCurveType {
TYPE1_PUMP, // flow varies stepwise with wet well volume
TYPE2_PUMP, // flow varies stepwise with inlet depth
TYPE2_PUMP, // flow varies stepwise with inlet depth
TYPE3_PUMP, // flow varies with head delivered
TYPE4_PUMP, // flow varies with inlet depth
TYPE5_PUMP, // variable speed version of TYPE3 pump
Expand Down
6 changes: 3 additions & 3 deletions src/solver/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void report_writeTimeStepStats(TTimeStepStats* timeStepStats);
void report_writeErrorMsg(int code, char* msg);
void report_writeErrorCode(void);
void report_writeInputErrorMsg(int k, int sect, char* line, long lineCount);
void report_writeWarningMsg(char* msg, char* id);
void report_writeWarningMsg(char* msg, char* id);
void report_writeTseriesErrorMsg(int code, TTable *tseries);

void inputrpt_writeInput(void);
Expand Down Expand Up @@ -270,7 +270,7 @@ void massbal_addSeepageLoss(int pollut, double seepLoss);
void massbal_addToFinalStorage(int pollut, double mass);
double massbal_getStepFlowError(void);
double massbal_getRunoffError(void);
double massbal_getFlowError(void);
double massbal_getFlowError(char isFinalStorage); // OWA EDIT - added isFinalStorage param to allow running flow error calcs

//-----------------------------------------------------------------------------
// Simulation Statistics Methods
Expand Down Expand Up @@ -496,7 +496,7 @@ void controls_addToCount(char* s);
int controls_addVariable(char* tok[], int ntoks);
int controls_addExpression(char* tok[], int ntoks);
int controls_addRuleClause(int rule, int keyword, char* Tok[], int nTokens);
int controls_evaluate(DateTime currentTime, DateTime elapsedTime,
int controls_evaluate(DateTime currentTime, DateTime elapsedTime,
double tStep);

//-----------------------------------------------------------------------------
Expand Down
18 changes: 9 additions & 9 deletions src/solver/gage.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ void gage_setState(int j, DateTime t)
// --- otherwise update next rainfall interval date
Gage[j].startDate = Gage[j].nextDate;
Gage[j].endDate = datetime_addSeconds(Gage[j].startDate,
Gage[j].rainInterval);
Gage[j].rainInterval);
Gage[j].rainfall = Gage[j].nextRainfall;
if ( !getNextRainfall(j) ) Gage[j].nextDate = NO_DATE;
}
Expand Down Expand Up @@ -670,11 +670,11 @@ int getNextRainfall(int j)
{
if ( Frain.file && Gage[j].currentFilePos < Gage[j].endFilePos )
{
fseek(Frain.file, Gage[j].currentFilePos, SEEK_SET);
fread(&Gage[j].nextDate, sizeof(DateTime), 1, Frain.file);
fread(&vNext, sizeof(float), 1, Frain.file);
Gage[j].currentFilePos = ftell(Frain.file);
rNext = convertRainfall(j, (double)vNext);
fseek(Frain.file, Gage[j].currentFilePos, SEEK_SET);
fread(&Gage[j].nextDate, sizeof(DateTime), 1, Frain.file);
fread(&vNext, sizeof(float), 1, Frain.file);
Gage[j].currentFilePos = ftell(Frain.file);
rNext = convertRainfall(j, (double)vNext);
}
else return 0;
}
Expand All @@ -684,9 +684,9 @@ int getNextRainfall(int j)
k = Gage[j].tSeries;
if ( k >= 0 )
{
if ( !table_getNextEntry(&Tseries[k],
&Gage[j].nextDate, &rNext) ) return 0;
rNext = convertRainfall(j, rNext);
if ( !table_getNextEntry(&Tseries[k],
&Gage[j].nextDate, &rNext) ) return 0;
rNext = convertRainfall(j, rNext);
}
else return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/solver/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// - Minimum dynamic wave routing variable time step added.
// Build 5.1.011:
// - Changed WarningCode to Warnings (# warnings issued)
// - Added error message text as a variable.
// - Added error message text as a variable.
// - Added elapsed simulation time (in decimal days) variable.
// - Added variables associated with detailed routing events.
// Build 5.1.012:
Expand Down
30 changes: 30 additions & 0 deletions src/solver/include/toolkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "../enums.h"
#include "../datetime.h"
#include "../lid.h"
#include "../inlet.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -312,6 +313,24 @@ EXPORT_TOOLKIT int swmm_getLinkParam(int index, SM_LinkProperty param, double *v
*/
EXPORT_TOOLKIT int swmm_setLinkParam(int index, SM_LinkProperty param, double value);

/**
@brief Get a property value for the inlets of a specified link.
@param index The index of a link
@param Param The property type code (See @ref SM_InletProperty)
@param[out] value The value of the inlet's property
@return Error code
*/
EXPORT_TOOLKIT int swmm_getInletParam(int index, SM_InletProperty param, double *value);

/**
@brief Set a property value for the inlets of a specified link.
@param index The index of a link
@param Param The property type code (See @ref SM_InletProperty)
@param value The new value of the inlet's property
@return Error code
*/
EXPORT_TOOLKIT int swmm_setInletParam(int index, SM_InletProperty param, double value);

/**
@brief Get a property value for specified subcatchment.
@param index The index of a subcatchment
Expand Down Expand Up @@ -421,6 +440,17 @@ EXPORT_TOOLKIT int swmm_setLinkPollut(int index, SM_LinkPollut type, int polluta
*/
EXPORT_TOOLKIT int swmm_getLinkResult(int index, SM_LinkResult type, double *result);

/**
@brief Gets results for the inlets of a specified link.
@param index The index of a link with inlets
@param type The result type code (See @ref SM_InletResult)
@param result Pollutant index to set
@param[out] result The result of the inlet's property
@return Error code
*/
EXPORT_TOOLKIT int swmm_getInletResult(int index, SM_InletResult type, double *result);


/**
@brief Gets pollutant values for a specified link.
@param index The index of a link
Expand Down
16 changes: 16 additions & 0 deletions src/solver/include/toolkit_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,21 @@ typedef enum {
SM_STORAGEDRAIN = 29, /**< Underdrain flow rate layer */
} SM_LidResult;

typedef enum {
SM_INLETNUMINLETS = 0,
SM_INLETCLOGFACTOR = 1,
SM_INLETFLOWLIMIT = 2,
SM_INLETLOCALDEPRESS = 3,
SM_INLETLOCALWIDTH = 4
} SM_InletProperty;

typedef enum {
SM_INLETFLOWFACTOR = 0,
SM_INLETFLOWCAPTURE = 1,
SM_INLETBACKFLOW = 2,
SM_INLETBACKFLOWRATIO = 3,

} SM_InletResult;


#endif /* TOOLKIT_ENUMS_H_ */
1 change: 1 addition & 0 deletions src/solver/include/toolkit_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum ToolkitErrorType {
ERR_TKAPI_LIDUNIT_INDEX = 2009,
ERR_TKAPI_UNDEFINED_LID = 2010,
ERR_TKAPI_MEMORY = 2011,
ERR_TKAPI_NO_INLET = 2012,

TKMAXERRMSG = 3000
};
1 change: 1 addition & 0 deletions src/solver/include/toolkit_errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ ERR(2008, "\n API Key Error: Invalid Pattern Index")
ERR(2009, "\n API Key Error: Invalid Lid Unit Index")
ERR(2010, "\n API Key Error: Undefined Subcatchment Lid")
ERR(2011, "\n API Key Error: No memory allocated for return value")
ERR(2012, "\n API Key Error: Specified link is not assigned an inlet")
67 changes: 22 additions & 45 deletions src/solver/inlet.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// Project: EPA SWMM5
// Version: 5.2
// Date: 06/01/22 (Build 5.2.1)
// Date: 10/08/22 (Build 5.2.2)
// Author: L. Rossman
//
// Street/Channel Inlet Functions
Expand All @@ -16,6 +16,8 @@
//
// Build 5.2.1:
// - Substitutes the constant BIG for HUGE.
// Build 5.2.2:
// - Additional statistics added to Street Flow Summary table.
//-----------------------------------------------------------------------------
#define _CRT_SECURE_NO_DEPRECATE

Expand Down Expand Up @@ -68,38 +70,7 @@ typedef struct
} TInletDesign;


// Inlet performance statistics
typedef struct
{
int flowPeriods; // # periods with approach flow
int capturePeriods; // # periods with captured flow
int backflowPeriods; // # periods with backflow
double peakFlow; // peak flow seen by inlet (cfs)
double peakFlowCapture; // capture efficiency at peak flow
double avgFlowCapture; // average capture efficiency
double bypassFreq; // frequency of bypass flow
} TInletStats;

// Inlet list object
struct TInlet
{
int linkIndex; // index of conduit link with the inlet
int designIndex; // index of inlet's design
int nodeIndex; // index of node receiving captured flow
int numInlets; // # inlets on each side of street or in channel
int placement; // whether inlet is on-grade or on-sag
double clogFactor; // fractional degree of inlet clogging
double flowLimit; // inlet flow restriction (cfs)
double localDepress; // local gutter depression (ft)
double localWidth; // local depression width (ft)

double flowFactor; // flow = flowFactor * (flow spread)^2.67
double flowCapture; // captured flow rate (cfs)
double backflow; // backflow from capture node (cfs)
double backflowRatio; // inlet backflow / capture node overflow
TInletStats stats; // inlet performance statistics
TInlet * nextInlet; // next inlet in list
};
// OWA EDIT - TInlet and TInletStats struct defs moved to inlet.h to be shared by toolkit.c

// Shared inlet variables
TInletDesign * InletDesigns; // array of available inlet designs
Expand Down Expand Up @@ -1030,17 +1001,18 @@ void writeStreetStatsHeader()
report_writeLine("*******************");
report_writeLine("");
fprintf(Frpt.file,
"\n ----------------------------------------------------------------------------------------------------------------------"
"\n Peak Maximum Maximum Peak Flow Average Bypass BackFlow"
"\n Flow Spread Depth Inlet Inlet Capture Capture Frequency Frequency");
"\n ---------------------------------------------------------------------------------------------------------------------------------------"
"\n Peak Avg. Bypass Back Peak Peak"
"\n Peak Maximum Maximum Flow Flow Flow Flow Capture Bypass"
"\n Flow Spread Depth Inlet Inlet Inlet Capture Capture Freq Freq / Inlet Flow");
if (UnitSystem == US) fprintf(Frpt.file,
"\n Street Conduit %3s ft ft Design Location %% %% %% %%",
FlowUnitWords[FlowUnits]);
"\n Street Conduit %3s ft ft Design Location Count Pcnt Pcnt Pcnt Pcnt %3s %3s",
FlowUnitWords[FlowUnits], FlowUnitWords[FlowUnits], FlowUnitWords[FlowUnits]);
else fprintf(Frpt.file,
"\n Street Conduit %3s m m Design Location %% %% %% %%",
FlowUnitWords[FlowUnits]);
"\n Street Conduit %3s m m Design Location Pcnt Pcnt Pcnt Pcnt %3s %3s",
FlowUnitWords[FlowUnits], FlowUnitWords[FlowUnits], FlowUnitWords[FlowUnits]);
fprintf(Frpt.file,
"\n ----------------------------------------------------------------------------------------------------------------------");
"\n ---------------------------------------------------------------------------------------------------------------------------------------");
}

//=============================================================================
Expand Down Expand Up @@ -1095,19 +1067,24 @@ void writeStreetStats(int link)
fprintf(Frpt.file, " ON-GRADE");
else
fprintf(Frpt.file, " ON-SAG ");
fprintf(Frpt.file, " %5d", inlet->numInlets);
fp = inlet->stats.flowPeriods / 100.0;
if (fp > 0.0)
{
cp = inlet->stats.capturePeriods / 100.0;
fprintf(Frpt.file, " %9.2f", inlet->stats.peakFlowCapture);
fprintf(Frpt.file, " %7.2f", inlet->stats.peakFlowCapture);
if (cp > 0.0)
{
afc = inlet->stats.avgFlowCapture / cp;
bpf = inlet->stats.bypassFreq / cp;
}
fprintf(Frpt.file, " %9.2f", afc);
fprintf(Frpt.file, " %9.2f", bpf);
fprintf(Frpt.file, " %9.2f", inlet->stats.backflowPeriods / fp);
fprintf(Frpt.file, " %7.2f", afc);
fprintf(Frpt.file, " %7.2f", bpf);
fprintf(Frpt.file, " %7.2f", inlet->stats.backflowPeriods / fp);
fprintf(Frpt.file, " %7.2f", (maxFlow / Street[t].sides) * UCF(FLOW) *
0.01 * inlet->stats.peakFlowCapture / inlet->numInlets);
fprintf(Frpt.file, " %7.2f", maxFlow * UCF(FLOW) * 0.01 *
(100.0 - inlet->stats.peakFlowCapture));
}
}
}
Expand Down
Loading

0 comments on commit 8266e44

Please sign in to comment.