OGS
SWMMInterface.h
Go to the documentation of this file.
1
9#pragma once
10
11#include <map>
12#include <memory>
13#include <string>
14#include <vector>
15
16
17#include "GeoLib/Station.h"
18
19namespace GeoLib {
20 class GEOObjects;
21 class Point;
22 class Polyline;
23}
24
25namespace MeshLib {
26 class Mesh;
27 class Node;
28 class Element;
29}
30
31namespace FileIO
32{
33
35enum class SwmmObject
36{
37 SUBCATCHMENT = 0,
38 NODE = 1,
39 LINK = 2,
40 SYSTEM = 3
41};
42
60class SwmmInterface final
61{
62public:
65 static std::unique_ptr<SwmmInterface> create(std::string const& file_name);
66
69 static bool addResultsToMesh(MeshLib::Mesh &mesh, SwmmObject const type,
70 std::string const& vec_name, std::vector<double> const& data);
71
73 MeshLib::Mesh& getMesh() const { return *_mesh; }
74
76 std::string getArrayName(SwmmObject obj_type, std::size_t var_idx) const;
77
79 std::vector<std::string> getNames(SwmmObject obj_type) const;
80
82 std::string getName(SwmmObject obj_type, std::size_t idx) const;
83
85 std::size_t getNumberOfObjects(SwmmObject obj_type) const;
86
88 std::size_t getNumberOfParameters(SwmmObject obj_type) const;
89
91 std::size_t getNumberOfTimeSteps() const;
92
94 std::vector<double> getArrayAtTimeStep(SwmmObject obj_type, std::size_t time_step, std::size_t var_idx) const;
95
97 std::vector<double> getArrayForObject(SwmmObject obj_type, std::size_t obj_idx, std::size_t var_idx) const;
98
100 bool getNodeCoordinateVectors(std::vector<double> &x, std::vector<double> &y, std::vector<double> &z) const;
101
103 bool getLinkPointIds(std::vector<std::size_t> &inlets, std::vector<std::size_t> &outlets) const;
104
106 bool writeCsvForTimestep(std::string const& file_name, SwmmObject obj_type, std::size_t time_step) const;
107
109 bool writeCsvForObject(std::string const& file_name, SwmmObject obj_type, std::size_t obj_idx) const;
110
112 static bool isSwmmInputFile(std::string const& inp_file_name);
113
115 bool existsSwmmOutputFile() const;
116
118 static std::string swmmObjectTypeToString(SwmmObject const obj_type);
119
121 static bool convertSwmmInputToGeometry(std::string const& inp_file_name,
122 GeoLib::GEOObjects &geo_objects, bool add_subcatchments);
123
126
127private:
129 SwmmInterface(std::string const& swmm_base_name);
130
133
136 template <typename T>
137 static bool readCoordinates(std::ifstream &in, std::vector<T*> &points, std::vector<std::string> &names);
138
140 bool readNodeData(std::ifstream &in, std::vector<MeshLib::Node*> &nodes,
141 std::map<std::string, std::size_t> const& name_id_map,
142 std::vector<double> &max_depth, bool read_max_depth);
143
145 bool readLineElements(std::ifstream &in, std::vector<MeshLib::Element*> &elements,
146 std::vector<MeshLib::Node*> const& nodes, std::map<std::string, std::size_t> const& name_id_map);
147
149 bool readSubcatchments(std::ifstream &in, std::map< std::string, std::size_t> const& name_id_map);
150
152 bool readPollutants(std::ifstream &in);
153
155 std::string getArrayName(SwmmObject obj_type, std::size_t var_idx, std::size_t n_pollutants) const;
156
158 bool addRainGaugeTimeSeriesLocations(std::ifstream &in);
159
161 bool matchSubcatchmentsWithPolygons(std::vector<GeoLib::Polyline*> const& lines, std::vector<std::string> const& names);
162
164 std::vector<std::string> getSubcatchmentNameMap() const;
165
167 static bool addPointElevation(std::ifstream &in,
168 std::vector<GeoLib::Point*> &points, std::map<std::string,
169 std::size_t> const& name_id_map);
170
172 static bool readLinksAsPolylines(std::ifstream &in,
173 std::vector<GeoLib::Polyline*> &lines, std::vector<std::string> &line_names,
174 std::vector<GeoLib::Point*> const& points, std::map<std::string, std::size_t> const& point_names);
175
178 static bool readPolygons(std::ifstream &in, std::vector<GeoLib::Polyline*> &lines,
179 std::vector<std::string> &line_names, std::vector<GeoLib::Point*> &points,
180 std::vector<std::string> &pnt_names);
181
183 static bool isSectionFinished(std::string const& str);
184
186 static bool isCommentLine(std::string const& str);
187
191 {
192 std::string name;
193 std::size_t rain_gauge;
194 std::size_t outlet;
195 double area;
197 };
198
199 //variables
201 std::string const _base_name;
203 std::vector<std::string> _id_nodename_map;
205 std::vector<std::string> _id_linkname_map;
207 std::vector<std::string> _pollutant_names;
209 std::vector<Subcatchment> _subcatchments;
211 std::vector<GeoLib::Point*> _subcatchment_points;
213 std::vector< std::pair<GeoLib::Station, std::string> > _rain_gauges;
215 std::unique_ptr<MeshLib::Mesh> _mesh;
216};
217
218} // namespace FileIO
Definition of the Station class.
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.
MeshLib::Mesh & getMesh() const
Returns the mesh generated from SWMM file content.
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.
Definition GEOObjects.h:57
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition Polyline.h:40
SwmmObject
SWMM object types.
TemplateElement< PointRule1 > Point
Definition Point.h:20