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
or the outlet concentration ) 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 that depends on flow, HRT (hydraulic residence time), or other pollutant concentrations.
- An outlet concentration 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
-
Grid (
TStringGrid
):- Two columns: Pollutant (read-only) and Treatment Expression (editable).
- Rows correspond to each pollutant in the project. For row ,
Cells[0, i+1]
is the pollutant’s name, andCells[1, i+1]
is the user’s expression for that pollutant.
-
HintMemo:
- A memo panel that displays usage hints for writing expressions (for instance, showing the allowable process variables, example formulas, etc.).
-
OKBtn, CancelBtn, HelpBtn:
- Standard form actions. When the user clicks OK, the form returns with the updated treatment expressions.
-
Splitter1:
- Allows resizing between the
HintMemo
and theGrid
.
- Allows resizing between the
2.2 Data Flow
- Each node in SWMM’s
Project
has aTreatment
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)
- Finds the node from
Project.GetNode(NodeType, NodeIndex)
. - Sets the form’s caption to something like
"Treatment Editor for Node [ID]"
. - Fills row 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 , if
Cells[1,i+1]
is non-empty, it forms a string"pollutantName=expression"
and adds it toaNode.Treatment
. Otherwise, it is ignored.
- For each row , if
- 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:
- 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.
- E.g.
- 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.
- E.g.
- 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:
Post a Comment