OGS
MeshToolsLib::Mesh2MeshPropertyInterpolation Class Referencefinal

Detailed Description

Class Mesh2MeshPropertyInterpolation transfers properties of mesh elements of a (source) mesh to mesh elements of another (destination) mesh deploying weighted interpolation. The two meshes must have the same dimension.

Definition at line 23 of file Mesh2MeshPropertyInterpolation.h.

#include <Mesh2MeshPropertyInterpolation.h>

Collaboration diagram for MeshToolsLib::Mesh2MeshPropertyInterpolation:
[legend]

Public Member Functions

 Mesh2MeshPropertyInterpolation (MeshLib::Mesh const &src_mesh, std::string const &property_name)
bool setPropertiesForMesh (MeshLib::Mesh &dest_mesh) const

Private Member Functions

void interpolatePropertiesForMesh (MeshLib::Mesh const &dest_mesh, MeshLib::PropertyVector< double > &dest_properties) const
void interpolateElementPropertiesToNodeProperties (std::vector< double > &interpolated_properties) const

Private Attributes

MeshLib::Mesh const & _src_mesh
std::string const & _property_name

Constructor & Destructor Documentation

◆ Mesh2MeshPropertyInterpolation()

MeshToolsLib::Mesh2MeshPropertyInterpolation::Mesh2MeshPropertyInterpolation ( MeshLib::Mesh const & src_mesh,
std::string const & property_name )

Constructor taking the source or input mesh and properties.

Parameters
src_meshthe mesh the given property information is assigned to.
property_nameis the name of a PropertyVector in the source_mesh

Definition at line 19 of file Mesh2MeshPropertyInterpolation.cpp.

References _property_name, and _src_mesh.

Member Function Documentation

◆ interpolateElementPropertiesToNodeProperties()

void MeshToolsLib::Mesh2MeshPropertyInterpolation::interpolateElementPropertiesToNodeProperties ( std::vector< double > & interpolated_properties) const
private

Method interpolates the element wise given properties to the nodes of the element

Parameters
interpolated_propertiesthe vector must have the same number of entries as the source mesh has number of nodes, the content of the particular entries will be overwritten

Definition at line 139 of file Mesh2MeshPropertyInterpolation.cpp.

142{
143 // fetch the source of property values
144 if (!_src_mesh.getProperties().existsPropertyVector<double>(_property_name))
145 {
146 WARN("Did not find PropertyVector<double> '{:s}'.", _property_name);
147 return;
148 }
149 auto const* elem_props =
150 _src_mesh.getProperties().getPropertyVector<double>(_property_name);
151
152 std::vector<MeshLib::Node*> const& src_nodes(_src_mesh.getNodes());
153 const std::size_t n_src_nodes(src_nodes.size());
154 for (std::size_t k(0); k < n_src_nodes; k++)
155 {
156 const std::size_t n_con_elems(
157 _src_mesh.getElementsConnectedToNode(*src_nodes[k]).size());
158 interpolated_properties[k] = (*elem_props)
159 [_src_mesh.getElementsConnectedToNode(*src_nodes[k])[0]->getID()];
160 for (std::size_t j(1); j < n_con_elems; j++)
161 {
162 interpolated_properties[k] +=
163 (*elem_props)[_src_mesh
164 .getElementsConnectedToNode(*src_nodes[k])[j]
165 ->getID()];
166 }
167 interpolated_properties[k] /= n_con_elems;
168 }
169}
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34

References _property_name, _src_mesh, and WARN().

Referenced by interpolatePropertiesForMesh().

◆ interpolatePropertiesForMesh()

void MeshToolsLib::Mesh2MeshPropertyInterpolation::interpolatePropertiesForMesh ( MeshLib::Mesh const & dest_mesh,
MeshLib::PropertyVector< double > & dest_properties ) const
private
Parameters
dest_mesh
dest_properties

Definition at line 75 of file Mesh2MeshPropertyInterpolation.cpp.

78{
79 std::vector<double> interpolated_src_node_properties(
80 _src_mesh.getNumberOfNodes());
82 interpolated_src_node_properties);
83
84 // idea: looping over the destination elements and calculate properties
85 // from interpolated_src_node_properties to accelerate the (source) point
86 // search construct a grid
87 std::vector<MeshLib::Node*> const& src_nodes(_src_mesh.getNodes());
88 GeoLib::Grid<MeshLib::Node> src_grid(src_nodes.begin(), src_nodes.end(),
89 64);
90
91 auto const& dest_elements(dest_mesh.getElements());
92 const std::size_t n_dest_elements(dest_elements.size());
93 for (std::size_t k(0); k < n_dest_elements; k++)
94 {
95 MeshLib::Element& dest_element(*dest_elements[k]);
96 if (dest_element.getGeomType() == MeshLib::MeshElemType::LINE)
97 {
98 continue;
99 }
100
101 // compute axis aligned bounding box around the current element
102 const GeoLib::AABB elem_aabb(
103 dest_element.getNodes(),
104 dest_element.getNodes() + dest_element.getNumberOfBaseNodes());
105
106 // request "interesting" nodes from grid
107 std::vector<std::vector<MeshLib::Node*> const*> const nodes =
108 src_grid.getPntVecsOfGridCellsIntersectingCuboid(
109 elem_aabb.getMinPoint(), elem_aabb.getMaxPoint());
110
111 std::size_t cnt(0);
112 double average_value(0.0);
113
114 for (auto const* nodes_vec : nodes)
115 {
116 for (auto const* node : *nodes_vec)
117 {
118 if (elem_aabb.containsPointXY(*node) &&
119 MeshLib::isPointInElementXY(*node, dest_element))
120 {
121 average_value +=
122 interpolated_src_node_properties[node->getID()];
123 cnt++;
124 }
125 }
126 }
127
128 if (cnt == 0)
129 {
130 OGS_FATAL(
131 "Mesh2MeshInterpolation: Could not find values in source mesh "
132 "for the element {:d}.",
133 k);
134 }
135 dest_properties[k] = average_value / cnt;
136 }
137}
#define OGS_FATAL(...)
Definition Error.h:19
void interpolateElementPropertiesToNodeProperties(std::vector< double > &interpolated_properties) const
bool isPointInElementXY(MathLib::Point3d const &p, Element const &e)
Definition Element.cpp:178

References _src_mesh, GeoLib::AABB::containsPointXY(), MeshLib::Mesh::getElements(), MeshLib::Element::getGeomType(), GeoLib::AABB::getMaxPoint(), GeoLib::AABB::getMinPoint(), MeshLib::Element::getNodes(), MeshLib::Element::getNumberOfBaseNodes(), GeoLib::Grid< POINT >::getPntVecsOfGridCellsIntersectingCuboid(), interpolateElementPropertiesToNodeProperties(), MeshLib::isPointInElementXY(), MeshLib::LINE, and OGS_FATAL.

Referenced by setPropertiesForMesh().

◆ setPropertiesForMesh()

bool MeshToolsLib::Mesh2MeshPropertyInterpolation::setPropertiesForMesh ( MeshLib::Mesh & dest_mesh) const

Calculates entries for the property vector and sets appropriate indices in the mesh elements.

Parameters
dest_meshthe mesh the property information will be calculated and set via weighted interpolation
Returns
true if the operation was successful, false on error

Definition at line 25 of file Mesh2MeshPropertyInterpolation.cpp.

27{
28 if (_src_mesh.getDimension() != dest_mesh.getDimension())
29 {
30 ERR("MeshLib::Mesh2MeshPropertyInterpolation::setPropertiesForMesh() "
31 "dimension of source (dim = {:d}) and destination (dim = {:d}) "
32 "mesh does not match.",
33 _src_mesh.getDimension(), dest_mesh.getDimension());
34 return false;
35 }
36
37 if (_src_mesh.getDimension() != 2)
38 {
39 WARN(
40 "MeshLib::Mesh2MeshPropertyInterpolation::setPropertiesForMesh() "
41 "implemented only for 2D case at the moment.");
42 return false;
43 }
44
45 MeshLib::PropertyVector<double>* dest_properties;
46 if (dest_mesh.getProperties().existsPropertyVector<double>(_property_name))
47 {
48 dest_properties =
50 assert(dest_properties->size() != dest_mesh.getNumberOfElements());
51 }
52 else
53 {
54 INFO("Create new PropertyVector '{:s}' of type double.",
56 dest_properties =
57 dest_mesh.getProperties().createNewPropertyVector<double>(
59 dest_mesh.getNumberOfElements(), 1);
60 if (!dest_properties)
61 {
62 WARN(
63 "Could not get or create a PropertyVector of type double using "
64 "the given name '{:s}'.",
66 return false;
67 }
68 }
69
70 interpolatePropertiesForMesh(dest_mesh, *dest_properties);
71
72 return true;
73}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:79
Properties & getProperties()
Definition Mesh.h:125
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:88
bool existsPropertyVector(std::string_view name) const
PropertyVector< T > * createNewPropertyVector(std::string_view name, MeshItemType mesh_item_type, std::size_t n_components=1)
PropertyVector< T > const * getPropertyVector(std::string_view name) const
constexpr std::size_t size() const
void interpolatePropertiesForMesh(MeshLib::Mesh const &dest_mesh, MeshLib::PropertyVector< double > &dest_properties) const

References _property_name, _src_mesh, MeshLib::Cell, MeshLib::Properties::createNewPropertyVector(), ERR(), MeshLib::Properties::existsPropertyVector(), MeshLib::Mesh::getDimension(), MeshLib::Mesh::getNumberOfElements(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), INFO(), interpolatePropertiesForMesh(), MeshLib::PropertyVector< PROP_VAL_TYPE >::size(), and WARN().

Referenced by main().

Member Data Documentation

◆ _property_name

std::string const& MeshToolsLib::Mesh2MeshPropertyInterpolation::_property_name
private

◆ _src_mesh

MeshLib::Mesh const& MeshToolsLib::Mesh2MeshPropertyInterpolation::_src_mesh
private

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