OGS
LayeredMeshGenerator Class Referenceabstract

Detailed Description

Base class for creation of 3D subsurface meshes based on raster data.

Definition at line 37 of file LayeredMeshGenerator.h.

#include <LayeredMeshGenerator.h>

Inheritance diagram for LayeredMeshGenerator:
[legend]

Public Member Functions

virtual bool createLayers (MeshLib::Mesh const &mesh, std::vector< GeoLib::Raster const * > const &rasters, double minimum_thickness, double noDataReplacementValue=0.0) final
 
virtual bool createRasterLayers (MeshLib::Mesh const &mesh, std::vector< GeoLib::Raster const * > const &rasters, double minimum_thickness, double noDataReplacementValue)=0
 
std::unique_ptr< MeshLib::MeshgetMesh (std::string const &mesh_name) const
 Returns a mesh of the subsurface representation.
 

Protected Member Functions

 LayeredMeshGenerator ()=default
 
virtual ~LayeredMeshGenerator ()=default
 
virtual void addLayerToMesh (MeshLib::Mesh const &mesh_layer, unsigned layer_id, GeoLib::Raster const &raster)=0
 Adds another layer to the subsurface mesh.
 
MeshLib::NodegetNewLayerNode (MeshLib::Node const &dem_node, MeshLib::Node const &last_layer_node, GeoLib::Raster const &raster, std::size_t new_node_id) const
 

Static Protected Member Functions

static double calcEpsilon (GeoLib::Raster const &low, GeoLib::Raster const &high)
 Calculates a data-dependent epsilon value.
 

Protected Attributes

double _elevation_epsilon {0.0001}
 
double _minimum_thickness {std::numeric_limits<float>::epsilon()}
 
std::vector< int > _materials
 
std::vector< MeshLib::Node * > _nodes
 
std::vector< MeshLib::Element * > _elements
 

Constructor & Destructor Documentation

◆ LayeredMeshGenerator()

LayeredMeshGenerator::LayeredMeshGenerator ( )
protecteddefault

◆ ~LayeredMeshGenerator()

virtual LayeredMeshGenerator::~LayeredMeshGenerator ( )
protectedvirtualdefault

Member Function Documentation

◆ addLayerToMesh()

virtual void LayeredMeshGenerator::addLayerToMesh ( MeshLib::Mesh const &  mesh_layer,
unsigned  layer_id,
GeoLib::Raster const &  raster 
)
protectedpure virtual

Adds another layer to the subsurface mesh.

Implemented in LayeredVolume, and MeshToolsLib::MeshLayerMapper.

◆ calcEpsilon()

double LayeredMeshGenerator::calcEpsilon ( GeoLib::Raster const &  low,
GeoLib::Raster const &  high 
)
staticprotected

Calculates a data-dependent epsilon value.

Definition at line 103 of file LayeredMeshGenerator.cpp.

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}

References GeoLib::Raster::begin(), and GeoLib::Raster::end().

Referenced by LayeredVolume::createRasterLayers().

◆ createLayers()

bool LayeredMeshGenerator::createLayers ( MeshLib::Mesh const &  mesh,
std::vector< GeoLib::Raster const * > const &  rasters,
double  minimum_thickness,
double  noDataReplacementValue = 0.0 
)
finalvirtual

Returns a subsurface representation of a region represented by a 2D mesh by reading raster files and calling the appropriate construction method.

Parameters
meshThe 2D surface mesh that is used as a basis for the subsurface mesh
rastersContaining all the rasters for the subsurface layers from bottom to top (starting with the bottom of the oldest layer and ending with the DEM)
minimum_thicknessMinimum thickness of each of the newly created layers (i.e. nodes with a vertical distance smaller than this will be collapsed)
noDataReplacementValueDefault z-coordinate if there are mesh nodes not located on the DEM raster (i.e. raster_paths[0])
Returns
true if the subsurface representation has been created, false if there was an error

Definition at line 31 of file LayeredMeshGenerator.cpp.

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}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition: Logging.h:45
Class Raster is used for managing raster data.
Definition: Raster.h:49
virtual bool createRasterLayers(MeshLib::Mesh const &mesh, std::vector< GeoLib::Raster const * > const &rasters, double minimum_thickness, double noDataReplacementValue)=0
static std::map< MeshLib::MeshElemType, unsigned > getNumberOfElementTypes(const MeshLib::Mesh &mesh)

References createRasterLayers(), ERR(), MeshLib::Mesh::getDimension(), MeshToolsLib::MeshInformation::getNumberOfElementTypes(), and MeshLib::QUAD.

Referenced by MeshLayerEditDialog::createPrismMesh(), MeshLayerEditDialog::createTetMesh(), and main().

◆ createRasterLayers()

virtual bool LayeredMeshGenerator::createRasterLayers ( MeshLib::Mesh const &  mesh,
std::vector< GeoLib::Raster const * > const &  rasters,
double  minimum_thickness,
double  noDataReplacementValue 
)
pure virtual

Constructs a subsurface representation based on a 2D mesh and a number of rasters representing subsurface layer boundaries.

Parameters
meshThe 2D surface mesh that is used as a basis for the subsurface mesh
rastersContaining all the raster-data for the subsurface layers from bottom to top (starting with the bottom of the oldest layer and ending with the DEM)
minimum_thicknessMinimum thickness of each of the newly created layers (i.e. nodes with a vertical distance smaller than this will be collapsed)
noDataReplacementValueDefault z-coordinate if there are mesh nodes not located on the DEM raster (i.e. raster_paths[0])
Returns
true if the subsurface representation has been created, false if there was an error

Implemented in LayeredVolume, and MeshToolsLib::MeshLayerMapper.

Referenced by createLayers().

◆ getMesh()

std::unique_ptr< MeshLib::Mesh > LayeredMeshGenerator::getMesh ( std::string const &  mesh_name) const

Returns a mesh of the subsurface representation.

Definition at line 59 of file LayeredMeshGenerator.cpp.

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(MeshToolsLib::removeNodes(
97 *result, ns.getSearchedNodeIDs(), mesh_name));
98 return new_mesh;
99 }
100 return result;
101}
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition: Logging.h:40
std::vector< int > _materials
std::vector< MeshLib::Node * > _nodes
std::vector< MeshLib::Element * > _elements
Node search class.
Definition: NodeSearch.h:25
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)
MeshLib::Mesh * removeNodes(const MeshLib::Mesh &mesh, const std::vector< std::size_t > &del_nodes_idx, const std::string &new_mesh_name)

References _elements, _materials, _nodes, MeshLib::Cell, MeshLib::Properties::createNewPropertyVector(), MeshLib::NodeSearch::getSearchedNodeIDs(), MeshToolsLib::removeNodes(), MeshLib::NodeSearch::searchUnused(), and WARN().

Referenced by MeshLayerEditDialog::createPrismMesh(), MeshLayerEditDialog::createTetMesh(), and main().

◆ getNewLayerNode()

MeshLib::Node * LayeredMeshGenerator::getNewLayerNode ( MeshLib::Node const &  dem_node,
MeshLib::Node const &  last_layer_node,
GeoLib::Raster const &  raster,
std::size_t  new_node_id 
) const
protected

Calculates the node Position of a subsurface node based on the given raster but also constrained by the DEM layer as an upper bound and the the layer located below as a lower bound (i.e. older stratigraphic layers are favored and nodes cannot be located above surface).

Parameters
dem_nodeThe node at this xy-location on the DEM
last_layer_nodeThe node at this xy-location on the layer below
rasterThe raster file for the current layer
new_node_idNode ID to be used if there is a meaningful node position to be found
Returns
A new node at the given xy position.

Definition at line 111 of file LayeredMeshGenerator.cpp.

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}

References _minimum_thickness, GeoLib::Raster::getHeader(), GeoLib::Raster::interpolateValueAtPoint(), and GeoLib::RasterHeader::no_data.

Referenced by LayeredVolume::addLayerToMesh(), and MeshToolsLib::MeshLayerMapper::addLayerToMesh().

Member Data Documentation

◆ _elements

◆ _elevation_epsilon

double LayeredMeshGenerator::_elevation_epsilon {0.0001}
protected

Definition at line 116 of file LayeredMeshGenerator.h.

Referenced by LayeredVolume::createRasterLayers().

◆ _materials

◆ _minimum_thickness

double LayeredMeshGenerator::_minimum_thickness {std::numeric_limits<float>::epsilon()}
protected

◆ _nodes


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