Below is a step-by-step explanation of globals.h
, which contains global variables shared across EPA SWMM5. These variables store the current state of an SWMM simulation, including file handles, simulation options, time parameters, and large arrays for subcatchments, nodes, links, etc.
1. Header and Update History
// globals.h
// Project: EPA SWMM5
// ...
// Global Variables
// ...
- The header comment explains that this file holds global variables for the SWMM project.
- The update history lines describe changes in different builds of SWMM (like added or modified variables).
2. Include Guard
#ifndef GLOBALS_H
#define GLOBALS_H
...
#endif //GLOBALS_H
- Prevents multiple inclusion errors if
globals.h
is included in more than one source file.
3. Global File Handles (TFile
)
EXTERN TFile
Finp, Fout, Frpt, Fclimate, Frain, Frunoff, Frdii,
Fhotstart1, Fhotstart2, Finflows, Foutflows;
- Each
TFile
object references a file used by SWMM:Finp
: The primary input file (the.inp
format).Fout
: The binary results file (internal format).Frpt
: The report file (the.rpt
text output).Fclimate
: The climate file (daily temperature, evaporation, wind speed, etc.).Frain
: A rainfall interface file (external format).Frunoff
: A runoff interface file (converting subcatchment runoff to routing).Frdii
: The RDII inflow file (rainfall-derived infiltration/inflow).Fhotstart1
&Fhotstart2
: The hotstart files for saving/initializing states.Finflows
&Foutflows
: Additional interface files for inflows/outflows.
EXTERN
means these variables are declared as external to be defined once in another .c
file (usually globals.c
).
4. Simulation Counters and Text Buffers
EXTERN long
Nperiods, TotalStepCount, ReportStepCount, NonConvergeCount;
EXTERN char
Msg[MAXMSG+1],
ErrorMsg[MAXMSG+1],
Title[MAXTITLE][MAXMSG+1],
TempDir[MAXFNAME+1],
InpDir[MAXFNAME+1];
Nperiods
: Number of times the program saves results (reporting periods).TotalStepCount
,ReportStepCount
: Count how many times steps SWMM has performed in routing, and how many of those were at reporting intervals.NonConvergeCount
: Number of time steps that failed to converge in dynamic wave.Msg[]
andErrorMsg[]
: Buffers for storing text messages or error messages.Title[][]
: Up toMAXTITLE
lines of project title text.TempDir
andInpDir
: Directories used for temporary files or the input file’s directory.
5. Reporting Flags and Object Counts
EXTERN TRptFlags RptFlags; // Reporting options
EXTERN int
Nobjects[MAX_OBJ_TYPES],
Nnodes[MAX_NODE_TYPES],
Nlinks[MAX_LINK_TYPES],
...
RptFlags
: A structure controlling which data SWMM reports.Nobjects[]
: how many objects (gages, subcatchments, nodes, links, etc.) appear.Nnodes[]
andNlinks[]
store how many node or link sub‐types (like outfalls or pumps) exist.
6. Major Simulation Options / Flags
EXTERN int
UnitSystem,
FlowUnits,
InfilModel,
RouteModel,
ForceMainEqn,
LinkOffsets,
SurchargeMethod,
AllowPonding,
InertDamping,
NormalFlowLtd,
SlopeWeighting,
Compatibility,
SkipSteadyState,
IgnoreRainfall,
IgnoreRDII,
IgnoreSnowmelt,
IgnoreGwater,
IgnoreRouting,
IgnoreQuality,
ErrorCode,
Warnings,
WetStep,
DryStep,
ReportStep,
RuleStep,
SweepStart, SweepEnd,
MaxTrials,
NumThreads,
NumEvents;
Each integer configures a major piece of SWMM logic:
UnitSystem
: US or SI.FlowUnits
: CFS, GPM, CMS, etc.InfilModel
: infiltration method (Horton, Green-Ampt, etc.).RouteModel
: routing method (None, Kinematic Wave, Dynamic Wave).ForceMainEqn
: Hazen-Williams or Darcy-Weisbach for force mains.LinkOffsets
: depth vs. elevation offset.SurchargeMethod
: EXTRAN or Preissmann slot.AllowPonding
: node ponding.InertDamping
,NormalFlowLtd
,SlopeWeighting
,Compatibility
,SkipSteadyState
: advanced dynamic wave or compatibility options.IgnoreRainfall
,IgnoreRDII
,IgnoreSnowmelt
,IgnoreGwater
,IgnoreRouting
,IgnoreQuality
: skip certain processes.ErrorCode
: tracks the last error code.Warnings
: number of warnings issued so far.WetStep
,DryStep
,ReportStep
,RuleStep
: time steps (seconds) for runoff and reporting.SweepStart
,SweepEnd
: day of year for street sweeping.MaxTrials
: max trials in dynamic wave.NumThreads
: parallel threads for dynamic wave.NumEvents
: number of detailed routing events.
7. Time Step Values
EXTERN double
RouteStep,
MinRouteStep,
LengtheningStep,
StartDryDays,
CourantFactor,
MinSurfArea,
MinSlope,
RunoffError,
GwaterError,
FlowError,
QualError,
HeadTol,
SysFlowTol,
LatFlowTol,
CrownCutoff;
RouteStep
: current routing time step in seconds (may be smaller thanReportStep
).MinRouteStep
: lower limit for dynamic wave variable stepping.LengtheningStep
: an alternative approach to reduce wave speeds.StartDryDays
: how many dry days before simulation start.CourantFactor
: factor in dynamic wave stepping.MinSurfArea
: min. nodal area to avoid continuity issues.MinSlope
: min. conduit slope.*_Error
: store continuity errors for runoff, groundwater, flow, or quality.HeadTol
,SysFlowTol
,LatFlowTol
: tolerances for dynamic wave or system flow stability.CrownCutoff
: fraction for partial pipe flow classification.
8. Simulation Date/Time Variables
EXTERN DateTime
StartDate, StartTime, StartDateTime,
EndDate, EndTime, EndDateTime,
ReportStartDate, ReportStartTime, ReportStart;
EXTERN double
ReportTime, OldRunoffTime, NewRunoffTime,
OldRoutingTime, NewRoutingTime, TotalDuration, ElapsedTime;
- Dates are stored in
DateTime
(a double representing days from some reference). StartDateTime
=StartDate + StartTime
.EndDateTime
=EndDate + EndTime
.ReportStart
=ReportStartDate + ReportStartTime
.ReportTime
: current reporting time in milliseconds.OldRunoffTime
,NewRunoffTime
,OldRoutingTime
,NewRoutingTime
: track the previous/current times in msec for runoff or routing steps.TotalDuration
: total sim length in msec.ElapsedTime
: current elapsed simulation time in days.
9. Climate & Weather Structures
EXTERN TTemp Temp;
EXTERN TEvap Evap;
EXTERN TWind Wind;
EXTERN TSnow Snow;
EXTERN TAdjust Adjust;
- These structures store temperature data, evaporation settings, wind speed, snow data, and monthly adjustments (like
Adjust
has monthly multipliers for infiltration or rainfall, etc.).
10. Dynamic Arrays of Objects
EXTERN TSnowmelt* Snowmelt;
EXTERN TGage* Gage;
EXTERN TSubcatch* Subcatch;
EXTERN TAquifer* Aquifer;
EXTERN TUnitHyd* UnitHyd;
EXTERN TNode* Node;
EXTERN TOutfall* Outfall;
EXTERN TDivider* Divider;
EXTERN TStorage* Storage;
EXTERN TLink* Link;
EXTERN TConduit* Conduit;
EXTERN TPump* Pump;
EXTERN TOrifice* Orifice;
EXTERN TWeir* Weir;
EXTERN TOutlet* Outlet;
EXTERN TPollut* Pollut;
EXTERN TLanduse* Landuse;
EXTERN TPattern* Pattern;
EXTERN TTable* Curve;
EXTERN TTable* Tseries;
EXTERN TTransect* Transect;
EXTERN TStreet* Street;
EXTERN TShape* Shape;
EXTERN TEvent* Event;
- Each pointer references a block of memory allocated at runtime. For example, once SWMM knows
Nobjects[GAGE]
is 5, it allocatesTGage *Gage
of length 5. Node
,Link
,Pollut
, etc. each reference an array of their respective structures.
11. Final Observations
- This file does not define these variables; it only declares them with
EXTERN
. - Typically,
globals.c
or similar is where they’re defined.
Hence, globals.h
is a single point that gathers all cross‐module global variables, so the entire SWMM codebase can access them consistently.
No comments:
Post a Comment