Wednesday, December 25, 2024

How to Add a Volume Variable to SWMM 5

How to Add a Volume Variable to SWMM 5

This guide explains how to add a volume variable to the DOS version of SWMM 5, enabling it to save volume data in the text output file (after recompiling the modified C code). These modifications only affect the SWMM 5 engine; they do not impact the SWMM 5 GUI or DLL.

Adding a new report variable involves a straightforward five-step process:


Step 1: Add the LINK_VOLUME Variable in enums.h

  1. Navigate to the enums.h file.
  2. Add a new variable, LINK_VOLUME, to the LinkResultType enum. Ensure this variable is added before the water quality variables.
#define MAX_LINK_RESULTS 7  // Increment this value by 1
enum LinkResultType {
    LINK_FLOW,          // Flow rate
    LINK_DEPTH,         // Flow depth
    LINK_VELOCITY,      // Flow velocity
    LINK_FROUDE,        // Froude number
    LINK_CAPACITY,      // Depth to full-depth ratio
    LINK_VOLUME,        // Current volume of the conduit (e.g., added August 2007)
    LINK_QUAL           // Concentration of each pollutant
};

Step 2: Update output_open in output.c

  1. Add the report index for LINK_VOLUME to the output_open procedure in output.c.
  2. Write the index for LINK_VOLUME to the binary output file.
k = LINK_VOLUME; 
fwrite(&k, sizeof(int), 1, Fout.file);
for (j = 0; j < nPolluts; j++) {
    // Existing pollutant index writing logic remains here
}

Step 3: Save LINK_VOLUME to the Binary Output File

  1. Open the link.c file.
  2. Locate the procedure link_get_results. Save the newVolume value from the Link structure into the binary output array.
x[LINK_CAPACITY] = (float)c;
x[LINK_VOLUME]   = (float)Link[j].newVolume;  // Save the current volume of the link

Step 4: Update report_links in report.c

  1. Modify the report_links procedure to include LINK_VOLUME in the report output.
  2. Append the new variable to the formatted output string.
fprintf(Frpt.file, "\n  %11s %8s  %9.3f %9.3f %9.3f %9.1f %9.1f",
    theDate, theTime, 
    LinkResults[LINK_FLOW], 
    LinkResults[LINK_VELOCITY], 
    LinkResults[LINK_DEPTH], 
    LinkResults[LINK_CAPACITY] * 100.0,
    LinkResults[LINK_VOLUME]  // Include volume in the output
);

Step 5: Update the Link Header in report_LinkHeader

  1. Modify the report_LinkHeader procedure in report.c to reflect the new volume variable.
  2. Add a column header for Volume to the output.
fprintf(Frpt.file,
"\n                             Flow  Velocity     Depth   Percent      Volume");

Final Steps:

  1. Recompile the SWMM 5 engine to apply these changes.
  2. Run a simulation and verify that the LINK_VOLUME data is correctly output to the text file.

Summary

By following these steps, you can seamlessly add a new volume variable to SWMM 5. This allows the model to store and report conduit volumes in the binary and text outputs, enhancing its analytical capabilities without affecting the GUI or DLL functionality. Let me know if further clarification is needed!

No comments:

How Does Green Ampt Initial Moisture Defiict in SWMM 5?

  How Does Green Ampt Initial Moisture Defiict in SWMM 5? The Green Ampt method in SWMM 5 uses several parameters to calculate infiltration ...