OGS
SWMMInterface.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <map>
11 #include <memory>
12 #include <string>
13 #include <vector>
14 
15 
16 #include "GeoLib/Station.h"
17 
18 namespace GeoLib {
19  class GEOObjects;
20  class Point;
21  class Polyline;
22 }
23 
24 namespace MeshLib {
25  class Mesh;
26  class Node;
27  class Element;
28 }
29 
30 namespace FileIO
31 {
32 
34 enum class SwmmObject
35 {
36  SUBCATCHMENT = 0,
37  NODE = 1,
38  LINK = 2,
39  SYSTEM = 3
40 };
41 
59 class SwmmInterface final
60 {
61 public:
64  static std::unique_ptr<SwmmInterface> create(std::string const& file_name);
65 
68  static bool addResultsToMesh(MeshLib::Mesh &mesh, SwmmObject const type,
69  std::string const& vec_name, std::vector<double> const& data);
70 
72  MeshLib::Mesh& getMesh() const { return *_mesh; }
73 
75  std::string getArrayName(SwmmObject obj_type, std::size_t var_idx) const;
76 
78  std::vector<std::string> getNames(SwmmObject obj_type) const;
79 
81  std::string getName(SwmmObject obj_type, std::size_t idx) const;
82 
84  std::size_t getNumberOfObjects(SwmmObject obj_type) const;
85 
87  std::size_t getNumberOfParameters(SwmmObject obj_type) const;
88 
90  std::size_t getNumberOfTimeSteps() const;
91 
93  std::vector<double> getArrayAtTimeStep(SwmmObject obj_type, std::size_t time_step, std::size_t var_idx) const;
94 
96  std::vector<double> getArrayForObject(SwmmObject obj_type, std::size_t obj_idx, std::size_t var_idx) const;
97 
99  bool getNodeCoordinateVectors(std::vector<double> &x, std::vector<double> &y, std::vector<double> &z) const;
100 
102  bool getLinkPointIds(std::vector<std::size_t> &inlets, std::vector<std::size_t> &outlets) const;
103 
105  bool writeCsvForTimestep(std::string const& file_name, SwmmObject obj_type, std::size_t time_step) const;
106 
108  bool writeCsvForObject(std::string const& file_name, SwmmObject obj_type, std::size_t obj_idx) const;
109 
111  static bool isSwmmInputFile(std::string const& inp_file_name);
112 
114  bool existsSwmmOutputFile() const;
115 
117  static std::string swmmObjectTypeToString(SwmmObject const obj_type);
118 
120  static bool convertSwmmInputToGeometry(std::string const& inp_file_name,
121  GeoLib::GEOObjects &geo_objects, bool add_subcatchments);
122 
124  ~SwmmInterface();
125 
126 private:
128  SwmmInterface(std::string const& swmm_base_name);
129 
132 
135  template <typename T>
136  static bool readCoordinates(std::ifstream &in, std::vector<T*> &points, std::vector<std::string> &names);
137 
139  bool readNodeData(std::ifstream &in, std::vector<MeshLib::Node*> &nodes,
140  std::map<std::string, std::size_t> const& name_id_map,
141  std::vector<double> &max_depth, bool read_max_depth);
142 
144  bool readLineElements(std::ifstream &in, std::vector<MeshLib::Element*> &elements,
145  std::vector<MeshLib::Node*> const& nodes, std::map<std::string, std::size_t> const& name_id_map);
146 
148  bool readSubcatchments(std::ifstream &in, std::map< std::string, std::size_t> const& name_id_map);
149 
151  bool readPollutants(std::ifstream &in);
152 
154  std::string getArrayName(SwmmObject obj_type, std::size_t var_idx, std::size_t n_pollutants) const;
155 
157  bool addRainGaugeTimeSeriesLocations(std::ifstream &in);
158 
160  bool matchSubcatchmentsWithPolygons(std::vector<GeoLib::Polyline*> const& lines, std::vector<std::string> const& names);
161 
163  std::vector<std::string> getSubcatchmentNameMap() const;
164 
166  static bool addPointElevation(std::ifstream &in,
167  std::vector<GeoLib::Point*> &points, std::map<std::string,
168  std::size_t> const& name_id_map);
169 
171  static bool readLinksAsPolylines(std::ifstream &in,
172  std::vector<GeoLib::Polyline*> &lines, std::vector<std::string> &line_names,
173  std::vector<GeoLib::Point*> const& points, std::map<std::string, std::size_t> const& point_names);
174 
177  static bool readPolygons(std::ifstream &in, std::vector<GeoLib::Polyline*> &lines,
178  std::vector<std::string> &line_names, std::vector<GeoLib::Point*> &points,
179  std::vector<std::string> &pnt_names);
180 
182  static bool isSectionFinished(std::string const& str);
183 
185  static bool isCommentLine(std::string const& str);
186 
190  {
191  std::string name;
192  std::size_t rain_gauge;
193  std::size_t outlet;
194  double area;
196  };
197 
198  //variables
200  std::string const _base_name;
202  std::vector<std::string> _id_nodename_map;
204  std::vector<std::string> _id_linkname_map;
206  std::vector<std::string> _pollutant_names;
208  std::vector<Subcatchment> _subcatchments;
210  std::vector<GeoLib::Point*> _subcatchment_points;
212  std::vector< std::pair<GeoLib::Station, std::string> > _rain_gauges;
214  std::unique_ptr<MeshLib::Mesh> _mesh;
215 };
216 
217 } // namespace FileIO
Definition of the Station class.
~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...
MeshLib::Mesh & getMesh() const
Returns the mesh generated from SWMM file content.
Definition: SWMMInterface.h:72
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.
Definition: GEOObjects.h:61
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition: Polyline.h:51
SwmmObject
SWMM object types.
Definition: SWMMInterface.h:35
TemplateElement< PointRule1 > Point
Definition: Point.h:20