OGS
SWMMConverter.cpp File Reference

Detailed Description

Definition in file SWMMConverter.cpp.

Include dependency graph for SWMMConverter.cpp:

Go to the source code of this file.

Functions

int writeGeoOutput (std::string input_file, std::string output_file)
 
int addObjectsToMesh (FileIO::SwmmInterface &swmm, MeshLib::Mesh &mesh, FileIO::SwmmObject const type, std::size_t const timestep)
 
int writeMeshOutput (std::string const &input_file, std::string const &output_file, bool const node_args, bool const link_args)
 
void writeObjectsOfSwmmTypeToCsv (FileIO::SwmmInterface &swmm, FileIO::SwmmObject const type, std::string const &base, std::string const &ext)
 
int writeCsvOutput (std::string input_file, std::string output_file, bool const node_args, bool const link_args, bool const catchment_args, bool const system_args)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ addObjectsToMesh()

int addObjectsToMesh ( FileIO::SwmmInterface & swmm,
MeshLib::Mesh & mesh,
FileIO::SwmmObject const type,
std::size_t const timestep )

Definition at line 36 of file SWMMConverter.cpp.

40{
41 std::size_t const n_node_params(swmm.getNumberOfParameters(type));
42 for (std::size_t j = 0; j < n_node_params; ++j)
43 {
44 std::string const vec_name(swmm.getArrayName(type, j));
45 if (vec_name.empty())
46 return -2;
47 std::vector<double> data_vec =
48 swmm.getArrayAtTimeStep(type, timestep, j);
49 if (!swmm.addResultsToMesh(mesh, type, vec_name, data_vec))
50 return -3;
51 }
52 return 0;
53}
std::vector< double > getArrayAtTimeStep(SwmmObject obj_type, std::size_t time_step, std::size_t var_idx) const
Returns an array for a given variable at all nodes/links from a SWMM output file for a given time ste...
static bool addResultsToMesh(MeshLib::Mesh &mesh, SwmmObject const type, std::string const &vec_name, std::vector< double > const &data)
std::size_t getNumberOfParameters(SwmmObject obj_type) const
Returns the number of parameters (incl. pollutants) of the given type.
std::string getArrayName(SwmmObject obj_type, std::size_t var_idx) const
Returns the name of the data array for the given object type and parameter index.

References FileIO::SwmmInterface::addResultsToMesh(), FileIO::SwmmInterface::getArrayAtTimeStep(), FileIO::SwmmInterface::getArrayName(), and FileIO::SwmmInterface::getNumberOfParameters().

Referenced by writeMeshOutput().

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 160 of file SWMMConverter.cpp.

161{
162 TCLAP::CmdLine cmd(
163 "Read files for the Storm Water Management Model (SWMM) and converts "
164 "them into OGS data structures.\n\n"
165 "OpenGeoSys-6 software, version " +
167 ".\n"
168 "Copyright (c) 2012-2024, OpenGeoSys Community "
169 "(http://www.opengeosys.org)",
171 TCLAP::ValueArg<std::string> mesh_output_arg(
172 "m", "mesh", "mesh output file (*.vtu)", false, "", "mesh output file");
173 cmd.add(mesh_output_arg);
174 TCLAP::ValueArg<std::string> geo_output_arg(
175 "g", "geo", "geometry output file (*.gml)", false, "",
176 "geometry output file");
177 cmd.add(geo_output_arg);
178 TCLAP::ValueArg<std::string> csv_output_arg(
179 "c", "csv", "csv output file (*.csv)", false, "", "CSV output file");
180 cmd.add(csv_output_arg);
181 TCLAP::ValueArg<std::string> swmm_input_arg(
182 "i", "input", "SWMM input file (*.inp)", true, "", "input file");
183 cmd.add(swmm_input_arg);
184 TCLAP::SwitchArg add_nodes_arg(
185 "", "node_vars", "Read node variables and add to output mesh");
186 cmd.add(add_nodes_arg);
187 TCLAP::SwitchArg add_links_arg(
188 "", "link_vars", "Read link variables and add to output mesh");
189 cmd.add(add_links_arg);
190 TCLAP::SwitchArg add_subcatchments_arg(
191 "", "subcatchment_vars",
192 "Read subcatchment variables and write to CSV-file");
193 cmd.add(add_subcatchments_arg);
194 TCLAP::SwitchArg add_system_arg(
195 "", "system_vars", "Read system variables and write to CSV-file");
196 cmd.add(add_system_arg);
197 cmd.parse(argc, argv);
198
199 BaseLib::MPI::Setup mpi_setup(argc, argv);
200
201 if (!(geo_output_arg.isSet() || mesh_output_arg.isSet() ||
202 csv_output_arg.isSet()))
203 {
204 ERR("No output format given. Please specify OGS geometry or mesh "
205 "output file.");
206 return -1;
207 }
208
209 if ((add_subcatchments_arg.getValue() || add_system_arg.getValue()) &&
210 !csv_output_arg.isSet())
211 {
212 ERR("Please specify csv output file for exporting subcatchment or "
213 "system parameters.");
214 return -1;
215 }
216
217 if (geo_output_arg.isSet())
218 writeGeoOutput(swmm_input_arg.getValue(), geo_output_arg.getValue());
219
220 if (mesh_output_arg.isSet())
221 writeMeshOutput(swmm_input_arg.getValue(), mesh_output_arg.getValue(),
222 add_nodes_arg.getValue(), add_links_arg.getValue());
223
224 if (csv_output_arg.isSet())
225 writeCsvOutput(swmm_input_arg.getValue(),
226 csv_output_arg.getValue(),
227 add_nodes_arg.getValue(),
228 add_links_arg.getValue(),
229 add_subcatchments_arg.getValue(),
230 add_system_arg.getValue());
231
232 return 0;
233}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
int writeCsvOutput(std::string input_file, std::string output_file, bool const node_args, bool const link_args, bool const catchment_args, bool const system_args)
int writeGeoOutput(std::string input_file, std::string output_file)
int writeMeshOutput(std::string const &input_file, std::string const &output_file, bool const node_args, bool const link_args)
GITINFOLIB_EXPORT const std::string ogs_version

References ERR(), GitInfoLib::GitInfo::ogs_version, writeCsvOutput(), writeGeoOutput(), and writeMeshOutput().

◆ writeCsvOutput()

int writeCsvOutput ( std::string input_file,
std::string output_file,
bool const node_args,
bool const link_args,
bool const catchment_args,
bool const system_args )

Definition at line 112 of file SWMMConverter.cpp.

118{
119 std::unique_ptr<FileIO::SwmmInterface> swmm =
121 if (swmm == nullptr)
122 return -1;
123
124 if (!swmm->existsSwmmOutputFile())
125 {
126 INFO("No output file found, skipping data conversion to CSV.");
127 return -1;
128 }
129
130 if (!(node_args || link_args || catchment_args || system_args))
131 {
132 INFO("No data category selected. Nothing to write.");
133 return 0;
134 }
135
136 std::string const basename = BaseLib::dropFileExtension(output_file);
137 std::string const extension = BaseLib::getFileExtension(output_file);
138
139 if (node_args)
141 extension);
142
143 if (link_args)
145 extension);
146
147 if (catchment_args)
149 basename, extension);
150
151 if (system_args)
152 {
153 std::string const obj_file_name =
154 std::string(basename + "_system" + extension);
155 swmm->writeCsvForObject(obj_file_name, FileIO::SwmmObject::SYSTEM, 0);
156 }
157 return 0;
158}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void writeObjectsOfSwmmTypeToCsv(FileIO::SwmmInterface &swmm, FileIO::SwmmObject const type, std::string const &base, std::string const &ext)
static std::unique_ptr< SwmmInterface > create(std::string const &file_name)
std::string getFileExtension(const std::string &path)
std::string dropFileExtension(std::string const &filename)

References FileIO::SwmmInterface::create(), BaseLib::dropFileExtension(), BaseLib::getFileExtension(), INFO(), FileIO::LINK, FileIO::NODE, FileIO::SUBCATCHMENT, FileIO::SYSTEM, and writeObjectsOfSwmmTypeToCsv().

Referenced by main().

◆ writeGeoOutput()

int writeGeoOutput ( std::string input_file,
std::string output_file )

Definition at line 23 of file SWMMConverter.cpp.

24{
25 GeoLib::GEOObjects geo_objects;
27 geo_objects, true))
28 return -1;
29
30 GeoLib::IO::BoostXmlGmlInterface xml(geo_objects);
31 xml.export_name = BaseLib::extractBaseNameWithoutExtension(input_file);
32 BaseLib::IO::writeStringToFile(xml.writeToString(), output_file);
33 return 0;
34}
static bool convertSwmmInputToGeometry(std::string const &inp_file_name, GeoLib::GEOObjects &geo_objects, bool add_subcatchments)
Reading a SWMM input file and conversion into OGS geometry.
Container class for geometric objects.
Definition GEOObjects.h:57
int writeStringToFile(std::string_view content, std::filesystem::path const &file_path)
Definition Writer.cpp:45
std::string extractBaseNameWithoutExtension(std::string const &pathname)

References FileIO::SwmmInterface::convertSwmmInputToGeometry(), BaseLib::IO::XMLInterface::export_name, BaseLib::extractBaseNameWithoutExtension(), BaseLib::IO::writeStringToFile(), and BaseLib::IO::Writer::writeToString().

Referenced by main().

◆ writeMeshOutput()

int writeMeshOutput ( std::string const & input_file,
std::string const & output_file,
bool const node_args,
bool const link_args )

Definition at line 55 of file SWMMConverter.cpp.

59{
60 std::unique_ptr<FileIO::SwmmInterface> swmm =
62 if (swmm == nullptr)
63 return -1;
64
65 MeshLib::Mesh& mesh = swmm->getMesh();
66
67 bool const no_output_file = !swmm->existsSwmmOutputFile();
68 if (!(node_args || link_args) || no_output_file)
69 {
70 if (no_output_file)
71 INFO("No output file found.");
72 MeshLib::IO::VtuInterface vtkIO(&mesh, 0, false);
73 vtkIO.writeToFile(output_file);
74 return 0;
75 }
76
77 std::string const basename = BaseLib::dropFileExtension(output_file);
78 std::string const extension = BaseLib::getFileExtension(output_file);
79 std::size_t const n_time_steps(swmm->getNumberOfTimeSteps());
80 INFO("Number of simulation time steps: {:d}", n_time_steps);
81 for (std::size_t i = 0; i < n_time_steps; i++)
82 {
83 if (node_args)
85
86 if (link_args)
88
89 MeshLib::IO::VtuInterface vtkio(&mesh, 0, false);
90 std::string name(basename + std::to_string(i) + extension);
91 vtkio.writeToFile(name);
92 }
93 return 0;
94}
int addObjectsToMesh(FileIO::SwmmInterface &swmm, MeshLib::Mesh &mesh, FileIO::SwmmObject const type, std::size_t const timestep)
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....

References addObjectsToMesh(), FileIO::SwmmInterface::create(), BaseLib::dropFileExtension(), BaseLib::getFileExtension(), INFO(), FileIO::LINK, FileIO::NODE, and MeshLib::IO::VtuInterface::writeToFile().

Referenced by main().

◆ writeObjectsOfSwmmTypeToCsv()

void writeObjectsOfSwmmTypeToCsv ( FileIO::SwmmInterface & swmm,
FileIO::SwmmObject const type,
std::string const & base,
std::string const & ext )

Definition at line 96 of file SWMMConverter.cpp.

100{
101 std::size_t n_objects = swmm.getNumberOfObjects(type);
102 std::string const& type_str(swmm.swmmObjectTypeToString(type));
103 for (std::size_t i = 0; i < n_objects; ++i)
104 {
105 std::string const obj_name = swmm.getName(type, i);
106 std::string const obj_file_name =
107 std::string(base + "_" + type_str + "_" + obj_name + ext);
108 swmm.writeCsvForObject(obj_file_name, type, i);
109 }
110}
std::size_t getNumberOfObjects(SwmmObject obj_type) const
Returns the number of objects of the given type.
bool writeCsvForObject(std::string const &file_name, SwmmObject obj_type, std::size_t obj_idx) const
Write a CSV file for one object of the given type for all time steps.
std::string getName(SwmmObject obj_type, std::size_t idx) const
Returns the Name for the indexed object of the given type (or an empty string if an error occurred).
static std::string swmmObjectTypeToString(SwmmObject const obj_type)
Returns a string with the name of the object type.

References FileIO::SwmmInterface::getName(), FileIO::SwmmInterface::getNumberOfObjects(), FileIO::SwmmInterface::swmmObjectTypeToString(), and FileIO::SwmmInterface::writeCsvForObject().

Referenced by writeCsvOutput().