OGS
LayeredMeshGenerator.cpp
Go to the documentation of this file.
1
16
17#include <fstream>
18#include <vector>
19
20#include "BaseLib/Logging.h"
21#include "GeoLib/Raster.h"
23#include "MeshLib/Mesh.h"
25#include "MeshLib/Node.h"
26#include "MeshLib/Properties.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
59std::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,
93 _nodes,
95 true /* compute_element_neighbors */,
96 properties));
97 MeshLib::NodeSearch ns(*result);
98 if (ns.searchUnused() > 0)
99 {
100 std::unique_ptr<MeshLib::Mesh> new_mesh(MeshToolsLib::removeNodes(
101 *result, ns.getSearchedNodeIDs(), mesh_name));
102 return new_mesh;
103 }
104 return result;
105}
106
108 GeoLib::Raster const& high)
109{
110 const double max(*std::max_element(high.begin(), high.end()));
111 const double min(*std::min_element(low.begin(), low.end()));
112 return ((max - min) * 1e-07);
113}
114
116 MeshLib::Node const& dem_node,
117 MeshLib::Node const& last_layer_node,
118 GeoLib::Raster const& raster,
119 std::size_t new_node_id) const
120{
121 double const elevation =
122 std::min(raster.interpolateValueAtPoint(dem_node), dem_node[2]);
123
124 if ((std::abs(elevation - raster.getHeader().no_data) <
125 std::numeric_limits<double>::epsilon()) ||
126 (elevation - last_layer_node[2] < _minimum_thickness))
127 {
128 return new MeshLib::Node(last_layer_node);
129 }
130
131 return new MeshLib::Node(dem_node[0], dem_node[1], elevation, new_node_id);
132}
Definition of the Element class.
Definition of the SubsurfaceMapper class.
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
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:49
std::vector< double >::const_iterator begin() const
Definition Raster.h:96
double interpolateValueAtPoint(const MathLib::Point3d &pnt) const
Definition Raster.cpp:85
RasterHeader const & getHeader() const
Returns the complete header information.
Definition Raster.h:85
std::vector< double >::const_iterator end() const
Definition Raster.h:106
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
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:88
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.
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
Definition Properties.h:36
PropertyVector< T > * createNewPropertyVector(std::string_view name, MeshItemType mesh_item_type, std::size_t n_components=1)
Definition Properties.h:17
static std::map< MeshLib::MeshElemType, unsigned > getNumberOfElementTypes(const MeshLib::Mesh &mesh)
MeshLib::Mesh * removeNodes(const MeshLib::Mesh &mesh, const std::vector< std::size_t > &del_nodes_idx, const std::string &new_mesh_name)