10#include <tclap/CmdLine.h>
42 std::size_t
const timestep)
45 for (std::size_t j = 0; j < n_node_params; ++j)
50 std::vector<double> data_vec =
59 std::string
const& output_file,
63 std::unique_ptr<FileIO::SwmmInterface> swmm =
70 bool const no_output_file = !swmm->existsSwmmOutputFile();
71 if (!(node_args || link_args) || no_output_file)
74 INFO(
"No output file found.");
82 std::size_t
const n_time_steps(swmm->getNumberOfTimeSteps());
83 INFO(
"Number of simulation time steps: {:d}", n_time_steps);
84 for (std::size_t i = 0; i < n_time_steps; i++)
93 std::string name(basename + std::to_string(i) + extension);
101 std::string
const& base,
102 std::string
const& ext)
106 for (std::size_t i = 0; i < n_objects; ++i)
108 std::string
const obj_name = swmm.
getName(type, i);
109 std::string
const obj_file_name =
110 std::string(base +
"_" + type_str +
"_" + obj_name + ext);
116 std::string output_file,
117 bool const node_args,
118 bool const link_args,
119 bool const catchment_args,
120 bool const system_args)
122 std::unique_ptr<FileIO::SwmmInterface> swmm =
127 if (!swmm->existsSwmmOutputFile())
129 INFO(
"No output file found, skipping data conversion to CSV.");
133 if (!(node_args || link_args || catchment_args || system_args))
135 INFO(
"No data category selected. Nothing to write.");
152 basename, extension);
156 std::string
const obj_file_name =
157 std::string(basename +
"_system" + extension);
163int main(
int argc,
char* argv[])
166 "Read files for the Storm Water Management Model (SWMM) and converts "
167 "them into OGS data structures.\n\n"
168 "OpenGeoSys-6 software, version " +
171 "Copyright (c) 2012-2024, OpenGeoSys Community "
172 "(http://www.opengeosys.org)",
174 TCLAP::ValueArg<std::string> mesh_output_arg(
175 "m",
"mesh",
"mesh output file (*.vtu)",
false,
"",
"mesh output file");
176 cmd.add(mesh_output_arg);
177 TCLAP::ValueArg<std::string> geo_output_arg(
178 "g",
"geo",
"geometry output file (*.gml)",
false,
"",
179 "geometry output file");
180 cmd.add(geo_output_arg);
181 TCLAP::ValueArg<std::string> csv_output_arg(
182 "c",
"csv",
"csv output file (*.csv)",
false,
"",
"CSV output file");
183 cmd.add(csv_output_arg);
184 TCLAP::ValueArg<std::string> swmm_input_arg(
185 "i",
"input",
"SWMM input file (*.inp)",
true,
"",
"input file");
186 cmd.add(swmm_input_arg);
187 TCLAP::SwitchArg add_nodes_arg(
188 "",
"node_vars",
"Read node variables and add to output mesh");
189 cmd.add(add_nodes_arg);
190 TCLAP::SwitchArg add_links_arg(
191 "",
"link_vars",
"Read link variables and add to output mesh");
192 cmd.add(add_links_arg);
193 TCLAP::SwitchArg add_subcatchments_arg(
194 "",
"subcatchment_vars",
195 "Read subcatchment variables and write to CSV-file");
196 cmd.add(add_subcatchments_arg);
197 TCLAP::SwitchArg add_system_arg(
198 "",
"system_vars",
"Read system variables and write to CSV-file");
199 cmd.add(add_system_arg);
200 cmd.parse(argc, argv);
203 MPI_Init(&argc, &argv);
206 if (!(geo_output_arg.isSet() || mesh_output_arg.isSet() ||
207 csv_output_arg.isSet()))
209 ERR(
"No output format given. Please specify OGS geometry or mesh "
217 if ((add_subcatchments_arg.getValue() || add_system_arg.getValue()) &&
218 !csv_output_arg.isSet())
220 ERR(
"Please specify csv output file for exporting subcatchment or "
221 "system parameters.");
228 if (geo_output_arg.isSet())
229 writeGeoOutput(swmm_input_arg.getValue(), geo_output_arg.getValue());
231 if (mesh_output_arg.isSet())
233 add_nodes_arg.getValue(), add_links_arg.getValue());
235 if (csv_output_arg.isSet())
237 csv_output_arg.getValue(),
238 add_nodes_arg.getValue(),
239 add_links_arg.getValue(),
240 add_subcatchments_arg.getValue(),
241 add_system_arg.getValue());
Definition of the BoostXmlGmlInterface class.
Definition of the GEOObjects class.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the class Properties that implements a container of properties.
Definition of the Mesh class.
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)
void writeObjectsOfSwmmTypeToCsv(FileIO::SwmmInterface &swmm, FileIO::SwmmObject const type, std::string const &base, std::string const &ext)
int main(int argc, char *argv[])
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)
Implementation of the VtuInterface class.
std::string writeToString()
Writes the object to a string.
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::unique_ptr< SwmmInterface > create(std::string const &file_name)
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)
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.
static std::string swmmObjectTypeToString(SwmmObject const obj_type)
Returns a string with the name of the object type.
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.
Container class for geometric objects.
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
bool writeToFile(std::filesystem::path const &file_path)
int writeStringToFile(std::string_view content, std::filesystem::path const &file_path)
std::string getFileExtension(const std::string &path)
std::string extractBaseNameWithoutExtension(std::string const &pathname)
std::string dropFileExtension(std::string const &filename)
SwmmObject
SWMM object types.
GITINFOLIB_EXPORT const std::string ogs_version