Skip to content

Commit

Permalink
Merge pull request #401 from pyswmm/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
karosc authored Sep 5, 2023
2 parents 8266e44 + c760dbf commit 27dc699
Show file tree
Hide file tree
Showing 34 changed files with 1,495 additions and 120 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [windows-2022, ubuntu-20.04, macos-10.15]
os: [windows-2022, ubuntu-20.04, macos-12]
requirements: [requirements-swmm.txt]
include:
- os: windows-2022
Expand Down Expand Up @@ -58,9 +58,9 @@ jobs:
shell: bash
working-directory: ./ci-tools/linux

- os: macos-10.15
- os: macos-12
sys_pkgs: brew install libomp #boost
boost_platform_version: 10.15
boost_platform_version: 12
boost_toolsit: clang
build_unit_test: make.zsh -t -g "Xcode"
build_reg_test: make.zsh -g "Xcode"
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
- name: Clone ci-tools repo
uses: actions/checkout@v3
with:
repository: OpenWaterAnalytics/ci-tools
repository: pyswmm/ci-tools
ref: master
path: ci-tools

Expand All @@ -111,19 +111,19 @@ jobs:
# install boost on mac and linux
- name: Install required system packages on mac and linux
run: ${{ matrix.sys_pkgs }}
if: ${{ runner.os == 'macOS' }}
if: ${{ runner.os == 'macOS' }}

# boost takes a while to install on windows, so try to cache
- name: Install boost
# if: ${{runner.os == 'Windows'}}
# if: ${{runner.os == 'Windows'}}
uses: MarkusJx/[email protected]
id: install-boost
with:
# REQUIRED: Specify the required boost version
# A list of supported versions can be found here:
# https://github.com/MarkusJx/prebuilt-boost/blob/main/versions-manifest.json
boost_version: 1.81.0
link: shared
link: shared
# OPTIONAL: Specify a custon install location
# boost_install_dir: C:\some_directory
# OPTIONAL: Specify a platform version
Expand All @@ -143,8 +143,8 @@ jobs:

- name: Before reg test
env:
NRTESTS_URL: https://github.com/OpenWaterAnalytics/swmm-nrtestsuite
BENCHMARK_TAG: v3.0.1
NRTESTS_URL: https://github.com/pyswmm/swmm-nrtestsuite
BENCHMARK_TAG: v3.1.0
run: ./${{ matrix.before_reg_test }} ${{ env.BENCHMARK_TAG }}

- name: Run reg test
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ endif()


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

Expand Down
1 change: 1 addition & 0 deletions extern/version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define COMPILER_VERSION "@CMAKE_C_COMPILER_VERSION@"
#define BUILD_ID "@BUILD_ID@"

#define TOOLKIT_VERSION "1.0"

static inline int get_version_legacy() { \
return VERSION_MAJOR * 10000 + VERSION_MINOR * 1000 + VERSION_PATCH; \
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: 02/12/23 (Build 5.2.3)
// Date: 07/15/23 (Build 5.2.4)
// Author: L. Rossman
//
// Various Constants
Expand All @@ -17,7 +17,7 @@
//------------------

// OWA Version string stored in version.h
// #define VERSION 52003
// #define VERSION 52004
#define MAGICNUMBER 516114522
#define EOFMARK 0x1A // Use 0x04 for UNIX systems
#define MAXTITLE 3 // Max. # title lines
Expand Down
6 changes: 4 additions & 2 deletions src/solver/dwflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// Project: EPA SWMM5
// Version: 5.2
// Date: 08/01/22 (Build 5.2.1)
// Date: 06/12/23 (Build 5.2.4)
// Author: L. Rossman
// M. Tryby (EPA)
// R. Dickinson (CDM)
Expand All @@ -26,6 +26,8 @@
// (qOld) in call to link_getLossRate.
// Build 5.2.1:
// - Implements the new option to skip checking for normal flow limitations.
// Build 5.2.4:
// - Arguments to function link_getLossRate changed.
//-----------------------------------------------------------------------------
#define _CRT_SECURE_NO_DEPRECATE

Expand Down Expand Up @@ -231,7 +233,7 @@ void dwflow_findConduitFlow(int j, int steps, double omega, double dt)
}

// --- 6. term for evap and seepage losses per unit length
dq6 = link_getLossRate(j, qLast) * 2.5 * dt * v / link_getLength(j);
dq6 = link_getLossRate(j, DW, qLast, dt) * 2.5 * dt * v / link_getLength(j);

// --- combine terms to find new conduit flow
denom = 1.0 + dq1 + dq5;
Expand Down
49 changes: 31 additions & 18 deletions src/solver/dynwave.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// Project: EPA SWMM5
// Version: 5.2
// Date: 11/01/21 (Build 5.2.0)
// Date: 07/13/23 (Build 5.2.4)
// Author: L. Rossman
// M. Tryby (EPA)
// R. Dickinson (CDM)
Expand Down Expand Up @@ -44,6 +44,9 @@
// - Roll back the 5.1.014 change for conduit losses in updateNodeFlows().
// Build 5.2.0:
// - Support added for reporting most frequent non-converging links.
// Build 5.2.4:
// - Conduit evap+seepage outflow split evenly between outflow from
// conduit's upstream and non-outfall downstream nodes.
//-----------------------------------------------------------------------------
#define _CRT_SECURE_NO_DEPRECATE

Expand Down Expand Up @@ -129,7 +132,7 @@ void dynwave_init()
" Not enough memory for dynamic wave routing.");
return;
}

// --- initialize node surface areas & crown elev.
for (i = 0; i < Nobjects[NODE]; i++ )
{
Expand All @@ -144,6 +147,7 @@ void dynwave_init()
j = Link[i].node1;
z = Node[j].invertElev + Link[i].offset1 + Link[i].xsect.yFull;
Node[j].crownElev = MAX(Node[j].crownElev, z);

j = Link[i].node2;
z = Node[j].invertElev + Link[i].offset2 + Link[i].xsect.yFull;
Node[j].crownElev = MAX(Node[j].crownElev, z);
Expand Down Expand Up @@ -534,29 +538,39 @@ void updateNodeFlows(int i)
int n1 = Link[i].node1;
int n2 = Link[i].node2;
double q = Link[i].newFlow;
double uniformLossRate = 0.0;

// --- compute any uniform seepage loss from a conduit
if ( Link[i].type == CONDUIT )
{
k = Link[i].subIndex;
uniformLossRate = Conduit[k].evapLossRate + Conduit[k].seepLossRate;
barrels = Conduit[k].barrels;
uniformLossRate *= barrels;
}
double conduitLossRate = 0.0;

// --- update total inflow & outflow at upstream/downstream nodes
if ( q >= 0.0 )
{
Node[n1].outflow += q + uniformLossRate;
Node[n1].outflow += q;
Node[n2].inflow += q;
}
else
{
Node[n1].inflow -= q;
Node[n2].outflow -= q - uniformLossRate;
Node[n2].outflow -= q;
}


// --- add any uniform evap & seepage loss from conduit link
if ( Link[i].type == CONDUIT )
{
k = Link[i].subIndex;
barrels = Conduit[k].barrels;
conduitLossRate = (Conduit[k].evapLossRate + Conduit[k].seepLossRate) *
barrels;
if (conduitLossRate > 0.0)
{
// --- outfall nodes do not share evap & seepage losses
if (Node[n1].type != OUTFALL && Node[n2].type != OUTFALL)
conduitLossRate /= 2.0;
if (Node[n1].type != OUTFALL)
Node[n1].outflow += conduitLossRate;
if (Node[n2].type != OUTFALL)
Node[n2].outflow += conduitLossRate;
}
}

// --- add surf. area contributions to upstream/downstream nodes
Xnode[Link[i].node1].newSurfArea += Link[i].surfArea1 * barrels;
Xnode[Link[i].node2].newSurfArea += Link[i].surfArea2 * barrels;
Expand Down Expand Up @@ -585,7 +599,7 @@ int findNodeDepths(double dt)
//
{
int i;
double yOld; // previous node depth (ft)
double yOld = 0.0; // previous node depth (ft)

// --- compute outfall depths based on flow in connecting link
for ( i = 0; i < Nobjects[LINK]; i++ ) link_setOutfallDepth(i);
Expand Down Expand Up @@ -654,12 +668,11 @@ void setNodeDepth(int i, double dt)
Node[i].overflow = 0.0;
surfArea = Xnode[i].newSurfArea;
surfArea = MAX(surfArea, MinSurfArea);

// --- determine average net flow volume into node over the time step
dQ = Node[i].inflow - Node[i].outflow;
dV = 0.5 * (Node[i].oldNetInflow + dQ) * dt;


// --- determine if node is EXTRAN surcharged
if (SurchargeMethod == EXTRAN)
{
Expand Down
6 changes: 4 additions & 2 deletions src/solver/flowrout.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// Project: EPA SWMM5
// Version: 5.2
// Date: 05/02/22 (Build 5.2.1)
// Date: 06/12/23 (Build 5.2.4)
// Author: L. Rossman
// M. Tryby (EPA)
//
Expand All @@ -27,6 +27,8 @@
// Build 5.2.1:
// - For storage routing, after convergence the reported depth is now
// based on the last volume found rather than the next trial depth.
// Build 5.2.4:
// - Arguments to link_getLossRate changed.
//-----------------------------------------------------------------------------
#define _CRT_SECURE_NO_DEPRECATE

Expand Down Expand Up @@ -767,7 +769,7 @@ int steadyflow_execute(int j, double* qin, double* qout, double tStep)
else
{
// --- adjust flow for evap and infil losses
q -= link_getLossRate(j, q);
q -= link_getLossRate(j, SF, q, tStep);

// --- flow can't exceed full flow
if ( q > Link[j].qFull )
Expand Down
6 changes: 4 additions & 2 deletions src/solver/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// Project: EPA SWMM5
// Version: 5.2
// Date: 11/01/21 (Build 5.2.0)
// Date: 06/12/23 (Build 5.2.4)
// Author: L. Rossman
// M. Tryby (EPA)
//
Expand All @@ -29,6 +29,8 @@
// - Support added for named variables & math expressions in control rules.
// - Support added for tracking a gage's prior n-hour rainfall total.
// - Refactored external inflow code.
// Build 5.2.4:
// - Additional arguments added to function link_getLossRate.
//-----------------------------------------------------------------------------

#ifndef FUNCS_H
Expand Down Expand Up @@ -425,7 +427,7 @@ double link_getYnorm(int link, double q);
double link_getVelocity(int link, double q, double y);
double link_getFroude(int link, double v, double y);
double link_getPower(int link);
double link_getLossRate(int link, double q);
double link_getLossRate(int link, int routeModel, double q, double tstep);
char link_getFullState(double a1, double a2, double aFull);

void link_getResults(int link, double wt, float x[]);
Expand Down
16 changes: 16 additions & 0 deletions src/solver/include/toolkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ EXPORT_TOOLKIT int swmm_getSimulationAnalysisSetting(SM_SimOption type, int *val
*/
EXPORT_TOOLKIT int swmm_getSimulationParam(SM_SimSetting type, double *value);

/**
@brief Set Simulation Analysis Setting
@param type Option code (see @ref SM_SimSetting)
@param value Option value
@return Error code
*/
EXPORT_TOOLKIT int swmm_setSimulationParam(SM_SimSetting type, double value);

/**
@brief Use/override a hotstart file before the simulation starts.
@param type The property type code (see @ref SM_HotStart)
@param hsfile The file name of the hot start file that the user would like to use.
@return Error code
*/
EXPORT_TOOLKIT int swmm_hotstart(SM_HotStart type, const char *hsfile);

/**
@brief Gets Object Count
@param type Option code (see @ref SM_ObjectType)
Expand Down
9 changes: 8 additions & 1 deletion src/solver/include/toolkit_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,16 @@ typedef enum {
SM_QUALERROR = 10, /**< Quality routing error */
SM_HEADTOL = 11, /**< DW routing head tolerance (ft) */
SM_SYSFLOWTOL = 12, /**< Tolerance for steady system flow */
SM_LATFLOWTOL = 13 /**< Tolerance for steady nodal inflow */
SM_LATFLOWTOL = 13, /**< Tolerance for steady nodal inflow */
SM_THREADS = 14 /**< Number of Threads for this process */
} SM_SimSetting;

/// Hot Start File Manager
typedef enum {
SM_HOTSTART_USE = 0, /**< Use Hotstart File */
SM_HOTSTART_SAVE = 1 /**< Save Hotstart File */
} SM_HotStart;

/// Node property codes
typedef enum {
SM_INVERTEL = 0, /**< Invert Elevation */
Expand Down
1 change: 1 addition & 0 deletions src/solver/include/toolkit_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum ToolkitErrorType {
ERR_TKAPI_UNDEFINED_LID = 2010,
ERR_TKAPI_MEMORY = 2011,
ERR_TKAPI_NO_INLET = 2012,
ERR_TKAPI_SIM_RUNNING = 2013,

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 @@ -13,3 +13,4 @@ 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")
ERR(2013, "\n API Key Error: Simulation Already Started or Running.")
12 changes: 8 additions & 4 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: 10/08/22 (Build 5.2.2)
// Date: 07/13/23 (Build 5.2.4)
// Author: L. Rossman
//
// Street/Channel Inlet Functions
Expand All @@ -18,6 +18,10 @@
// - Substitutes the constant BIG for HUGE.
// Build 5.2.2:
// - Additional statistics added to Street Flow Summary table.
// Build 5.2.4:
// - Fixed expression for equivalent gutter slope in getCurbInletCapture.
// - Corrected sign in equation for effective head in a curb inlet
// with an inclined throat opening in getCurbOrificeFlow.
//-----------------------------------------------------------------------------
#define _CRT_SECURE_NO_DEPRECATE

Expand Down Expand Up @@ -1444,7 +1448,7 @@ double getCurbInletCapture(double Q, double L)
// Input: Q = flow rate seen by inlet (cfs)
// L = length of inlet opening (ft)
// Output: returns captured flow rate (cfs)
// Purpose: finds the flow captured by an on-sag inlet.
// Purpose: finds the flow captured by an on-grade curb opening inlet.
//
{
double Se = Sx, // equivalent gutter slope
Expand All @@ -1460,7 +1464,7 @@ double getCurbInletCapture(double Q, double L)
{
Sr = Sw / Sx;
Eo = getEo(Sr, T-W, W);
Se = Sx + Sw * Eo; //HEC-22 Eq(4-24)
Se = Sx + (a/W) * Eo; //HEC-22 Eq(4-24)
}

// --- opening length for full capture
Expand Down Expand Up @@ -1741,7 +1745,7 @@ double getCurbOrificeFlow(double di, double h, double L, int throatAngle)
if (throatAngle == HORIZONTAL_THROAT)
d = di - h / 2.0;
else if (throatAngle == INCLINED_THROAT)
d = di + (h / 2.0) * 0.7071;
d = di - (h / 2.0) * 0.7071;
return 0.67 * h * L * sqrt(2.0 * 32.16 * d); //HEC-22 Eq(4-31a)
}

Expand Down
Loading

0 comments on commit 27dc699

Please sign in to comment.