OGS
|
Interface for reading files used within the Storm Water Management Model (SWMM) and converting the data therein into corresponding OGS data structures. SWMM distinguishes four different object types (defined in the SwmmObject enum):
Definition at line 60 of file SWMMInterface.h.
#include <SWMMInterface.h>
Classes | |
struct | Subcatchment |
Public Member Functions | |
MeshLib::Mesh & | getMesh () const |
Returns the mesh generated from SWMM file content. | |
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< std::string > | getNames (SwmmObject obj_type) const |
Get all the object names for a given object type. | |
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). | |
std::size_t | getNumberOfObjects (SwmmObject obj_type) const |
Returns the number of objects of the given type. | |
std::size_t | getNumberOfParameters (SwmmObject obj_type) const |
Returns the number of parameters (incl. pollutants) of the given type. | |
std::size_t | getNumberOfTimeSteps () const |
Returns the number of time steps for the simulation results. | |
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 step. | |
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 steps. | |
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 | 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. | |
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 | existsSwmmOutputFile () const |
Checks if a SWMM output file exists for the current input. | |
~SwmmInterface () | |
Destructor. | |
Static Public Member Functions | |
static std::unique_ptr< SwmmInterface > | create (std::string const &file_name) |
static bool | addResultsToMesh (MeshLib::Mesh &mesh, SwmmObject const type, std::string const &vec_name, std::vector< double > const &data) |
static bool | isSwmmInputFile (std::string const &inp_file_name) |
Checks if file is a SWMM input file. | |
static std::string | swmmObjectTypeToString (SwmmObject const obj_type) |
Returns a string with the name of the object type. | |
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. | |
Private Member Functions | |
SwmmInterface (std::string const &swmm_base_name) | |
Constructor. | |
bool | readSwmmInputToLineMesh () |
Reading a SWMM input file and creating an OGS line mesh. This is automatically called when the object is created. | |
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.) | |
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 | readSubcatchments (std::ifstream &in, std::map< std::string, std::size_t > const &name_id_map) |
Reads subcatchment information. | |
bool | readPollutants (std::ifstream &in) |
Reads pollutant names and parameters. | |
std::string | getArrayName (SwmmObject obj_type, std::size_t var_idx, std::size_t n_pollutants) const |
Returns the name of an array (or an empty string if errors occurred) | |
bool | addRainGaugeTimeSeriesLocations (std::ifstream &in) |
Reads the location of external rain gauge time series 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 subcatchments. | |
std::vector< std::string > | getSubcatchmentNameMap () const |
Creates a temporary string vector containing all subcatchment names in correct order. | |
Static Private Member Functions | |
template<typename T > | |
static bool | readCoordinates (std::ifstream &in, std::vector< T * > &points, std::vector< std::string > &names) |
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. | |
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. | |
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) |
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. | |
static bool | isCommentLine (std::string const &str) |
Checks if the given line string is a comment line. | |
Private Attributes | |
std::string const | _base_name |
All files for a given SWMM simulation have the same base name. | |
std::vector< std::string > | _id_nodename_map |
Vector storing the names of all nodes/junctions. | |
std::vector< std::string > | _id_linkname_map |
Vector storing the names of all links/conduits. | |
std::vector< std::string > | _pollutant_names |
Vector storing the names of all pollutants. | |
std::vector< Subcatchment > | _subcatchments |
Vector storing information about all subcatchments. | |
std::vector< GeoLib::Point * > | _subcatchment_points |
Separate node vector containing points for defining subcatchment outlines. | |
std::vector< std::pair< GeoLib::Station, std::string > > | _rain_gauges |
Vector containing rain gauge information as well the position of external time series files. | |
std::unique_ptr< MeshLib::Mesh > | _mesh |
Mesh generated from SWMM input (+ optional output data) | |
FileIO::SwmmInterface::~SwmmInterface | ( | ) |
Destructor.
Definition at line 114 of file SWMMInterface.cpp.
References _subcatchment_points, and _subcatchments.
|
private |
Constructor.
Definition at line 109 of file SWMMInterface.cpp.
Referenced by create().
|
staticprivate |
During geometry conversion, this adds elevation values to the existing point vector.
Definition at line 266 of file SWMMInterface.cpp.
References ERR(), isCommentLine(), isSectionFinished(), BaseLib::splitString(), and BaseLib::str2number().
Referenced by convertSwmmInputToGeometry().
|
private |
Reads the location of external rain gauge time series files.
Definition at line 1231 of file SWMMInterface.cpp.
References _rain_gauges, ERR(), isCommentLine(), isSectionFinished(), BaseLib::splitString(), and WARN().
Referenced by readSwmmInputToLineMesh().
|
static |
If a mesh has already been created, this methods allows to add node- or link-arrays as property to that mesh. The data vectors can be created using the getArrayAtTimeStep() method.
Definition at line 990 of file SWMMInterface.cpp.
References MeshLib::Cell, ERR(), MeshLib::Mesh::getNumberOfElements(), MeshLib::Mesh::getNumberOfNodes(), MeshLib::getOrCreateMeshProperty(), FileIO::LINK, FileIO::NODE, and MeshLib::Node.
Referenced by addObjectsToMesh().
|
static |
Reading a SWMM input file and conversion into OGS geometry.
Definition at line 353 of file SWMMInterface.cpp.
References addPointElevation(), GeoLib::GEOObjects::addPointVec(), GeoLib::GEOObjects::addPolylineVec(), BaseLib::cleanupVectorElements(), ERR(), BaseLib::extractBaseNameWithoutExtension(), GeoLib::PointVec::getIDMap(), GeoLib::GEOObjects::getPointVecObj(), INFO(), isSwmmInputFile(), readCoordinates(), readLinksAsPolylines(), readPolygons(), and GeoLib::GEOObjects::removePointVec().
Referenced by writeGeoOutput().
|
static |
Basic method to create the interface (containing a mesh) from a SWMM file Other non-static methods rely on this being called in the beginning.
Definition at line 86 of file SWMMInterface.cpp.
References SwmmInterface(), ERR(), isSwmmInputFile(), and readSwmmInputToLineMesh().
Referenced by writeCsvOutput(), and writeMeshOutput().
bool FileIO::SwmmInterface::existsSwmmOutputFile | ( | ) | const |
Checks if a SWMM output file exists for the current input.
Definition at line 167 of file SWMMInterface.cpp.
References _base_name.
std::vector< double > FileIO::SwmmInterface::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 step.
Definition at line 1038 of file SWMMInterface.cpp.
References _base_name, ERR(), getArrayName(), INFO(), FileIO::LINK, FileIO::n_obj_params, FileIO::NODE, FileIO::SUBCATCHMENT, and FileIO::SYSTEM.
Referenced by addObjectsToMesh(), and writeCsvForTimestep().
std::vector< double > FileIO::SwmmInterface::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 steps.
Definition at line 1110 of file SWMMInterface.cpp.
References _base_name, ERR(), FileIO::LINK, FileIO::n_obj_params, FileIO::NODE, FileIO::SUBCATCHMENT, and FileIO::SYSTEM.
Referenced by writeCsvForObject().
std::string FileIO::SwmmInterface::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.
Definition at line 1184 of file SWMMInterface.cpp.
References _base_name, and getArrayName().
Referenced by addObjectsToMesh(), getArrayAtTimeStep(), getArrayName(), writeCsvForObject(), and writeCsvForTimestep().
|
private |
Returns the name of an array (or an empty string if errors occurred)
Definition at line 1196 of file SWMMInterface.cpp.
References _pollutant_names, ERR(), FileIO::LINK, FileIO::link_vars, FileIO::n_obj_params, FileIO::NODE, FileIO::node_vars, FileIO::SUBCATCHMENT, FileIO::subcatchment_vars, FileIO::SYSTEM, and FileIO::system_vars.
bool FileIO::SwmmInterface::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.
Definition at line 1316 of file SWMMInterface.cpp.
References _mesh, ERR(), and MeshLib::LINE.
|
inline |
Returns the mesh generated from SWMM file content.
Definition at line 73 of file SWMMInterface.h.
References _mesh.
std::string FileIO::SwmmInterface::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).
Definition at line 907 of file SWMMInterface.cpp.
References _id_linkname_map, _id_nodename_map, _subcatchments, ERR(), FileIO::LINK, FileIO::NODE, FileIO::SUBCATCHMENT, and FileIO::SYSTEM.
Referenced by writeObjectsOfSwmmTypeToCsv().
std::vector< std::string > FileIO::SwmmInterface::getNames | ( | SwmmObject | obj_type | ) | const |
Get all the object names for a given object type.
Definition at line 888 of file SWMMInterface.cpp.
References _id_linkname_map, _id_nodename_map, ERR(), getSubcatchmentNameMap(), FileIO::LINK, FileIO::NODE, FileIO::SUBCATCHMENT, and FileIO::SYSTEM.
Referenced by writeCsvForTimestep().
bool FileIO::SwmmInterface::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.
Definition at line 1302 of file SWMMInterface.cpp.
References _mesh.
std::size_t FileIO::SwmmInterface::getNumberOfObjects | ( | SwmmObject | obj_type | ) | const |
Returns the number of objects of the given type.
Definition at line 928 of file SWMMInterface.cpp.
References _base_name, ERR(), FileIO::LINK, FileIO::NODE, FileIO::SUBCATCHMENT, and FileIO::SYSTEM.
Referenced by writeCsvForTimestep(), and writeObjectsOfSwmmTypeToCsv().
std::size_t FileIO::SwmmInterface::getNumberOfParameters | ( | SwmmObject | obj_type | ) | const |
Returns the number of parameters (incl. pollutants) of the given type.
Definition at line 951 of file SWMMInterface.cpp.
References _base_name, ERR(), FileIO::LINK, FileIO::n_obj_params, FileIO::NODE, FileIO::SUBCATCHMENT, and FileIO::SYSTEM.
Referenced by addObjectsToMesh(), writeCsvForObject(), and writeCsvForTimestep().
std::size_t FileIO::SwmmInterface::getNumberOfTimeSteps | ( | ) | const |
Returns the number of time steps for the simulation results.
Definition at line 980 of file SWMMInterface.cpp.
References _base_name.
Referenced by writeCsvForObject().
|
private |
Creates a temporary string vector containing all subcatchment names in correct order.
Definition at line 878 of file SWMMInterface.cpp.
References _subcatchments.
Referenced by getNames().
|
staticprivate |
Checks if the given line string is a comment line.
Definition at line 1297 of file SWMMInterface.cpp.
Referenced by addPointElevation(), addRainGaugeTimeSeriesLocations(), isSwmmInputFile(), readCoordinates(), readLineElements(), readLinksAsPolylines(), readNodeData(), readPollutants(), readPolygons(), and readSubcatchments().
|
staticprivate |
Checks if the given line string is empty. Empty strings mark the end of sections in a SWMM input file.
Definition at line 1285 of file SWMMInterface.cpp.
Referenced by addPointElevation(), addRainGaugeTimeSeriesLocations(), readCoordinates(), readLineElements(), readLinksAsPolylines(), readNodeData(), readPollutants(), readPolygons(), and readSubcatchments().
|
static |
Checks if file is a SWMM input file.
Definition at line 123 of file SWMMInterface.cpp.
References ERR(), BaseLib::getFileExtension(), INFO(), and isCommentLine().
Referenced by convertSwmmInputToGeometry(), create(), and readSwmmInputToLineMesh().
|
private |
Matches existing subcatchment names with subsequently read polylines marking the outlines of said subcatchments.
Definition at line 845 of file SWMMInterface.cpp.
References _subcatchments, and ERR().
Referenced by readSwmmInputToLineMesh().
|
staticprivate |
Reading points from SWMM input file and converting them into OGS point-type vector. This method is shared by geometry- and mesh conversion.
Definition at line 176 of file SWMMInterface.cpp.
References ERR(), isCommentLine(), isSectionFinished(), BaseLib::splitString(), and BaseLib::str2number().
Referenced by convertSwmmInputToGeometry(), and readSwmmInputToLineMesh().
|
private |
Reads links/conduits and returns them as a vector of OGS line elements.
Definition at line 556 of file SWMMInterface.cpp.
References _id_linkname_map, ERR(), isCommentLine(), isSectionFinished(), and BaseLib::splitString().
Referenced by readSwmmInputToLineMesh().
|
staticprivate |
During geometry conversion, this reads links (conduits/pumps/weirs) and converts them into polylines.
Definition at line 301 of file SWMMInterface.cpp.
References GeoLib::Polyline::addPoint(), ERR(), isCommentLine(), isSectionFinished(), and BaseLib::splitString().
Referenced by convertSwmmInputToGeometry().
|
private |
Reads input information associated with nodes (elevation, depth, etc.)
Definition at line 515 of file SWMMInterface.cpp.
References ERR(), isCommentLine(), isSectionFinished(), BaseLib::splitString(), and BaseLib::str2number().
Referenced by readSwmmInputToLineMesh().
|
private |
Reads pollutant names and parameters.
Definition at line 1263 of file SWMMInterface.cpp.
References _pollutant_names, ERR(), isCommentLine(), isSectionFinished(), and BaseLib::splitString().
Referenced by readSwmmInputToLineMesh().
|
staticprivate |
During geometry conversion, this reads polygones representing subcatchments from the SWMM input file and converts them into OGS polyline vector.
Definition at line 207 of file SWMMInterface.cpp.
References ERR(), isCommentLine(), isSectionFinished(), BaseLib::splitString(), and BaseLib::str2number().
Referenced by convertSwmmInputToGeometry(), and readSwmmInputToLineMesh().
|
private |
Reads subcatchment information.
Definition at line 606 of file SWMMInterface.cpp.
References _rain_gauges, _subcatchments, FileIO::SwmmInterface::Subcatchment::area, ERR(), isCommentLine(), isSectionFinished(), FileIO::SwmmInterface::Subcatchment::name, FileIO::SwmmInterface::Subcatchment::outlet, FileIO::SwmmInterface::Subcatchment::rain_gauge, BaseLib::splitString(), and BaseLib::str2number().
Referenced by readSwmmInputToLineMesh().
|
private |
Reading a SWMM input file and creating an OGS line mesh. This is automatically called when the object is created.
Definition at line 657 of file SWMMInterface.cpp.
References _base_name, _id_nodename_map, _mesh, _rain_gauges, _subcatchment_points, addRainGaugeTimeSeriesLocations(), MeshLib::Cell, MeshLib::Properties::createNewPropertyVector(), ERR(), INFO(), isSwmmInputFile(), matchSubcatchmentsWithPolygons(), MeshLib::Node, readCoordinates(), readLineElements(), readNodeData(), readPollutants(), readPolygons(), and readSubcatchments().
Referenced by create().
|
static |
Returns a string with the name of the object type.
Definition at line 1333 of file SWMMInterface.cpp.
References FileIO::LINK, FileIO::NODE, FileIO::SUBCATCHMENT, and FileIO::SYSTEM.
Referenced by writeCsvForObject(), and writeObjectsOfSwmmTypeToCsv().
bool FileIO::SwmmInterface::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.
Definition at line 1369 of file SWMMInterface.cpp.
References FileIO::CsvInterface::addIndexVectorForWriting(), FileIO::CsvInterface::addVectorForWriting(), ERR(), getArrayForObject(), getArrayName(), FileIO::CsvInterface::getNArrays(), getNumberOfParameters(), getNumberOfTimeSteps(), INFO(), swmmObjectTypeToString(), BaseLib::IO::writeStringToFile(), and BaseLib::IO::Writer::writeToString().
Referenced by writeObjectsOfSwmmTypeToCsv().
bool FileIO::SwmmInterface::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.
Definition at line 1346 of file SWMMInterface.cpp.
References FileIO::CsvInterface::addIndexVectorForWriting(), FileIO::CsvInterface::addVectorForWriting(), ERR(), getArrayAtTimeStep(), getArrayName(), getNames(), FileIO::CsvInterface::getNArrays(), getNumberOfObjects(), getNumberOfParameters(), BaseLib::IO::writeStringToFile(), and BaseLib::IO::Writer::writeToString().
|
private |
All files for a given SWMM simulation have the same base name.
Definition at line 201 of file SWMMInterface.h.
Referenced by existsSwmmOutputFile(), getArrayAtTimeStep(), getArrayForObject(), getArrayName(), getNumberOfObjects(), getNumberOfParameters(), getNumberOfTimeSteps(), and readSwmmInputToLineMesh().
|
private |
Vector storing the names of all links/conduits.
Definition at line 205 of file SWMMInterface.h.
Referenced by getName(), getNames(), and readLineElements().
|
private |
Vector storing the names of all nodes/junctions.
Definition at line 203 of file SWMMInterface.h.
Referenced by getName(), getNames(), and readSwmmInputToLineMesh().
|
private |
Mesh generated from SWMM input (+ optional output data)
Definition at line 215 of file SWMMInterface.h.
Referenced by getLinkPointIds(), getMesh(), getNodeCoordinateVectors(), and readSwmmInputToLineMesh().
|
private |
Vector storing the names of all pollutants.
Definition at line 207 of file SWMMInterface.h.
Referenced by getArrayName(), and readPollutants().
|
private |
Vector containing rain gauge information as well the position of external time series files.
Definition at line 213 of file SWMMInterface.h.
Referenced by addRainGaugeTimeSeriesLocations(), readSubcatchments(), and readSwmmInputToLineMesh().
|
private |
Separate node vector containing points for defining subcatchment outlines.
Definition at line 211 of file SWMMInterface.h.
Referenced by ~SwmmInterface(), and readSwmmInputToLineMesh().
|
private |
Vector storing information about all subcatchments.
Definition at line 209 of file SWMMInterface.h.
Referenced by ~SwmmInterface(), getName(), getSubcatchmentNameMap(), matchSubcatchmentsWithPolygons(), and readSubcatchments().