Sunday, December 29, 2024

SWMM5 Delphi GUI Uexport.pas Summary

 Extended Summary for Uexport.pas

The Uexport.pas unit plays a central role in exporting the current SWMM project’s data into a formatted text file (or equivalently, into a TStringList). The data it exports includes:

  1. Main project data (subcatchments, nodes, links, infiltration parameters, pollutants, land uses, etc.).
  2. User options and simulation parameters (simulation dates, time steps, infiltration model, etc.).
  3. Additional items such as control rules, time series, curves, map coordinates, and even user-defined events.

It also handles special “save” tasks such as writing out a hotstart file or partial sets of results.


1. Responsibilities of the Unit

The Uexport unit provides a series of helper methods to write:

  • Project Setup: [TITLE], [OPTIONS], [FILES], [EVAPORATION], [TEMPERATURE]
  • Rain Gages: [RAINGAGES]
  • Subcatchment-Related Data: [SUBCATCHMENTS], [SUBAREAS], [INFILTRATION], [SNOWPACKS], [GROUNDWATER], etc.
  • Node & Link Data: [JUNCTIONS], [OUTFALLS], [DIVIDERS], [STORAGE], [CONDUITS], [PUMPS], [ORIFICES], [WEIRS], [OUTLETS], [XSECTIONS], [STREETS], [INLETS], [LOSSES], etc.
  • Pollutant & Land Use: [POLLUTANTS], [LANDUSES], [BUILDUP], [WASHOFF], etc.
  • Water Quality: [TREATMENT] for node-level pollutant treatment equations.
  • Inflows: [INFLOWS], [DWF], [RDII], etc.
  • Hydrographs & Time Series: [HYDROGRAPHS], [TIMESERIES], [PATTERNS], [CURVES]
  • Controls & Reporting: [CONTROLS], [REPORT]
  • Map Data: [MAP], [COORDINATES], [VERTICES], [Polygons], [SYMBOLS], [LABELS], [BACKDROP]
  • Adjustment factors: [ADJUSTMENTS] for monthly climate adjustments.
  • Optional: [EVENTS] if the user is using the event analysis feature.
  • Additional: [TAGS] for object tags, and [PROFILES] for user-created profile plots.

The unit also defines:

  • SaveProject(Fname): Writes the entire SWMM input file for the current project to a file Fname.
  • SaveResults(Fname): Renames and saves a run's [REPORT] & [OUTFILE].
  • SaveHotstartFile(Fname): Writes hotstart data (current flow and depths, etc.) to a binary file.
  • RelativePathName(Fname): Converts an absolute file path to a path relative to the directory of the saved project file.

2. Key Data and Helper Routines

2.1 Internal Variables

  • Tab: A string that holds either a tab character or a single space, depending on whether the user wants a tab-delimited or spaced-delimited format.
  • SaveToPath: The directory path to which the project file is being saved. Used to produce “relative” paths for external files.
  • DXFCount, DWFCount, RDIICount, TreatCount: Counters used to track how many nodes have external inflows, dry-weather flows, RDII flows, or treatment definitions. This guides whether to export [INFLOWS], [DWF], [RDII], [TREATMENT] sections.

2.2 Modularity

Each major SWMM input section ([JUNCTIONS], [CONDUITS], [STORAGE], etc.) has its own procedure:

  • ExportTitle -> [TITLE]
  • ExportOptions -> [OPTIONS]
  • ExportRaingages -> [RAINGAGES]
  • ExportSubcatchments, ExportSubAreas, ExportInfiltration, …
  • ExportJunctions, ExportOutfalls, …, etc.

The pattern is consistent: build a header line with S.Add(...), then loop through the relevant items in Project.Lists[...], generating lines of data. Comments are also exported for each object using ExportComment(...).

2.3 Project-Wide Exports

  1. ExportProject(S, P): The main aggregator that calls each individual export subroutine in a specific order, building a complete SWMM input file in the stringlist S.

  2. ExportMap(S): Exports map geometry data such as [COORDINATES] for each node, [VERTICES] for each link, [Polygons] for subcatchments, [LABELS] for map labels, etc.

  3. SaveProject(Fname):

    • Creates a TStringList.
    • Calls ExportProject to add all text lines.
    • Appends [TAGS], [MAP], [PROFILES].
    • Saves the final text to Fname.
    • If Fname has a .ini extension, also writes certain layout data with Uinifile.SaveProjIniFile.

2.4 Output & Intermediate Files

  • Temporary: The code references TempReportFile and TempOutputFile—where the engine run results might have been stored. SaveResults(Fname) tries to rename these to permanent names (like *.rpt, *.out) if possible.

  • Hotstart: The SaveHotstartFile(Fname) function writes out flow depths, water levels, etc., to a binary file in a special format for a subsequent run to be initialized with.

    • It writes the # of subcatchments, nodes, links, & pollutants, plus unit info, plus current state for each subcatchment, node, & link.

3. Typical Flow

  1. User selects “File -> Save As” for a SWMM project.
  2. SaveProject(Fname) is called.
  3. Internally, a new TStringList is created and passed to ExportProject.
  4. ExportProject calls each subordinate ExportXxx procedure in the recommended SWMM input order, building up a final text representation.
  5. The final text is saved to disk as an *.inp file, and possibly an .ini file is created with some UI-specific details.

Additionally, “File -> Save Results” might call SaveResults(Fname), which manipulates the previously generated “temporary” output and report files.


4. Notable Implementation Details

  • The code is mindful of whether a user has set output objects to “No” results, so many references to Uoutput or counters like DXFCount detect if a section is actually needed.
  • The routine RelativePathName(Fname) ensures that external references (like a time series file, or a rain data file) are given relative to the project file’s folder if possible, to make the project file more portable.
  • Many small labeling procedures ensure the formatting is consistent with SWMM’s expected column widths, like Format('%-16s', [...]), Tab + Format('%-10s', [...]), etc.

5. Conclusion

Uexport.pas collects all project data and organizes it into the standard SWMM text input format. Each object category has its own dedicated procedure that reads from the project database, writes to an output TStringList, and can optionally handle advanced features like infiltration models, external inflows, or special shapes. This design provides a straightforward, structured approach to exporting a complete SWMM model file.

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