OGS
MeshLib Namespace Reference

Namespaces

namespace  detail
namespace  details
namespace  IO
namespace  views
 MeshLib specific, lazy, non-owning, non-mutating, composable range views.

Classes

class  CellRule
class  CoordinateSystem
 Coordinate systems. More...
struct  CoordinateSystemType
 Coordinate system type. More...
class  EdgeRule
class  Element
class  ElementCoordinatesMappingLocal
class  ElementSearch
 Element search class. More...
class  ElementStatus
class  FaceRule
class  HexRule
class  HexRule20
class  HexRule8
 Description of the stored integration point meta data for all fields. More...
struct  IntegrationPointMetaDataSingleField
struct  IntegrationPointWriter
class  LinearEdgeReturn
 Returns linear order edge. More...
class  LineRule
class  LineRule2
class  LineRule3
struct  Location
class  Mesh
class  MeshElementGrid
struct  MeshNodalCoordinatesBackend
class  MeshSubset
 A subset of nodes on a single mesh. More...
class  Node
class  NodeAdjacencyTable
class  NodePartitionedMesh
class  NodeSearch
 Node search class. More...
class  NoEdgeReturn
 Returns always null pointer. More...
class  PointRule1
 A 0d point element. More...
class  PrismRule
class  PrismRule15
class  PrismRule6
class  Properties
 Property manager on mesh items. Class Properties manages scalar, vector or matrix properties. For instance in groundwater flow porosity is a scalar property and permeabilty can be stored as a tensor property. Properties are assigned to mesh items, i.e. Node or Element objects. The createNewPropertyVector() method first creates a PropertyVector of template type T (scalar, vector or matrix). This class stores the PropertyVector, accessible by a combination of the name and the type of the mesh item (Node or Element). More...
class  PropertyVector
class  PropertyVector< T * >
class  PropertyVectorBase
class  PyramidRule
class  PyramidRule13
class  PyramidRule5
class  QuadraticEdgeReturn
 Returns quadratic order edge. More...
class  QuadRule
class  QuadRule4
class  QuadRule8
class  QuadRule9
class  TemplateElement
class  TetRule
class  TetRule10
class  TetRule4
class  TriRule
class  TriRule3
class  TriRule6
class  VertexRule
class  VtkMappedMeshSource
 VtkMappedMeshSource is a source class to transform OGS meshes into complete vtkUnstructuredGrids. Usage: More...
class  VtkMeshConverter
 Converter for VtkUnstructured Grids to OGS meshes. More...

Typedefs

using RotationMatrix = Eigen::Matrix<double, 3u, 3u, Eigen::RowMajor>
using AllElementTypes
using Hex = TemplateElement<MeshLib::HexRule8>
using Hex20 = TemplateElement<MeshLib::HexRule20>
using Line = TemplateElement<MeshLib::LineRule2>
using Line3 = TemplateElement<MeshLib::LineRule3>
using Point = TemplateElement<PointRule1>
using Prism = TemplateElement<MeshLib::PrismRule6>
using Prism15 = TemplateElement<MeshLib::PrismRule15>
using Pyramid = TemplateElement<MeshLib::PyramidRule5>
using Pyramid13 = TemplateElement<MeshLib::PyramidRule13>
using Quad = TemplateElement<MeshLib::QuadRule4>
using Quad8 = TemplateElement<MeshLib::QuadRule8>
using Quad9 = TemplateElement<MeshLib::QuadRule9>
using Tet = TemplateElement<MeshLib::TetRule4>
using Tet10 = TemplateElement<MeshLib::TetRule10>
using Tri = TemplateElement<MeshLib::TriRule3>
using Tri6 = TemplateElement<MeshLib::TriRule6>

Enumerations

enum class  MeshItemType {
  Node , Edge , Face , Cell ,
  IntegrationPoint
}
enum class  MeshElemType {
  INVALID = 0 , POINT = 1 , LINE = 3 , QUAD = 9 ,
  HEXAHEDRON = 12 , TRIANGLE = 5 , TETRAHEDRON = 10 , PRISM = 16 ,
  PYRAMID = 14
}
 Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum. More...
enum class  CellType {
  INVALID = 0 , POINT1 = 1 , LINE2 = 2 , LINE3 = 3 ,
  TRI3 = 4 , TRI6 = 5 , QUAD4 = 6 , QUAD8 = 7 ,
  QUAD9 = 8 , TET4 = 9 , TET10 = 10 , HEX8 = 11 ,
  HEX20 = 12 , HEX27 = 13 , PRISM6 = 14 , PRISM15 = 15 ,
  PRISM18 = 16 , PYRAMID5 = 17 , PYRAMID13 = 18 , enum_length
}
 Types of mesh elements supported by OpenGeoSys. More...
enum class  MeshQualityType {
  INVALID = 0 , ELEMENTSIZE , SIZEDIFFERENCE , EDGERATIO ,
  EQUIANGLESKEW , RADIUSEDGERATIO
}
 Describes a mesh quality metric. More...
enum class  UseIntensityAs { ELEVATION , MATERIALS , DATAVECTOR , NONE }
 Selection of possible interpretations for intensities. More...

Functions

std::ostream & operator<< (std::ostream &os, Element const &e)
bool areNeighbors (Element const *const element, Element const *const other)
 Returns true if elem is a neighbour of this element and false otherwise.
bool hasZeroVolume (MeshLib::Element const &element)
 Returns true if the element has zero length/area/volume.
MathLib::Point3d getCenterOfGravity (MeshLib::Element const &element)
 Calculates the center of gravity for the mesh element.
std::pair< double, double > computeSqrNodeDistanceRange (MeshLib::Element const &element, bool const check_allnodes=true)
 Compute the minimum and maximum node distances for this element.
std::pair< double, double > computeSqrEdgeLengthRange (Element const &element)
 Compute the minimum and maximum squared edge length for this element.
bool isPointInElementXY (MathLib::Point3d const &p, Element const &e)
unsigned getNodeIDinElement (Element const &element, const Node *node)
 Returns the position of the given node in the node array of this element.
std::size_t getNodeIndex (Element const &element, unsigned const idx)
MathLib::Point3d getBulkElementPoint (MeshLib::CellType const bulk_element_cell_type, std::size_t const bulk_face_id, MathLib::WeightedPoint const &point_on_face)
MathLib::Point3d getBulkElementPoint (MeshLib::Element const &bulk_element, std::size_t const bulk_face_id, MathLib::WeightedPoint const &point_on_face)
 Overload provided for convenience.
std::vector< Node * > getBaseNodes (std::vector< Element * > const &elements)
Eigen::Vector3d calculateNormalizedSurfaceNormal (MeshLib::Element const &surface_element, MeshLib::Element const &bulk_element)
std::vector< std::size_t > findElementsWithinRadius (Element const &start_element, double const radius_squared)
std::ostream & operator<< (std::ostream &os, MeshItemType const &t)
std::ostream & operator<< (std::ostream &os, Location const &l)
bool operator< (const Location &left, const Location &right)
 Lexicographic order of Location.
std::vector< std::vector< Element const * > > findElementsConnectedToNodes (Mesh const &mesh)
std::pair< double, double > minMaxEdgeLength (std::vector< Element * > const &elements)
 Returns the minimum and maximum edge length for given elements.
PropertyVector< int > const * materialIDs (Mesh const &mesh)
PropertyVector< int > * materialIDs (Mesh &mesh)
PropertyVector< std::size_t > const * bulkNodeIDs (Mesh const &mesh)
PropertyVector< std::size_t > const * bulkElementIDs (Mesh const &mesh)
std::vector< std::vector< Node * > > calculateNodesConnectedByElements (Mesh const &mesh)
bool isBaseNode (Node const &node, std::vector< Element const * > const &elements_connected_to_node)
MeshfindMeshByName (std::vector< std::unique_ptr< Mesh > > const &meshes, std::string_view const name)
bool operator== (Mesh const &a, Mesh const &b)
 Meshes are equal if their id's are equal.
bool operator!= (Mesh const &a, Mesh const &b)
template<typename T>
bool idsComparator (T const a, T const b)
std::string MeshElemType2String (const MeshElemType t)
 Given a MeshElemType this returns the appropriate string.
std::string MeshElemType2StringShort (const MeshElemType t)
 Given a MeshElemType this returns the appropriate string with a short name.
MeshElemType String2MeshElemType (const std::string &s)
 Given a string of the shortened name of the element type, this returns the corresponding MeshElemType.
std::vector< MeshElemTypegetMeshElemTypes ()
 Returns a vector of all mesh element types.
std::vector< std::string > getMeshElemTypeStringsShort ()
 Returns a vector of strings of mesh element types.
std::string CellType2String (const CellType t)
 Given a MeshElemType this returns the appropriate string.
std::string MeshQualityType2String (const MeshQualityType t)
MeshLib::MeshQualityType String2MeshQualityType (std::string const &s)
static constexpr char const * toString (const MeshItemType t)
 Returns a char array for a specific MeshItemType.
template<typename Container, typename Predicate>
std::vector< std::size_t > filter (Container const &container, Predicate const &p)
std::vector< Node * > getUniqueNodes (std::vector< Element * > const &elements)
 Create a vector of unique nodes used by given elements.
std::ostream & operator<< (std::ostream &os, MeshLib::Node const &n)
std::vector< int > getEndNodeIDRanks (std::size_t const n_global_nodes, std::vector< std::size_t > const &n_regular_base_nodes_at_rank, std::vector< std::size_t > const &n_regular_high_order_nodes_at_rank)
template<typename Function>
void applyToPropertyVectors (Properties const &properties, Function f)
constexpr std::string_view getBulkIDString (MeshItemType mesh_item_type)
constexpr std::string_view globalIDString (MeshLib::MeshItemType const mesh_item_type)
template<typename T>
void addPropertyToMesh (Mesh &mesh, std::string_view name, MeshItemType item_type, std::size_t number_of_components, std::span< T const > values)
std::unique_ptr< MeshLib::MeshcreateMaterialIDsBasedSubMesh (MeshLib::Mesh const &mesh, std::vector< int > const &material_ids, std::string const &name_for_created_mesh)
std::unique_ptr< MeshLib::MeshcreateMeshFromElementSelection (std::string mesh_name, std::vector< MeshLib::Element * > const &elements)
std::unique_ptr< MeshcreateMeshFromElementSelection (std::string mesh_name, std::vector< Element * > const &elements)
std::vector< Node * > copyNodeVector (const std::vector< Node * > &nodes)
 Creates a deep copy of a Node vector.
std::vector< Element * > copyElementVector (std::vector< Element * > const &elements, std::vector< Node * > const &new_nodes, std::vector< std::size_t > const *const node_id_map)
template<typename E>
ElementcopyElement (Element const *const element, const std::vector< Node * > &nodes, std::vector< std::size_t > const *const id_map)
ElementcopyElement (Element const *const element, const std::vector< Node * > &nodes, std::vector< std::size_t > const *const id_map)
std::vector< Element * > cloneElements (std::vector< Element * > const &elements)
 Clones a vector of elements using the Element::clone() function.
std::vector< Eigen::MatrixXd > getElementRotationMatrices (int const space_dimension, int const mesh_dimension, std::vector< Element * > const &elements)
 Element rotation matrix computation.
std::vector< double > getMaxiumElementEdgeLengths (std::vector< Element * > const &elements)
 Returns the maximum lengths of the edges for each element.
std::vector< MeshLib::Element * > getMeshElementsForMaterialIDs (MeshLib::Mesh const &mesh, std::vector< int > const &selected_material_ids)
template<typename T>
PropertyVector< T > * getOrCreateMeshProperty (Mesh &mesh, std::string const &property_name, MeshItemType const item_type, int const number_of_components)
int getSpaceDimension (std::vector< Node * > const &nodes)
 Computes dimension of the embedding space containing the set of given points.
IntegrationPointMetaDataSingleField getIntegrationPointMetaDataSingleField (std::optional< IntegrationPointMetaData > const &ip_meta_data, std::string const &field_name)
void addIntegrationPointDataToMesh (MeshLib::Mesh &mesh, std::vector< std::unique_ptr< IntegrationPointWriter > > const &integration_point_writer)
std::optional< IntegrationPointMetaDatagetIntegrationPointMetaData (MeshLib::Properties const &properties)
bool is2DMeshOnRotatedVerticalPlane (Mesh const &mesh)
void scaleMeshPropertyVector (MeshLib::Mesh &mesh, std::string const &property_name, double factor)
void setMeshSpaceDimension (std::vector< std::unique_ptr< Mesh > > const &meshes)
std::pair< std::vector< Node * >, std::vector< Element * > > copyNodesAndElements (std::vector< Element * > const &input_elements)
unsigned long computeNumberOfRegularNodes (NodePartitionedMesh const *bulk_mesh, Mesh const *subdomain_mesh)
std::vector< std::size_t > computeRegularBaseNodeGlobalNodeIDsOfSubDomainPartition (NodePartitionedMesh const *bulk_mesh, Mesh const *subdomain_mesh)
std::vector< std::size_t > computeGhostBaseNodeGlobalNodeIDsOfSubDomainPartition (NodePartitionedMesh const *bulk_mesh, Mesh const *subdomain_mesh, std::vector< std::size_t > const &global_regular_base_node_ids)
std::vector< std::size_t > computeNumberOfRegularBaseNodesAtRank (Mesh const *subdomain_mesh)
std::vector< std::size_t > computeNumberOfRegularHigherOrderNodesAtRank (Mesh const *subdomain_mesh)
std::vector< std::size_t > computeGlobalNodeIDsOfSubDomainPartition (NodePartitionedMesh const *bulk_mesh, Mesh const *subdomain_mesh)
unsigned long getNumberOfGlobalNodes (Mesh const *subdomain_mesh)
std::unique_ptr< NodePartitionedMeshtransformMeshToNodePartitionedMesh (NodePartitionedMesh const *const bulk_mesh, Mesh const *const subdomain_mesh)
 vtkStandardNewMacro (VtkMappedMeshSource) void VtkMappedMeshSource

Variables

static constexpr char const * mesh_item_type_strings []
 Char array names for all of MeshItemType values.

Typedef Documentation

◆ AllElementTypes

Initial value:
std::tuple<Point, Line, Line3, Quad, Quad8, Quad9, Hex, Hex20, Tri, Tri6,
TemplateElement< MeshLib::QuadRule9 > Quad9
Definition Quad.h:19
TemplateElement< MeshLib::TetRule10 > Tet10
Definition Tet.h:15
TemplateElement< MeshLib::HexRule20 > Hex20
Definition Hex.h:15
TemplateElement< MeshLib::TetRule4 > Tet
Definition Tet.h:14
TemplateElement< MeshLib::LineRule2 > Line
Definition Line.h:14
TemplateElement< MeshLib::QuadRule8 > Quad8
Definition Quad.h:18
TemplateElement< MeshLib::PyramidRule13 > Pyramid13
Definition Pyramid.h:15
TemplateElement< MeshLib::QuadRule4 > Quad
Definition Quad.h:17
TemplateElement< MeshLib::TriRule3 > Tri
Definition Tri.h:15
TemplateElement< MeshLib::PyramidRule5 > Pyramid
Definition Pyramid.h:14
TemplateElement< MeshLib::PrismRule6 > Prism
Definition Prism.h:14
TemplateElement< PointRule1 > Point
TemplateElement< MeshLib::PrismRule15 > Prism15
Definition Prism.h:15
TemplateElement< MeshLib::TriRule6 > Tri6
Definition Tri.h:16
TemplateElement< MeshLib::LineRule3 > Line3
Definition Line.h:15
TemplateElement< MeshLib::HexRule8 > Hex
Definition Hex.h:14

A list of types listing all mesh element types supported by OGS.

This type alias is intended for template metaprogramming et al., not for direct use/instantiation.

Definition at line 23 of file Elements.h.

◆ Hex

Definition at line 14 of file Hex.h.

◆ Hex20

Definition at line 15 of file Hex.h.

◆ Line

Definition at line 14 of file Line.h.

◆ Line3

Definition at line 15 of file Line.h.

◆ Point

◆ Prism

Definition at line 14 of file Prism.h.

◆ Prism15

Definition at line 15 of file Prism.h.

◆ Pyramid

Definition at line 14 of file Pyramid.h.

◆ Pyramid13

◆ Quad

Definition at line 17 of file Quad.h.

◆ Quad8

Definition at line 18 of file Quad.h.

◆ Quad9

Definition at line 19 of file Quad.h.

◆ RotationMatrix

using MeshLib::RotationMatrix = Eigen::Matrix<double, 3u, 3u, Eigen::RowMajor>

Definition at line 18 of file ElementCoordinatesMappingLocal.h.

◆ Tet

Definition at line 14 of file Tet.h.

◆ Tet10

Definition at line 15 of file Tet.h.

◆ Tri

Definition at line 15 of file Tri.h.

◆ Tri6

Definition at line 16 of file Tri.h.

Enumeration Type Documentation

◆ CellType

enum class MeshLib::CellType
strong

Types of mesh elements supported by OpenGeoSys.

Enumerator
INVALID 
POINT1 
LINE2 
LINE3 
TRI3 
TRI6 
QUAD4 
QUAD8 
QUAD9 
TET4 
TET10 
HEX8 
HEX20 
HEX27 
PRISM6 
PRISM15 
PRISM18 
PYRAMID5 
PYRAMID13 
enum_length 

Definition at line 52 of file MeshEnums.h.

◆ MeshElemType

enum class MeshLib::MeshElemType
strong

Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.

Enumerator
INVALID 
POINT 
LINE 
QUAD 
HEXAHEDRON 
TRIANGLE 
TETRAHEDRON 
PRISM 
PYRAMID 

Definition at line 36 of file MeshEnums.h.

◆ MeshItemType

enum class MeshLib::MeshItemType
strong
Enumerator
Node 
Edge 
Face 
Cell 
IntegrationPoint 

Definition at line 11 of file MeshEnums.h.

◆ MeshQualityType

enum class MeshLib::MeshQualityType
strong

Describes a mesh quality metric.

Enumerator
INVALID 
ELEMENTSIZE 
SIZEDIFFERENCE 
EDGERATIO 
EQUIANGLESKEW 
RADIUSEDGERATIO 

Definition at line 79 of file MeshEnums.h.

◆ UseIntensityAs

enum class MeshLib::UseIntensityAs
strong

Selection of possible interpretations for intensities.

Enumerator
ELEVATION 
MATERIALS 
DATAVECTOR 
NONE 

Definition at line 92 of file MeshEnums.h.

Function Documentation

◆ addIntegrationPointDataToMesh()

void MeshLib::addIntegrationPointDataToMesh ( MeshLib::Mesh & mesh,
std::vector< std::unique_ptr< IntegrationPointWriter > > const & integration_point_writer )

Add integration point data the the mesh's properties.

Adds all integration point data arrays given by the input vector and the corresponding meta data as VTK's field data. Integration point data stored as field data (contrary to point or cell data), as plain double arrays. The data is supplemented with information in JSON format, which is stored as array of characters.

Definition at line 51 of file IntegrationPointWriter.cpp.

55{
56 auto meta_data = IntegrationPointMetaData{
57 integration_point_writer |
58 ranges::views::transform(
59 [&](auto const& ip_writer)
60 { return addIntegrationPointData(mesh, *ip_writer); })};
61
62 if (!meta_data.empty())
63 {
65 }
66}
static MeshLib::IntegrationPointMetaDataSingleField addIntegrationPointData(MeshLib::Mesh &mesh, MeshLib::IntegrationPointWriter const &writer)
static void addIntegrationPointMetaDataSingleField(MeshLib::Mesh &mesh, MeshLib::IntegrationPointMetaData const &ip_meta_data)
Description of the stored integration point meta data for all fields.

References addIntegrationPointData(), and addIntegrationPointMetaDataSingleField().

◆ addPropertyToMesh()

template<typename T>
void MeshLib::addPropertyToMesh ( Mesh & mesh,
std::string_view name,
MeshItemType item_type,
std::size_t number_of_components,
std::span< T const > values )

Creates a new PropertyVector in the given mesh and initializes it with the given data. A PropertyVector with the same name must not exist.

Parameters
meshA Mesh the new ProperyVector will be created in.
nameA string that contains the name of the new PropertyVector.
item_typeOne of the values MeshLib::MeshItemType::Cell or MeshLib::MeshItemType::Node that shows the association of the property values either to Element's / cells or Node's
number_of_componentsthe number of components of a property
valuesA vector containing the values that are used for initialization.

Definition at line 25 of file addPropertyToMesh.h.

28{
29 if (item_type == MeshItemType::Node)
30 {
31 if (mesh.getNumberOfNodes() != values.size() / number_of_components)
32 {
34 "Error number of nodes ({:d}) does not match the number of "
35 "tuples ({:d}).",
36 mesh.getNumberOfNodes(), values.size() / number_of_components);
37 }
38 }
39 if (item_type == MeshItemType::Cell)
40 {
41 if (mesh.getNumberOfElements() != values.size() / number_of_components)
42 {
44 "Error number of elements ({:d}) does not match the number of "
45 "tuples ({:d}).",
47 values.size() / number_of_components);
48 }
49 }
50
51 auto* const property = mesh.getProperties().createNewPropertyVector<T>(
52 name, item_type, values.size() / number_of_components,
53 number_of_components);
54 if (!property)
55 {
56 OGS_FATAL("Error while creating PropertyVector '{:s}'.", name);
57 }
58 assert(property->size() == values.size());
59 property->assign(values);
60}
#define OGS_FATAL(...)
Definition Error.h:19
Properties & getProperties()
Definition Mesh.h:125
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition Mesh.h:91
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:88
PropertyVector< T > * createNewPropertyVector(std::string_view name, MeshItemType mesh_item_type, std::size_t n_components=1)

References Cell, MeshLib::Properties::createNewPropertyVector(), MeshLib::Mesh::getNumberOfElements(), MeshLib::Mesh::getNumberOfNodes(), MeshLib::Mesh::getProperties(), Node, and OGS_FATAL.

Referenced by MeshToolsLib::addBulkIDPropertiesToMesh(), convert(), createMeshFromElementSelection(), ParameterLib::createRandomFieldMeshElementParameter(), and main().

◆ applyToPropertyVectors()

template<typename Function>
void MeshLib::applyToPropertyVectors ( Properties const & properties,
Function f )

Applies a function of the form f(type, name) -> bool for each of the properties names. The type argument is used to call f<decltype(type)>(name). At least one of the functions must return the 'true' value, but at most one is executed.

Definition at line 264 of file Properties-impl.h.

265{
266 for (auto [name, property] : properties)
267 {
268 // Open question, why is the 'unsigned long' case not compiling giving
269 // an error "expected '(' for function-style cast or type construction"
270 // with clang-7, and "error C4576: a parenthesized type followed by an
271 // initializer list is a non-standard explicit type conversion syntax"
272 // with MSVC-15.
273 bool success = f(double{}, property) || f(float{}, property) ||
274 f(int{}, property) || f(unsigned{}, property) ||
275 f(long{}, property) ||
276 f(static_cast<unsigned long>(0), property) ||
277 f(std::size_t{}, property) || f(char{}, property) ||
278 f(static_cast<unsigned char>(0), property);
279 if (!success)
280 {
281 OGS_FATAL("Could not apply function to PropertyVector '{:s}'.",
282 property->getPropertyName());
283 }
284 }
285}

References OGS_FATAL.

Referenced by MeshToolsLib::mergeMeshToBulkMesh(), ApplicationUtils::partitionProperties(), and ApplicationUtils::writeProperties().

◆ areNeighbors()

bool MeshLib::areNeighbors ( Element const *const element,
Element const *const other )

Returns true if elem is a neighbour of this element and false otherwise.

Definition at line 113 of file Element.cpp.

114{
115 unsigned nNeighbors(element->getNumberOfNeighbors());
116 for (unsigned i = 0; i < nNeighbors; i++)
117 {
118 if (element->getNeighbor(i) == other)
119 {
120 return true;
121 }
122 }
123 return false;
124}

References MeshLib::Element::getNeighbor(), and MeshLib::Element::getNumberOfNeighbors().

Referenced by MeshLib::Element::addNeighbor().

◆ bulkElementIDs()

◆ bulkNodeIDs()

◆ calculateNodesConnectedByElements()

std::vector< std::vector< Node * > > MeshLib::calculateNodesConnectedByElements ( Mesh const & mesh)

Computes the element-connectivity of nodes. Two nodes i and j are connected if they are shared by an element.

Definition at line 298 of file Mesh.cpp.

300{
301 auto const elements_connected_to_nodes = findElementsConnectedToNodes(mesh);
302
303 std::vector<std::vector<Node*>> nodes_connected_by_elements;
304 auto const& nodes = mesh.getNodes();
305 nodes_connected_by_elements.resize(nodes.size());
306 for (std::size_t i = 0; i < nodes.size(); ++i)
307 {
308 auto& adjacent_nodes = nodes_connected_by_elements[i];
309 auto const node_id = nodes[i]->getID();
310
311 // Get all elements, to which this node is connected.
312 auto const& connected_elements = elements_connected_to_nodes[node_id];
313
314 // And collect all elements' nodes.
315 for (Element const* const element : connected_elements)
316 {
317 Node* const* const single_elem_nodes = element->getNodes();
318 std::size_t const nnodes = element->getNumberOfNodes();
319 for (std::size_t n = 0; n < nnodes; n++)
320 {
321 adjacent_nodes.push_back(single_elem_nodes[n]);
322 }
323 }
324
325 // Make nodes unique and sorted by their ids.
326 // This relies on the node's id being equivalent to it's address.
327 std::sort(adjacent_nodes.begin(), adjacent_nodes.end(),
329 auto const last =
330 std::unique(adjacent_nodes.begin(), adjacent_nodes.end());
331 adjacent_nodes.erase(last, adjacent_nodes.end());
332 }
333 return nodes_connected_by_elements;
334}
std::vector< std::vector< Element const * > > findElementsConnectedToNodes(Mesh const &mesh)
Definition Mesh.cpp:35
bool idsComparator(T const a, T const b)
Definition Mesh.h:197

References findElementsConnectedToNodes(), MeshLib::Mesh::getNodes(), and idsComparator().

Referenced by MeshLib::NodeAdjacencyTable::createTable(), MeshLib::NodePartitionedMesh::getMaximumNConnectedNodesToNode(), and main().

◆ calculateNormalizedSurfaceNormal()

Eigen::Vector3d MeshLib::calculateNormalizedSurfaceNormal ( MeshLib::Element const & surface_element,
MeshLib::Element const & bulk_element )
inline

Definition at line 36 of file MeshLib/Elements/Utils.h.

39{
40 Eigen::Vector3d surface_element_normal;
41
42 switch (surface_element.getDimension())
43 {
44 case 2:
45 surface_element_normal =
47 break;
48 case 1:
49 {
50 auto const bulk_element_normal =
52 auto const& v0 = surface_element.getNode(0)->asEigenVector3d();
53 auto const& v1 = surface_element.getNode(1)->asEigenVector3d();
54 Eigen::Vector3d const edge_vector = v1 - v0;
55 surface_element_normal = -bulk_element_normal.cross(edge_vector);
56 break;
57 }
58 case 0:
59 {
60 assert(surface_element.getCellType() == CellType::POINT1);
61 assert(bulk_element.getCellType() == CellType::LINE2 ||
62 bulk_element.getCellType() == CellType::LINE3);
63
64 auto const& x = surface_element.getNode(0)->asEigenVector3d();
65
66 // The start of the line element.
67 auto const& a = bulk_element.getNode(0)->asEigenVector3d();
68
69 // The end of the line element is the 2nd base node of the line,
70 // which is the 2nd node.
71 auto const& b = bulk_element.getNode(1)->asEigenVector3d();
72
73 // x coincides either with the start or with the end of the line.
74 // a + b - 2 * x evaluates to a - b or to b - a, respectively.
75 // The formula assumes that the line is perfectly straight, even in
76 // the LINE3 case.
77 surface_element_normal = a + b - 2 * x;
78 }
79 }
80
81 surface_element_normal.normalize();
82 // At the moment (2018-04-26) the surface normal is not oriented
83 // according to the right hand rule
84 // for correct results it is necessary to multiply the normal with
85 // -1
86 surface_element_normal *= -1;
87
88 return surface_element_normal;
89}
static Eigen::Vector3d getSurfaceNormal(Element const &e)
Returns the surface normal of a 2D element.
Definition FaceRule.cpp:33

References MathLib::Point3d::asEigenVector3d(), MeshLib::Element::getCellType(), MeshLib::Element::getDimension(), MeshLib::Element::getNode(), MeshLib::FaceRule::getSurfaceNormal(), LINE2, LINE3, and POINT1.

◆ CellType2String()

std::string MeshLib::CellType2String ( const CellType t)

◆ cloneElements()

std::vector< Element * > MeshLib::cloneElements ( std::vector< Element * > const & elements)

Clones a vector of elements using the Element::clone() function.

Definition at line 106 of file DuplicateMeshComponents.cpp.

107{
108 std::vector<Element*> cloned_elements;
109 cloned_elements.reserve(elements.size());
110 std::transform(begin(elements), end(elements),
111 std::back_inserter(cloned_elements),
112 [](Element const* const e) { return e->clone(); });
113 return cloned_elements;
114}
virtual Element * clone() const =0

References MeshLib::Element::clone().

Referenced by MeshGeoToolsLib::constructAdditionalMeshesFromGeometries(), copyNodesAndElements(), ProcessLib::createDeactivatedSubdomainMesh(), and createMaterialIDsBasedSubMesh().

◆ computeGhostBaseNodeGlobalNodeIDsOfSubDomainPartition()

std::vector< std::size_t > MeshLib::computeGhostBaseNodeGlobalNodeIDsOfSubDomainPartition ( NodePartitionedMesh const * bulk_mesh,
Mesh const * subdomain_mesh,
std::vector< std::size_t > const & global_regular_base_node_ids )

Definition at line 152 of file transformMeshToNodePartitionedMesh.cpp.

156{
158
159 // count regular nodes that is the offset in the mapping
160 auto const local_bulk_node_ids_for_subdomain =
161 *bulkNodeIDs(*subdomain_mesh);
162
163 // compute mapping subdomain ghost node id <-> bulk ghost node id
164 std::vector<std::size_t> subdomain_node_id_to_bulk_node_id;
165 for (auto const id : subdomain_mesh->getNodes() | MeshLib::views::ids)
166 {
167 if (!isRegularNode(*bulk_mesh, {local_bulk_node_ids_for_subdomain}, id))
168 {
169 auto const bulk_node_id = local_bulk_node_ids_for_subdomain[id];
170 // this puts the global bulk node id at pos:
171 // subdomain_node->getID() - number_of_regular_nodes
172 subdomain_node_id_to_bulk_node_id.push_back(
173 bulk_mesh->getGlobalNodeID(bulk_node_id));
174 }
175 }
176
177 // Send ids of bulk ghost nodes belonging to the subdomain mesh to all
178 // other ranks and at the same time receive from all other ranks.
179 std::vector<std::size_t> ghost_node_ids_of_all_ranks;
180 std::vector<int> const offsets =
181 BaseLib::MPI::allgatherv(std::span{subdomain_node_id_to_bulk_node_id},
182 ghost_node_ids_of_all_ranks, mpi);
183
184 std::size_t const global_number_of_subdomain_node_id_to_bulk_node_id =
185 offsets.back();
186 DBUG("[{}] global_number_of_subdomain_node_id_to_bulk_node_id: '{}' ",
187 subdomain_mesh->getName(),
188 global_number_of_subdomain_node_id_to_bulk_node_id);
189
190 // construct a map for fast search of local bulk node ids
191 std::map<std::size_t, std::size_t> global_to_local_bulk_node_ids;
192 for (auto const id : bulk_mesh->getNodes() | MeshLib::views::ids)
193 {
194 if (!bulk_mesh->isGhostNode(id))
195 {
196 global_to_local_bulk_node_ids[bulk_mesh->getGlobalNodeID(id)] = id;
197 }
198 }
199
200 // construct a map for fast search of local sub-domain node ids
201 std::map<std::size_t, std::size_t> local_subdomain_node_ids;
202 for (auto const id : subdomain_mesh->getNodes() | MeshLib::views::ids)
203 {
204 local_subdomain_node_ids[local_bulk_node_ids_for_subdomain[id]] = id;
205 }
206
207 std::vector<std::size_t> subdomain_node_ids_of_all_ranks(
208 global_number_of_subdomain_node_id_to_bulk_node_id,
209 std::numeric_limits<std::size_t>::max());
210 // search in all ranks within the bulk ids for the corresponding id
211 for (int rank = 0; rank < mpi.size; ++rank)
212 {
213 if (rank == mpi.rank)
214 {
215 continue;
216 }
217 for (int i = offsets[rank]; i < offsets[rank + 1]; ++i)
218 {
219 auto it = global_to_local_bulk_node_ids.find(
220 ghost_node_ids_of_all_ranks[i]);
221 if (it == global_to_local_bulk_node_ids.end())
222 {
223 continue;
224 }
225 auto const local_bulk_node_id = it->second;
226 subdomain_node_ids_of_all_ranks[i] = global_regular_base_node_ids
227 [local_subdomain_node_ids.find(local_bulk_node_id)->second];
228 DBUG(
229 "[{}] found global subdomain node id: '{}' for global bulk "
230 "node id {} ",
231 subdomain_mesh->getName(),
232 subdomain_node_ids_of_all_ranks[i],
233 ghost_node_ids_of_all_ranks[i]);
234 }
235 }
236
237 // find maximum over all ranks
238 BaseLib::MPI::allreduceInplace(subdomain_node_ids_of_all_ranks, MPI_MAX,
239 mpi);
240
241 std::vector<std::size_t> global_ids_for_subdomain_ghost_nodes(
242 subdomain_node_ids_of_all_ranks.begin() + offsets[mpi.rank],
243 subdomain_node_ids_of_all_ranks.begin() + offsets[mpi.rank + 1]);
244 return global_ids_for_subdomain_ghost_nodes;
245}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
static void allreduceInplace(std::vector< T > &vector, MPI_Op const &mpi_op, Mpi const &mpi)
Definition MPI.h:143
static std::vector< int > allgatherv(std::span< T > const send_buffer, std::vector< std::remove_const_t< T > > &receive_buffer, Mpi const &mpi)
Definition MPI.h:158
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition Mesh.h:216
PropertyVector< std::size_t > const * bulkNodeIDs(Mesh const &mesh)
Definition Mesh.cpp:282

References BaseLib::MPI::allgatherv(), BaseLib::MPI::allreduceInplace(), bulkNodeIDs(), DBUG(), MeshLib::NodePartitionedMesh::getGlobalNodeID(), MeshLib::Mesh::getName(), MeshLib::Mesh::getNodes(), MeshLib::views::ids, MeshLib::NodePartitionedMesh::isGhostNode(), BaseLib::MPI::Mpi::rank, and BaseLib::MPI::Mpi::size.

Referenced by computeGlobalNodeIDsOfSubDomainPartition().

◆ computeGlobalNodeIDsOfSubDomainPartition()

std::vector< std::size_t > MeshLib::computeGlobalNodeIDsOfSubDomainPartition ( NodePartitionedMesh const * bulk_mesh,
Mesh const * subdomain_mesh )

Definition at line 279 of file transformMeshToNodePartitionedMesh.cpp.

281{
282 auto global_regular_base_node_ids =
284 subdomain_mesh);
285 auto const local_ids_for_subdomain_ghost_nodes =
287 bulk_mesh, subdomain_mesh, global_regular_base_node_ids);
288
289 // At the moment higher order bulk meshes aren't handled correctly.
290 // If it should become necessary in the future, the necessary things must be
291 // implemented at this point.
292 /*
293 auto const regular_higher_order_node_global_node_ids =
294 computeRegularHigherOrderNodeGlobalNodeIDsofSubDomainPartition(
295 bulk_mesh, subdomain_mesh);
296 auto const ghost_higher_order_node_global_node_ids =
297 computeGhostHigherOrderNodeGlobalNodeIDsofSubDomainPartition(
298 bulk_mesh, subdomain_mesh);
299 */
300
301 std::vector<std::size_t> global_node_ids(
302 std::move(global_regular_base_node_ids));
303 global_node_ids.insert(global_node_ids.end(),
304 local_ids_for_subdomain_ghost_nodes.begin(),
305 local_ids_for_subdomain_ghost_nodes.end());
306
307 return global_node_ids;
308}
std::vector< std::size_t > computeRegularBaseNodeGlobalNodeIDsOfSubDomainPartition(NodePartitionedMesh const *bulk_mesh, Mesh const *subdomain_mesh)
std::vector< std::size_t > computeGhostBaseNodeGlobalNodeIDsOfSubDomainPartition(NodePartitionedMesh const *bulk_mesh, Mesh const *subdomain_mesh, std::vector< std::size_t > const &global_regular_base_node_ids)

References computeGhostBaseNodeGlobalNodeIDsOfSubDomainPartition(), and computeRegularBaseNodeGlobalNodeIDsOfSubDomainPartition().

Referenced by transformMeshToNodePartitionedMesh().

◆ computeNumberOfRegularBaseNodesAtRank()

std::vector< std::size_t > MeshLib::computeNumberOfRegularBaseNodesAtRank ( Mesh const * subdomain_mesh)

Definition at line 247 of file transformMeshToNodePartitionedMesh.cpp.

249{
250 auto const number_of_regular_base_nodes =
251 subdomain_mesh->computeNumberOfBaseNodes();
252
254
255 std::vector<std::size_t> const gathered_number_of_regular_base_nodes =
256 BaseLib::MPI::allgather(number_of_regular_base_nodes, mpi);
257
258 return BaseLib::sizesToOffsets(gathered_number_of_regular_base_nodes);
259}
static std::vector< T > allgather(T const &value, Mpi const &mpi)
Definition MPI.h:98
std::vector< ranges::range_value_t< R > > sizesToOffsets(R const &sizes)
Definition Algorithm.h:276

References BaseLib::MPI::allgather(), MeshLib::Mesh::computeNumberOfBaseNodes(), and BaseLib::sizesToOffsets().

Referenced by transformMeshToNodePartitionedMesh().

◆ computeNumberOfRegularHigherOrderNodesAtRank()

std::vector< std::size_t > MeshLib::computeNumberOfRegularHigherOrderNodesAtRank ( Mesh const * subdomain_mesh)

Definition at line 262 of file transformMeshToNodePartitionedMesh.cpp.

264{
266
267 auto const number_of_regular_base_nodes =
268 subdomain_mesh->computeNumberOfBaseNodes();
269
270 auto const number_of_regular_higher_order_nodes =
271 subdomain_mesh->getNumberOfNodes() - number_of_regular_base_nodes;
272 std::vector<std::size_t> gathered_number_of_regular_higher_order_nodes =
273 BaseLib::MPI::allgather(number_of_regular_higher_order_nodes, mpi);
274
276 gathered_number_of_regular_higher_order_nodes);
277}

References BaseLib::MPI::allgather(), MeshLib::Mesh::computeNumberOfBaseNodes(), MeshLib::Mesh::getNumberOfNodes(), and BaseLib::sizesToOffsets().

Referenced by transformMeshToNodePartitionedMesh().

◆ computeNumberOfRegularNodes()

unsigned long MeshLib::computeNumberOfRegularNodes ( NodePartitionedMesh const * bulk_mesh,
Mesh const * subdomain_mesh )

Definition at line 84 of file transformMeshToNodePartitionedMesh.cpp.

86{
87 auto const& subdomain_nodes = subdomain_mesh->getNodes();
88 auto const& local_bulk_node_ids_for_subdomain =
89 *bulkNodeIDs(*subdomain_mesh);
90 unsigned long const number_of_regular_nodes = ranges::count_if(
91 subdomain_nodes | MeshLib::views::ids,
92 [&](std::size_t const id) {
93 return isRegularNode(*bulk_mesh,
94 {local_bulk_node_ids_for_subdomain}, id);
95 });
96
97 DBUG("[{}] number of regular nodes: {}", subdomain_mesh->getName(),
98 number_of_regular_nodes);
99 return number_of_regular_nodes;
100}

References bulkNodeIDs(), DBUG(), MeshLib::Mesh::getName(), MeshLib::Mesh::getNodes(), and MeshLib::views::ids.

Referenced by computeRegularBaseNodeGlobalNodeIDsOfSubDomainPartition(), and transformMeshToNodePartitionedMesh().

◆ computeRegularBaseNodeGlobalNodeIDsOfSubDomainPartition()

std::vector< std::size_t > MeshLib::computeRegularBaseNodeGlobalNodeIDsOfSubDomainPartition ( NodePartitionedMesh const * bulk_mesh,
Mesh const * subdomain_mesh )

Definition at line 103 of file transformMeshToNodePartitionedMesh.cpp.

105{
106 // create/fill global nodes information of the sub-domain partition
107 auto const& subdomain_nodes = subdomain_mesh->getNodes();
108 auto const& local_bulk_node_ids_for_subdomain =
109 *bulkNodeIDs(*subdomain_mesh);
110
111 // global node ids for the sub-domain:
112 // | regular base node ids | ghost base node ids | regular higher
113 // order node ids | ghost higher order node ids |
114 // | partition offset + local ids | regular node ids from other
115 // partitions |
116
117 // In order to compute the global node ids for the subdomain mesh nodes the
118 // sum of the number of regular nodes of the previous partitions is required
119 // first.
120 // Count the local regular base nodes to compute offset for other subsequent
121 // partitions
122 std::size_t const number_of_regular_nodes =
123 computeNumberOfRegularNodes(bulk_mesh, subdomain_mesh);
124
126
127 // send own number of regular nodes to all others
128 std::vector<std::size_t> const gathered_number_of_regular_nodes =
129 BaseLib::MPI::allgather(number_of_regular_nodes, mpi);
130
131 // compute the 'offset' in the global_node_ids
132 std::vector<std::size_t> const numbers_of_regular_nodes_at_rank =
133 BaseLib::sizesToOffsets(gathered_number_of_regular_nodes);
134
135 // add the offset to the partitioned-owned subdomain
136 std::vector<std::size_t> subdomain_global_node_ids;
137 subdomain_global_node_ids.reserve(subdomain_nodes.size());
138 auto const partition_offset = numbers_of_regular_nodes_at_rank[mpi.rank];
139 DBUG("[{}] partition offset: {}", subdomain_mesh->getName(),
140 partition_offset);
141 // set the global id for the regular base nodes
142 for (auto const id : subdomain_nodes | MeshLib::views::ids)
143 {
144 if (isRegularNode(*bulk_mesh, {local_bulk_node_ids_for_subdomain}, id))
145 {
146 subdomain_global_node_ids.emplace_back(partition_offset + id);
147 }
148 }
149 return subdomain_global_node_ids;
150}
unsigned long computeNumberOfRegularNodes(NodePartitionedMesh const *bulk_mesh, Mesh const *subdomain_mesh)

References BaseLib::MPI::allgather(), bulkNodeIDs(), computeNumberOfRegularNodes(), DBUG(), MeshLib::Mesh::getName(), MeshLib::Mesh::getNodes(), MeshLib::views::ids, BaseLib::MPI::Mpi::rank, and BaseLib::sizesToOffsets().

Referenced by computeGlobalNodeIDsOfSubDomainPartition().

◆ computeSqrEdgeLengthRange()

std::pair< double, double > MeshLib::computeSqrEdgeLengthRange ( Element const & element)

Compute the minimum and maximum squared edge length for this element.

Definition at line 163 of file Element.cpp.

164{
165 double min = std::numeric_limits<double>::max();
166 double max = 0;
167 const unsigned nEdges(element.getNumberOfEdges());
168 for (unsigned i = 0; i < nEdges; i++)
169 {
170 const double dist(MathLib::sqrDist(*element.getEdgeNode(i, 0),
171 *element.getEdgeNode(i, 1)));
172 min = std::min(dist, min);
173 max = std::max(dist, max);
174 }
175 return {min, max};
176}
double sqrDist(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition Point3d.cpp:19

References MeshLib::Element::getEdgeNode(), MeshLib::Element::getNumberOfEdges(), and MathLib::sqrDist().

Referenced by getMaxiumElementEdgeLengths(), and minMaxEdgeLength().

◆ computeSqrNodeDistanceRange()

std::pair< double, double > MeshLib::computeSqrNodeDistanceRange ( MeshLib::Element const & element,
bool const check_allnodes )

Compute the minimum and maximum node distances for this element.

Definition at line 143 of file Element.cpp.

145{
146 double min = std::numeric_limits<double>::max();
147 double max = 0;
148 const unsigned nnodes = check_allnodes ? element.getNumberOfNodes()
149 : element.getNumberOfBaseNodes();
150 for (unsigned i = 0; i < nnodes; i++)
151 {
152 for (unsigned j = i + 1; j < nnodes; j++)
153 {
154 const double dist(
155 MathLib::sqrDist(*element.getNode(i), *element.getNode(j)));
156 min = std::min(dist, min);
157 max = std::max(dist, max);
158 }
159 }
160 return {min, max};
161}

References MeshLib::Element::getNode(), MeshLib::Element::getNumberOfBaseNodes(), MeshLib::Element::getNumberOfNodes(), and MathLib::sqrDist().

Referenced by MeshGeoToolsLib::HeuristicSearchLength::HeuristicSearchLength(), and MeshGeoToolsLib::snapPointToElementNode().

◆ copyElement() [1/2]

template<typename E>
Element * MeshLib::copyElement ( Element const *const element,
const std::vector< Node * > & nodes,
std::vector< std::size_t > const *const id_map )

Copies an element without change, using the nodes vector from the result mesh.

Copies an element without change, using the nodes vector from the result mesh and an optional mapping from the nodes the 'old' elements.

Definition at line 39 of file DuplicateMeshComponents.cpp.

42{
43 unsigned const number_of_element_nodes(element->getNumberOfNodes());
44 auto** new_nodes = new Node*[number_of_element_nodes];
45 if (id_map)
46 {
47 for (unsigned i = 0; i < number_of_element_nodes; ++i)
48 {
49 new_nodes[i] = nodes[(*id_map)[element->getNode(i)->getID()]];
50 }
51 }
52 else
53 {
54 for (unsigned i = 0; i < number_of_element_nodes; ++i)
55 {
56 new_nodes[i] = nodes[element->getNode(i)->getID()];
57 }
58 }
59 return new E(new_nodes);
60}

References MathLib::Point3dWithID::getID(), MeshLib::Element::getNode(), and MeshLib::Element::getNumberOfNodes().

Referenced by copyElement(), and MeshToolsLib::MeshRevision::simplifyMesh().

◆ copyElement() [2/2]

Element * MeshLib::copyElement ( Element const *const element,
const std::vector< Node * > & nodes,
std::vector< std::size_t > const *const id_map = nullptr )

Copies an element without change, using the nodes vector from the result mesh and an optional mapping from the nodes the 'old' elements.

Definition at line 62 of file DuplicateMeshComponents.cpp.

65{
66 switch (element->getCellType())
67 {
68 case CellType::LINE2:
69 return copyElement<Line>(element, nodes, id_map);
70 case CellType::LINE3:
71 return copyElement<Line3>(element, nodes, id_map);
72 case CellType::TRI3:
73 return copyElement<Tri>(element, nodes, id_map);
74 case CellType::TRI6:
75 return copyElement<Tri6>(element, nodes, id_map);
76 case CellType::QUAD4:
77 return copyElement<Quad>(element, nodes, id_map);
78 case CellType::QUAD8:
79 return copyElement<Quad8>(element, nodes, id_map);
80 case CellType::QUAD9:
81 return copyElement<Quad9>(element, nodes, id_map);
82 case CellType::TET4:
83 return copyElement<Tet>(element, nodes, id_map);
84 case CellType::TET10:
85 return copyElement<Tet10>(element, nodes, id_map);
86 case CellType::HEX8:
87 return copyElement<Hex>(element, nodes, id_map);
88 case CellType::HEX20:
89 return copyElement<Hex20>(element, nodes, id_map);
91 return copyElement<Pyramid>(element, nodes, id_map);
93 return copyElement<Pyramid13>(element, nodes, id_map);
95 return copyElement<Prism>(element, nodes, id_map);
97 return copyElement<Prism15>(element, nodes, id_map);
98 default:
99 {
100 ERR("Error: Unknown cell type.");
101 return nullptr;
102 }
103 }
104}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
Element * copyElement(Element const *const element, const std::vector< Node * > &nodes, std::vector< std::size_t > const *const id_map)

References copyElement(), ERR(), MeshLib::Element::getCellType(), HEX20, HEX8, LINE2, LINE3, PRISM15, PRISM6, PYRAMID13, PYRAMID5, QUAD4, QUAD8, QUAD9, TET10, TET4, TRI3, and TRI6.

◆ copyElementVector()

std::vector< Element * > MeshLib::copyElementVector ( std::vector< Element * > const & elements,
std::vector< Node * > const & new_nodes,
std::vector< std::size_t > const *const node_id_map = nullptr )

Creates a deep copy of an element vector using the given Node vector.

Parameters
elementsThe element vector that should be duplicated.
new_nodesThe new node vector used for the duplicated element vector.
node_id_mapAn optional mapping from the nodes the 'old' elements based on to the new nodes. This should be consistent with the original node vector.
Returns
A deep copy of the elements vector using the new nodes vector.

Definition at line 22 of file DuplicateMeshComponents.cpp.

26{
27 std::vector<Element*> new_elements;
28 new_elements.reserve(elements.size());
29 std::transform(elements.begin(), elements.end(),
30 std::back_inserter(new_elements),
31 [&new_nodes, &node_id_map](auto const& element)
32 { return copyElement(element, new_nodes, node_id_map); });
33 return new_elements;
34}

Referenced by ProcessLib::LIE::PostProcessTool::PostProcessTool(), MeshToolsLib::addLayerToMesh(), MeshGeoToolsLib::appendLinesAlongPolylines(), LayeredVolume::createRasterLayers(), MeshToolsLib::BoundaryExtraction::getBoundaryElementsAsMesh(), MeshToolsLib::MeshSurfaceExtraction::getMeshSurface(), main(), MeshToolsLib::removeElements(), and MeshToolsLib::removeNodes().

◆ copyNodesAndElements()

std::pair< std::vector< Node * >, std::vector< Element * > > MeshLib::copyNodesAndElements ( std::vector< Element * > const & input_elements)

Definition at line 40 of file transformMeshToNodePartitionedMesh.cpp.

42{
43 auto elements = cloneElements(input_elements);
44
45 // original node ids to newly created nodes.
46 std::unordered_map<std::size_t, Node*> id_node_hash_map;
47 id_node_hash_map.reserve(
48 elements.size()); // There will be at least one node per element.
49
50 for (auto& e : elements)
51 {
52 // For each node find a cloned node in map or create if there is none.
53 unsigned const n_nodes = e->getNumberOfNodes();
54 for (unsigned i = 0; i < n_nodes; ++i)
55 {
56 Node const* n = e->getNode(i);
57 auto const it = id_node_hash_map.find(n->getID());
58 if (it == id_node_hash_map.end())
59 {
60 auto new_node_in_map = id_node_hash_map[n->getID()] =
61 new Node(*n);
62 e->setNode(i, new_node_in_map);
63 }
64 else
65 {
66 e->setNode(i, it->second);
67 }
68 }
69 }
70
71 std::map<std::size_t, Node*> nodes_map;
72 for (auto const& n : id_node_hash_map)
73 {
74 nodes_map[n.first] = n.second;
75 }
76
77 // Copy the unique nodes pointers.
78 auto element_nodes =
79 nodes_map | ranges::views::values | ranges::to<std::vector>;
80
81 return std::make_pair(element_nodes, elements);
82}
std::size_t getID() const
std::vector< Element * > cloneElements(std::vector< Element * > const &elements)
Clones a vector of elements using the Element::clone() function.

References cloneElements(), MathLib::Point3dWithID::getID(), and Node.

Referenced by transformMeshToNodePartitionedMesh().

◆ copyNodeVector()

std::vector< Node * > MeshLib::copyNodeVector ( const std::vector< Node * > & nodes)

Creates a deep copy of a Node vector.

Definition at line 10 of file DuplicateMeshComponents.cpp.

11{
12 const std::size_t nNodes(nodes.size());
13 std::vector<Node*> new_nodes;
14 new_nodes.reserve(nNodes);
15 for (std::size_t k = 0; k < nNodes; ++k)
16 {
17 new_nodes.push_back(new Node(nodes[k]->data(), new_nodes.size()));
18 }
19 return new_nodes;
20}

References Node.

Referenced by ProcessLib::LIE::PostProcessTool::PostProcessTool(), MeshToolsLib::addLayerToMesh(), MeshGeoToolsLib::appendLinesAlongPolylines(), MeshToolsLib::createQuadraticOrderMesh(), LayeredVolume::createRasterLayers(), main(), MeshToolsLib::removeElements(), and MeshToolsLib::removeNodes().

◆ createMaterialIDsBasedSubMesh()

std::unique_ptr< MeshLib::Mesh > MeshLib::createMaterialIDsBasedSubMesh ( MeshLib::Mesh const & mesh,
std::vector< int > const & material_ids,
std::string const & name_for_created_mesh )

Definition at line 13 of file createMaterialIDsBasedSubMesh.cpp.

16{
17 auto const elements =
20 name_for_created_mesh, MeshLib::cloneElements(elements));
21}
std::unique_ptr< MeshLib::Mesh > createMeshFromElementSelection(std::string mesh_name, std::vector< MeshLib::Element * > const &elements)
std::vector< MeshLib::Element * > getMeshElementsForMaterialIDs(MeshLib::Mesh const &mesh, std::vector< int > const &selected_material_ids)

References cloneElements(), createMeshFromElementSelection(), and getMeshElementsForMaterialIDs().

Referenced by parseOutputMeshConfig().

◆ createMeshFromElementSelection() [1/2]

std::unique_ptr< Mesh > MeshLib::createMeshFromElementSelection ( std::string mesh_name,
std::vector< Element * > const & elements )

Creates a new mesh from a vector of elements.

Note
The elements are owned by the returned mesh object as well as the nodes and will be destructed together with the mesh.

◆ createMeshFromElementSelection() [2/2]

std::unique_ptr< MeshLib::Mesh > MeshLib::createMeshFromElementSelection ( std::string mesh_name,
std::vector< MeshLib::Element * > const & elements )

Definition at line 20 of file createMeshFromElementSelection.cpp.

22{
23 auto ids_vector = views::ids | ranges::to<std::vector>();
24
25 DBUG("Found {:d} elements in the mesh", elements.size());
26
27 // Store bulk element ids for each of the new elements.
28 auto bulk_element_ids = elements | ids_vector;
29
30 // original node ids to newly created nodes.
31 std::unordered_map<std::size_t, MeshLib::Node*> id_node_hash_map;
32 id_node_hash_map.reserve(
33 elements.size()); // There will be at least one node per element.
34
35 for (auto& e : elements)
36 {
37 // For each node find a cloned node in map or create if there is none.
38 unsigned const n_nodes = e->getNumberOfNodes();
39 for (unsigned i = 0; i < n_nodes; ++i)
40 {
41 const MeshLib::Node* n = e->getNode(i);
42 auto const it = id_node_hash_map.find(n->getID());
43 if (it == id_node_hash_map.end())
44 {
45 auto new_node_in_map = id_node_hash_map[n->getID()] =
46 new MeshLib::Node(*n);
47 e->setNode(i, new_node_in_map);
48 }
49 else
50 {
51 e->setNode(i, it->second);
52 }
53 }
54 }
55
56 std::map<std::size_t, MeshLib::Node*> nodes_map;
57 for (const auto& n : id_node_hash_map)
58 {
59 nodes_map[n.first] = n.second;
60 }
61
62 // Copy the unique nodes pointers.
63 auto element_nodes =
64 nodes_map | ranges::views::values | ranges::to<std::vector>;
65
66 // Store bulk node ids for each of the new nodes.
67 auto bulk_node_ids =
68 nodes_map | ranges::views::keys | ranges::to<std::vector>;
69
70 auto mesh = std::make_unique<MeshLib::Mesh>(
71 std::move(mesh_name), std::move(element_nodes), std::move(elements),
72 true /* compute_element_neighbors */);
73 assert(mesh != nullptr);
74
77 MeshLib::MeshItemType::Cell, 1, {bulk_element_ids});
80 MeshLib::MeshItemType::Node, 1, {bulk_node_ids});
81
82 return mesh;
83}
void addPropertyToMesh(Mesh &mesh, std::string_view name, MeshItemType item_type, std::size_t number_of_components, std::span< T const > values)

References addPropertyToMesh(), Cell, DBUG(), getBulkIDString(), MathLib::Point3dWithID::getID(), MeshLib::views::ids, and Node.

Referenced by ProcessLib::createDeactivatedSubdomainMesh(), and createMaterialIDsBasedSubMesh().

◆ filter()

template<typename Container, typename Predicate>
std::vector< std::size_t > MeshLib::filter ( Container const & container,
Predicate const & p )

Definition at line 20 of file ElementSearch.cpp.

21{
22 return ranges::views::filter(container, p) | views::ids |
23 ranges::to<std::vector>;
24}

References MeshLib::views::ids.

Referenced by MeshLib::ElementSearch::searchByBoundingBox(), MeshLib::ElementSearch::searchByContent(), and MeshLib::ElementSearch::searchByElementType().

◆ findElementsConnectedToNodes()

std::vector< std::vector< Element const * > > MeshLib::findElementsConnectedToNodes ( Mesh const & mesh)

Definition at line 35 of file Mesh.cpp.

37{
38 std::vector<std::vector<Element const*>> elements_connected_to_nodes;
39 auto const& nodes = mesh.getNodes();
40 elements_connected_to_nodes.resize(nodes.size());
41
42 for (auto const* element : mesh.getElements())
43 {
44 for (auto const node_id : element->nodes() | views::ids)
45 {
46 elements_connected_to_nodes[node_id].push_back(element);
47 }
48 }
49 return elements_connected_to_nodes;
50}

References MeshLib::Mesh::getElements(), MeshLib::Mesh::getNodes(), and MeshLib::views::ids.

Referenced by MeshLib::Mesh::Mesh(), MeshLib::Mesh::Mesh(), and calculateNodesConnectedByElements().

◆ findElementsWithinRadius()

std::vector< std::size_t > MeshLib::findElementsWithinRadius ( Element const & start_element,
double const radius_squared )

Find neighbor elements in given radius of the element.

Returns
ids of elements for which at least one node lies inside the radius of any node of the given element.
Note
There are corner-cases not correctly handled by this algorithm: Elements where an edge, but not the edge' nodes, fall inside the search radius are not included. The algorithm is only considering node to node distances and does not take into account if there is a part of an element (an edge or a face) but not the nodes falls inside the search radius.
For radius 0 only the given element's id is returned.

Definition at line 16 of file findElementsWithinRadius.cpp.

18{
19 // Special case for 0 radius. All other radii will include at least one
20 // neighbor of the start element.
21 if (radius_squared == 0.)
22 {
23 return {start_element.getID()};
24 }
25
26 // Collect start element node coordinates into local contigiuos memory.
27 std::vector<MathLib::Point3d> start_element_nodes;
28 {
29 auto const start_element_n_nodes = start_element.getNumberOfNodes();
30 start_element_nodes.reserve(start_element_n_nodes);
31 for (unsigned n = 0; n < start_element_n_nodes; ++n)
32 {
33 start_element_nodes.push_back(*start_element.getNode(n));
34 }
35 }
36
37 // Returns true if the test node is inside the radius of any of the
38 // element's nodes.
39 auto node_inside_radius =
40 [&start_element_nodes, radius_squared](Node const* test_node)
41 {
42 return std::any_of(
43 start_element_nodes.begin(), start_element_nodes.end(),
44 [test_node, &radius_squared](auto const node)
45 { return MathLib::sqrDist(*test_node, node) <= radius_squared; });
46 };
47
48 // Returns true if any of the test element's nodes is inside the start
49 // element's radius.
50 auto element_in_radius = [&node_inside_radius](Element const& element)
51 {
52 auto const n_nodes = element.getNumberOfNodes();
53 for (unsigned i = 0; i < n_nodes; ++i)
54 {
55 if (node_inside_radius(element.getNode(i)))
56 {
57 return true;
58 }
59 }
60 return false;
61 };
62
63 std::set<std::size_t> found_elements;
64 std::vector<Element const*> neighbors_to_visit;
65 std::unordered_set<std::size_t> visited_elements;
66
67 auto mark_visited_and_add_neighbors =
68 [&found_elements, &neighbors_to_visit, &visited_elements](
69 Element const& element)
70 {
71 found_elements.insert(element.getID());
72 visited_elements.insert(element.getID());
73 auto const n_neighbors = element.getNumberOfNeighbors();
74 for (unsigned n = 0; n < n_neighbors; ++n)
75 {
76 auto neighbor = element.getNeighbor(n);
77 if (neighbor == nullptr)
78 {
79 continue;
80 }
81 auto x = visited_elements.find(neighbor->getID());
82 if (x != visited_elements.end())
83 {
84 continue;
85 }
86
87 neighbors_to_visit.push_back(neighbor);
88
89 visited_elements.insert(neighbor->getID());
90 }
91 };
92
93 // The result always contains the starting element.
94 mark_visited_and_add_neighbors(start_element);
95
96 while (!neighbors_to_visit.empty())
97 {
98 auto const& current_element = *neighbors_to_visit.back();
99 neighbors_to_visit.pop_back();
100
101 // If any node is inside the radius, all neighbors are visited.
102 if (element_in_radius(current_element))
103 {
104 mark_visited_and_add_neighbors(current_element);
105 }
106 }
107
108 return {std::begin(found_elements), std::end(found_elements)};
109}

References MeshLib::Element::getID(), MeshLib::Element::getNode(), and MeshLib::Element::getNumberOfNodes().

◆ findMeshByName()

Mesh & MeshLib::findMeshByName ( std::vector< std::unique_ptr< Mesh > > const & meshes,
std::string_view const name )

Definition at line 354 of file Mesh.cpp.

356{
358 meshes,
359 [&name](auto const& mesh)
360 {
361 assert(mesh != nullptr);
362 return mesh->getName() == name;
363 },
364 [&]() { OGS_FATAL("Required mesh named {:s} not found.", name); });
365}
ranges::range_reference_t< Range > findElementOrError(Range &range, std::predicate< ranges::range_reference_t< Range > > auto &&predicate, std::invocable auto error_callback)
Definition Algorithm.h:74

References BaseLib::findElementOrError(), and OGS_FATAL.

Referenced by ParameterLib::createParameter(), ProcessLib::SurfaceFluxData::createSurfaceFluxData(), anonymous_namespace{ProcessVariable.cpp}::findMeshInConfig(), ProjectData::getMesh(), parseOutputMeshConfig(), ProjectData::parseProcessVariables(), and ProcessLib::Output::prepareSubmesh().

◆ getBaseNodes()

std::vector< Node * > MeshLib::getBaseNodes ( std::vector< Element * > const & elements)
inline

Returns a vector of node pointers containing the base nodes of the elements input vector.

Definition at line 19 of file MeshLib/Elements/Utils.h.

20{
21 std::vector<Node*> base_nodes;
22 base_nodes.reserve(elements.size() * 2); // Save some of the realloctions.
23
24 for (auto* const e : elements)
25 {
26 std::copy(e->getNodes(), e->getNodes() + e->getNumberOfBaseNodes(),
27 std::back_inserter(base_nodes));
28 }
29
31
32 base_nodes.shrink_to_fit();
33 return base_nodes;
34}
void makeVectorUnique(std::vector< T > &v)
Definition Algorithm.h:173

References idsComparator(), and BaseLib::makeVectorUnique().

Referenced by ProcessLib::HydroMechanics::HydroMechanicsProcess< DisplacementDim >::constructDofTable(), ProcessLib::LIE::HydroMechanics::HydroMechanicsProcess< DisplacementDim >::constructDofTable(), ProcessLib::RichardsMechanics::RichardsMechanicsProcess< DisplacementDim >::constructDofTable(), ProcessLib::TH2M::TH2MProcess< DisplacementDim >::constructDofTable(), ProcessLib::ThermoHydroMechanics::ThermoHydroMechanicsProcess< DisplacementDim >::constructDofTable(), and ProcessLib::ThermoRichardsMechanics::ThermoRichardsMechanicsProcess< DisplacementDim, ConstitutiveTraits >::constructDofTable().

◆ getBulkElementPoint() [1/2]

MathLib::Point3d MeshLib::getBulkElementPoint ( MeshLib::CellType const bulk_element_cell_type,
std::size_t const bulk_face_id,
MathLib::WeightedPoint const & point_on_face )

Maps the given point_on_face on the face a bulk element of type bulk_element_cell_type to the given point in the bulk element.

The input and output coordinates are natural coordinates of the surface and bulk element, respectively. I.e., the output point has one coordinate more than the input point.

Definition at line 212 of file MapBulkElementPoint.cpp.

216{
217 if (point_on_face.getDimension() == 3)
218 {
219 // TODO disable the 3d elements in the local assembler creator
220 return MathLib::ORIGIN;
221 }
222
223 switch (bulk_element_cell_type)
224 {
225 // 3D bulk elements
226 case CellType::HEX8:
227 return getBulkElementPointHex(bulk_face_id, point_on_face);
228 case CellType::PRISM6:
229 return getBulkElementPointPrism(bulk_face_id, point_on_face);
231 return getBulkElementPointPyramid(bulk_face_id, point_on_face);
232 case CellType::TET4:
233 return getBulkElementPointTet(bulk_face_id, point_on_face);
234 // 2D bulk elements
235 case CellType::QUAD4:
236 return getBulkElementPointQuad(bulk_face_id, point_on_face);
237 case CellType::TRI3:
238 return getBulkElementPointTri(bulk_face_id, point_on_face);
239 // 1D bulk elements
240 case CellType::LINE2:
241 return getBulkElementPointLine(bulk_face_id);
242 default:
243 OGS_FATAL(
244 "Wrong cell type '{:s}' or functionality not yet implemented.",
245 CellType2String(bulk_element_cell_type));
246 }
247}
const Point3d ORIGIN
Definition Point3d.h:89
std::string CellType2String(const CellType t)
Given a MeshElemType this returns the appropriate string.

References CellType2String(), MathLib::WeightedPoint::getDimension(), HEX8, LINE2, OGS_FATAL, MathLib::ORIGIN, PRISM6, PYRAMID5, QUAD4, TET4, and TRI3.

Referenced by ProcessLib::ConstraintDirichletBoundaryConditionLocalAssembler< ShapeFunction, GlobalDim >::ConstraintDirichletBoundaryConditionLocalAssembler(), ProcessLib::HCNonAdvectiveFreeComponentFlowBoundaryConditionLocalAssembler< ShapeFunction, GlobalDim >::assemble(), getBulkElementPoint(), and ProcessLib::SurfaceFluxLocalAssembler< ShapeFunction, GlobalDim >::integrate().

◆ getBulkElementPoint() [2/2]

MathLib::Point3d MeshLib::getBulkElementPoint ( MeshLib::Element const & bulk_element,
std::size_t const bulk_face_id,
MathLib::WeightedPoint const & point_on_face )
inline

Overload provided for convenience.

Definition at line 29 of file MapBulkElementPoint.h.

33{
35 bulk_element.getCellType(), bulk_face_id, point_on_face);
36}
MathLib::Point3d getBulkElementPoint(MeshLib::CellType const bulk_element_cell_type, std::size_t const bulk_face_id, MathLib::WeightedPoint const &point_on_face)

References getBulkElementPoint(), and MeshLib::Element::getCellType().

◆ getBulkIDString()

std::string_view MeshLib::getBulkIDString ( MeshItemType mesh_item_type)
constexpr

Returns the mapping MeshItemType -> bulk ID property name, i.e. MeshItemType::Node -> bulk_node_ids MeshItemType::Cell -> bulk_element_ids MeshItemType::Face -> bulk_face_ids

Definition at line 183 of file MeshLib/Properties.h.

184{
185 switch (mesh_item_type)
186 {
188 return "bulk_node_ids";
189 break;
191 return "bulk_element_ids";
192 break;
194 return "bulk_edge_ids";
195 break;
197 return "bulk_face_ids";
198 break;
200 OGS_FATAL("MeshItemType::IntegrationPoint is not handled.");
201 return "";
202 break;
203 default:
204 OGS_FATAL(
205 "Unknown mesh item type '{}'. At the moment mapping names only "
206 "for mesh item types 'Node', 'Cell', 'Edge', and 'Face' are "
207 "specified.",
208 static_cast<int>(mesh_item_type));
209 return "";
210 }
211}

References Cell, Edge, Face, IntegrationPoint, Node, and OGS_FATAL.

Referenced by ProcessLib::GenericNaturalBoundaryCondition< BoundaryConditionData, LocalAssemblerImplementation >::GenericNaturalBoundaryCondition(), ProcessLib::SurfaceFlux::SurfaceFlux(), ProcessLib::addBulkMeshPropertyToSubMesh(), MeshToolsLib::addLayerToMesh(), bulkElementIDs(), bulkNodeIDs(), anonymous_namespace{SubmeshResiduumOutputConfig.cpp}::checkBulkIDMappingsPresent(), ProcessLib::checkParametersOfDirichletBoundaryCondition(), ProcessLib::createHCNonAdvectiveFreeComponentFlowBoundaryCondition(), createMeshFromElementSelection(), ProcessLib::createSourceTerm(), MeshToolsLib::MeshValidation::detectHoles(), DirectConditionGenerator::directWithSurfaceIntegration(), extractBoundaries(), ProcessLib::extractElementsAlongOuterNodes(), getBulkNodeIdMapForPetscIfNecessary(), MeshGeoToolsLib::identifySubdomainMesh(), main(), ApplicationUtils::NodeWiseMeshPartitioner::partitionOtherMesh(), ApplicationUtils::NodeWiseMeshPartitioner::renumberBulkIdsProperty(), and transferPropertiesFromPartitionedMeshToUnpartitionedMesh().

◆ getCenterOfGravity()

MathLib::Point3d MeshLib::getCenterOfGravity ( Element const & element)

Calculates the center of gravity for the mesh element.

Definition at line 131 of file Element.cpp.

132{
133 const unsigned nNodes(element.getNumberOfBaseNodes());
134 MathLib::Point3d center{{0, 0, 0}};
135 for (unsigned i = 0; i < nNodes; ++i)
136 {
137 center.asEigenVector3d() += element.getNode(i)->asEigenVector3d();
138 }
139 center.asEigenVector3d() /= nNodes;
140 return center;
141}
Eigen::Vector3d const & asEigenVector3d() const
Definition Point3d.h:55

References MathLib::Point3d::asEigenVector3d(), MeshLib::Element::getNode(), and MeshLib::Element::getNumberOfBaseNodes().

Referenced by MeshToolsLib::MeshGenerator::AddFaultToVoxelGrid::addFaultToVoxelGrid(), ProcessLib::NormalTractionBoundaryCondition::computeElementNormal(), anonymous_namespace{AddFaultToVoxelGrid.cpp}::markFaults(), LayeredVolume::removeCongruentElements(), FileIO::FEFLOWMeshInterface::setMaterialIDs(), setMaterialIDs(), MeshLib::CellRule::testElementNodeOrder(), and FileIO::TetGenInterface::write3dElements().

◆ getElementRotationMatrices()

std::vector< Eigen::MatrixXd > MeshLib::getElementRotationMatrices ( int const space_dimension,
int const mesh_dimension,
std::vector< Element * > const & elements )

Element rotation matrix computation.

This function returns a vector containing the rotation matrices of given elements. The rotation matrix of an element is used to map the local vector to the global coordinate system. If an element is not inclined, the identity matrix is used as its rotation matrix.

Parameters
space_dimensionThe space dimension.
mesh_dimensionThe mesh dimension.
elementsThe mesh elements.
Returns
A vector of rotation matrices of given elements.

Definition at line 13 of file GetElementRotationMatrices.cpp.

16{
17 std::vector<Eigen::MatrixXd> element_rotation_matrices;
18 element_rotation_matrices.reserve(elements.size());
19 for (auto const* const element : elements)
20 {
21 int const element_dimension = static_cast<int>(element->getDimension());
22 if (element_dimension == space_dimension)
23 {
24 element_rotation_matrices.emplace_back(Eigen::MatrixXd::Identity(
25 element_dimension, element_dimension));
26 }
27 else
28 {
30 *element, mesh_dimension);
31
32 element_rotation_matrices.emplace_back(
33 coordinates_mapping.getRotationMatrixToGlobal().topLeftCorner(
34 space_dimension, element_dimension));
35 }
36 }
37
38 return element_rotation_matrices;
39}

References MeshLib::ElementCoordinatesMappingLocal::getRotationMatrixToGlobal().

Referenced by ProcessLib::ComponentTransport::createComponentTransportProcess(), ProcessLib::HT::createHTProcess(), and ProcessLib::LiquidFlow::createLiquidFlowProcess().

◆ getEndNodeIDRanks()

std::vector< int > MeshLib::getEndNodeIDRanks ( std::size_t const n_global_nodes,
std::vector< std::size_t > const & n_regular_base_nodes_at_rank,
std::vector< std::size_t > const & n_regular_high_order_nodes_at_rank )

Definition at line 8 of file NodePartitionedMesh.cpp.

12{
13 std::vector<int> data;
14
15 std::transform(n_regular_base_nodes_at_rank.begin() + 1,
16 n_regular_base_nodes_at_rank.end(),
17 n_regular_high_order_nodes_at_rank.begin() + 1,
18 std::back_inserter(data), std::plus<int>());
19
20 data.push_back(n_global_nodes);
21
22 return data;
23}

Referenced by MeshLib::NodePartitionedMesh::NodePartitionedMesh().

◆ getIntegrationPointMetaData()

std::optional< IntegrationPointMetaData > MeshLib::getIntegrationPointMetaData ( MeshLib::Properties const & properties)

Returns integration point meta data contained in the mesh properties or an empty optional if the 'IntegrationPointMetaData' array does not exist. The data is read from a JSON encoded string stored in field data array.

Definition at line 68 of file IntegrationPointWriter.cpp.

70{
71 if (!properties.existsPropertyVector<char>("IntegrationPointMetaData"))
72 {
73 return std::nullopt;
74 }
75 auto const& mesh_property_ip_meta_data =
76 *properties.template getPropertyVector<char>(
77 "IntegrationPointMetaData");
78
79 if (mesh_property_ip_meta_data.getMeshItemType() !=
81 {
82 OGS_FATAL("IntegrationPointMetaData array must be field data.");
83 }
84
85 // Find the current integration point data entry and extract the
86 // meta data.
87 return IntegrationPointMetaData{std::string_view{
88 mesh_property_ip_meta_data.data(), mesh_property_ip_meta_data.size()}};
89}

References MeshLib::Properties::existsPropertyVector(), IntegrationPoint, and OGS_FATAL.

Referenced by ApplicationUtils::checkFieldPropertyVectorSize(), ApplicationUtils::copyFieldPropertyDataToPartitions(), createPropertyVector(), determineIntegrationOrder(), MeshToolsLib::getIntegrationPointDataOffsetsOfMeshElements(), MeshToolsLib::mergeMeshToBulkMesh(), ApplicationUtils::setIntegrationPointNumberOfPartition(), and ProcessLib::setIPDataInitialConditions().

◆ getIntegrationPointMetaDataSingleField()

IntegrationPointMetaDataSingleField MeshLib::getIntegrationPointMetaDataSingleField ( std::optional< IntegrationPointMetaData > const & ip_meta_data,
std::string const & field_name )

Returns integration point meta data for single field or an error if an empty optional ip_meta_data is passed.

Definition at line 90 of file IntegrationPointMetaData.cpp.

93{
94 if (!ip_meta_data)
95 {
97 "The required 'IntegrationPointMetaData' array is not available in "
98 "the vtk field data but is needed to evaluate the integration "
99 "point property '{:s}'.",
100 field_name);
101 }
102 return (*ip_meta_data)[field_name];
103}

References OGS_FATAL.

Referenced by ApplicationUtils::checkFieldPropertyVectorSize(), ApplicationUtils::copyFieldPropertyDataToPartitions(), MeshToolsLib::createIntegrationPointProperties(), createPropertyVector(), determineIntegrationOrder(), MeshToolsLib::getIntegrationPointDataOffsetsOfMeshElements(), and ApplicationUtils::setIntegrationPointNumberOfPartition().

◆ getMaxiumElementEdgeLengths()

std::vector< double > MeshLib::getMaxiumElementEdgeLengths ( std::vector< Element * > const & elements)

Returns the maximum lengths of the edges for each element.

Definition at line 11 of file getMaxiumElementEdgeLengths.cpp.

13{
14 std::vector<double> element_edge_lengths(elements.size());
15 for (auto const element : elements)
16 {
17 assert(element->getGeomType() != MeshElemType::POINT);
18
19 auto const& [min_edge_length, max_edge_length] =
21 (void)min_edge_length;
22
23 element_edge_lengths[element->getID()] = std::sqrt(max_edge_length);
24 }
25
26 return element_edge_lengths;
27}
std::pair< double, double > computeSqrEdgeLengthRange(Element const &element)
Compute the minimum and maximum squared edge length for this element.
Definition Element.cpp:163

References computeSqrEdgeLengthRange(), and POINT.

Referenced by NumLib::createNumericalStabilization().

◆ getMeshElementsForMaterialIDs()

std::vector< MeshLib::Element * > MeshLib::getMeshElementsForMaterialIDs ( MeshLib::Mesh const & mesh,
std::vector< int > const & selected_material_ids )

Definition at line 13 of file getMeshElementsForMaterialIDs.cpp.

15{
16 auto const material_ids = *materialIDs(mesh);
17 auto const& elements = mesh.getElements();
18 std::vector<MeshLib::Element*> selected_elements;
19
20 for (std::size_t i = 0; i < material_ids.size(); ++i)
21 {
22 if (ranges::contains(selected_material_ids, material_ids[i]))
23 {
24 selected_elements.push_back(elements[i]);
25 }
26 }
27 return selected_elements;
28}
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition Mesh.cpp:258

References MeshLib::Mesh::getElements(), and materialIDs().

Referenced by createMaterialIDsBasedSubMesh().

◆ getMeshElemTypes()

std::vector< MeshElemType > MeshLib::getMeshElemTypes ( )

Returns a vector of all mesh element types.

Definition at line 121 of file MeshEnums.cpp.

122{
123 std::vector<MeshElemType> vec;
124 vec.push_back(MeshElemType::POINT);
125 vec.push_back(MeshElemType::LINE);
126 vec.push_back(MeshElemType::QUAD);
127 vec.push_back(MeshElemType::HEXAHEDRON);
128 vec.push_back(MeshElemType::TRIANGLE);
129 vec.push_back(MeshElemType::TETRAHEDRON);
130 vec.push_back(MeshElemType::PRISM);
131 vec.push_back(MeshElemType::PYRAMID);
132 return vec;
133}

References HEXAHEDRON, LINE, POINT, PRISM, PYRAMID, QUAD, TETRAHEDRON, and TRIANGLE.

Referenced by MeshModel::createMeshElemTypeMap(), and getMeshElemTypeStringsShort().

◆ getMeshElemTypeStringsShort()

std::vector< std::string > MeshLib::getMeshElemTypeStringsShort ( )

Returns a vector of strings of mesh element types.

Definition at line 135 of file MeshEnums.cpp.

136{
137 std::vector<std::string> vec;
138 auto const& mesh_elem_types = getMeshElemTypes();
139 std::transform(mesh_elem_types.begin(), mesh_elem_types.end(),
140 std::back_inserter(vec),
141 [](auto const& element_type)
142 { return MeshElemType2StringShort(element_type); });
143 return vec;
144}
std::vector< MeshElemType > getMeshElemTypes()
Returns a vector of all mesh element types.

References getMeshElemTypes().

Referenced by main().

◆ getNodeIDinElement()

unsigned MeshLib::getNodeIDinElement ( Element const & element,
const MeshLib::Node * node )

Returns the position of the given node in the node array of this element.

Definition at line 213 of file Element.cpp.

214{
215 const unsigned nNodes(element.getNumberOfNodes());
216 for (unsigned i(0); i < nNodes; i++)
217 {
218 if (node == element.getNode(i))
219 {
220 return i;
221 }
222 }
223 return std::numeric_limits<unsigned>::max();
224}

References MeshLib::Element::getNode(), and MeshLib::Element::getNumberOfNodes().

Referenced by isBaseNode(), and anonymous_namespace{MeshRevision.cpp}::reduceHex().

◆ getNodeIndex()

std::size_t MeshLib::getNodeIndex ( Element const & element,
unsigned idx )

Get the global node index of the node with the local index idx within the element. The index should be at most the number of nodes of the element.

Parameters
elementThe element object that will be searched for the index.
idxLocal index of Node, at most the number of nodes of the element that you can obtain with Element::getNumberOfBaseNodes().
Returns
the global index if idx < Element::getNumberOfBaseNodes. Otherwise in debug mode the value std::numeric_limits<unsigned>::max(). In release mode the behaviour is undefined.
See also
Element::getNode()

Definition at line 226 of file Element.cpp.

227{
228#ifndef NDEBUG
229 if (idx >= element.getNumberOfNodes())
230 {
231 ERR("Error in MeshLib::getNodeIndex() - Index does not "
232 "exist.");
233 return std::numeric_limits<std::size_t>::max();
234 }
235#endif
236 return element.getNode(idx)->getID();
237}

References ERR(), MathLib::Point3dWithID::getID(), MeshLib::Element::getNode(), and MeshLib::Element::getNumberOfNodes().

Referenced by anonymous_namespace{IdentifySubdomainMesh.cpp}::identifySubdomainMeshElements(), and MeshLib::NodeSearch::searchNodesConnectedToOnlyGivenElements().

◆ getNumberOfGlobalNodes()

unsigned long MeshLib::getNumberOfGlobalNodes ( Mesh const * subdomain_mesh)

Definition at line 310 of file transformMeshToNodePartitionedMesh.cpp.

311{
312 // sum all nodes over all partitions in number_of_global_nodes
313 unsigned long const number_of_global_nodes = BaseLib::MPI::allreduce(
314 subdomain_mesh->getNodes().size(), MPI_SUM, BaseLib::MPI::Mpi{});
315 DBUG("[{}] number_of_global_nodes: {}'", subdomain_mesh->getName(),
316 number_of_global_nodes);
317 return number_of_global_nodes;
318}
static T allreduce(T const &value, MPI_Op const &mpi_op, Mpi const &mpi)
Definition MPI.h:122

References BaseLib::MPI::allreduce(), DBUG(), MeshLib::Mesh::getName(), and MeshLib::Mesh::getNodes().

Referenced by transformMeshToNodePartitionedMesh().

◆ getOrCreateMeshProperty()

template<typename T>
PropertyVector< T > * MeshLib::getOrCreateMeshProperty ( Mesh & mesh,
std::string const & property_name,
MeshItemType const item_type,
int const number_of_components )
Returns
a PropertyVector of the corresponding type, name on nodes, or cells, or integration points if such exists, or creates a new one.
Attention
For the integration points the result's size is zero.
See also
MeshLib::addPropertyToMesh()

Definition at line 17 of file getOrCreateMeshProperty.h.

21{
22 if (property_name.empty())
23 {
25 "Trying to get or to create a mesh property with empty name.");
26 }
27
28 auto numberOfMeshItems = [&mesh, &item_type]() -> std::size_t
29 {
30 switch (item_type)
31 {
33 return mesh.getNumberOfElements();
35 return mesh.getNumberOfNodes();
37 return 0; // For the integration point data the size is
38 // variable
39 default:
41 "getOrCreateMeshProperty cannot handle other "
42 "types than Node, Cell, or IntegrationPoint.");
43 }
44 return 0;
45 };
46
47 if (mesh.getProperties().existsPropertyVector<T>(property_name))
48 {
49 auto result =
50 mesh.getProperties().template getPropertyVector<T>(property_name);
51 assert(result);
52 if (item_type != MeshItemType::IntegrationPoint)
53 {
54 // Test the size if number of mesh items is known, which is not the
55 // case for the integration point data.
56 assert(result->size() ==
57 numberOfMeshItems() * number_of_components);
58 }
59 return result;
60 }
61
62 auto result = mesh.getProperties().template createNewPropertyVector<T>(
63 property_name, item_type, numberOfMeshItems(), number_of_components);
64 assert(result);
65 return result;
66}
bool existsPropertyVector(std::string_view name) const

References Cell, MeshLib::Properties::existsPropertyVector(), MeshLib::Mesh::getNumberOfElements(), MeshLib::Mesh::getNumberOfNodes(), MeshLib::Mesh::getProperties(), IntegrationPoint, Node, and OGS_FATAL.

Referenced by ProcessLib::HMPhaseField::HMPhaseFieldProcess< DisplacementDim >::HMPhaseFieldProcess(), ProcessLib::LargeDeformation::LargeDeformationProcess< DisplacementDim >::LargeDeformationProcess(), ProcessLib::LiquidFlow::LiquidFlowProcess::LiquidFlowProcess(), ProcessLib::PhaseField::PhaseFieldProcess< DisplacementDim >::PhaseFieldProcess(), ProcessLib::SolutionDependentDirichletBoundaryCondition::SolutionDependentDirichletBoundaryCondition(), ProcessLib::SurfaceFluxData::SurfaceFluxData(), ProcessLib::ThermoMechanics::ThermoMechanicsProcess< DisplacementDim >::ThermoMechanicsProcess(), ProcessLib::addBulkMeshPropertyToSubMesh(), FileIO::Gocad::GocadSGridReader::addGocadPropertiesToMesh(), addIntegrationPointData(), addIntegrationPointMetaDataSingleField(), addOgsVersion(), addPrimaryVariablesToMesh(), FileIO::SwmmInterface::addResultsToMesh(), addSecondaryVariableNodes(), addSecondaryVariableResiduals(), ChemistryLib::PhreeqcIOData::createAqueousSolution(), MeshToolsLib::createCellProperties(), ChemistryLib::PhreeqcIOData::createEquilibriumReactants(), ChemistryLib::PhreeqcKernelData::createEquilibriumReactants(), ChemistryLib::PhreeqcIOData::createExchange(), MeshToolsLib::createIntegrationPointProperties(), ChemistryLib::PhreeqcIOData::createKineticReactants(), ChemistryLib::PhreeqcKernelData::createKineticReactants(), MeshToolsLib::createMergedPropertyVector(), MeshToolsLib::createNodeProperties(), ProcessLib::LIE::PostProcessTool::createProperty(), createPropertyVector(), anonymous_namespace{AssemblyMixin.cpp}::createResiduumVectors(), ChemistryLib::PhreeqcIOData::createSurface(), ChemistryLib::PhreeqcIOData::createUserPunch(), ProcessLib::CellAverageData::getOrCreatePropertyVector(), ProcessLib::ComponentTransport::ComponentTransportProcess::initializeConcreteProcess(), ProcessLib::HMPhaseField::HMPhaseFieldProcess< DisplacementDim >::initializeConcreteProcess(), ProcessLib::HydroMechanics::HydroMechanicsProcess< DisplacementDim >::initializeConcreteProcess(), ProcessLib::LIE::HydroMechanics::HydroMechanicsProcess< DisplacementDim >::initializeConcreteProcess(), ProcessLib::LIE::SmallDeformation::SmallDeformationProcess< DisplacementDim >::initializeConcreteProcess(), ProcessLib::RichardsMechanics::RichardsMechanicsProcess< DisplacementDim >::initializeConcreteProcess(), ProcessLib::TH2M::TH2MProcess< DisplacementDim >::initializeConcreteProcess(), ProcessLib::ThermoHydroMechanics::ThermoHydroMechanicsProcess< DisplacementDim >::initializeConcreteProcess(), ProcessLib::ThermoRichardsFlow::ThermoRichardsFlowProcess::initializeConcreteProcess(), ProcessLib::ThermoRichardsMechanics::ThermoRichardsMechanicsProcess< DisplacementDim, ConstitutiveTraits >::initializeConcreteProcess(), ProcessLib::WellboreSimulator::WellboreSimulatorProcess::initializeConcreteProcess(), ProcessLib::SurfaceFluxData::integrate(), ProcessLib::LIE::HydroMechanics::HydroMechanicsProcess< DisplacementDim >::postTimestepConcreteProcess(), MeshToolsLib::processPropertyVector(), MeshGeoToolsLib::resetMeshElementProperty(), transfer(), ProcessLib::LIE::HydroMechanics::HydroMechanicsProcess< DisplacementDim >::updateElementLevelSets(), and ProcessLib::LIE::SmallDeformation::SmallDeformationProcess< DisplacementDim >::updateElementLevelSets().

◆ getSpaceDimension()

int MeshLib::getSpaceDimension ( std::vector< Node * > const & nodes)

Computes dimension of the embedding space containing the set of given points.

The space dimension is computed by accounting the non-zero norms of \(\mathbf x\), \(\mathbf y\), \(\mathbf z\), which are the coordinates of all nodes of the mesh. With this concept, the space dimension is:

  • 1, if all nodes are on a line that is parallel to \(x\) axis.
  • 2, if all nodes are on a line that is parallel to \(y\) axis.
  • 3, if all nodes are on a line that is parallel to \(z\) axis.
  • 2, if all nodes are distributed on a plane that is parallel to the origin coordinate plane of \(x-y\) (including the case of mesh with 1D inclined elements).
  • 3, if all nodes are distributed on a plane that is parallel to the origin coordinate plane of \(y-z\) or \(x-z\) (including the case of mesh with 1D inclined elements)..
  • 3, if all nodes are scattered in 3D space (e.g. mesh with inclined 1D, 2D elements, 3D elements).

Definition at line 15 of file GetSpaceDimension.cpp.

16{
17 Eigen::Vector3d x_magnitude = Eigen::Vector3d::Zero();
18 auto const x_ref = nodes[0]->asEigenVector3d();
19
20 for (auto const& node : nodes)
21 {
22 auto const x = node->asEigenVector3d();
23 x_magnitude += (x - x_ref).cwiseAbs();
24 }
25
26 // Z coordinate norm is not zero whichever 1D, 2D or 3D mesh:
27 if (x_magnitude[2] > 0)
28 {
29 return 3;
30 }
31
32 const auto computed_dimension = std::count_if(
33 x_magnitude.begin(), x_magnitude.end(),
34 [](const double x_i_magnitude)
35 { return x_i_magnitude > std::numeric_limits<double>::epsilon(); });
36
37 // 1D mesh in y direction:
38 if (computed_dimension == 1 && x_magnitude[1] > 0)
39 {
40 return 2;
41 }
42
43 return static_cast<int>(computed_dimension);
44}

Referenced by ProcessLib::ComponentTransport::createComponentTransportProcess(), ProcessLib::HeatConduction::createHeatConductionProcess(), ProcessLib::HT::createHTProcess(), ProcessLib::LiquidFlow::createLiquidFlowProcess(), main(), and setMeshSpaceDimension().

◆ getUniqueNodes()

std::vector< Node * > MeshLib::getUniqueNodes ( std::vector< Element * > const & elements)

Create a vector of unique nodes used by given elements.

Definition at line 156 of file NodeSearch.cpp.

157{
158 std::set<Node*> nodes_set;
159 for (auto e : elements)
160 {
161 Node* const* nodes = e->getNodes();
162 unsigned const nnodes = e->getNumberOfNodes();
163 nodes_set.insert(nodes, nodes + nnodes);
164 }
165
166 std::vector<Node*> nodes;
167 nodes.reserve(nodes_set.size());
168
169 std::move(nodes_set.cbegin(), nodes_set.cend(), std::back_inserter(nodes));
170
171 return nodes;
172}

◆ globalIDString()

std::string_view MeshLib::globalIDString ( MeshLib::MeshItemType const mesh_item_type)
constexpr

Definition at line 213 of file MeshLib/Properties.h.

215{
216 switch (mesh_item_type)
217 {
219 {
220 return "global_node_ids";
221 }
223 {
224 return "global_element_ids";
225 }
227 OGS_FATAL("MeshItemType::Edge is not handled in globalIDString.");
229 OGS_FATAL("MeshItemType::Face is not handled in globalIDString.");
231 OGS_FATAL(
232 "MeshItemType::IntegrationPoint is not handled in "
233 "globalIDString.");
234 default:
235 return "";
236 }
237}

References Cell, Edge, Face, IntegrationPoint, Node, and OGS_FATAL.

Referenced by addGlobalIDsToMesh(), addGlobalIDsToMesh(), and transferPropertiesFromPartitionedMeshToUnpartitionedMesh().

◆ hasZeroVolume()

bool MeshLib::hasZeroVolume ( MeshLib::Element const & element)

Returns true if the element has zero length/area/volume.

Definition at line 126 of file Element.cpp.

127{
128 return element.getContent() < std::numeric_limits<double>::epsilon();
129}

References MeshLib::Element::getContent().

Referenced by MeshLib::HexRule::validate(), MeshLib::LineRule::validate(), MeshLib::PointRule1::validate(), MeshLib::PrismRule::validate(), MeshLib::PyramidRule::validate(), MeshLib::QuadRule::validate(), MeshLib::TetRule::validate(), and MeshLib::TriRule::validate().

◆ idsComparator()

template<typename T>
bool MeshLib::idsComparator ( T const a,
T const b )

Lexicographic comparison of ids of two objects of type T. T can be a pointer or a value type.

Definition at line 197 of file Mesh.h.

198{
199 if constexpr (std::is_pointer_v<T>)
200 {
201 return a->getID() < b->getID();
202 }
203 else
204 {
205 return a.getID() < b.getID();
206 }
207}

Referenced by calculateNodesConnectedByElements(), getBaseNodes(), ProcessLib::HeatTransportBHE::getBHEDataInMesh(), ProcessLib::LIE::getFractureMatrixDataInMesh(), and reorderNonlinearNodes().

◆ is2DMeshOnRotatedVerticalPlane()

bool MeshLib::is2DMeshOnRotatedVerticalPlane ( Mesh const & mesh)

Definition at line 16 of file Is2DMeshOnRotatedVerticalPlane.cpp.

17{
18 auto const mesh_dimension = mesh.getDimension();
19 if (mesh_dimension != 2)
20 {
22 "A 2D mesh is required for this computation but the provided mesh, "
23 "mesh {:s}, has {:d}D elements.",
24 mesh.getName(), mesh_dimension);
25 }
26
27 auto const& elements = mesh.getElements();
28
29 bool const has_inclined_element =
30 std::any_of(elements.begin(), elements.end(),
31 [&mesh_dimension](auto const& element)
32 { return element->space_dimension_ != mesh_dimension; });
33
34 if (!has_inclined_element)
35 {
36 return false;
37 }
38
39 const bool is_rotated_around_y_axis = std::all_of(
40 elements.cbegin(), elements.cend(),
41 [](auto const& element)
42 {
43 // 3 nodes are enough to make up a plane.
44 auto const x1 = element->getNode(0)->data();
45 auto const x2 = element->getNode(1)->data();
46 auto const x3 = element->getNode(2)->data();
47
48 double const a0 = x2[0] - x1[0];
49 double const a2 = x2[2] - x1[2];
50
51 double const b0 = x3[0] - x1[0];
52 double const b2 = x3[2] - x1[2];
53
54 double const e_n_1 = -a0 * b2 + a2 * b0;
55 return std::fabs(e_n_1) < std::numeric_limits<double>::epsilon();
56 });
57
58 const bool is_rotated_around_z_axis = std::all_of(
59 elements.cbegin(), elements.cend(),
60 [](auto const& element)
61 {
62 // 3 nodes are enough to make up a plane.
63 auto const x1 = element->getNode(0)->data();
64 auto const x2 = element->getNode(1)->data();
65 auto const x3 = element->getNode(2)->data();
66
67 double const a0 = x2[0] - x1[0];
68 double const a1 = x2[1] - x1[1];
69
70 double const b0 = x3[0] - x1[0];
71 double const b1 = x3[1] - x1[1];
72
73 double const e_n_2 = a0 * b1 - a1 * b0;
74 return std::fabs(e_n_2) < std::numeric_limits<double>::epsilon();
75 });
76
77 if (!(is_rotated_around_y_axis || is_rotated_around_z_axis))
78 {
80 "2D Mesh {:s} is on an inclined plane, which is neither a vertical "
81 "nor horizontal plane that is required for the present "
82 "computation.",
83 mesh.getName());
84 }
85
86 return true;
87}

References MeshLib::Mesh::getDimension(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getName(), and OGS_FATAL.

Referenced by ProcessLib::HydroMechanics::createHydroMechanicsProcess().

◆ isBaseNode()

bool MeshLib::isBaseNode ( Node const & node,
std::vector< Element const * > const & elements_connected_to_node )

Returns true if the given node is a base node of a (first) element, or if it is not connected to any element i.e. an unconnected node.

Definition at line 336 of file Mesh.cpp.

338{
339 // Check if node is connected.
340 if (elements_connected_to_node.empty())
341 {
342 return true;
343 }
344
345 // In a mesh a node always belongs to at least one element.
346 auto const e = elements_connected_to_node[0];
347
348 auto const n_base_nodes = e->getNumberOfBaseNodes();
349 auto const local_index = getNodeIDinElement(*e, &node);
350 assert(local_index <= e->getNumberOfNodes());
351 return local_index < n_base_nodes;
352}
unsigned getNodeIDinElement(Element const &element, const MeshLib::Node *node)
Returns the position of the given node in the node array of this element.
Definition Element.cpp:213

References getNodeIDinElement().

Referenced by MeshGeoToolsLib::MeshNodesOnPoint::MeshNodesOnPoint(), MeshLib::Mesh::computeNumberOfBaseNodes(), NumLib::MeshComponentMap::createParallelMeshComponentMap(), and NumLib::MeshComponentMap::getSubset().

◆ isPointInElementXY()

bool MeshLib::isPointInElementXY ( MathLib::Point3d const & p,
Element const & e )

Let \(p'\) the orthogonal projection to the \(x\)- \(y\) plane of the point p and \(e'\) the orthogonal projection to the \(x\)- \(y\) plane of the element e. The method checks if \(p'\) is located in \(e'\).

Todo
At the moment the test works only for triangle and quad elements.
Parameters
pMathLib::Point3d is the test point
ethe element that is used for the request
Returns
true if the \(p' \in e'\) and false if \(p' \notin e'\)

Definition at line 178 of file Element.cpp.

179{
180 for (std::size_t i(0); i < e.getNumberOfBaseNodes(); ++i)
181 {
182 if (MathLib::sqrDist2d(p, *e.getNode(i)) <
183 std::numeric_limits<double>::epsilon())
184 {
185 return true;
186 }
187 }
188
189 if (e.getGeomType() == MeshElemType::TRIANGLE)
190 {
191 MathLib::Point3d const& n0(*e.getNode(0));
192 MathLib::Point3d const& n1(*e.getNode(1));
193 MathLib::Point3d const& n2(*e.getNode(2));
194
195 return MathLib::isPointInTriangleXY(p, n0, n1, n2);
196 }
197 if (e.getGeomType() == MeshElemType::QUAD)
198 {
199 MathLib::Point3d const& n0(*e.getNode(0));
200 MathLib::Point3d const& n1(*e.getNode(1));
201 MathLib::Point3d const& n2(*e.getNode(2));
202 MathLib::Point3d const& n3(*e.getNode(3));
203
204 return MathLib::isPointInTriangleXY(p, n0, n1, n2) ||
205 MathLib::isPointInTriangleXY(p, n0, n2, n3);
206 }
207
208 WARN("isPointInElementXY: element type '{:s}' is not supported.",
209 MeshLib::MeshElemType2String(e.getGeomType()));
210 return false;
211}
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34
double sqrDist2d(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition Point3d.h:114
bool isPointInTriangleXY(MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c)
std::string MeshElemType2String(const MeshElemType t)
Given a MeshElemType this returns the appropriate string.
Definition MeshEnums.cpp:10

References MeshLib::Element::getGeomType(), MeshLib::Element::getNode(), MeshLib::Element::getNumberOfBaseNodes(), MathLib::isPointInTriangleXY(), MeshElemType2String(), QUAD, MathLib::sqrDist2d(), TRIANGLE, and WARN().

Referenced by MeshToolsLib::Mesh2MeshPropertyInterpolation::interpolatePropertiesForMesh().

◆ materialIDs() [1/2]

PropertyVector< int > * MeshLib::materialIDs ( Mesh & mesh)

Definition at line 276 of file Mesh.cpp.

277{
278 return const_cast<PropertyVector<int>*>(
279 MeshLib::materialIDs(std::as_const(mesh)));
280}

References materialIDs().

◆ materialIDs() [2/2]

PropertyVector< int > const * MeshLib::materialIDs ( Mesh const & mesh)

Returns the material ids property vector defined on the mesh.

The material ids are always an int property named "MaterialIDs". If the property does not exists (or is of different type), a nullptr is returned.

Definition at line 258 of file Mesh.cpp.

259{
260 auto const& properties = mesh.getProperties();
261 if (properties.existsPropertyVector<int>("MaterialIDs",
263 {
264 return properties.getPropertyVector<int>(
265 "MaterialIDs", MeshLib::MeshItemType::Cell, 1);
266 }
267 if (properties.hasPropertyVector("MaterialIDs"))
268 {
269 WARN(
270 "The 'MaterialIDs' mesh property exists but is either of wrong "
271 "type (must be int), or it is not defined on element / cell data.");
272 }
273 return nullptr;
274}

References Cell, MeshLib::Mesh::getProperties(), and WARN().

Referenced by AddFaultsToVoxelGridDialog::accept(), ProcessLib::LIE::anonymous_namespace{MeshUtils.cpp}::findFracutreIntersections(), ProcessLib::HeatTransportBHE::getBHEDataInMesh(), MeshToolsLib::MeshInformation::getMaterialIDs(), getMeshElementsForMaterialIDs(), main(), anonymous_namespace{AddFaultToVoxelGrid.cpp}::markFaults(), markSpecificElements(), and materialIDs().

◆ MeshElemType2String()

std::string MeshLib::MeshElemType2String ( const MeshElemType t)

Given a MeshElemType this returns the appropriate string.

Definition at line 10 of file MeshEnums.cpp.

11{
12 if (t == MeshElemType::POINT)
13 {
14 return "Point";
15 }
16 if (t == MeshElemType::LINE)
17 {
18 return "Line";
19 }
20 if (t == MeshElemType::QUAD)
21 {
22 return "Quad";
23 }
25 {
26 return "Hexahedron";
27 }
29 {
30 return "Triangle";
31 }
33 {
34 return "Tetrahedron";
35 }
36 if (t == MeshElemType::PRISM)
37 {
38 return "Prism";
39 }
40 if (t == MeshElemType::PYRAMID)
41 {
42 return "Pyramid";
43 }
44 return "none";
45}

References HEXAHEDRON, LINE, POINT, PRISM, PYRAMID, QUAD, TETRAHEDRON, and TRIANGLE.

Referenced by MeshModel::createMeshElemTypeMap(), MeshLib::TemplateElement< ELEMENT_RULE >::getNode(), MeshLib::TemplateElement< ELEMENT_RULE >::getNode(), isPointInElementXY(), MeshLib::Element::operator<<, ElementTreeModel::setMesh(), and MeshToolsLib::MeshInformation::writeAllNumbersOfElementTypes().

◆ MeshElemType2StringShort()

std::string MeshLib::MeshElemType2StringShort ( const MeshElemType t)

Given a MeshElemType this returns the appropriate string with a short name.

Definition at line 47 of file MeshEnums.cpp.

48{
49 if (t == MeshElemType::POINT)
50 {
51 return "point";
52 }
53 if (t == MeshElemType::LINE)
54 {
55 return "line";
56 }
57 if (t == MeshElemType::QUAD)
58 {
59 return "quad";
60 }
62 {
63 return "hex";
64 }
66 {
67 return "tri";
68 }
70 {
71 return "tet";
72 }
73 if (t == MeshElemType::PRISM)
74 {
75 return "pris";
76 }
77 if (t == MeshElemType::PYRAMID)
78 {
79 return "pyra";
80 }
81 return "none";
82}

References HEXAHEDRON, LINE, POINT, PRISM, PYRAMID, QUAD, TETRAHEDRON, and TRIANGLE.

◆ MeshQualityType2String()

std::string MeshLib::MeshQualityType2String ( const MeshQualityType t)

Definition at line 175 of file MeshEnums.cpp.

176{
178 {
179 return "ElementSize";
180 }
182 {
183 return "EdgeRatio";
184 }
186 {
187 return "EquiAngleSkew";
188 }
190 {
191 return "RadiusEdgeRatio";
192 }
194 {
195 return "SizeDifference";
196 }
197 return "none";
198}

References EDGERATIO, ELEMENTSIZE, EQUIANGLESKEW, RADIUSEDGERATIO, and SIZEDIFFERENCE.

◆ minMaxEdgeLength()

std::pair< double, double > MeshLib::minMaxEdgeLength ( std::vector< Element * > const & elements)

Returns the minimum and maximum edge length for given elements.

Definition at line 179 of file Mesh.cpp.

181{
182 auto min_max = [](auto const a, auto const b) -> std::pair<double, double> {
183 return {std::min(a.first, b.first), std::max(a.second, b.second)};
184 };
185
186 using limits = std::numeric_limits<double>;
187 auto const bounds = ranges::accumulate(
188 elements, std::pair{limits::infinity(), -limits::infinity()}, min_max,
189 [](Element const* const e) { return computeSqrEdgeLengthRange(*e); });
190
191 return {std::sqrt(bounds.first), std::sqrt(bounds.second)};
192}

References computeSqrEdgeLengthRange().

◆ operator!=()

bool MeshLib::operator!= ( Mesh const & a,
Mesh const & b )
inline

Definition at line 170 of file Mesh.h.

171{
172 return !(a == b);
173}

◆ operator<()

bool MeshLib::operator< ( const Location & left,
const Location & right )
inline

Lexicographic order of Location.

Definition at line 30 of file Location.h.

31{
32 if (left.mesh_id != right.mesh_id)
33 {
34 return left.mesh_id < right.mesh_id;
35 }
36 if (left.item_type != right.item_type)
37 {
38 return left.item_type < right.item_type;
39 }
40 return left.item_id < right.item_id;
41}
std::size_t item_id
Definition Location.h:22
std::size_t mesh_id
Definition Location.h:20
MeshItemType item_type
Definition Location.h:21

References MeshLib::Location::item_id, MeshLib::Location::item_type, and MeshLib::Location::mesh_id.

◆ operator<<() [1/4]

std::ostream & MeshLib::operator<< ( std::ostream & os,
Element const & e )

Definition at line 97 of file Element.cpp.

98{
99 os << "element #" << e._id << " @ " << &e << " with "
100 << e.getNumberOfNeighbors() << " neighbours\n";
101
102 unsigned const nnodes = e.getNumberOfNodes();
103 MeshLib::Node* const* const nodes = e.getNodes();
104 os << "MeshElemType: " << MeshLib::MeshElemType2String(e.getGeomType())
105 << " with " << nnodes << " nodes: {\n";
106 for (unsigned n = 0; n < nnodes; ++n)
107 {
108 os << " " << *nodes[n] << " @ " << nodes[n] << '\n';
109 }
110 return os << '}';
111}

◆ operator<<() [2/4]

std::ostream & MeshLib::operator<< ( std::ostream & os,
Location const & l )

Definition at line 28 of file Location.cpp.

29{
30 return os << "(" << l.mesh_id << ", " << l.item_type << ", " << l.item_id
31 << ")";
32}

References MeshLib::Location::item_id, MeshLib::Location::item_type, and MeshLib::Location::mesh_id.

◆ operator<<() [3/4]

std::ostream & MeshLib::operator<< ( std::ostream & os,
MeshItemType const & t )

Definition at line 10 of file Location.cpp.

11{
12 switch (t)
13 {
15 return os << "N";
17 return os << "E";
19 return os << "F";
21 return os << "C";
23 return os << "I";
24 };
25 return os;
26}

References Cell, Edge, Face, IntegrationPoint, and Node.

◆ operator<<() [4/4]

std::ostream & MeshLib::operator<< ( std::ostream & os,
MeshLib::Node const & n )

Definition at line 26 of file Node.cpp.

27{
28 return os << "node #" << n.getID() << " { "
29 << static_cast<MathLib::Point3d const&>(n) << "}";
30}

◆ operator==()

bool MeshLib::operator== ( Mesh const & a,
Mesh const & b )
inline

Meshes are equal if their id's are equal.

Definition at line 165 of file Mesh.h.

166{
167 return a.getID() == b.getID();
168}

References MeshLib::Mesh::getID().

◆ scaleMeshPropertyVector()

void MeshLib::scaleMeshPropertyVector ( Mesh & mesh,
std::string const & property_name,
double factor )

Scales the mesh property with name property_name by given factor.

Note
The property must be a "double" property.

Definition at line 12 of file scaleMeshPropertyVector.cpp.

15{
16 if (!mesh.getProperties().existsPropertyVector<double>(property_name))
17 {
18 WARN("Did not find PropertyVector '{:s}' for scaling.", property_name);
19 return;
20 }
21 auto& pv = *mesh.getProperties().getPropertyVector<double>(property_name);
22 ranges::transform(pv, pv.begin(),
23 [factor](auto const& v) { return v * factor; });
24}
PropertyVector< T > const * getPropertyVector(std::string_view name) const

References MeshLib::Properties::existsPropertyVector(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), and WARN().

Referenced by main().

◆ setMeshSpaceDimension()

void MeshLib::setMeshSpaceDimension ( std::vector< std::unique_ptr< Mesh > > const & meshes)

In this function, the dimension of the space, which contains all nodes of the bulk mesh, is computed, and it is then set as a member of the elements of all meshes.

The space dimension is needed for the numerical simulations with a bulk mesh with elements with different dimensions. For example, in a bulk mesh for the numerical simulation of the liquid flow in the fractured porous media, the 1D or 2D elements can be used to represent the fractures, while the elements with higher dimension can be used to discretise the porous medium matrix domain.

Parameters
meshesAll meshes include the bulk mesh and the meshes for boundary conditions.

Definition at line 14 of file SetMeshSpaceDimension.cpp.

15{
16 // Get the space dimension from the bulk mesh:
17 auto const d = getSpaceDimension(meshes[0]->getNodes());
18 for (auto const& mesh : meshes)
19 {
20 ranges::for_each(mesh->getElements(),
21 [d](Element* const e) { e->space_dimension_ = d; });
22 }
23}
std::vector< std::size_t > getNodes(GeoLib::Point const &pnt, std::vector< MeshLib::Node * > const &nodes, MeshLib::PropertyVector< int > const &mat_ids, std::pair< int, int > const &mat_limits, std::pair< double, double > const &elevation_limits, MeshLib::Mesh const &mesh)
int getSpaceDimension(std::vector< Node * > const &nodes)
Computes dimension of the embedding space containing the set of given points.

References getNodes(), and getSpaceDimension().

Referenced by anonymous_namespace{ProjectData.cpp}::readMeshes().

◆ String2MeshElemType()

MeshElemType MeshLib::String2MeshElemType ( const std::string & s)

Given a string of the shortened name of the element type, this returns the corresponding MeshElemType.

Definition at line 84 of file MeshEnums.cpp.

85{
86 if (boost::iequals(s, "point"))
87 {
89 }
90 if (boost::iequals(s, "line"))
91 {
92 return MeshElemType::LINE;
93 }
94 if (boost::iequals(s, "quad") || boost::iequals(s, "Quadrilateral"))
95 {
96 return MeshElemType::QUAD;
97 }
98 if (boost::iequals(s, "hex") || boost::iequals(s, "Hexahedron"))
99 {
101 }
102 if (boost::iequals(s, "tri") || boost::iequals(s, "Triangle"))
103 {
105 }
106 if (boost::iequals(s, "tet") || boost::iequals(s, "Tetrahedron"))
107 {
109 }
110 if (boost::iequals(s, "pris") || boost::iequals(s, "Prism"))
111 {
112 return MeshElemType::PRISM;
113 }
114 if (boost::iequals(s, "pyra") || boost::iequals(s, "Pyramid"))
115 {
117 }
119}

References HEXAHEDRON, INVALID, LINE, POINT, PRISM, PYRAMID, QUAD, TETRAHEDRON, and TRIANGLE.

Referenced by MeshElementRemovalDialog::accept(), main(), and anonymous_namespace{MeshIO.cpp}::readElement().

◆ String2MeshQualityType()

MeshLib::MeshQualityType MeshLib::String2MeshQualityType ( std::string const & s)

Definition at line 200 of file MeshEnums.cpp.

201{
202 if (boost::iequals(s, "ElementSize"))
203 {
205 }
206 if (boost::iequals(s, "EdgeRatio"))
207 {
209 }
210 if (boost::iequals(s, "EquiAngleSkew"))
211 {
213 }
214 if (boost::iequals(s, "RadiusEdgeRatio"))
215 {
217 }
218 if (boost::iequals(s, "SizeDifference"))
219 {
221 }
223}

References EDGERATIO, ELEMENTSIZE, EQUIANGLESKEW, INVALID, RADIUSEDGERATIO, and SIZEDIFFERENCE.

Referenced by main().

◆ toString()

constexpr char const * MeshLib::toString ( const MeshItemType t)
staticconstexpr

◆ transformMeshToNodePartitionedMesh()

std::unique_ptr< MeshLib::NodePartitionedMesh > MeshLib::transformMeshToNodePartitionedMesh ( NodePartitionedMesh const *const bulk_mesh,
Mesh const *const subdomain_mesh )

Function computes all information necessary to transform the MeshLib::Mesh mesh into a NodePartitionedMesh subdomain mesh. Additional to the usual name, nodes and elements, the following information is computed:

  • a vector of global node ids of the subdomain mesh,
  • the number of global nodes (the sum of number of nodes of all subdomain meshes)
  • the number of regular nodes (the sum of number of non-ghost nodes of all subdomain meshes)
  • a vector containing the number of regular base nodes per rank
  • a vector containing the number of regular higher order nodes per rank

Definition at line 320 of file transformMeshToNodePartitionedMesh.cpp.

323{
324 DBUG("Creating NodePartitionedMesh from '{}'", subdomain_mesh->getName());
325
326 auto const subdomain_global_node_ids =
327 computeGlobalNodeIDsOfSubDomainPartition(bulk_mesh, subdomain_mesh);
328
329 // according to comment in struct PartitionedMeshInfo this value
330 // is unused
331 unsigned long number_of_global_base_nodes = 0;
332
333 unsigned long const number_of_global_nodes =
334 getNumberOfGlobalNodes(subdomain_mesh);
335 auto numbers_of_regular_base_nodes_at_rank =
337 auto numbers_of_regular_higher_order_nodes_at_rank =
339
340 auto const number_of_regular_nodes =
341 computeNumberOfRegularNodes(bulk_mesh, subdomain_mesh);
342 DBUG("[{}] number_of_regular_nodes: {}", subdomain_mesh->getName(),
343 number_of_regular_nodes);
344 auto const [nodes, elements] =
345 copyNodesAndElements(subdomain_mesh->getElements());
346
347 return std::make_unique<NodePartitionedMesh>(
348 subdomain_mesh->getName(), nodes, subdomain_global_node_ids, elements,
349 subdomain_mesh->getProperties(), number_of_global_base_nodes,
350 number_of_global_nodes, number_of_regular_nodes,
351 std::move(numbers_of_regular_base_nodes_at_rank),
352 std::move(numbers_of_regular_higher_order_nodes_at_rank));
353}
std::pair< std::vector< Node * >, std::vector< Element * > > copyNodesAndElements(std::vector< Element * > const &input_elements)
unsigned long getNumberOfGlobalNodes(Mesh const *subdomain_mesh)
std::vector< std::size_t > computeNumberOfRegularHigherOrderNodesAtRank(Mesh const *subdomain_mesh)
std::vector< std::size_t > computeGlobalNodeIDsOfSubDomainPartition(NodePartitionedMesh const *bulk_mesh, Mesh const *subdomain_mesh)
std::vector< std::size_t > computeNumberOfRegularBaseNodesAtRank(Mesh const *subdomain_mesh)

References computeGlobalNodeIDsOfSubDomainPartition(), computeNumberOfRegularBaseNodesAtRank(), computeNumberOfRegularHigherOrderNodesAtRank(), computeNumberOfRegularNodes(), copyNodesAndElements(), DBUG(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getName(), getNumberOfGlobalNodes(), and MeshLib::Mesh::getProperties().

Referenced by MeshGeoToolsLib::constructAdditionalMeshesFromGeometries(), and parseOutputMeshConfig().

◆ vtkStandardNewMacro()

MeshLib::vtkStandardNewMacro ( VtkMappedMeshSource )

Definition at line 25 of file VtkMappedMeshSource.cpp.

28{
29 this->Superclass::PrintSelf(os, indent);
30 os << indent << "Mesh: " << (_mesh ? _mesh->getName() : "(none)") << endl;
31}

References MeshLib::VtkMappedMeshSource::_mesh, and MeshLib::Mesh::getName().

Variable Documentation

◆ mesh_item_type_strings

char const* MeshLib::mesh_item_type_strings[]
staticconstexpr
Initial value:
= {
"node", "edge", "face", "cell", "integration_point"}

Char array names for all of MeshItemType values.

Definition at line 21 of file MeshEnums.h.

21 {
22 "node", "edge", "face", "cell", "integration_point"};

Referenced by toString().