Below is an overview of consts.h
in EPA SWMM5, highlighting what each constant represents and why the file includes them. Essentially, consts.h
provides global numeric definitions and common constants that other SWMM modules rely on—making the code more readable, maintainable, and consistent.
1. Purpose of consts.h
- Global numeric constants: Instead of scattering “magic numbers” throughout the code, SWMM consolidates them here. That way, a single header file holds units, tolerances, array limits, large/small values, etc.
- Compile-time definitions: By
#define
’ing these constants, we ensure every SWMM source file that includesconsts.h
sees the exact same definitions.
2. General Constants
#define VERSION 52004
VERSION
: 5.2.004.- This integer encodes SWMM version 5.2.4.
#define MAGICNUMBER 516114522
MAGICNUMBER
: A unique integer used in binary or hotstart file headers to confirm the file format.
#define EOFMARK 0x1A
EOFMARK
: Some OS’s or legacy systems used0x1A
(ASCII 26) or0x04
(ASCII EOT) to mark end-of-file.
#define MAXTITLE 3
#define MAXMSG 1024
#define MAXLINE 1024
#define MAXFNAME 259
#define MAXTOKS 40
#define MAXSTATES 10
#define MAXODES 4
MAXTITLE
: SWMM allows up to 3 title lines in input.MAXMSG
: Up to 1024 characters in a warning or error message.MAXLINE
: Up to 1024 characters in any single input line.MAXFNAME
: Max file name length, 259 characters (on Windows).MAXTOKS
: Up to 40 tokens (space-delimited) can exist in one input line.MAXSTATES
: Maximum number of computed hydraulic variables (e.g., flow, depth, velocity, etc.) in routing.MAXODES
: Max. number of ODE’s SWMM might solve in infiltration or water quality sub-models.
#define NA -1
#define TRUE 1
#define FALSE 0
NA
: Typically “not applicable” or “not available.”TRUE
,FALSE
: C doesn’t have a built-in bool in older standards, so SWMM uses 1/0.
#define BIG 1.E10
#define TINY 1.E-6
#define ZERO 1.E-10
#define MISSING -1.E10
BIG
: A large number (10^10). Often used for initialization or bounding.TINY
: A small number (10^-6). Used to avoid division by zero or floating underflow.ZERO
: Even smaller (10^-10).MISSING
: A placeholder if data is unavailable (-10^10).
#define PI 3.141592654
PI
: Approx. 3.14159…
#define GRAVITY 32.2
#define SI_GRAVITY 9.81
GRAVITY
: Acceleration of gravity (ft/s^2) in US Customary.SI_GRAVITY
: 9.81 m/s^2 in SI units.
3. Manning Equation Factor
#define PHI 1.486
PHI
: The constant 1.486 appears in Manning’s formula for flow in US units:
4. Minimum Flow/Depth Constants
#define MIN_RUNOFF_FLOW 0.001
#define MIN_EXCESS_DEPTH 0.0001
#define MIN_TOTAL_DEPTH 0.004167
#define MIN_RUNOFF 2.31481e-8
MIN_RUNOFF_FLOW = 0.001 cfs
: SWMM often zeroes out smaller flows.MIN_TOTAL_DEPTH = 0.004167 ft
(which is 0.05 inches). Small threshold to differentiate between a dry vs. wet node or conduit.- **
MIN_RUNOFF
= 2.31481e-8 ft/s = 0.001 in/hr. Another minimal precipitation-runoff threshold.
5. Steady State Tolerances
#define FLOW_TOL 0.00001
#define DEPTH_TOL 0.00001
#define VOLUME_TOL 0.01
- Used to check if changes in flow, depth, or volume are negligible, i.e., “steady state.”
6. Minimum Depth for Dynamic Wave
#define FUDGE 0.0001
FUDGE
: A small number (0.0001 ft).- If a computed link depth is below
FUDGE
, SWMM sets it toFUDGE
to avoid numeric instability (like dividing by zero area).
- If a computed link depth is below
7. Unit Conversion Factors
#define GPMperCFS 448.831
#define AFDperCFS 1.9837
#define MGDperCFS 0.64632
#define IMGDperCFS 0.5382
#define LPSperCFS 28.317
#define LPMperCFS 1699.0
#define CMHperCFS 101.94
#define CMDperCFS 2446.6
#define MLDperCFS 2.4466
#define M3perFT3 0.028317
#define LperFT3 28.317
#define MperFT 0.3048
#define PSIperFT 0.4333
#define KPAperPSI 6.895
#define KWperHP 0.7457
#define SECperDAY 86400
#define MSECperDAY 8.64e7
#define MMperINCH 25.40
- Provides conversions from cubic feet per second (cfs) to typical volumetric flow units: gallons per minute (GPM), million gallons per day (MGD), etc.
- Also length, pressure, power conversions:
MperFT = 0.3048
=> 1 ft = 0.3048 mPSIperFT = 0.4333
=> psi per foot of waterSECperDAY = 86400
=> # of seconds in a dayMMperINCH = 25.4
=> mm per inch
8. Token Separators
#define SEPSTR " \t\n\r"
- Characters used as delimiters (space, tab, newline, carriage return) when parsing lines.
9. Summary
consts.h
centralizes constants used across SWMM:- Array size limits (lines, tokens).
- Unit conversions (cfs to MGD, ft to m, etc.).
- Minimum thresholds (flow, depth, volume).
- Key “magic” numbers (version codes, missing values).
Thanks to these common definitions, the rest of SWMM’s code can cleanly reference ZERO
instead of 1.e-10
, or MperFT
for a length conversion, making the software more modular and maintainable.
No comments:
Post a Comment