Sunday, December 29, 2024

SWMM5 Delphi GUI Dinfil.pas Summary

 Below is an overview and walkthrough of the Dinfil.pas unit (from SWMM 5.2) highlighting the purpose of each section of the code and how it manages infiltration (or exfiltration) parameters:


1. Purpose and Context

This unit defines a Delphi Form class TInfilForm that is used to edit infiltration (for subcatchments) or exfiltration (for storage units) parameters in SWMM 5.2. The form supports several infiltration models:

  1. Horton (or Modified Horton)
  2. Green-Ampt (or Modified Green-Ampt)
  3. SCS Curve Number

Additionally, it can be used to edit seepage parameters for a storage node (exfiltration).


2. Key Components

2.1 Delphi Form Elements

  • TInfilForm: The main form class containing:
    • A TComboBox (ComboBox1) for selecting the infiltration model.
    • A TGridEditFrame (GridEdit) for displaying/editing parameter names and values.
    • OK, Cancel, and Help buttons.
    • A label (HintLabel) that shows hints or descriptions for each parameter row.
    • Several TPanel controls for layout.

2.2 Arrays Storing Parameter Values

  • HortonInfil: array of strings holding Horton infiltration parameters.
  • GreenAmptInfil: array of strings holding Green-Ampt infiltration parameters.
  • CurveNumInfil: array of strings holding Curve Number infiltration parameters.

Note: Each infiltration model uses a set of up to MAXINFILPROPS + 1 parameters.

2.3 Properties and Hints

Constant arrays define:

  • HortonProps: labels for Horton infiltration parameters.
  • GreenAmptProps: labels for Green-Ampt infiltration parameters.
  • CurveNumProps: labels for Curve Number infiltration parameters.

Likewise, there are arrays of hint text (e.g., HortonHint, GreenAmptHint, CurveNumHint, StorageInfilHint) that describe each parameter to the user.

2.4 Model Selection

SWMM infiltration model constants are typically something like:

  • HORTON_INFIL
  • GREEN_AMPT_INFIL
  • CURVE_NUMBER_INFIL
  • MOD_HORTON_INFIL
  • MOD_GREEN_AMPT_INFIL

The ComboBox1 is populated with textual options (see InfilOptions[]) corresponding to these constants.


3. Form Lifecycle and Event Handlers

3.1 FormCreate

  • Initializes the ComboBox1 with the infiltration model names (from InfilOptions).
  • Sets default infiltration parameter arrays for each model to DefHortonInfil, DefGreenAmptInfil, and DefCurveNumInfil.
  • Initializes the columns in GridEdit.Grid (property vs. value).

3.2 FormShow

  • Calls SetInfilProperties, which populates the grid with parameter labels and current values for the currently selected infiltration model.

3.3 ComboBox1Change

When the user selects a different infiltration model from the combo box:

  1. Saves the currently displayed grid values into the old model’s string array (HortonInfil, GreenAmptInfil, or CurveNumInfil) so changes aren’t lost.
  2. Updates NewInfilModel to the user’s new selection.
  3. Calls SetInfilProperties again to refresh the grid with the new model’s parameters.

3.4 SetInfilModel

  • Called externally to specify which infiltration model is currently in use (by name).
  • If the string S is empty, that indicates storage exfiltration parameters rather than subcatchment infiltration.
  • Otherwise, it matches S against the known infiltration model strings and sets OldInfilModel (and NewInfilModel) accordingly.

3.5 SetInfilProperties

  • Populates the grid (GridEdit.Grid) with row labels and values for the currently selected infiltration model.
  • If it’s storage seepage, the caption changes, and the ComboBox is hidden.

3.6 SetData / GetData

  • SetData: Load a set of infiltration parameters (InfilData) into the form’s string arrays, then call SetInfilProperties to display them.
  • GetData: Retrieve the current infiltration parameter values from the grid and store them in the passed-in array.
    • Also sets HasChanged if anything was edited or if the user changed infiltration models.

3.7 GetInfilModelName

  • Returns the name (text) of the current infiltration model selection in the combo box.

3.8 OKBtnClick

  • Validates the user’s input:
    1. Converts the grid’s values from strings to floating-point numbers.
    2. Checks for invalid relationships, e.g.:
      • Minimum infiltration rate > maximum infiltration rate for Horton.
      • Green-Ampt initial deficit > 1, etc.
    3. If invalid data is found, shows an error message, otherwise closes the form with ModalResult := mrOK.

3.9 HelpBtnClick

  • Uses Application.HelpCommand to open the appropriate Help topic based on the currently selected infiltration model.

3.10 FormKeyDown

  • If the user presses F1, it behaves as though the Help button was clicked.

4. Flow of Usage

When the form is used to edit infiltration properties:

  1. Initialization
    The form is created. Default infiltration parameters are loaded. The infiltration model is set via SetInfilModel.

  2. Presentation
    The form displays the infiltration parameter grid according to NewInfilModel. Hints for each parameter appear in HintLabel.

  3. User Edits

    • The user can change parameter values directly in the grid cells.
    • The user can switch infiltration models in the ComboBox. The form saves the old model’s data before switching to the new model’s data.
  4. Validation / Confirmation

    • On OK, numeric conversions and validations occur.
    • If something is invalid, an error message is shown, and the user must correct it.
    • If valid, the form returns with mrOK.
  5. Retrieval

    • Caller uses GetData to read infiltration parameters from the form.
    • Caller also uses GetInfilModelName to see which infiltration model the user chose.

5. Summary

  • Dinfil.pas defines a dialog for editing infiltration parameters in SWMM 5.2.
  • It handles multiple infiltration methods (Horton, Green-Ampt, SCS Curve Number) plus a special mode for storage exfiltration.
  • The form’s UI elements (combo box + grid) allow the user to switch among models, edit parameter values, see hints, validate inputs, and request context-sensitive help.
  • The arrays (HortonInfil, GreenAmptInfil, CurveNumInfil) store each model’s parameters in string form, which get updated whenever the user switches models or confirms changes.
  • This design encapsulates infiltration editing in a single form, simplifying data entry and validation logic.

Overall, TInfilForm provides a cohesive, user-friendly way for SWMM (or any Delphi application using these routines) to manage infiltration or exfiltration input parameters with built-in validation, help integration, and multiple model support.

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...