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.hfile. - Add a new variable,
LINK_VOLUME, to theLinkResultTypeenum. 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_VOLUMEto theoutput_openprocedure inoutput.c. - Write the index for
LINK_VOLUMEto 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.cfile. - Locate the procedure
link_get_results. Save thenewVolumevalue from theLinkstructure 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_linksprocedure to includeLINK_VOLUMEin 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_LinkHeaderprocedure inreport.cto reflect the new volume variable. - Add a column header for
Volumeto 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_VOLUMEdata 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