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 34 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 30 of file Mesh2MeshPropertyInterpolation.cpp.

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 152 of file Mesh2MeshPropertyInterpolation.cpp.

155{
156 // fetch the source of property values
158 {
159 WARN("Did not find PropertyVector<double> '{:s}'.", _property_name);
160 return;
161 }
162 auto const* elem_props =
164
165 std::vector<MeshLib::Node*> const& src_nodes(_src_mesh.getNodes());
166 const std::size_t n_src_nodes(src_nodes.size());
167 for (std::size_t k(0); k < n_src_nodes; k++)
168 {
169 const std::size_t n_con_elems(
170 _src_mesh.getElementsConnectedToNode(*src_nodes[k]).size());
171 interpolated_properties[k] = (*elem_props)
172 [_src_mesh.getElementsConnectedToNode(*src_nodes[k])[0]->getID()];
173 for (std::size_t j(1); j < n_con_elems; j++)
174 {
175 interpolated_properties[k] +=
176 (*elem_props)[_src_mesh
177 .getElementsConnectedToNode(*src_nodes[k])[j]
178 ->getID()];
179 }
180 interpolated_properties[k] /= n_con_elems;
181 }
182}
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:106
Properties & getProperties()
Definition Mesh.h:134
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
Definition Mesh.cpp:256
bool existsPropertyVector(std::string_view name) const
Definition Properties.h:74
PropertyVector< T > const * getPropertyVector(std::string_view name) const

References _property_name, _src_mesh, MeshLib::Properties::existsPropertyVector(), MeshLib::Mesh::getElementsConnectedToNode(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), 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 88 of file Mesh2MeshPropertyInterpolation.cpp.

91{
92 std::vector<double> interpolated_src_node_properties(
95 interpolated_src_node_properties);
96
97 // idea: looping over the destination elements and calculate properties
98 // from interpolated_src_node_properties to accelerate the (source) point
99 // search construct a grid
100 std::vector<MeshLib::Node*> const& src_nodes(_src_mesh.getNodes());
101 GeoLib::Grid<MeshLib::Node> src_grid(src_nodes.begin(), src_nodes.end(),
102 64);
103
104 auto const& dest_elements(dest_mesh.getElements());
105 const std::size_t n_dest_elements(dest_elements.size());
106 for (std::size_t k(0); k < n_dest_elements; k++)
107 {
108 MeshLib::Element& dest_element(*dest_elements[k]);
109 if (dest_element.getGeomType() == MeshLib::MeshElemType::LINE)
110 {
111 continue;
112 }
113
114 // compute axis aligned bounding box around the current element
115 const GeoLib::AABB elem_aabb(
116 dest_element.getNodes(),
117 dest_element.getNodes() + dest_element.getNumberOfBaseNodes());
118
119 // request "interesting" nodes from grid
120 std::vector<std::vector<MeshLib::Node*> const*> const nodes =
121 src_grid.getPntVecsOfGridCellsIntersectingCuboid(
122 elem_aabb.getMinPoint(), elem_aabb.getMaxPoint());
123
124 std::size_t cnt(0);
125 double average_value(0.0);
126
127 for (auto const* nodes_vec : nodes)
128 {
129 for (auto const* node : *nodes_vec)
130 {
131 if (elem_aabb.containsPointXY(*node) &&
132 MeshLib::isPointInElementXY(*node, dest_element))
133 {
134 average_value +=
135 interpolated_src_node_properties[node->getID()];
136 cnt++;
137 }
138 }
139 }
140
141 if (cnt == 0)
142 {
143 OGS_FATAL(
144 "Mesh2MeshInterpolation: Could not find values in source mesh "
145 "for the element {:d}.",
146 k);
147 }
148 dest_properties[k] = average_value / cnt;
149 }
150}
#define OGS_FATAL(...)
Definition Error.h:26
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:56
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition Mesh.h:100
void interpolateElementPropertiesToNodeProperties(std::vector< double > &interpolated_properties) const
bool isPointInElementXY(MathLib::Point3d const &p, Element const &e)
Definition Element.cpp:171

References _src_mesh, GeoLib::AABB::containsPointXY(), MeshLib::Mesh::getElements(), MeshLib::Element::getGeomType(), GeoLib::AABB::getMaxPoint(), GeoLib::AABB::getMinPoint(), MeshLib::Element::getNodes(), MeshLib::Mesh::getNodes(), MeshLib::Element::getNumberOfBaseNodes(), MeshLib::Mesh::getNumberOfNodes(), 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 36 of file Mesh2MeshPropertyInterpolation.cpp.

38{
39 if (_src_mesh.getDimension() != dest_mesh.getDimension())
40 {
41 ERR("MeshLib::Mesh2MeshPropertyInterpolation::setPropertiesForMesh() "
42 "dimension of source (dim = {:d}) and destination (dim = {:d}) "
43 "mesh does not match.",
44 _src_mesh.getDimension(), dest_mesh.getDimension());
45 return false;
46 }
47
48 if (_src_mesh.getDimension() != 2)
49 {
50 WARN(
51 "MeshLib::Mesh2MeshPropertyInterpolation::setPropertiesForMesh() "
52 "implemented only for 2D case at the moment.");
53 return false;
54 }
55
56 MeshLib::PropertyVector<double>* dest_properties;
57 if (dest_mesh.getProperties().existsPropertyVector<double>(_property_name))
58 {
59 dest_properties =
61 }
62 else
63 {
64 INFO("Create new PropertyVector '{:s}' of type double.",
66 dest_properties =
67 dest_mesh.getProperties().createNewPropertyVector<double>(
69 if (!dest_properties)
70 {
71 WARN(
72 "Could not get or create a PropertyVector of type double using "
73 "the given name '{:s}'.",
75 return false;
76 }
77 }
78 if (dest_properties->size() != dest_mesh.getNumberOfElements())
79 {
80 dest_properties->resize(dest_mesh.getNumberOfElements());
81 }
82
83 interpolatePropertiesForMesh(dest_mesh, *dest_properties);
84
85 return true;
86}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:88
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:97
PropertyVector< T > * createNewPropertyVector(std::string_view name, MeshItemType mesh_item_type, std::size_t n_components=1)
Definition Properties.h:17
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: