Sunday, December 29, 2024

SWMM5 Delphi GUI Doptions.pas Summary

 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:

  1. Which physical processes are included (rainfall, RDII, snowmelt, groundwater, etc.).
  2. Simulation start and end dates/times.
  3. Reporting time steps.
  4. Routing options (inertial damping, variable time step, force main equations, etc.).
  5. 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:

  1. 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.).
  2. 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).
  3. 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).
  4. 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 and ThreadsButton) to parallelize SWMM’s solver.
  5. 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.).

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 from Project.IfaceFiles.
  • 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:
    1. Project.Options.Data[START_DATE_INDEX] = the string version of StartDatePicker.Date.
    2. Project.Options.Data[IGNORE_RAINFALL_INDEX] = 'YES' if user unchecked the “Rainfall” box.
    3. DX (time step strings) are reconstructed with GetStepTime(RptDaysPicker, RptStepPicker).
    4. Project.IfaceFiles is cleared and re-filled from FileListBox.
  • 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() and GetStepTime() 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) and MinTimeStepEdit (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 current HasChanged status.
  • PageControl1Change restores it to avoid marking changes if the user only switches tabs.

5. Validation and OK

  • When the user presses OK:

    1. If variable time step was toggled, mark HasChanged.
    2. ModalResult := mrOK.
  • Back in the calling code, GetOptions is invoked to finalize changes in Project.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:

A comprehensive explanation of how minimum travel distance relates to link length in InfoSewer

In hydraulic modeling of sewer networks, the minimum travel distance is a fundamental parameter that affects how accurately the model can si...