Below is an overview of Doptions.pas, a Delphi unit from SWMM 5.2 that defines a dialog (TAnalysisOptionsForm) for editing a project's simulation options. These options dictate how SWMM conducts its rainfall-runoff, RDII, snowmelt, groundwater, flow routing, and water quality calculations.
1. Purpose and Context
In SWMM, project options control everything from the infiltration model and routing method to time-step durations, solver tolerances, and advanced engine settings. The TAnalysisOptionsForm provides multiple tabs (via TPageControl
) allowing the user to configure:
- Which physical processes are included (rainfall, RDII, snowmelt, groundwater, etc.).
- Simulation start and end dates/times.
- Reporting time steps.
- Routing options (inertial damping, variable time step, force main equations, etc.).
- External interface files (e.g., hotstart or interface flows).
When OK is pressed, these choices are written back into SWMM’s Project.Options data structure.
2. Main Form: TAnalysisOptionsForm
2.1 Tabs and Controls
The form includes a TPageControl
with 5 TabSheets, each containing groups of controls relevant to particular categories of options:
-
Simulation Models (TabSheet1)
- Checkboxes for ignoring or including processes like Rainfall, SnowMelt, Groundwater, FlowRouting, WaterQuality, and RDII.
- A radio group (
InfilModelsGroup
) to choose among infiltration models (Horton, Green-Ampt, Curve Number). - Another radio group (
RoutingMethodsGroup
) to pick routing method (Kinematic Wave, DW, or SWMM’s dynamic wave, etc.).
-
Dates/Times (TabSheet2)
- Start/Report/End date & time pickers (
TDateTimePicker
) for simulation period. - Street sweeping date pickers (
SweepStartPicker
,SweepEndPicker
) and “Days of No Rain” (DryDaysEdit
).
- Start/Report/End date & time pickers (
-
Time Steps (TabSheet3)
- Controls for Routing time step (
RouteStepEdit
), Reporting step (RptStepPicker
), Dry/Wet weather time step (DryStepPicker
,WetStepPicker
), etc. - SysFlowTolSpinner and LatFlowTolSpinner for system/lat-flow tolerances.
- Checkboxes like AllowPondingBox and SkipSteadyBox.
- Optional variable time step (
VarTimeStepBox
), with a spin edit for maximum time step (%) (VarStepEdit
).
- Controls for Routing time step (
-
Engine/Advanced (TabSheet4)
- Inertial damping combo (
InertialTermsCombo
), normal flow limiting combo (NormalFlowCombo
), and force main equation combo (ForceMainCombo
). - Surcharge method (
SurchargeCombo
), minimum nodal surface area (MinSurfAreaEdit
), solver tolerances (HeadTolEdit
), max trials, etc. - Number of threads (
ThreadsEdit
andThreadsButton
) to parallelize SWMM’s solver.
- Inertial damping combo (
-
Interface Files (TabSheet5)
- A list box (
FileListBox
) plus Add, Edit, Delete buttons. - These refer to external files that can store or retrieve intermediate states (hotstart, interface flows, etc.).
- A list box (
3. Data Flow
3.1 Loading Options: SetOptions(Page: Integer)
-
Reads from
Project.Options
and displays:- Dates: converts stored strings to
TDateTimePicker
(StartDatePicker
, etc.). - Time Steps: stored as “HH:MM:SS” strings, displayed using two pickers (days vs. clock time) via
SetStepTime()
. - Check/Radio Boxes: infiltration method, routing method, advanced solver combos, etc.
- Interface files: populates
FileListBox
fromProject.IfaceFiles
.
- Dates: converts stored strings to
-
Then it sets
PageControl1.TabIndex := Page
so the user sees the requested tab first.
3.2 Editing Options
- User modifies infiltration model, date/time pickers, advanced combos, or adds interface files.
- Some controls (e.g., infiltration model group) may cause immediate changes in default infiltration parameters if the model changes.
3.3 Saving Options: GetOptions
- The final user settings are stored back into
Project.Options
. For example:Project.Options.Data[START_DATE_INDEX]
= the string version ofStartDatePicker.Date
.Project.Options.Data[IGNORE_RAINFALL_INDEX]
='YES'
if user unchecked the “Rainfall” box.- DX (time step strings) are reconstructed with
GetStepTime(RptDaysPicker, RptStepPicker)
. Project.IfaceFiles
is cleared and re-filled fromFileListBox
.
- Some special logic:
- If infiltration model changed, reset default infiltration data.
- If user turned on variable time step (
VarTimeStepBox
), read the numeric spin for% time step
(VarStepEdit
).
4. Notable Controls and Methods
4.1 Time Pickers (TDateTimePicker
)
- For simulation start, end, and report times, plus a daily step pickers for “days” portion.
- The code splits hours from days using helper routines
SetStepTime()
andGetStepTime()
to handle times that can exceed 24 hours.
4.2 VarTimeStepBoxClick
- Toggles the variable time step feature in dynamic wave routing.
- When checked,
VarStepEdit
(spin) andMinTimeStepEdit
(float) become enabled.
4.3 Interface Files Section
- The user can Add (select or define a new file), Edit (change path or type?), or Delete.
- The form calls an TIfaceFileForm (
Diface.pas
) to manage details of each file.
4.4 DefaultsLabelLinkClick
- Sets various “good default” values for advanced solver options (inertial terms, normal flow limiting, force main eqn, etc.).
- The user can revert to these recommended defaults with one click.
4.5 ThreadsButtonClick
- Displays a message with the system’s CPU count (
MsgDlg(NumberOfCPUs, ...)
). - The user chooses how many solver threads to use (1..N) in
ThreadsEdit
.
4.6 Tab-Specific OnChanging / OnChange
PageControl1Changing
saves the currentHasChanged
status.PageControl1Change
restores it to avoid marking changes if the user only switches tabs.
5. Validation and OK
-
When the user presses OK:
- If variable time step was toggled, mark
HasChanged
. ModalResult := mrOK
.
- If variable time step was toggled, mark
-
Back in the calling code,
GetOptions
is invoked to finalize changes inProject.Options
.
6. Summary
Doptions.pas is SWMM’s comprehensive interface for configuring simulation settings—from basic infiltration models and simulation times to advanced numeric solver details. By splitting these controls into a TPageControl with multiple tabs, the code neatly organizes what can be a large set of parameters. The form ensures that user edits are validated, stored, and optionally reset to recommended defaults, supporting a flexible yet standardized way to set up a SWMM model run.
No comments:
Post a Comment