9 #include "SwmmInterface.h"
11 #include <swmm5_iface.h>
13 #include <boost/algorithm/string/predicate.hpp>
38 "infiltration losses",
40 "groundwater outflow",
43 "concentration of pollutant"};
46 const std::array<std::string, 7>
node_vars = {
"water depth",
48 "volume of stored water",
51 "flow lost to flooding",
52 "concentration of pollutant"};
55 const std::array<std::string, 6>
link_vars = {
"flow rate",
59 "fraction conduit/non-conduit",
60 "concentration of pollutant"};
67 "evaporation + infiltration loss",
73 "total lateral inflow",
74 "flow lost to flooding",
75 "flow leaving through outfalls",
76 "volume of stored water",
77 "actual evaporation rate",
78 "potential evaporation rate"};
85 std::string
const& file_name)
91 if (file_name.length() < 5)
97 std::string
const base_name(file_name.substr(0, file_name.length() - 4));
100 return std::unique_ptr<SwmmInterface>(swmm);
102 ERR(
"Error creating mesh from SWMM file.");
108 : _base_name(swmm_base_name), _mesh(nullptr)
125 ERR(
"SWMMInterface: {:s} is not a SWMM input file.", inp_file_name);
129 std::ifstream in(inp_file_name.c_str());
132 ERR(
"SWMMInterface: Could not open input file {:s}.", inp_file_name);
137 bool header_found(
false);
138 std::size_t pos_end(0);
139 while (!header_found)
141 if (!std::getline(in, line))
144 std::size_t
const pos_beg = line.find_first_not_of(
' ', pos_end);
145 pos_end = line.find_first_of(
" \n", pos_beg);
148 if (line.empty() || pos_beg == pos_end ||
isCommentLine(line))
151 if (line ==
"[TITLE]")
155 INFO(
"SWMMInterface: input file type {:s} not recognised.",
167 std::string
const outfile(
_base_name +
".out");
168 if (OpenSwmmOutFile(
const_cast<char*
>(outfile.c_str())) != 0)
173 template <
typename T>
175 std::vector<std::string>& names)
177 std::size_t id(points.size());
180 while (std::getline(in, line))
189 if (split_str.size() != 3)
191 ERR(
"Format not recognised.");
194 names.push_back(split_str[0]);
196 double const x = BaseLib::str2number<double>(split_str[1]);
197 double const y = BaseLib::str2number<double>(split_str[2]);
198 T* pnt =
new T(x, y, 0,
id);
199 points.push_back(pnt);
206 std::vector<GeoLib::Polyline*>& lines,
207 std::vector<std::string>& ply_names,
208 std::vector<GeoLib::Point*>& points,
209 std::vector<std::string>& pnt_names)
211 bool finished(
false);
212 std::size_t id(points.size());
214 std::string polygon_name(
"");
216 while (std::getline(in, line))
225 if (split_str.size() != 3)
227 ERR(
"Polygon format not recognised.");
233 if (split_str[0] != polygon_name)
237 p->addPoint(p->getPointID(0));
241 polygon_name = split_str[0];
243 ply_names.push_back(polygon_name);
246 double const x = BaseLib::str2number<double>(split_str[1]);
247 double const y = BaseLib::str2number<double>(split_str[2]);
249 p->addPoint(points.size() - 1);
250 pnt_names.push_back(
"");
257 p->addPoint(p->getPointID(0));
265 std::ifstream& in, std::vector<GeoLib::Point*>& points,
266 std::map<std::string, std::size_t>
const& name_id_map)
269 while (std::getline(in, line))
279 if (split_str.size() < 4)
281 ERR(
"Format not recognised.");
284 std::string
const current_name(split_str[0]);
285 auto const it = name_id_map.find(current_name);
286 if (it == name_id_map.end())
288 ERR(
"SwmmInterface::addPointElevation(): Name {:s} not found in "
293 std::size_t
const id = it->second;
294 (*points[id])[2] = BaseLib::str2number<double>(split_str[1]);
300 std::ifstream& in, std::vector<GeoLib::Polyline*>& lines,
301 std::vector<std::string>& line_names,
302 std::vector<GeoLib::Point*>
const& points,
303 std::map<std::string, std::size_t>
const& point_names)
306 while (std::getline(in, line))
316 if (split_str.size() < 7)
318 ERR(
"Conduit format not recognised.");
322 std::string
const inlet(split_str[1]);
323 auto const i_it = point_names.find(inlet);
324 if (i_it == point_names.end())
326 ERR(
"SwmmInterface::readLineElements(): Inlet node {:s} not found "
327 "in coordinates map.",
332 std::string
const outlet(split_str[2]);
333 auto const o_it = point_names.find(outlet);
334 if (o_it == point_names.end())
336 ERR(
"SwmmInterface::readLineElements(): Outlet node {:s} not found "
337 "in coordinates map.",
342 std::size_t a(i_it->second);
345 lines.push_back(ply);
346 line_names.push_back(split_str[0]);
353 bool add_subcatchments)
358 std::ifstream in(inp_file_name.c_str());
361 ERR(
"SWMMInterface: Could not open input file {:s}.", inp_file_name);
365 auto points = std::make_unique<std::vector<GeoLib::Point*>>();
366 auto lines = std::make_unique<std::vector<GeoLib::Polyline*>>();
367 std::vector<std::string> pnt_names;
368 std::vector<std::string> line_names;
370 std::string geo_name =
373 while (std::getline(in, line))
375 if (line ==
"[COORDINATES]" || line ==
"[VERTICES]" ||
378 if (!readCoordinates<GeoLib::Point>(in, *points, pnt_names))
384 if (line ==
"[Polygons]" && add_subcatchments)
386 if (!
readPolygons(in, *lines, line_names, *points, pnt_names))
396 ERR(
"No points found in file");
399 if (points->size() != pnt_names.size())
401 ERR(
"Length of point vector and point name vector do not match.");
406 auto name_id_map = std::make_unique<std::map<std::string, std::size_t>>();
408 std::size_t
const n_names(pnt_names.size());
409 for (std::size_t i = 0; i < n_names; ++i)
411 if (!pnt_names[i].empty())
412 name_id_map->insert(std::make_pair(pnt_names[i], i));
420 while (std::getline(in, line))
422 if (line ==
"[JUNCTIONS]")
424 INFO(
"Reading point elevation...");
431 if (line ==
"[CONDUITS]")
433 INFO(
"Reading conduits...");
441 else if (line ==
"[PUMPS]")
443 INFO(
"Reading pumps...");
451 else if (line ==
"[WEIRS]")
453 INFO(
"Reading weirs...");
463 geo_objects.
addPointVec(std::move(points), geo_name,
464 std::move(name_id_map));
467 if (lines->size() != line_names.size())
469 ERR(
"Length of line vector and line name vector do not match.");
471 for (
auto ply : *lines)
476 std::make_unique<std::map<std::string, std::size_t>>();
478 std::size_t
const n_names(line_names.size());
479 for (std::size_t i = 0; i < n_names; ++i)
481 line_id_map->insert(std::make_pair(line_names[i], i));
484 std::vector<std::size_t>
const& pnt_id_map(
488 for (std::size_t i = 0; i < polyline->getNumberOfPoints(); ++i)
490 polyline->setPointID(i, pnt_id_map[polyline->getPointID(i)]);
492 polyline->getPointID(i - 1) == polyline->getPointID(i))
494 polyline->removePoint(i);
498 if (polyline->getPointID(0) ==
499 polyline->getPointID(polyline->getNumberOfPoints() - 1))
501 polyline->removePoint(polyline->getNumberOfPoints() - 1);
502 polyline->addPoint(polyline->getPointID(0));
506 std::move(line_id_map));
512 std::ifstream& in, std::vector<MeshLib::Node*>& nodes,
513 std::map<std::string, std::size_t>
const& name_id_map,
514 std::vector<double>& max_depth,
bool read_max_depth)
517 while (std::getline(in, line))
527 if (split_str.size() < 3)
529 ERR(
"Format not recognised.");
532 std::string
const current_name(split_str[0]);
533 auto const it = name_id_map.find(current_name);
534 if (it == name_id_map.end())
536 ERR(
"SwmmInterface::readNodeData(): Name {:s} not found in "
541 std::size_t
const id = it->second;
542 (*nodes[id])[2] = BaseLib::str2number<double>(split_str[1]);
545 max_depth[id] = BaseLib::str2number<double>(split_str[2]);
553 std::ifstream& in, std::vector<MeshLib::Element*>& elements,
554 std::vector<MeshLib::Node*>
const& nodes,
555 std::map<std::string, std::size_t>
const& name_id_map)
558 while (std::getline(in, line))
568 if (split_str.size() < 7)
570 ERR(
"Conduit format not recognised.");
574 std::string
const inlet(split_str[1]);
575 auto const i_it = name_id_map.find(inlet);
576 if (i_it == name_id_map.end())
578 ERR(
"SwmmInterface::readLineElements(): Inlet node {:s} not found "
579 "in coordinates map.",
584 std::string
const outlet(split_str[2]);
585 auto const o_it = name_id_map.find(outlet);
586 if (o_it == name_id_map.end())
588 ERR(
"SwmmInterface::readLineElements(): Outlet node {:s} not found "
589 "in coordinates map.",
594 std::array<MeshLib::Node*, 2>
const line_nodes = {nodes[i_it->second],
595 nodes[o_it->second]};
603 std::ifstream& in, std::map<std::string, std::size_t>
const& name_id_map)
606 while (getline(in, line))
615 if (split_str.size() < 8)
617 ERR(
"Subcatchment format not recognised.");
622 sc.
name = split_str[0];
623 sc.
rain_gauge = std::numeric_limits<std::size_t>::max();
625 for (std::size_t i = 0; i < n_gauges; ++i)
633 if (sc.
rain_gauge == std::numeric_limits<std::size_t>::max())
635 ERR(
"Rain gauge for subcatchment '{:s}' not found.", split_str[0]);
639 auto const it = name_id_map.find(split_str[2]);
640 if (it == name_id_map.end())
642 ERR(
"Outlet node for subcatchment '{:s}' not found.", split_str[0]);
646 sc.
area = BaseLib::str2number<double>(split_str[3]);
655 if (
_mesh !=
nullptr)
657 ERR(
"Mesh already exists.");
661 std::string
const inp_file_name(
_base_name +
".inp");
665 std::ifstream in(inp_file_name.c_str());
668 ERR(
"SWMMInterface: Could not open input file {:s}.", inp_file_name);
673 std::vector<MeshLib::Node*> nodes;
675 while (getline(in, line))
677 if (line ==
"[COORDINATES]")
679 INFO(
"Reading coordinates...");
691 else if (line ==
"[SYMBOLS]")
693 INFO(
"Reading symbols...");
694 std::vector<GeoLib::Point*> points;
695 std::vector<std::string> names;
698 for (std::size_t i = 0; i < points.size(); ++i)
702 std::pair<GeoLib::Station, std::string>(stn,
""));
712 std::map<std::string, std::size_t> name_id_map;
713 std::size_t
const n_nodes(nodes.size());
714 for (std::size_t i = 0; i < n_nodes; ++i)
719 std::vector<MeshLib::Element*> elements;
720 std::vector<double> max_depth(n_nodes);
721 std::size_t
const n_types = 3;
722 std::array<std::size_t, n_types> n_elem_types{{0, 0, 0}};
723 while (getline(in, line))
725 if (line ==
"[RAINGAGES]")
730 else if (line ==
"[SUBCATCHMENTS]")
732 INFO(
"Reading subcatchment information...");
736 else if (line ==
"[SUBAREAS]")
740 else if (line ==
"[INFILTRATION]")
744 else if (line ==
"[JUNCTIONS]")
746 INFO(
"Reading junctions...");
747 if (!
readNodeData(in, nodes, name_id_map, max_depth,
true))
750 else if (line ==
"[OUTFALLS]")
752 INFO(
"Reading outfalls...");
753 if (!
readNodeData(in, nodes, name_id_map, max_depth,
false))
756 else if (line ==
"[STORAGE]")
758 INFO(
"Reading storages...");
759 if (!
readNodeData(in, nodes, name_id_map, max_depth,
true))
762 else if (line ==
"[CONDUITS]")
764 INFO(
"Reading conduits...");
767 n_elem_types[0] = elements.size();
769 else if (line ==
"[PUMPS]")
771 INFO(
"Reading pumps...");
774 n_elem_types[1] = elements.size();
776 else if (line ==
"[WEIRS]")
778 INFO(
"Reading weirs...");
781 n_elem_types[2] = elements.size();
783 else if (line ==
"[POLLUTANTS]")
788 else if (line ==
"[Polygons]")
790 INFO(
"Reading subcatchments...");
791 std::vector<GeoLib::Polyline*> lines;
792 std::vector<std::string> line_names;
793 std::vector<std::string>
805 if (elements.empty())
815 mat_ids->resize(elements.size(), 0);
816 for (std::size_t i = 1; i < n_types; ++i)
818 if (n_elem_types[i] > 0)
819 std::fill(mat_ids->begin() + n_elem_types[i - 1],
820 mat_ids->begin() + n_elem_types[i], i);
823 if (nodes.size() == max_depth.size())
827 depth->reserve(max_depth.size());
828 std::copy(max_depth.cbegin(), max_depth.cend(),
829 std::back_inserter(*depth));
832 ERR(
"Size of max depth array does not fit number of elements. Skipping "
840 std::vector<GeoLib::Polyline*>
const& lines,
841 std::vector<std::string>
const& names)
843 std::size_t
const n_lines(lines.size());
846 if (n_lines != n_subcatchments)
848 ERR(
"Number of subcatchments does not match number of outlines.");
851 for (std::size_t i = 0; i < n_lines; ++i)
854 for (std::size_t j = 0; j < n_subcatchments; ++j)
865 ERR(
"No match in subcatcments for outline '{:s}'.", names[i]);
874 std::vector<std::string> names;
877 std::back_inserter(names),
878 [](
auto const& sc) { return sc.name; });
893 std::vector<std::string> system_name{
"System"};
896 ERR(
"Object type has no name map");
897 std::vector<std::string> empty_vec;
916 return std::string(
"System");
918 ERR(
"Index out of bounds.");
919 return std::string(
"");
924 std::string
const outfile(
_base_name +
".out");
925 if (OpenSwmmOutFile(
const_cast<char*
>(outfile.c_str())) != 0)
931 return SWMM_Nsubcatch;
939 ERR(
"Object type not recognised.");
947 std::string
const outfile(
_base_name +
".out");
948 std::size_t n_time_steps(std::numeric_limits<std::size_t>::max());
949 if (OpenSwmmOutFile(
const_cast<char*
>(outfile.c_str())) != 0)
952 std::size_t n_params(0);
968 ERR(
"Object type not recognised.");
976 std::string
const outfile(
_base_name +
".out");
977 if (OpenSwmmOutFile(
const_cast<char*
>(outfile.c_str())) != 0)
978 return std::numeric_limits<std::size_t>::max();
979 std::size_t
const n_time_steps(
static_cast<std::size_t
>(SWMM_Nperiods));
986 std::string
const& vec_name,
987 std::vector<double>
const& data)
991 ERR(
"Information of this object type cannot be added to mesh.");
997 ERR(
"Data array is empty and cannot be added to mesh.");
1003 ERR(
"Number of mesh nodes ({:d}) does not match length of array "
1012 ERR(
"Number of mesh elements ({:d}) does not match length of array "
1022 MeshLib::getOrCreateMeshProperty<double>(mesh, vec_name, item_type, 1);
1025 ERR(
"Error fetching array '{:s}'.", vec_name);
1028 std::copy(data.cbegin(), data.cend(), prop->begin());
1033 std::size_t time_step,
1034 std::size_t var_idx)
const
1036 std::vector<double> data;
1037 std::string
const outfile(
_base_name +
".out");
1038 if (OpenSwmmOutFile(
const_cast<char*
>(outfile.c_str())) != 0)
1041 if (time_step >= SWMM_Nperiods)
1043 ERR(
"Time step {:d} not available, file contains only {:d} periods.",
1044 time_step, SWMM_Nperiods);
1048 bool is_var_idx_okay =
true;
1050 std::size_t n_objects;
1055 n_objects = SWMM_Nsubcatch;
1056 if (var_idx > (
n_obj_params[obj_type_id] - 1 + SWMM_Npolluts))
1057 is_var_idx_okay =
false;
1061 n_objects = SWMM_Nnodes;
1062 if (var_idx > (
n_obj_params[obj_type_id] + SWMM_Npolluts))
1063 is_var_idx_okay =
false;
1067 n_objects = SWMM_Nlinks;
1068 if (var_idx > (
n_obj_params[obj_type_id] + SWMM_Npolluts))
1069 is_var_idx_okay =
false;
1075 is_var_idx_okay =
false;
1078 ERR(
"Object type not recognised.");
1083 if (!is_var_idx_okay)
1085 ERR(
"Requested variable does not exist.");
1090 INFO(
"Fetching '{:s}'-data for time step {:d}...",
1091 getArrayName(obj_type, var_idx, SWMM_Npolluts), time_step);
1093 for (std::size_t i = 0; i < n_objects; ++i)
1096 GetSwmmResult(obj_type_id, i, var_idx, time_step, &val);
1097 data.push_back(
static_cast<double>(val));
1105 std::size_t obj_idx,
1106 std::size_t var_idx)
const
1108 std::vector<double> data;
1109 std::string
const outfile(
_base_name +
".out");
1110 if (OpenSwmmOutFile(
const_cast<char*
>(outfile.c_str())) != 0)
1113 bool is_var_idx_okay =
true;
1114 bool is_obj_idx_okay =
true;
1120 if (obj_idx >= SWMM_Nsubcatch)
1121 is_obj_idx_okay =
false;
1122 if (var_idx > (
n_obj_params[obj_type_id] + SWMM_Npolluts))
1123 is_var_idx_okay =
false;
1127 if (obj_idx >= SWMM_Nnodes)
1128 is_obj_idx_okay =
false;
1129 if (var_idx > (
n_obj_params[obj_type_id] + SWMM_Npolluts))
1130 is_var_idx_okay =
false;
1134 if (obj_idx >= SWMM_Nlinks)
1135 is_obj_idx_okay =
false;
1136 if (var_idx > (
n_obj_params[obj_type_id] + SWMM_Npolluts))
1137 is_var_idx_okay =
false;
1142 is_obj_idx_okay =
false;
1144 is_var_idx_okay =
false;
1147 ERR(
"Object type not recognised.");
1152 if (!is_obj_idx_okay)
1154 ERR(
"Requested object index does not exist.");
1159 if (!is_var_idx_okay)
1161 ERR(
"Requested variable does not exist.");
1166 std::size_t
const n_time_steps(
static_cast<std::size_t
>(SWMM_Nperiods));
1167 for (std::size_t i = 0; i < n_time_steps; ++i)
1170 GetSwmmResult(obj_type_id, obj_idx, var_idx, i, &val);
1171 data.push_back(
static_cast<double>(val));
1179 std::size_t var_idx)
const
1181 std::string
const outfile(
_base_name +
".out");
1182 if (OpenSwmmOutFile(
const_cast<char*
>(outfile.c_str())) != 0)
1183 return std::string(
"");
1191 std::size_t var_idx,
1192 std::size_t n_pollutants)
const
1206 return std::string(
"Node_" +
1214 return std::string(
"Link_" +
1221 ERR(
"SwmmInterface::getArrayName() - Index error, no name found.");
1222 return std::string(
"");
1228 while (getline(in, line))
1237 if (split_str.size() < 6)
1239 ERR(
"Rain gauge parameter format not recognised.");
1245 if (stn.first.getName() == split_str[0] && split_str[4] ==
"FILE")
1246 stn.second = split_str[5].substr(1, split_str[5].size() - 2);
1251 if (stn.second.empty())
1252 WARN(
"No associated time series found for rain gauge '{:s}'.",
1253 stn.first.getName());
1260 while (getline(in, line))
1269 if (split_str.size() < 6)
1271 ERR(
"Parameter format for pollutants not recognised.");
1284 std::size_t
const pos_beg = str.find_first_not_of(
' ', 0);
1285 if (pos_beg == str.find_first_of(
" \n", pos_beg))
1293 return (str.compare(str.find_first_not_of(
' ', 0), 1,
";") == 0);
1297 std::vector<double>& y,
1298 std::vector<double>& z)
const
1300 std::vector<MeshLib::Node*>
const& nodes(
_mesh->getNodes());
1303 x.push_back((*node)[0]);
1304 y.push_back((*node)[1]);
1305 z.push_back((*node)[2]);
1311 std::vector<std::size_t>& outlets)
const
1313 std::vector<MeshLib::Element*>
const& elements(
_mesh->getElements());
1318 ERR(
"Non line-element found in mesh.");
1334 return "subcatchment";
1342 std::size_t time_step)
const
1348 for (std::size_t i = 0; i < n_params; ++i)
1356 ERR(
"No data to write");
1365 std::size_t obj_idx)
const
1372 for (std::size_t i = 0; i < n_params; ++i)
1380 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(char const *fmt, Args const &... args)
void ERR(char const *fmt, Args const &... args)
void WARN(char const *fmt, Args const &... 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.
const PointVec * getPointVecObj(const std::string &name) const
bool removePointVec(const std::string &name)
void addPointVec(std::unique_ptr< std::vector< Point * >> points, std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> pnt_id_name_map=nullptr, double eps=std::sqrt(std::numeric_limits< double >::epsilon()))
void addPolylineVec(std::unique_ptr< std::vector< Polyline * >> lines, const std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> ply_names=nullptr)
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::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 const &name, MeshItemType mesh_item_type, std::size_t n_components=1)
int writeStringToFile(std::string content, std::filesystem::path const &file_path)
std::string getFileExtension(const std::string &path)
std::string extractBaseNameWithoutExtension(std::string const &pathname)
std::vector< std::string > splitString(std::string const &str)
void cleanupVectorElements(std::vector< T1 * > const &items, std::vector< T2 * > const &dependent_items)
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
void copy(PETScVector const &x, PETScVector &y)
std::size_t getNodeIndex(Element const &element, unsigned const idx)