diff --git a/Applications/FileIO/SWMM/SWMMInterface.cpp b/Applications/FileIO/SWMM/SWMMInterface.cpp index 441787c5bd147de24fd801c0b7f8ce122ba0d2f4..78548f6fc42c994e1cfbd6b5e936745b23c9332f 100644 --- a/Applications/FileIO/SWMM/SWMMInterface.cpp +++ b/Applications/FileIO/SWMM/SWMMInterface.cpp @@ -973,12 +973,14 @@ bool SwmmInterface::addResultsToMesh(MeshLib::Mesh &mesh, SwmmObject const swmm_ return false; } - MeshLib::MeshItemType const item_type = (swmm_type == SwmmObject::NODE) ? - MeshLib::MeshItemType::Node : MeshLib::MeshItemType::Cell; - MeshLib::PropertyVector<double>* prop = MeshLib::getOrCreateMeshProperty<double>(mesh, vec_name, item_type, 1); + MeshLib::MeshItemType const item_type = (swmm_type == SwmmObject::NODE) + ? MeshLib::MeshItemType::Node + : MeshLib::MeshItemType::Cell; + MeshLib::PropertyVector<double>* prop = + MeshLib::getOrCreateMeshProperty<double>(mesh, vec_name, item_type, 1); if (!prop) { - ERR ("Error fetching array \"%s\".", vec_name.c_str()); + ERR("Error fetching array \"%s\".", vec_name.c_str()); return false; } std::copy(data.cbegin(), data.cend(), prop->begin()); @@ -1152,14 +1154,16 @@ std::string SwmmInterface::getArrayName(SwmmObject obj_type, std::size_t var_idx if (var_idx < n_obj_params[1]) return node_vars[var_idx]; if (var_idx < n_obj_params[1]+n_pollutants) - return std::string("Node_" + _pollutant_names[var_idx-n_obj_params[1]]); + return std::string("Node_" + + _pollutant_names[var_idx - n_obj_params[1]]); } if (obj_type == SwmmObject::LINK) { if (var_idx < n_obj_params[2]) return link_vars[var_idx]; if (var_idx < n_obj_params[2]+n_pollutants) - return std::string("Link_" + _pollutant_names[var_idx-n_obj_params[2]]); + return std::string("Link_" + + _pollutant_names[var_idx - n_obj_params[2]]); } if (obj_type == SwmmObject::SYSTEM && var_idx < n_obj_params[3]) { @@ -1305,7 +1309,8 @@ bool SwmmInterface::writeCsvForTimestep(std::string const& file_name, SwmmObject bool SwmmInterface::writeCsvForObject(std::string const& file_name, SwmmObject obj_type, std::size_t obj_idx) const { FileIO::CsvInterface csv; - INFO ("Writing data for %s %d.", swmmObjectTypeToString(obj_type).c_str(), obj_idx); + INFO("Writing data for %s %d.", swmmObjectTypeToString(obj_type).c_str(), + obj_idx); csv.addIndexVectorForWriting(getNumberOfTimeSteps()); std::size_t const n_params (getNumberOfParameters(obj_type)); for (std::size_t i=0; i<n_params; ++i) diff --git a/Applications/Utils/SWMMConverter/SWMMConverter.cpp b/Applications/Utils/SWMMConverter/SWMMConverter.cpp index 337660dc8c2501d709b7c976b5b6052e7cdfba27..52527b66472aaeb5b9ddee6667bcce5eef202aa2 100644 --- a/Applications/Utils/SWMMConverter/SWMMConverter.cpp +++ b/Applications/Utils/SWMMConverter/SWMMConverter.cpp @@ -27,7 +27,8 @@ int writeGeoOutput(std::string input_file, std::string output_file) { GeoLib::GEOObjects geo_objects; - if (!FileIO::SwmmInterface::convertSwmmInputToGeometry(input_file, geo_objects, true)) + if (!FileIO::SwmmInterface::convertSwmmInputToGeometry(input_file, + geo_objects, true)) return -1; GeoLib::IO::BoostXmlGmlInterface xml(geo_objects); @@ -36,34 +37,34 @@ int writeGeoOutput(std::string input_file, std::string output_file) return 0; } -int addObjectsToMesh( - FileIO::SwmmInterface &swmm, - MeshLib::Mesh &mesh, - FileIO::SwmmObject const type, - std::size_t const timestep) +int addObjectsToMesh(FileIO::SwmmInterface& swmm, + MeshLib::Mesh& mesh, + FileIO::SwmmObject const type, + std::size_t const timestep) { std::size_t const n_node_params(swmm.getNumberOfParameters(type)); - for (std::size_t j = 0; j<n_node_params; ++j) + for (std::size_t j = 0; j < n_node_params; ++j) { std::string const vec_name(swmm.getArrayName(type, j)); if (vec_name.empty()) return -2; - std::vector<double> data_vec = swmm.getArrayAtTimeStep(type, timestep, j); + std::vector<double> data_vec = + swmm.getArrayAtTimeStep(type, timestep, j); if (!swmm.addResultsToMesh(mesh, type, vec_name, data_vec)) return -3; } return 0; } -int writeMeshOutput( - std::string const& input_file, - std::string const& output_file, - bool const node_args, - bool const link_args) +int writeMeshOutput(std::string const& input_file, + std::string const& output_file, + bool const node_args, + bool const link_args) { - std::unique_ptr<FileIO::SwmmInterface> swmm = FileIO::SwmmInterface::create(input_file); + std::unique_ptr<FileIO::SwmmInterface> swmm = + FileIO::SwmmInterface::create(input_file); if (swmm == nullptr) - return -1; + return -1; MeshLib::Mesh& mesh = swmm->getMesh(); @@ -78,10 +79,11 @@ int writeMeshOutput( } std::string const basename = BaseLib::dropFileExtension(output_file); - std::string const extension = std::string("." + BaseLib::getFileExtension(output_file)); + std::string const extension = + std::string("." + BaseLib::getFileExtension(output_file)); std::size_t const n_time_steps(swmm->getNumberOfTimeSteps()); INFO("Number of simulation time steps: %d", n_time_steps); - for (std::size_t i=0; i<n_time_steps; i++) + for (std::size_t i = 0; i < n_time_steps; i++) { if (node_args) addObjectsToMesh(*swmm, mesh, FileIO::SwmmObject::NODE, i); @@ -96,31 +98,31 @@ int writeMeshOutput( return 0; } -void writeObjectsOfSwmmTypeToCsv( - FileIO::SwmmInterface &swmm, - FileIO::SwmmObject const type, - std::string const& base, - std::string const& ext) +void writeObjectsOfSwmmTypeToCsv(FileIO::SwmmInterface& swmm, + FileIO::SwmmObject const type, + std::string const& base, + std::string const& ext) { std::size_t n_objects = swmm.getNumberOfObjects(type); - std::string const& type_str (swmm.swmmObjectTypeToString(type)); - for (std::size_t i = 0; i<n_objects; ++i) + std::string const& type_str(swmm.swmmObjectTypeToString(type)); + for (std::size_t i = 0; i < n_objects; ++i) { std::string const obj_name = swmm.getName(type, i); - std::string const obj_file_name = std::string(base + "_" + type_str + "_" + obj_name + ext); + std::string const obj_file_name = + std::string(base + "_" + type_str + "_" + obj_name + ext); swmm.writeCsvForObject(obj_file_name, type, i); } } -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 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) { - std::unique_ptr<FileIO::SwmmInterface> swmm = FileIO::SwmmInterface::create(input_file); + std::unique_ptr<FileIO::SwmmInterface> swmm = + FileIO::SwmmInterface::create(input_file); if (swmm == nullptr) return -1; @@ -137,62 +139,79 @@ int writeCsvOutput( } std::string const basename = BaseLib::dropFileExtension(output_file); - std::string const extension = std::string("." + BaseLib::getFileExtension(output_file)); + std::string const extension = + std::string("." + BaseLib::getFileExtension(output_file)); if (node_args) - writeObjectsOfSwmmTypeToCsv(*swmm, FileIO::SwmmObject::NODE, basename, extension); + writeObjectsOfSwmmTypeToCsv(*swmm, FileIO::SwmmObject::NODE, basename, + extension); if (link_args) - writeObjectsOfSwmmTypeToCsv(*swmm, FileIO::SwmmObject::LINK, basename, extension); + writeObjectsOfSwmmTypeToCsv(*swmm, FileIO::SwmmObject::LINK, basename, + extension); if (catchment_args) - writeObjectsOfSwmmTypeToCsv(*swmm, FileIO::SwmmObject::SUBCATCHMENT, basename, extension); + writeObjectsOfSwmmTypeToCsv(*swmm, FileIO::SwmmObject::SUBCATCHMENT, + basename, extension); if (system_args) { - std::string const obj_file_name = std::string(basename + "_system" + extension); + std::string const obj_file_name = + std::string(basename + "_system" + extension); swmm->writeCsvForObject(obj_file_name, FileIO::SwmmObject::SYSTEM, 0); } return 0; } -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { ApplicationsLib::LogogSetup setup; - TCLAP::CmdLine cmd - ("Read files for the Storm Water Management Model (SWMM) and converts them into OGS data structures.", ' ', "0.1"); - TCLAP::ValueArg<std::string> mesh_output_arg - ("m","mesh", "mesh output file (*.vtu)", false, "", "mesh output file"); + TCLAP::CmdLine cmd( + "Read files for the Storm Water Management Model (SWMM) and converts " + "them into OGS data structures.", + ' ', "0.1"); + TCLAP::ValueArg<std::string> mesh_output_arg( + "m", "mesh", "mesh output file (*.vtu)", false, "", "mesh output file"); cmd.add(mesh_output_arg); - TCLAP::ValueArg<std::string> geo_output_arg - ("g","geo", "geometry output file (*.gml)", false, "", "geometry output file"); + TCLAP::ValueArg<std::string> geo_output_arg( + "g", "geo", "geometry output file (*.gml)", false, "", + "geometry output file"); cmd.add(geo_output_arg); - TCLAP::ValueArg<std::string> csv_output_arg - ("c", "csv", "csv output file (*.csv)", false, "", "CSV output file"); + TCLAP::ValueArg<std::string> csv_output_arg( + "c", "csv", "csv output file (*.csv)", false, "", "CSV output file"); cmd.add(csv_output_arg); - TCLAP::ValueArg<std::string> swmm_input_arg - ("i","input", "SWMM input file (*.inp)", true, "", "input file"); + TCLAP::ValueArg<std::string> swmm_input_arg( + "i", "input", "SWMM input file (*.inp)", true, "", "input file"); cmd.add(swmm_input_arg); - TCLAP::SwitchArg add_nodes_arg ("", "node_vars", "Read node variables and add to output mesh"); + TCLAP::SwitchArg add_nodes_arg( + "", "node_vars", "Read node variables and add to output mesh"); cmd.add(add_nodes_arg); - TCLAP::SwitchArg add_links_arg ("", "link_vars", "Read link variables and add to output mesh"); + TCLAP::SwitchArg add_links_arg( + "", "link_vars", "Read link variables and add to output mesh"); cmd.add(add_links_arg); - TCLAP::SwitchArg add_subcatchments_arg ("", "subcatchment_vars", "Read subcatchment variables and write to CSV-file"); + TCLAP::SwitchArg add_subcatchments_arg( + "", "subcatchment_vars", + "Read subcatchment variables and write to CSV-file"); cmd.add(add_subcatchments_arg); - TCLAP::SwitchArg add_system_arg ("", "system_vars", "Read system variables and write to CSV-file"); + TCLAP::SwitchArg add_system_arg( + "", "system_vars", "Read system variables and write to CSV-file"); cmd.add(add_system_arg); - cmd.parse( argc, argv ); + cmd.parse(argc, argv); - if (!(geo_output_arg.isSet() || mesh_output_arg.isSet() || csv_output_arg.isSet())) + if (!(geo_output_arg.isSet() || mesh_output_arg.isSet() || + csv_output_arg.isSet())) { - ERR ("No output format given. Please specify OGS geometry or mesh output file."); + ERR("No output format given. Please specify OGS geometry or mesh " + "output file."); return -1; } - if ((add_subcatchments_arg.getValue() || add_system_arg.getValue()) && !csv_output_arg.isSet()) + if ((add_subcatchments_arg.getValue() || add_system_arg.getValue()) && + !csv_output_arg.isSet()) { - ERR("Please specify csv output file for exporting subcatchment or system parameters."); + ERR("Please specify csv output file for exporting subcatchment or " + "system parameters."); return -1; } @@ -201,16 +220,15 @@ int main(int argc, char *argv[]) if (mesh_output_arg.isSet()) writeMeshOutput(swmm_input_arg.getValue(), mesh_output_arg.getValue(), - add_nodes_arg.getValue(), add_links_arg.getValue()); + add_nodes_arg.getValue(), add_links_arg.getValue()); if (csv_output_arg.isSet()) - writeCsvOutput( - swmm_input_arg.getValue(), - csv_output_arg.getValue(), - add_nodes_arg.getValue(), - add_links_arg.getValue(), - add_subcatchments_arg.getValue(), - add_system_arg.getValue()); + writeCsvOutput(swmm_input_arg.getValue(), + csv_output_arg.getValue(), + add_nodes_arg.getValue(), + add_links_arg.getValue(), + add_subcatchments_arg.getValue(), + add_system_arg.getValue()); return 0; }