OGS
LayeredMeshGenerator.cpp
Go to the documentation of this file.
1 
15 #include "LayeredMeshGenerator.h"
16 
17 #include <fstream>
18 #include <vector>
19 
20 #include "BaseLib/Logging.h"
21 #include "GeoLib/Raster.h"
23 #include "MeshLib/Mesh.h"
27 #include "MeshLib/Node.h"
28 #include "MeshLib/Properties.h"
29 #include "MeshLib/PropertyVector.h"
30 
32  MeshLib::Mesh const& mesh,
33  std::vector<GeoLib::Raster const*> const& rasters,
34  double minimum_thickness,
35  double noDataReplacementValue)
36 {
37  if (mesh.getDimension() != 2)
38  {
39  return false;
40  }
41 
42  auto const elem_count =
44  if (elem_count.find(MeshLib::MeshElemType::QUAD) != elem_count.end())
45  {
46  ERR("Input mesh contains QUAD-elements. Please use input mesh "
47  "containing LINE and TRIANGLE elements only.");
48  return false;
49  }
50 
51  bool result = createRasterLayers(
52  mesh, rasters, minimum_thickness, noDataReplacementValue);
53  std::for_each(rasters.begin(),
54  rasters.end(),
55  [](GeoLib::Raster const* const raster) { delete raster; });
56  return result;
57 }
58 
59 std::unique_ptr<MeshLib::Mesh> LayeredMeshGenerator::getMesh(
60  std::string const& mesh_name) const
61 {
62  if (_nodes.empty())
63  {
64  WARN("LayeredMeshGenerator has not created any nodes.");
65  return nullptr;
66  }
67  if (_elements.empty())
68  {
69  WARN("LayeredMeshGenerator has not created any elements.");
70  return nullptr;
71  }
72 
73  MeshLib::Properties properties;
74  if (_materials.size() == _elements.size())
75  {
76  auto* const materials = properties.createNewPropertyVector<int>(
77  "MaterialIDs", MeshLib::MeshItemType::Cell);
78  assert(materials != nullptr);
79  materials->reserve(_materials.size());
80  std::copy(_materials.cbegin(),
81  _materials.cend(),
82  std::back_inserter(*materials));
83  }
84  else
85  {
86  WARN(
87  "Skipping MaterialID information, number of entries does not match "
88  "element number");
89  }
90 
91  std::unique_ptr<MeshLib::Mesh> result(
92  new MeshLib::Mesh(mesh_name, _nodes, _elements, properties));
93  MeshLib::NodeSearch ns(*result);
94  if (ns.searchUnused() > 0)
95  {
96  std::unique_ptr<MeshLib::Mesh> new_mesh(
97  MeshLib::removeNodes(*result, ns.getSearchedNodeIDs(), mesh_name));
98  return new_mesh;
99  }
100  return result;
101 }
102 
104  GeoLib::Raster const& high)
105 {
106  const double max(*std::max_element(high.begin(), high.end()));
107  const double min(*std::min_element(low.begin(), low.end()));
108  return ((max - min) * 1e-07);
109 }
110 
112  MeshLib::Node const& dem_node,
113  MeshLib::Node const& last_layer_node,
114  GeoLib::Raster const& raster,
115  std::size_t new_node_id) const
116 {
117  double const elevation =
118  std::min(raster.interpolateValueAtPoint(dem_node), dem_node[2]);
119 
120  if ((std::abs(elevation - raster.getHeader().no_data) <
121  std::numeric_limits<double>::epsilon()) ||
122  (elevation - last_layer_node[2] < _minimum_thickness))
123  {
124  return new MeshLib::Node(last_layer_node);
125  }
126 
127  return new MeshLib::Node(dem_node[0], dem_node[1], elevation, new_node_id);
128 }
Definition of the Element class.
Definition of the SubsurfaceMapper class.
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
void WARN(char const *fmt, Args const &... args)
Definition: Logging.h:37
Definition of the MeshInformation class.
Definition of the class Properties that implements a container of properties.
Definition of the Mesh class.
Definition of the Node class.
Definition of the GeoLib::Raster class.
Class Raster is used for managing raster data.
Definition: Raster.h:42
double interpolateValueAtPoint(const MathLib::Point3d &pnt) const
Interpolates the elevation of the given point based on the 8-neighbourhood of the raster cell it is l...
Definition: Raster.cpp:92
const_iterator begin() const
Definition: Raster.h:81
RasterHeader const & getHeader() const
Returns the complete header information.
Definition: Raster.h:70
const_iterator end() const
Definition: Raster.h:86
virtual bool createLayers(MeshLib::Mesh const &mesh, std::vector< GeoLib::Raster const * > const &rasters, double minimum_thickness, double noDataReplacementValue=0.0) final
std::vector< int > _materials
static double calcEpsilon(GeoLib::Raster const &low, GeoLib::Raster const &high)
Calculates a data-dependent epsilon value.
MeshLib::Node * getNewLayerNode(MeshLib::Node const &dem_node, MeshLib::Node const &last_layer_node, GeoLib::Raster const &raster, std::size_t new_node_id) const
std::vector< MeshLib::Node * > _nodes
virtual bool createRasterLayers(MeshLib::Mesh const &mesh, std::vector< GeoLib::Raster const * > const &rasters, double minimum_thickness, double noDataReplacementValue)=0
std::unique_ptr< MeshLib::Mesh > getMesh(std::string const &mesh_name) const
Returns a mesh of the subsurface representation.
std::vector< MeshLib::Element * > _elements
static std::map< MeshElemType, unsigned > getNumberOfElementTypes(const MeshLib::Mesh &mesh)
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition: Mesh.h:71
Node search class.
Definition: NodeSearch.h:25
const std::vector< std::size_t > & getSearchedNodeIDs() const
return marked node IDs
Definition: NodeSearch.h:30
std::size_t searchUnused()
Marks all unused nodes.
Definition: NodeSearch.cpp:58
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
Definition: Properties.h:36
PropertyVector< T > * createNewPropertyVector(std::string const &name, MeshItemType mesh_item_type, std::size_t n_components=1)
void copy(PETScVector const &x, PETScVector &y)
Definition: LinAlg.cpp:37
MeshLib::Mesh * removeNodes(const MeshLib::Mesh &mesh, const std::vector< std::size_t > &del_nodes_idx, const std::string &new_mesh_name)