10#include <tclap/CmdLine.h>
41 std::size_t
const timestep)
44 for (std::size_t j = 0; j < n_node_params; ++j)
49 std::vector<double> data_vec =
58 std::string
const& output_file,
62 std::unique_ptr<FileIO::SwmmInterface> swmm =
69 bool const no_output_file = !swmm->existsSwmmOutputFile();
70 if (!(node_args || link_args) || no_output_file)
73 INFO(
"No output file found.");
81 std::size_t
const n_time_steps(swmm->getNumberOfTimeSteps());
82 INFO(
"Number of simulation time steps: {:d}", n_time_steps);
83 for (std::size_t i = 0; i < n_time_steps; i++)
92 std::string name(basename + std::to_string(i) + extension);
100 std::string
const& base,
101 std::string
const& ext)
105 for (std::size_t i = 0; i < n_objects; ++i)
107 std::string
const obj_name = swmm.
getName(type, i);
108 std::string
const obj_file_name =
109 std::string(base +
"_" + type_str +
"_" + obj_name + ext);
115 std::string output_file,
116 bool const node_args,
117 bool const link_args,
118 bool const catchment_args,
119 bool const system_args)
121 std::unique_ptr<FileIO::SwmmInterface> swmm =
126 if (!swmm->existsSwmmOutputFile())
128 INFO(
"No output file found, skipping data conversion to CSV.");
132 if (!(node_args || link_args || catchment_args || system_args))
134 INFO(
"No data category selected. Nothing to write.");
151 basename, extension);
155 std::string
const obj_file_name =
156 std::string(basename +
"_system" + extension);
162int main(
int argc,
char* argv[])
165 "Read files for the Storm Water Management Model (SWMM) and converts "
166 "them into OGS data structures.\n\n"
167 "OpenGeoSys-6 software, version " +
170 "Copyright (c) 2012-2025, OpenGeoSys Community "
171 "(http://www.opengeosys.org)",
173 TCLAP::ValueArg<std::string> mesh_output_arg(
174 "m",
"mesh",
"Output (.vtu). Mesh output file ",
false,
"",
176 cmd.add(mesh_output_arg);
177 TCLAP::ValueArg<std::string> geo_output_arg(
178 "g",
"geo",
"Output (.gml). Geometry output file ",
false,
"",
180 cmd.add(geo_output_arg);
181 TCLAP::ValueArg<std::string> csv_output_arg(
182 "c",
"csv",
"Output (.csv). csv output file",
false,
"",
"OUTPUT_FILE");
183 cmd.add(csv_output_arg);
185 cmd.add(log_level_arg);
186 TCLAP::ValueArg<std::string> swmm_input_arg(
187 "i",
"input",
"Input (.inp). SWMM input file",
true,
"",
"INPUT_FILE");
188 cmd.add(swmm_input_arg);
189 TCLAP::SwitchArg add_nodes_arg(
190 "",
"node_vars",
"Read node variables and add to output mesh");
191 cmd.add(add_nodes_arg);
192 TCLAP::SwitchArg add_links_arg(
193 "",
"link_vars",
"Read link variables and add to output mesh");
194 cmd.add(add_links_arg);
195 TCLAP::SwitchArg add_subcatchments_arg(
196 "",
"subcatchment_vars",
197 "Read subcatchment variables and write to CSV-file");
198 cmd.add(add_subcatchments_arg);
199 TCLAP::SwitchArg add_system_arg(
200 "",
"system_vars",
"Read system variables and write to CSV-file");
201 cmd.add(add_system_arg);
202 cmd.parse(argc, argv);
207 if (!(geo_output_arg.isSet() || mesh_output_arg.isSet() ||
208 csv_output_arg.isSet()))
210 ERR(
"No output format given. Please specify OGS geometry or mesh "
215 if ((add_subcatchments_arg.getValue() || add_system_arg.getValue()) &&
216 !csv_output_arg.isSet())
218 ERR(
"Please specify csv output file for exporting subcatchment or "
219 "system parameters.");
223 if (geo_output_arg.isSet())
224 writeGeoOutput(swmm_input_arg.getValue(), geo_output_arg.getValue());
226 if (mesh_output_arg.isSet())
228 add_nodes_arg.getValue(), add_links_arg.getValue());
230 if (csv_output_arg.isSet())
232 csv_output_arg.getValue(),
233 add_nodes_arg.getValue(),
234 add_links_arg.getValue(),
235 add_subcatchments_arg.getValue(),
236 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)
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
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