10#include "SwmmInterface.h"
12#include <swmm5_iface.h>
14#include <boost/algorithm/string/predicate.hpp>
40 "infiltration losses",
42 "groundwater outflow",
45 "concentration of pollutant"};
48const std::array<std::string, 7>
node_vars = {
"water depth",
50 "volume of stored water",
53 "flow lost to flooding",
54 "concentration of pollutant"};
57const std::array<std::string, 6>
link_vars = {
"flow rate",
61 "fraction conduit/non-conduit",
62 "concentration of pollutant"};
69 "evaporation + infiltration loss",
75 "total lateral inflow",
76 "flow lost to flooding",
77 "flow leaving through outfalls",
78 "volume of stored water",
79 "actual evaporation rate",
80 "potential evaporation rate"};
87 std::string
const& file_name)
93 if (file_name.length() < 5)
99 std::string
const base_name(file_name.substr(0, file_name.length() - 4));
102 return std::unique_ptr<SwmmInterface>(swmm);
104 ERR(
"Error creating mesh from SWMM file.");
110 : _base_name(swmm_base_name), _mesh(nullptr)
127 ERR(
"SWMMInterface: {:s} is not a SWMM input file.", inp_file_name);
131 std::ifstream in(inp_file_name.c_str());
134 ERR(
"SWMMInterface: Could not open input file {:s}.", inp_file_name);
139 bool header_found(
false);
140 std::size_t pos_end(0);
141 while (!header_found)
143 if (!std::getline(in, line))
146 std::size_t
const pos_beg = line.find_first_not_of(
' ', pos_end);
147 pos_end = line.find_first_of(
" \n", pos_beg);
150 if (line.empty() || pos_beg == pos_end ||
isCommentLine(line))
153 if (line ==
"[TITLE]")
157 INFO(
"SWMMInterface: input file type {:s} not recognised.",
169 std::string
const outfile(
_base_name +
".out");
170 if (OpenSwmmOutFile(
const_cast<char*
>(outfile.c_str())) != 0)
177 std::vector<std::string>& names)
179 std::size_t id(points.size());
182 while (std::getline(in, line))
191 if (split_str.size() != 3)
193 ERR(
"Format not recognised.");
196 names.push_back(split_str[0]);
200 T* pnt =
new T(x, y, 0,
id);
201 points.push_back(pnt);
208 std::vector<GeoLib::Polyline*>& lines,
209 std::vector<std::string>& ply_names,
210 std::vector<GeoLib::Point*>& points,
211 std::vector<std::string>& pnt_names)
213 bool finished(
false);
214 std::size_t id(points.size());
216 std::string polygon_name(
"");
218 while (std::getline(in, line))
227 if (split_str.size() != 3)
229 ERR(
"Polygon format not recognised.");
235 if (split_str[0] != polygon_name)
239 p->addPoint(p->getPointID(0));
243 polygon_name = split_str[0];
245 ply_names.push_back(polygon_name);
251 p->addPoint(points.size() - 1);
252 pnt_names.push_back(
"");
259 p->addPoint(p->getPointID(0));
267 std::ifstream& in, std::vector<GeoLib::Point*>& points,
268 std::map<std::string, std::size_t>
const& name_id_map)
271 while (std::getline(in, line))
281 if (split_str.size() < 4)
283 ERR(
"Format not recognised.");
286 std::string
const current_name(split_str[0]);
287 auto const it = name_id_map.find(current_name);
288 if (it == name_id_map.end())
290 ERR(
"SwmmInterface::addPointElevation(): Name {:s} not found in "
295 std::size_t
const id = it->second;
302 std::ifstream& in, std::vector<GeoLib::Polyline*>& lines,
303 std::vector<std::string>& line_names,
304 std::vector<GeoLib::Point*>
const& points,
305 std::map<std::string, std::size_t>
const& point_names)
308 while (std::getline(in, line))
318 if (split_str.size() < 7)
320 ERR(
"Conduit format not recognised.");
324 std::string
const inlet(split_str[1]);
325 auto const i_it = point_names.find(inlet);
326 if (i_it == point_names.end())
328 ERR(
"SwmmInterface::readLineElements(): Inlet node {:s} not found "
329 "in coordinates map.",
334 std::string
const outlet(split_str[2]);
335 auto const o_it = point_names.find(outlet);
336 if (o_it == point_names.end())
338 ERR(
"SwmmInterface::readLineElements(): Outlet node {:s} not found "
339 "in coordinates map.",
344 std::size_t a(i_it->second);
347 lines.push_back(ply);
348 line_names.push_back(split_str[0]);
355 bool add_subcatchments)
360 std::ifstream in(inp_file_name.c_str());
363 ERR(
"SWMMInterface: Could not open input file {:s}.", inp_file_name);
367 std::vector<GeoLib::Point*> points;
368 std::vector<GeoLib::Polyline*> lines;
369 std::vector<std::string> pnt_names;
370 std::vector<std::string> line_names;
372 std::string geo_name =
375 while (std::getline(in, line))
377 if (line ==
"[COORDINATES]" || line ==
"[VERTICES]" ||
380 INFO(
"Reading {:s}...", line);
387 if (line ==
"[Polygons]" && add_subcatchments)
389 INFO(
"Reading {:s}...", line);
390 if (!
readPolygons(in, lines, line_names, points, pnt_names))
400 ERR(
"No points found in file");
403 if (points.size() != pnt_names.size())
405 ERR(
"Length of point vector and point name vector do not match.");
412 std::size_t
const n_names(pnt_names.size());
413 for (std::size_t i = 0; i < n_names; ++i)
415 if (!pnt_names[i].empty())
416 name_id_map.insert(std::make_pair(pnt_names[i], i));
424 while (std::getline(in, line))
426 if (line ==
"[JUNCTIONS]" || line ==
"[OUTFALLS]" ||
429 INFO(
"Reading {:s} elevation...", line);
436 if (line ==
"[CONDUITS]")
438 INFO(
"Reading conduits...");
446 else if (line ==
"[PUMPS]")
448 INFO(
"Reading pumps...");
456 else if (line ==
"[WEIRS]")
458 INFO(
"Reading weirs...");
468 geo_objects.
addPointVec(std::move(points), geo_name,
469 std::move(name_id_map));
472 if (lines.size() != line_names.size())
474 ERR(
"Length of line vector and line name vector do not match.");
476 for (
auto ply : lines)
482 std::size_t
const n_names(line_names.size());
483 for (std::size_t i = 0; i < n_names; ++i)
485 line_id_map.insert(std::make_pair(line_names[i], i));
488 std::vector<std::size_t>
const& pnt_id_map(
492 for (std::size_t i = 0; i < polyline->getNumberOfPoints(); ++i)
494 polyline->setPointID(i, pnt_id_map[polyline->getPointID(i)]);
496 polyline->getPointID(i - 1) == polyline->getPointID(i))
498 polyline->removePoint(i);
502 if (polyline->getPointID(0) ==
503 polyline->getPointID(polyline->getNumberOfPoints() - 1))
505 polyline->removePoint(polyline->getNumberOfPoints() - 1);
506 polyline->addPoint(polyline->getPointID(0));
510 std::move(line_id_map));
516 std::ifstream& in, std::vector<MeshLib::Node*>& nodes,
517 std::map<std::string, std::size_t>
const& name_id_map,
518 std::vector<double>& max_depth,
bool read_max_depth)
521 while (std::getline(in, line))
531 if (split_str.size() < 3)
533 ERR(
"Format not recognised.");
536 std::string
const current_name(split_str[0]);
537 auto const it = name_id_map.find(current_name);
538 if (it == name_id_map.end())
540 ERR(
"SwmmInterface::readNodeData(): Name {:s} not found in "
545 std::size_t
const id = it->second;
557 std::ifstream& in, std::vector<MeshLib::Element*>& elements,
558 std::vector<MeshLib::Node*>
const& nodes,
559 std::map<std::string, std::size_t>
const& name_id_map)
562 while (std::getline(in, line))
572 if (split_str.size() < 7)
574 ERR(
"Conduit format not recognised.");
578 std::string
const inlet(split_str[1]);
579 auto const i_it = name_id_map.find(inlet);
580 if (i_it == name_id_map.end())
582 ERR(
"SwmmInterface::readLineElements(): Inlet node {:s} not found "
583 "in coordinates map.",
588 std::string
const outlet(split_str[2]);
589 auto const o_it = name_id_map.find(outlet);
590 if (o_it == name_id_map.end())
592 ERR(
"SwmmInterface::readLineElements(): Outlet node {:s} not found "
593 "in coordinates map.",
598 std::array<MeshLib::Node*, 2>
const line_nodes = {nodes[i_it->second],
599 nodes[o_it->second]};
607 std::ifstream& in, std::map<std::string, std::size_t>
const& name_id_map)
610 while (std::getline(in, line))
619 if (split_str.size() < 8)
621 ERR(
"Subcatchment format not recognised.");
626 sc.
name = split_str[0];
627 sc.
rain_gauge = std::numeric_limits<std::size_t>::max();
629 for (std::size_t i = 0; i < n_gauges; ++i)
637 if (sc.
rain_gauge == std::numeric_limits<std::size_t>::max())
639 ERR(
"Rain gauge for subcatchment '{:s}' not found.", split_str[0]);
643 auto const it = name_id_map.find(split_str[2]);
644 if (it == name_id_map.end())
646 ERR(
"Outlet node for subcatchment '{:s}' not found.", split_str[0]);
659 if (
_mesh !=
nullptr)
661 ERR(
"Mesh already exists.");
665 std::string
const inp_file_name(
_base_name +
".inp");
669 std::ifstream in(inp_file_name.c_str());
672 ERR(
"SWMMInterface: Could not open input file {:s}.", inp_file_name);
677 std::vector<MeshLib::Node*> nodes;
679 while (std::getline(in, line))
681 if (line ==
"[COORDINATES]")
683 INFO(
"Reading coordinates...");
695 else if (line ==
"[SYMBOLS]")
697 INFO(
"Reading symbols...");
698 std::vector<GeoLib::Point*> points;
699 std::vector<std::string> names;
702 for (std::size_t i = 0; i < points.size(); ++i)
706 std::pair<GeoLib::Station, std::string>(stn,
""));
716 std::map<std::string, std::size_t> name_id_map;
717 std::size_t
const n_nodes(nodes.size());
718 for (std::size_t i = 0; i < n_nodes; ++i)
723 std::vector<MeshLib::Element*> elements;
724 std::vector<double> max_depth(n_nodes);
725 std::size_t
const n_types = 3;
726 std::array<std::size_t, n_types> n_elem_types{{0, 0, 0}};
727 while (std::getline(in, line))
729 if (line ==
"[RAINGAGES]")
734 else if (line ==
"[SUBCATCHMENTS]")
736 INFO(
"Reading subcatchment information...");
740 else if (line ==
"[SUBAREAS]")
744 else if (line ==
"[INFILTRATION]")
748 else if (line ==
"[JUNCTIONS]")
750 INFO(
"Reading junctions...");
751 if (!
readNodeData(in, nodes, name_id_map, max_depth,
true))
754 else if (line ==
"[OUTFALLS]")
756 INFO(
"Reading outfalls...");
757 if (!
readNodeData(in, nodes, name_id_map, max_depth,
false))
760 else if (line ==
"[STORAGE]")
762 INFO(
"Reading storages...");
763 if (!
readNodeData(in, nodes, name_id_map, max_depth,
true))
766 else if (line ==
"[CONDUITS]")
768 INFO(
"Reading conduits...");
771 n_elem_types[0] = elements.size();
773 else if (line ==
"[PUMPS]")
775 INFO(
"Reading pumps...");
778 n_elem_types[1] = elements.size();
780 else if (line ==
"[WEIRS]")
782 INFO(
"Reading weirs...");
785 n_elem_types[2] = elements.size();
787 else if (line ==
"[POLLUTANTS]")
792 else if (line ==
"[Polygons]")
794 INFO(
"Reading subcatchments...");
795 std::vector<GeoLib::Polyline*> lines;
796 std::vector<std::string> line_names;
797 std::vector<std::string>
809 if (elements.empty())
819 mat_ids->resize(elements.size(), 0);
820 for (std::size_t i = 1; i < n_types; ++i)
822 if (n_elem_types[i] > 0)
823 std::fill(mat_ids->begin() + n_elem_types[i - 1],
824 mat_ids->begin() + n_elem_types[i], i);
827 if (nodes.size() == max_depth.size())
831 depth->reserve(max_depth.size());
832 std::copy(max_depth.cbegin(), max_depth.cend(),
833 std::back_inserter(*depth));
836 ERR(
"Size of max depth array does not fit number of elements. Skipping "
846 std::vector<GeoLib::Polyline*>
const& lines,
847 std::vector<std::string>
const& names)
849 std::size_t
const n_lines(lines.size());
852 if (n_lines != n_subcatchments)
854 ERR(
"Number of subcatchments does not match number of outlines.");
857 for (std::size_t i = 0; i < n_lines; ++i)
860 for (std::size_t j = 0; j < n_subcatchments; ++j)
871 ERR(
"No match in subcatcments for outline '{:s}'.", names[i]);
880 std::vector<std::string> names;
883 std::back_inserter(names),
884 [](
auto const& sc) { return sc.name; });
899 std::vector<std::string> system_name{
"System"};
902 ERR(
"Object type has no name map");
903 std::vector<std::string> empty_vec;
922 return std::string(
"System");
924 ERR(
"Index out of bounds.");
925 return std::string(
"");
930 std::string
const outfile(
_base_name +
".out");
931 if (OpenSwmmOutFile(
const_cast<char*
>(outfile.c_str())) != 0)
937 return SWMM_Nsubcatch;
945 ERR(
"Object type not recognised.");
953 std::string
const outfile(
_base_name +
".out");
954 std::size_t n_time_steps(std::numeric_limits<std::size_t>::max());
955 if (OpenSwmmOutFile(
const_cast<char*
>(outfile.c_str())) != 0)
958 std::size_t n_params(0);
974 ERR(
"Object type not recognised.");
982 std::string
const outfile(
_base_name +
".out");
983 if (OpenSwmmOutFile(
const_cast<char*
>(outfile.c_str())) != 0)
984 return std::numeric_limits<std::size_t>::max();
985 std::size_t
const n_time_steps(
static_cast<std::size_t
>(SWMM_Nperiods));
992 std::string
const& vec_name,
993 std::vector<double>
const& data)
997 ERR(
"Information of this object type cannot be added to mesh.");
1003 ERR(
"Data array is empty and cannot be added to mesh.");
1009 ERR(
"Number of mesh nodes ({:d}) does not match length of array "
1018 ERR(
"Number of mesh elements ({:d}) does not match length of array "
1031 ERR(
"Error fetching array '{:s}'.", vec_name);
1034 std::copy(data.cbegin(), data.cend(), prop->begin());
1039 std::size_t time_step,
1040 std::size_t var_idx)
const
1042 std::vector<double> data;
1043 std::string
const outfile(
_base_name +
".out");
1044 if (OpenSwmmOutFile(
const_cast<char*
>(outfile.c_str())) != 0)
1047 if (time_step >= SWMM_Nperiods)
1049 ERR(
"Time step {:d} not available, file contains only {:d} periods.",
1050 time_step, SWMM_Nperiods);
1054 bool is_var_idx_okay =
true;
1056 std::size_t n_objects;
1061 n_objects = SWMM_Nsubcatch;
1062 if (var_idx > (
n_obj_params[obj_type_id] - 1 + SWMM_Npolluts))
1063 is_var_idx_okay =
false;
1067 n_objects = SWMM_Nnodes;
1068 if (var_idx > (
n_obj_params[obj_type_id] + SWMM_Npolluts))
1069 is_var_idx_okay =
false;
1073 n_objects = SWMM_Nlinks;
1074 if (var_idx > (
n_obj_params[obj_type_id] + SWMM_Npolluts))
1075 is_var_idx_okay =
false;
1081 is_var_idx_okay =
false;
1084 ERR(
"Object type not recognised.");
1089 if (!is_var_idx_okay)
1091 ERR(
"Requested variable does not exist.");
1096 INFO(
"Fetching '{:s}'-data for time step {:d}...",
1097 getArrayName(obj_type, var_idx, SWMM_Npolluts), time_step);
1099 for (std::size_t i = 0; i < n_objects; ++i)
1102 GetSwmmResult(obj_type_id, i, var_idx, time_step, &val);
1103 data.push_back(
static_cast<double>(val));
1111 std::size_t obj_idx,
1112 std::size_t var_idx)
const
1114 std::vector<double> data;
1115 std::string
const outfile(
_base_name +
".out");
1116 if (OpenSwmmOutFile(
const_cast<char*
>(outfile.c_str())) != 0)
1119 bool is_var_idx_okay =
true;
1120 bool is_obj_idx_okay =
true;
1126 if (obj_idx >= SWMM_Nsubcatch)
1127 is_obj_idx_okay =
false;
1128 if (var_idx > (
n_obj_params[obj_type_id] + SWMM_Npolluts))
1129 is_var_idx_okay =
false;
1133 if (obj_idx >= SWMM_Nnodes)
1134 is_obj_idx_okay =
false;
1135 if (var_idx > (
n_obj_params[obj_type_id] + SWMM_Npolluts))
1136 is_var_idx_okay =
false;
1140 if (obj_idx >= SWMM_Nlinks)
1141 is_obj_idx_okay =
false;
1142 if (var_idx > (
n_obj_params[obj_type_id] + SWMM_Npolluts))
1143 is_var_idx_okay =
false;
1148 is_obj_idx_okay =
false;
1150 is_var_idx_okay =
false;
1153 ERR(
"Object type not recognised.");
1158 if (!is_obj_idx_okay)
1160 ERR(
"Requested object index does not exist.");
1165 if (!is_var_idx_okay)
1167 ERR(
"Requested variable does not exist.");
1172 std::size_t
const n_time_steps(
static_cast<std::size_t
>(SWMM_Nperiods));
1173 for (std::size_t i = 0; i < n_time_steps; ++i)
1176 GetSwmmResult(obj_type_id, obj_idx, var_idx, i, &val);
1177 data.push_back(
static_cast<double>(val));
1185 std::size_t var_idx)
const
1187 std::string
const outfile(
_base_name +
".out");
1188 if (OpenSwmmOutFile(
const_cast<char*
>(outfile.c_str())) != 0)
1189 return std::string(
"");
1191 std::string
const name =
getArrayName(obj_type, var_idx, SWMM_Npolluts);
1197 std::size_t var_idx,
1198 std::size_t n_pollutants)
const
1212 return std::string(
"Node_" +
1220 return std::string(
"Link_" +
1227 ERR(
"SwmmInterface::getArrayName() - Index error, no name found.");
1228 return std::string(
"");
1234 while (std::getline(in, line))
1243 if (split_str.size() < 6)
1245 ERR(
"Rain gauge parameter format not recognised.");
1251 if (stn.first.getName() == split_str[0] && split_str[4] ==
"FILE")
1252 stn.second = split_str[5].substr(1, split_str[5].size() - 2);
1257 if (stn.second.empty())
1258 WARN(
"No associated time series found for rain gauge '{:s}'.",
1259 stn.first.getName());
1266 while (std::getline(in, line))
1275 if (split_str.size() < 6)
1277 ERR(
"Parameter format for pollutants not recognised.");
1290 std::size_t
const pos_beg = str.find_first_not_of(
' ', 0);
1291 if (pos_beg == str.find_first_of(
" \n", pos_beg))
1299 return (str.compare(str.find_first_not_of(
' ', 0), 1,
";") == 0);
1303 std::vector<double>& y,
1304 std::vector<double>& z)
const
1306 std::vector<MeshLib::Node*>
const& nodes(
_mesh->getNodes());
1309 x.push_back((*node)[0]);
1310 y.push_back((*node)[1]);
1311 z.push_back((*node)[2]);
1317 std::vector<std::size_t>& outlets)
const
1319 std::vector<MeshLib::Element*>
const& elements(
_mesh->getElements());
1324 ERR(
"Non line-element found in mesh.");
1327 inlets.push_back(getNodeIndex(*elem, 0));
1328 outlets.push_back(getNodeIndex(*elem, 1));
1340 return "subcatchment";
1348 std::size_t time_step)
const
1354 for (std::size_t i = 0; i < n_params; ++i)
1362 ERR(
"No data to write");
1371 std::size_t obj_idx)
const
1378 for (std::size_t i = 0; i < n_params; ++i)
1386 ERR(
"No data to write");
Definition of the CsvInterface class.
Definition of the GEOObjects class.
Definition of the Point class.
Definition of the Line class.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the class Properties that implements a container of properties.
Definition of the Mesh class.
Definition of the Node class.
Definition of the PointVec class.
Definition of the Polygon class.
Definition of the PolyLine class.
std::string writeToString()
Writes the object to a string.
bool addVectorForWriting(std::string const &vec_name, std::vector< T > const &vec)
void addIndexVectorForWriting(std::size_t s)
Adds an index vector of size s to the CSV file.
std::size_t getNArrays() const
Returns the number of vectors currently staged for writing.
~SwmmInterface()
Destructor.
std::unique_ptr< MeshLib::Mesh > _mesh
Mesh generated from SWMM input (+ optional output data)
std::vector< std::string > _id_nodename_map
Vector storing the names of all nodes/junctions.
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.
bool readPollutants(std::ifstream &in)
Reads pollutant names and parameters.
bool readSubcatchments(std::ifstream &in, std::map< std::string, std::size_t > const &name_id_map)
Reads subcatchment information.
std::vector< std::string > getSubcatchmentNameMap() const
Creates a temporary string vector containing all subcatchment names in correct order.
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 bool isCommentLine(std::string const &str)
Checks if the given line string is a comment line.
std::string const _base_name
All files for a given SWMM simulation have the same base name.
bool getNodeCoordinateVectors(std::vector< double > &x, std::vector< double > &y, std::vector< double > &z) const
Writes the node coordinates into double vectors for writing of CSV files.
bool getLinkPointIds(std::vector< std::size_t > &inlets, std::vector< std::size_t > &outlets) const
Writes the inlet- and outlet IDs for links into vectors for writing of CSV files.
bool matchSubcatchmentsWithPolygons(std::vector< GeoLib::Polyline * > const &lines, std::vector< std::string > const &names)
Matches existing subcatchment names with subsequently read polylines marking the outlines of said sub...
SwmmInterface(std::string const &swmm_base_name)
Constructor.
static bool readPolygons(std::ifstream &in, std::vector< GeoLib::Polyline * > &lines, std::vector< std::string > &line_names, std::vector< GeoLib::Point * > &points, std::vector< std::string > &pnt_names)
bool addRainGaugeTimeSeriesLocations(std::ifstream &in)
Reads the location of external rain gauge time series files.
std::vector< GeoLib::Point * > _subcatchment_points
Separate node vector containing points for defining subcatchment outlines.
static bool isSwmmInputFile(std::string const &inp_file_name)
Checks if file is a SWMM input file.
bool readLineElements(std::ifstream &in, std::vector< MeshLib::Element * > &elements, std::vector< MeshLib::Node * > const &nodes, std::map< std::string, std::size_t > const &name_id_map)
Reads links/conduits and returns them as a vector of OGS line elements.
bool writeCsvForTimestep(std::string const &file_name, SwmmObject obj_type, std::size_t time_step) const
Write a CSV file for all object of the given type at one time step.
std::vector< std::pair< GeoLib::Station, std::string > > _rain_gauges
Vector containing rain gauge information as well the position of external time series files.
static bool readLinksAsPolylines(std::ifstream &in, std::vector< GeoLib::Polyline * > &lines, std::vector< std::string > &line_names, std::vector< GeoLib::Point * > const &points, std::map< std::string, std::size_t > const &point_names)
During geometry conversion, this reads links (conduits/pumps/weirs) and converts them into polylines.
std::vector< std::string > _id_linkname_map
Vector storing the names of all links/conduits.
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...
std::size_t getNumberOfTimeSteps() const
Returns the number of time steps for the simulation results.
static bool readCoordinates(std::ifstream &in, std::vector< T * > &points, std::vector< std::string > &names)
static bool addResultsToMesh(MeshLib::Mesh &mesh, SwmmObject const type, std::string const &vec_name, std::vector< double > const &data)
bool existsSwmmOutputFile() const
Checks if a SWMM output file exists for the current input.
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.
bool readSwmmInputToLineMesh()
Reading a SWMM input file and creating an OGS line mesh. This is automatically called when the object...
std::size_t getNumberOfParameters(SwmmObject obj_type) const
Returns the number of parameters (incl. pollutants) of the given type.
static bool addPointElevation(std::ifstream &in, std::vector< GeoLib::Point * > &points, std::map< std::string, std::size_t > const &name_id_map)
During geometry conversion, this adds elevation values to the existing point vector.
bool readNodeData(std::ifstream &in, std::vector< MeshLib::Node * > &nodes, std::map< std::string, std::size_t > const &name_id_map, std::vector< double > &max_depth, bool read_max_depth)
Reads input information associated with nodes (elevation, depth, etc.)
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.
std::vector< Subcatchment > _subcatchments
Vector storing information about all subcatchments.
static bool isSectionFinished(std::string const &str)
Checks if the given line string is empty. Empty strings mark the end of sections in a SWMM input file...
std::vector< double > getArrayForObject(SwmmObject obj_type, std::size_t obj_idx, std::size_t var_idx) const
Returns an array for a given variable for one specific object from a SWMM output file for all time st...
std::vector< std::string > getNames(SwmmObject obj_type) const
Get all the object names for a given object type.
std::vector< std::string > _pollutant_names
Vector storing the names of all pollutants.
Container class for geometric objects.
void addPolylineVec(std::vector< Polyline * > &&lines, std::string const &name, PolylineVec::NameIdMap &&ply_names)
void addPointVec(std::vector< Point * > &&points, std::string &name, PointVec::NameIdMap &&pnt_id_name_map, double const eps=std::sqrt(std::numeric_limits< double >::epsilon()))
const PointVec * getPointVecObj(const std::string &name) const
bool removePointVec(const std::string &name)
const std::vector< std::size_t > & getIDMap() const
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
virtual bool addPoint(std::size_t pnt_id)
A Station (observation site) is basically a Point with some additional information.
std::map< std::string, std::size_t > NameIdMap
std::size_t getNumberOfNodes() const
Get the number of nodes.
std::size_t getNumberOfElements() const
Get the number of elements.
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
PropertyVector< T > * createNewPropertyVector(std::string_view name, MeshItemType mesh_item_type, std::size_t n_components=1)
int writeStringToFile(std::string_view content, std::filesystem::path const &file_path)
std::string getFileExtension(const std::string &path)
void cleanupVectorElements(std::vector< T * > &items)
std::string extractBaseNameWithoutExtension(std::string const &pathname)
std::vector< std::string > splitString(std::string const &str)
T str2number(const std::string &str)
SwmmObject
SWMM object types.
const std::array< std::string, 15 > system_vars
All variables that exist for the system.
const std::array< std::string, 6 > link_vars
Variables that always exist for links. There might be more.
const std::array< std::string, 9 > subcatchment_vars
Variables that always exist for subcatchments. There might be more.
const std::array< std::string, 7 > node_vars
Variables that always exist for nodes. There might be more.
std::array< std::size_t, 4 > const n_obj_params
PropertyVector< T > * getOrCreateMeshProperty(Mesh &mesh, std::string const &property_name, MeshItemType const item_type, int const number_of_components)