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
- Navigate to the
enums.h
file. - Add a new variable,
LINK_VOLUME
, to theLinkResultType
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
- Add the report index for
LINK_VOLUME
to theoutput_open
procedure inoutput.c
. - 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
- Open the
link.c
file. - Locate the procedure
link_get_results
. Save thenewVolume
value from theLink
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
- Modify the
report_links
procedure to includeLINK_VOLUME
in the report output. - 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
- Modify the
report_LinkHeader
procedure inreport.c
to reflect the new volume variable. - Add a column header for
Volume
to the output.
fprintf(Frpt.file,
"\n Flow Velocity Depth Percent Volume");
Final Steps:
- Recompile the SWMM 5 engine to apply these changes.
- 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:
Post a Comment