OGS
FileIO::GMSH::GMSHInterface Class Referencefinal

Detailed Description

Reads and writes GMSH-files to and from OGS data structures.

Definition at line 45 of file GMSHInterface.h.

#include <GMSHInterface.h>

Inheritance diagram for FileIO::GMSH::GMSHInterface:
[legend]
Collaboration diagram for FileIO::GMSH::GMSHInterface:
[legend]

Public Member Functions

 GMSHInterface (GeoLib::GEOObjects &geo_objs, bool include_stations_as_constraints, GMSH::MeshDensityAlgorithm mesh_density_algorithm, double pnt_density, double station_density, std::size_t max_pnts_per_leaf, std::vector< std::string > const &selected_geometries, bool rotate, bool keep_preprocessed_geometry)
 
 GMSHInterface (GMSHInterface const &)=delete
 
 GMSHInterface (GMSHInterface &&)=delete
 
GMSHInterfaceoperator= (GMSHInterface const &)=delete
 
GMSHInterfaceoperator= (GMSHInterface &&)=delete
 
 ~GMSHInterface () override
 
void writePhysicalGroups (bool flag)
 
- Public Member Functions inherited from BaseLib::IO::Writer
 Writer ()
 
virtual ~Writer ()=default
 
std::string writeToString ()
 Writes the object to a string. More...
 

Protected Member Functions

bool write () override
 Writes the object to the internal stream. This method must be implemented by a subclass. The implementation should return true on success, else false. More...
 

Private Member Functions

int writeGMSHInputFile (std::ostream &out)
 

Private Attributes

std::size_t _n_lines
 
std::size_t _n_plane_sfc
 
GeoLib::GEOObjects_geo_objs
 
std::vector< std::string > const & _selected_geometries
 
std::string _gmsh_geo_name
 
std::list< GMSH::GMSHPolygonTree * > _polygon_tree_list
 
std::vector< GMSH::GMSHPoint * > _gmsh_pnts
 
std::unique_ptr< GMSH::GMSHMeshDensityStrategy_mesh_density_strategy
 
Eigen::Matrix3d _inverse_rot_mat = Eigen::Matrix3d::Zero()
 
bool const _rotate = false
 
bool _keep_preprocessed_geometry = true
 
bool _write_physical_groups = false
 

Additional Inherited Members

- Protected Attributes inherited from BaseLib::IO::Writer
std::ostringstream out
 The stream to write to. More...
 

Constructor & Destructor Documentation

◆ GMSHInterface() [1/3]

FileIO::GMSH::GMSHInterface::GMSHInterface ( GeoLib::GEOObjects geo_objs,
bool  include_stations_as_constraints,
GMSH::MeshDensityAlgorithm  mesh_density_algorithm,
double  pnt_density,
double  station_density,
std::size_t  max_pnts_per_leaf,
std::vector< std::string > const &  selected_geometries,
bool  rotate,
bool  keep_preprocessed_geometry 
)
Parameters
geo_objsreference to instance of class GEOObject that maintains the geometries. The instance is used for preparation geometries for writing them to the gmsh file format.
include_stations_as_constraintsswitch to enable writing stations as constraints
mesh_density_algorithmone of the mesh density algorithms (@see enum MeshDensityAlgorithm)
pnt_densityparameter of the mesh density algorithm
station_densityparameter of the mesh density algorithm
max_pnts_per_leafparameter of the mesh density algorithm
selected_geometriesvector of names of geometries, that should be employed for mesh generation.
rotateif the value of the parameter is true then the input points will be rotated on the \(x\)- \(y\)-plane, else the input points will be (orthogonal) projected to the \(x\)- \(y\)-plane.
keep_preprocessed_geometrykeep the pre-processed geometry, useful for debugging the mesh creation

Definition at line 48 of file GMSHInterface.cpp.

55  : _n_lines(0),
56  _n_plane_sfc(0),
57  _geo_objs(geo_objs),
58  _selected_geometries(selected_geometries),
59  _rotate(rotate),
60  _keep_preprocessed_geometry(keep_preprocessed_geometry)
61 {
62  switch (mesh_density_algorithm)
63  {
66  std::make_unique<GMSH::GMSHFixedMeshDensity>(pnt_density);
67  break;
70  std::make_unique<GMSH::GMSHAdaptiveMeshDensity>(
71  pnt_density, station_density, max_pnts_per_leaf);
72  break;
73  }
74 }
std::unique_ptr< GMSH::GMSHMeshDensityStrategy > _mesh_density_strategy
std::vector< std::string > const & _selected_geometries
GeoLib::GEOObjects & _geo_objs
@ AdaptiveMeshDensity
computing the mesh density employing a QuadTree
@ FixedMeshDensity
set the parameter with a fixed value

References _mesh_density_strategy, FileIO::GMSH::AdaptiveMeshDensity, and FileIO::GMSH::FixedMeshDensity.

◆ GMSHInterface() [2/3]

FileIO::GMSH::GMSHInterface::GMSHInterface ( GMSHInterface const &  )
delete

◆ GMSHInterface() [3/3]

FileIO::GMSH::GMSHInterface::GMSHInterface ( GMSHInterface &&  )
delete

◆ ~GMSHInterface()

FileIO::GMSH::GMSHInterface::~GMSHInterface ( )
override

Definition at line 76 of file GMSHInterface.cpp.

77 {
78  for (auto* gmsh_pnt : _gmsh_pnts)
79  {
80  delete gmsh_pnt;
81  }
82  for (auto* polygon_tree : _polygon_tree_list)
83  {
84  delete polygon_tree;
85  }
86 }
std::vector< GMSH::GMSHPoint * > _gmsh_pnts
std::list< GMSH::GMSHPolygonTree * > _polygon_tree_list

References _gmsh_pnts, and _polygon_tree_list.

Member Function Documentation

◆ operator=() [1/2]

GMSHInterface& FileIO::GMSH::GMSHInterface::operator= ( GMSHInterface &&  )
delete

◆ operator=() [2/2]

GMSHInterface& FileIO::GMSH::GMSHInterface::operator= ( GMSHInterface const &  )
delete

◆ write()

bool FileIO::GMSH::GMSHInterface::write ( )
overrideprotectedvirtual

Writes the object to the internal stream. This method must be implemented by a subclass. The implementation should return true on success, else false.

Implements BaseLib::IO::Writer.

Definition at line 88 of file GMSHInterface.cpp.

89 {
90  out << "// GMSH input file created by OpenGeoSys "
92  out << "\n\n";
93 
94  return writeGMSHInputFile(out) <= 0;
95 }
std::ostringstream out
The stream to write to.
Definition: Writer.h:46
int writeGMSHInputFile(std::ostream &out)
GITINFOLIB_EXPORT const std::string ogs_version

References GitInfoLib::GitInfo::ogs_version, BaseLib::IO::Writer::out, and writeGMSHInputFile().

◆ writeGMSHInputFile()

int FileIO::GMSH::GMSHInterface::writeGMSHInputFile ( std::ostream &  out)
private
  1. get and merge data from _geo_objs
  2. compute topological hierarchy
    Parameters
    out
    Todo:
    activate error codes and hand them on to the Writer class, i.e. 0 = okay, 1 = geo_objects is empty, 2 = error while merging, 3 = error writing file

Definition at line 97 of file GMSHInterface.cpp.

98 {
99  DBUG("GMSHInterface::writeGMSHInputFile(): get data from GEOObjects.");
100 
101  if (_selected_geometries.empty())
102  {
103  return 1;
104  }
105 
106  // *** get and merge data from _geo_objs
107  if (_selected_geometries.size() > 1)
108  {
109  _gmsh_geo_name = "GMSHGeometry";
111  {
112  return 2;
113  }
114  }
115  else
116  {
119  }
120 
121  auto* merged_pnts(const_cast<std::vector<GeoLib::Point*>*>(
123  if (!merged_pnts)
124  {
125  ERR("GMSHInterface::writeGMSHInputFile(): Did not found any points.");
126  return 2;
127  }
128 
129  if (_rotate)
130  {
131  // Rotate points to the x-y-plane.
133  // Compute inverse rotation matrix to reverse the rotation later on.
134  _inverse_rot_mat.transposeInPlace();
135  }
136  else
137  {
138  // project data on the x-y-plane
139  _inverse_rot_mat = Eigen::Matrix3d::Identity();
140  for (auto pnt : *merged_pnts)
141  {
142  (*pnt)[2] = 0.0;
143  }
144  }
145 
146  std::vector<GeoLib::Polyline*> const* merged_plys(
148  DBUG("GMSHInterface::writeGMSHInputFile(): Obtained data.");
149 
150  if (!merged_plys)
151  {
152  ERR("GMSHInterface::writeGMSHInputFile(): Did not find any polylines.");
153  return 2;
154  }
155 
156  // *** compute and insert all intersection points between polylines
157  GeoLib::PointVec& pnt_vec(*const_cast<GeoLib::PointVec*>(
160  pnt_vec, *(const_cast<std::vector<GeoLib::Polyline*>*>(merged_plys)));
161 
162  std::vector<GeoLib::Polyline*> polygons;
163  // for each closed polyline add a PolygonWithSegmentMarker object into
164  // polygons
165  for (auto polyline : *merged_plys)
166  {
167  if (!polyline->isClosed())
168  {
169  continue;
170  }
171  polygons.push_back(new GeoLib::PolygonWithSegmentMarker(*polyline));
172  }
173  if (polygons.empty())
174  {
175  OGS_FATAL("GMSHInterface::writeGMSHInputFile(): no polygons found.");
176  }
177  // let the polygon memory management be done by GEOObjects
179  // create for each polygon a PolygonTree
180  for (auto* polygon : polygons)
181  {
182  _polygon_tree_list.push_back(new GMSH::GMSHPolygonTree(
183  dynamic_cast<GeoLib::PolygonWithSegmentMarker*>(polygon), nullptr,
185  }
186  DBUG(
187  "GMSHInterface::writeGMSHInputFile(): Computed topological hierarchy - "
188  "detected {:d} polygons.",
189  _polygon_tree_list.size());
190  // compute topological hierarchy of polygons
191  GeoLib::createPolygonTrees<GMSH::GMSHPolygonTree>(_polygon_tree_list);
192  DBUG(
193  "GMSHInterface::writeGMSHInputFile(): Computed topological hierarchy - "
194  "calculated {:d} polygon trees.",
195  _polygon_tree_list.size());
196 
197  // *** Mark in each polygon tree the segments shared by two polygons.
198  for (auto* polygon_tree : _polygon_tree_list)
199  {
200  polygon_tree->markSharedSegments();
201  }
202 
203  // *** insert stations and polylines (except polygons) in the appropriate
204  // object of
205  // class GMSHPolygonTree
206  // *** insert stations
207  auto gmsh_stations = std::make_unique<std::vector<GeoLib::Point*>>();
208  for (auto const& geometry_name : _selected_geometries)
209  {
210  auto const* stations(_geo_objs.getStationVec(geometry_name));
211  if (stations)
212  {
213  for (auto* station : *stations)
214  {
215  bool found(false);
216  for (auto it(_polygon_tree_list.begin());
217  it != _polygon_tree_list.end() && !found;
218  ++it)
219  {
220  gmsh_stations->emplace_back(new GeoLib::Station(
221  *static_cast<GeoLib::Station*>(station)));
222  if ((*it)->insertStation(gmsh_stations->back()))
223  {
224  found = true;
225  }
226  }
227  }
228  }
229  }
230  std::string gmsh_stations_name(_gmsh_geo_name + "-Stations");
231  if (!gmsh_stations->empty())
232  {
233  _geo_objs.addStationVec(std::move(gmsh_stations), gmsh_stations_name);
234  }
235 
236  // *** insert polylines
237  for (auto polyline : *merged_plys)
238  {
239  if (!polyline->isClosed())
240  {
241  for (auto* polygon_tree : _polygon_tree_list)
242  {
243  auto polyline_with_segment_marker =
244  new GeoLib::PolylineWithSegmentMarker(*polyline);
245  polygon_tree->insertPolyline(polyline_with_segment_marker);
246  }
247  }
248  }
249 
250  // *** init mesh density strategies
251  for (auto& polygon_tree : _polygon_tree_list)
252  {
253  polygon_tree->initMeshDensityStrategy();
254  }
255 
256  // *** create GMSH data structures
257  const std::size_t n_merged_pnts(merged_pnts->size());
258  _gmsh_pnts.resize(n_merged_pnts);
259  for (std::size_t k(0); k < n_merged_pnts; k++)
260  {
261  _gmsh_pnts[k] = nullptr;
262  }
263  for (auto& polygon_tree : _polygon_tree_list)
264  {
265  polygon_tree->createGMSHPoints(_gmsh_pnts);
266  }
267 
268  // *** finally write data :-)
270  out << _gmsh_pnts;
271 
272  std::size_t pnt_id_offset(_gmsh_pnts.size());
273  for (auto* polygon_tree : _polygon_tree_list)
274  {
275  polygon_tree->writeLineLoop(_n_lines, _n_plane_sfc, out,
277  polygon_tree->writeSubPolygonsAsLineConstraints(_n_lines,
278  _n_plane_sfc - 1, out);
279  polygon_tree->writeLineConstraints(_n_lines, _n_plane_sfc - 1, out);
280  polygon_tree->writeStations(pnt_id_offset, _n_plane_sfc - 1, out);
281  polygon_tree->writeAdditionalPointData(pnt_id_offset, _n_plane_sfc - 1,
282  out);
283  }
284 
286  {
290  _geo_objs.removeStationVec(gmsh_stations_name);
291  }
292 
293  return 0;
294 }
#define OGS_FATAL(...)
Definition: Error.h:26
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
void DBUG(char const *fmt, Args const &... args)
Definition: Logging.h:27
Eigen::Matrix3d _inverse_rot_mat
void addStationVec(std::unique_ptr< std::vector< Point * >> stations, std::string &name)
Adds a vector of stations with the given name and colour to GEOObjects.
Definition: GEOObjects.cpp:122
const std::vector< Point * > * getPointVec(const std::string &name) const
Definition: GEOObjects.cpp:71
const PointVec * getPointVecObj(const std::string &name) const
Definition: GEOObjects.cpp:84
bool removePointVec(const std::string &name)
Definition: GEOObjects.cpp:97
bool removeSurfaceVec(const std::string &name)
Definition: GEOObjects.cpp:323
bool removeStationVec(const std::string &name)
Removes the station vector with the given name from GEOObjects.
Definition: GEOObjects.h:131
int mergeGeometries(std::vector< std::string > const &geo_names, std::string &merged_geo_name)
Definition: GEOObjects.cpp:435
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
Definition: GEOObjects.cpp:210
bool appendPolylineVec(const std::vector< Polyline * > &polylines, const std::string &name)
Definition: GEOObjects.cpp:180
const std::vector< GeoLib::Point * > * getStationVec(const std::string &name) const
Returns the station vector with the given name.
Definition: GEOObjects.cpp:131
bool removePolylineVec(const std::string &name)
Definition: GEOObjects.cpp:243
This class manages pointers to Points in a std::vector along with a name. It also handles the deletio...
Definition: PointVec.h:38
A Station (observation site) is basically a Point with some additional information.
Definition: Station.h:37
void computeAndInsertAllIntersectionPoints(GeoLib::PointVec &pnt_vec, std::vector< GeoLib::Polyline * > &plys)
void rotatePoints(Eigen::Matrix3d const &rot_mat, InputIterator pnts_begin, InputIterator pnts_end)
Eigen::Matrix3d rotatePointsToXY(InputIterator1 p_pnts_begin, InputIterator1 p_pnts_end, InputIterator2 r_pnts_begin, InputIterator2 r_pnts_end)

References _geo_objs, _gmsh_geo_name, _gmsh_pnts, _inverse_rot_mat, _keep_preprocessed_geometry, _mesh_density_strategy, _n_lines, _n_plane_sfc, _polygon_tree_list, _rotate, _selected_geometries, _write_physical_groups, GeoLib::GEOObjects::addStationVec(), GeoLib::GEOObjects::appendPolylineVec(), GeoLib::computeAndInsertAllIntersectionPoints(), DBUG(), ERR(), GeoLib::GEOObjects::getPointVec(), GeoLib::GEOObjects::getPointVecObj(), GeoLib::GEOObjects::getPolylineVec(), GeoLib::GEOObjects::getStationVec(), GeoLib::GEOObjects::mergeGeometries(), OGS_FATAL, BaseLib::IO::Writer::out, GeoLib::GEOObjects::removePointVec(), GeoLib::GEOObjects::removePolylineVec(), GeoLib::GEOObjects::removeStationVec(), GeoLib::GEOObjects::removeSurfaceVec(), GeoLib::rotatePoints(), and GeoLib::rotatePointsToXY().

Referenced by write().

◆ writePhysicalGroups()

void FileIO::GMSH::GMSHInterface::writePhysicalGroups ( bool  flag)
inline

Definition at line 83 of file GMSHInterface.h.

83 { _write_physical_groups = flag; }

References _write_physical_groups.

Referenced by generateMesh().

Member Data Documentation

◆ _geo_objs

GeoLib::GEOObjects& FileIO::GMSH::GMSHInterface::_geo_objs
private

Definition at line 102 of file GMSHInterface.h.

Referenced by writeGMSHInputFile().

◆ _gmsh_geo_name

std::string FileIO::GMSH::GMSHInterface::_gmsh_geo_name
private

Definition at line 104 of file GMSHInterface.h.

Referenced by writeGMSHInputFile().

◆ _gmsh_pnts

std::vector<GMSH::GMSHPoint*> FileIO::GMSH::GMSHInterface::_gmsh_pnts
private

Definition at line 107 of file GMSHInterface.h.

Referenced by ~GMSHInterface(), and writeGMSHInputFile().

◆ _inverse_rot_mat

Eigen::Matrix3d FileIO::GMSH::GMSHInterface::_inverse_rot_mat = Eigen::Matrix3d::Zero()
private

Holds the inverse rotation matrix. The matrix is used to revert the rotation done in writeGMSHInputFile().

Definition at line 112 of file GMSHInterface.h.

Referenced by writeGMSHInputFile().

◆ _keep_preprocessed_geometry

bool FileIO::GMSH::GMSHInterface::_keep_preprocessed_geometry = true
private

Definition at line 116 of file GMSHInterface.h.

Referenced by writeGMSHInputFile().

◆ _mesh_density_strategy

std::unique_ptr<GMSH::GMSHMeshDensityStrategy> FileIO::GMSH::GMSHInterface::_mesh_density_strategy
private

Definition at line 109 of file GMSHInterface.h.

Referenced by GMSHInterface(), and writeGMSHInputFile().

◆ _n_lines

std::size_t FileIO::GMSH::GMSHInterface::_n_lines
private

Definition at line 99 of file GMSHInterface.h.

Referenced by writeGMSHInputFile().

◆ _n_plane_sfc

std::size_t FileIO::GMSH::GMSHInterface::_n_plane_sfc
private

Definition at line 100 of file GMSHInterface.h.

Referenced by writeGMSHInputFile().

◆ _polygon_tree_list

std::list<GMSH::GMSHPolygonTree*> FileIO::GMSH::GMSHInterface::_polygon_tree_list
private

Definition at line 105 of file GMSHInterface.h.

Referenced by ~GMSHInterface(), and writeGMSHInputFile().

◆ _rotate

bool const FileIO::GMSH::GMSHInterface::_rotate = false
private

Signals if the input points should be rotated or projected to the \(x\)- \(y\)-plane

Definition at line 115 of file GMSHInterface.h.

Referenced by writeGMSHInputFile().

◆ _selected_geometries

std::vector<std::string> const& FileIO::GMSH::GMSHInterface::_selected_geometries
private

Definition at line 103 of file GMSHInterface.h.

Referenced by writeGMSHInputFile().

◆ _write_physical_groups

bool FileIO::GMSH::GMSHInterface::_write_physical_groups = false
private

Definition at line 117 of file GMSHInterface.h.

Referenced by writeGMSHInputFile(), and writePhysicalGroups().


The documentation for this class was generated from the following files: