Sunday, December 29, 2024

SWMM5 Delphi GUI Fsimul.pas Summary

 Below is a high-level summary of Fsimul.pas, the Delphi unit that implements the TSimulationForm in SWMM. This form coordinates the call to the SWMM simulation engine (SWMM5.DLL), displays its progress via a progress bar, and reports the run’s final continuity errors.


1. Purpose

Fsimul.pas defines TSimulationForm, a dialog that:

  • Exports the current SWMM project data into a temporary input file,
  • Opens and runs the SWMM solver (DLL),
  • Displays the run’s percent complete in real-time (progress bar),
  • Ends the run if any errors occur or if the user stops it,
  • Retrieves and displays mass-balance continuity errors (for runoff, flow, and quality),
  • Sets the final run status (successful, warning, error, etc.) returned to the main SWMM application.

2. Key Elements and Behaviors

  1. Notebook Pages:

    • Page 1 (ProgressPage): shows a label, progress bar, “Stop” & “Minimize” buttons.
    • Page 2 (ResultsPage): shows final run status (successful, warnings, or errors) and continuity errors.
  2. Engine Calls:

    • swmm_open(), swmm_start(), swmm_step(), swmm_end(), swmm_close():
      • These are API calls from SWMM5.DLL that parse input, run the simulation step-by-step, retrieve error codes, etc.
  3. Progress Updates:

    • The form calls swmm_step() in a loop, periodically updating:
      • ProgressBar1 with % complete,
      • elapsed days or elapsed hours,
      • Windows application title for minimized state.
    • The user can click “Stop” to terminate the run (setting RunStatus = rsStopped).
  4. Continuity Errors:

    • After swmm_end() completes, the form obtains the final ErrRunoff, ErrFlow, ErrQual errors via swmm_getMassBalErr().
    • These appear on the second “ResultsPage,” along with an icon (info vs. error) and a textual message (e.g., “Run was successful,” “Run was unsuccessful,” etc.).
  5. Run Status:

    • The run status is determined by error codes and checks:
      • rsSuccess, rsWarning, rsError, rsFailed, etc.
      • If results are not generated or the solver encountered a system error, the form updates the final status accordingly (and sets a message in StatusLabel).
  6. User Controls:

    • Stop button sets RunStatus = rsStopped.
    • Minimize button calls Application.Minimize.
    • OK button dismisses the form after final results are displayed.

3. Summary

Fsimul.pas manages the overall process of exporting project data, invoking the SWMM solver DLL, reporting progress, and then presenting final results. Its TSimulationForm is the main interface where users see real-time simulation progress and final mass-balance continuity errors or error messages, enabling them to track and confirm SWMM’s execution within the EPA SWMM application.

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