Sunday, December 29, 2024

SWMM5 Delphi GUI Dtreat.pas Summary

 Below is an overview of Dtreat.pas, a Delphi unit from SWMM 5.2 that implements a dialog form (TTreatmentForm) for editing pollutant treatment expressions at a drainage system node. These expressions determine how pollutants are removed or altered at the node (e.g., the fractional removal 

RR or the outlet concentration CC) based on inflow pollutant levels and flow/process variables.


1. Purpose and Context

In SWMM, you can define treatment expressions at any node (junction, storage, or divider). These specify how pollutants are removed or transformed, such as:

  • A fractional removal RR that depends on flow, HRT (hydraulic residence time), or other pollutant concentrations.
  • An outlet concentration CC that is a function of inflow concentration and other variables.

The TTreatmentForm lets the user directly enter these expressions for each pollutant. SWMM then applies them during the water quality routing stage.


2. Main Form: TTreatmentForm

2.1 Visual Components

  1. Grid (TStringGrid):

    • Two columns: Pollutant (read-only) and Treatment Expression (editable).
    • Rows correspond to each pollutant in the project. For row i+1i+1, Cells[0, i+1] is the pollutant’s name, and Cells[1, i+1] is the user’s expression for that pollutant.
  2. HintMemo:

    • A memo panel that displays usage hints for writing expressions (for instance, showing the allowable process variables, example formulas, etc.).
  3. OKBtn, CancelBtn, HelpBtn:

    • Standard form actions. When the user clicks OK, the form returns with the updated treatment expressions.
  4. Splitter1:

    • Allows resizing between the HintMemo and the Grid.

2.2 Data Flow

  • Each node in SWMM’s Project has a Treatment string list. The user’s expressions are stored with the format "pollutantName=expression" for each pollutant that has a treatment expression.
  • SetData is called to load the existing expressions for each pollutant into the grid.
  • GetData is called to save any updated expressions from the grid back into the node’s Treatment list.

3. Key Methods

3.1 FormCreate

  • Initializes the hint memo with a multi-line string describing how to write treatment expressions (variables, example expressions, etc.).
  • Configures the grid:
    • The top row (row 0) has headers for “Pollutant” and “Treatment Expression.”
    • Additional rows (1..N) are for each pollutant in the project.

3.2 SetData(NodeType, NodeIndex)

  1. Finds the node from Project.GetNode(NodeType, NodeIndex).
  2. Sets the form’s caption to something like "Treatment Editor for Node [ID]".
  3. Fills row i+1i+1 in the grid with the pollutant name and the node’s existing expression for that pollutant, if any (taken from aNode.Treatment.ValueFromIndex[...]).

3.3 GetData(NodeType, NodeIndex)

  • Retrieves the updated expressions from the grid:
    • For each row i+1i+1, if Cells[1,i+1] is non-empty, it forms a string "pollutantName=expression" and adds it to aNode.Treatment. Otherwise, it is ignored.
  • This overwrites the node’s old Treatment list with the new one.

3.4 GridSetEditText

  • Whenever the user edits a cell, HasChanged := True, marking that changes have been made.

3.5 OKBtnClick

  • If the user is done, sets ModalResult := mrOK, letting GetData be called externally to finalize the changes.

3.6 HelpBtnClick

  • Launches a help topic about treatment expressions.

4. Expression Syntax

From the hints, the user can write:

  1. Removal expression: R = <some function>
    • E.g. R = 0.75 * R_TSS means the fractional removal of the pollutant is 0.75 times the removal fraction of TSS.
  2. Concentration expression: C = <some function>
    • E.g. C = BOD * exp(-0.05*HRT) means the outflow BOD concentration is the inflow BOD times an exponential decay based on HRT.
  3. The user can reference:
    • Other pollutant names
    • R_X for the fractional removal of pollutant X
    • Flow variables (FLOW, DEPTH, HRT, DT, AREA)

5. Summary

Dtreat.pas’s TTreatmentForm is a specialized UI for specifying pollutant treatment at a SWMM node:

  • Displaying each pollutant in a row,
  • Allowing an expression for fractional removal or outflow concentration,
  • Storing them in the node’s Treatment list,
  • Used by SWMM’s water quality model to reduce or transform pollutant loads based on the user-defined formula.

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