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
 
struct  IntegrationPointMetaData
 
struct  IntegrationPointWriter
 
class  LinearEdgeReturn
 Returns linear order edge. More...
 
class  LineRule
 
class  LineRule2
 
class  LineRule3
 
struct  Location
 
class  Mesh
 
class  MeshElementGrid
 
class  MeshSubset
 A subset of nodes on a single mesh. More...
 
class  Node
 
class  NodeAdjacencyTable
 
class  NodePartitionedMesh
 A subdomain mesh. More...
 
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
 
class  VtkMeshConverter
 Converter for VtkUnstructured Grids to OGS meshes. More...
 
class  VtkMeshNodalCoordinatesTemplate
 

Typedefs

using RotationMatrix = Eigen::Matrix< double, 3u, 3u, Eigen::RowMajor >
 
using AllElementTypes = std::tuple< Point, Line, Line3, Quad, Quad8, Quad9, Hex, Hex20, Tri, Tri6, Tet, Tet10, Prism, Prism15, Pyramid, Pyramid13 >
 
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)
 
static constexpr char const * toString (const MeshItemType t)
 Returns a char array for a specific MeshItemType.
 
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)
 
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)
 
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::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)
 
template<typename T >
void addPropertyToMesh (Mesh &mesh, std::string_view name, MeshItemType item_type, std::size_t number_of_components, std::vector< 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.
 
void addIntegrationPointDataToMesh (MeshLib::Mesh &mesh, std::vector< std::unique_ptr< IntegrationPointWriter > > const &integration_point_writer)
 
IntegrationPointMetaData getIntegrationPointMetaData (MeshLib::Properties const &properties, std::string const &name)
 
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< int, int > getMPIRankAndSize (MPI_Comm const &mpi_comm)
 
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

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 32 of file Elements.h.

◆ Hex

Definition at line 25 of file Hex.h.

◆ Hex20

Definition at line 26 of file Hex.h.

◆ Line

Definition at line 25 of file Line.h.

◆ Line3

Definition at line 26 of file Line.h.

◆ Point

Definition at line 20 of file Point.h.

◆ Prism

Definition at line 25 of file Prism.h.

◆ Prism15

Definition at line 26 of file Prism.h.

◆ Pyramid

Definition at line 25 of file Pyramid.h.

◆ Pyramid13

Definition at line 26 of file Pyramid.h.

◆ Quad

Definition at line 28 of file Quad.h.

◆ Quad8

Definition at line 29 of file Quad.h.

◆ Quad9

Definition at line 30 of file Quad.h.

◆ RotationMatrix

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

Definition at line 24 of file ElementCoordinatesMappingLocal.h.

◆ Tet

Definition at line 25 of file Tet.h.

◆ Tet10

Definition at line 26 of file Tet.h.

◆ Tri

Definition at line 26 of file Tri.h.

◆ Tri6

Definition at line 27 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 42 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 26 of file MeshEnums.h.

◆ MeshItemType

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

Definition at line 21 of file Location.h.

◆ MeshQualityType

enum class MeshLib::MeshQualityType
strong

Describes a mesh quality metric.

Enumerator
INVALID 
ELEMENTSIZE 
SIZEDIFFERENCE 
EDGERATIO 
EQUIANGLESKEW 
RADIUSEDGERATIO 

Definition at line 69 of file MeshEnums.h.

◆ UseIntensityAs

enum class MeshLib::UseIntensityAs
strong

Selection of possible interpretations for intensities.

Enumerator
ELEVATION 
MATERIALS 
DATAVECTOR 
NONE 

Definition at line 82 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 92 of file IntegrationPointWriter.cpp.

96{
97 std::vector<IntegrationPointMetaData> meta_data;
98 meta_data.reserve(size(integration_point_writer));
99 transform(cbegin(integration_point_writer), cend(integration_point_writer),
100 back_inserter(meta_data),
101 [&](auto const& ip_writer)
102 { return addIntegrationPointData(mesh, *ip_writer); });
103 if (!meta_data.empty())
104 {
105 addIntegrationPointMetaData(mesh, meta_data);
106 }
107}
static MeshLib::IntegrationPointMetaData addIntegrationPointData(MeshLib::Mesh &mesh, MeshLib::IntegrationPointWriter const &writer)
static void addIntegrationPointMetaData(MeshLib::Mesh &mesh, std::vector< MeshLib::IntegrationPointMetaData > const &meta_data)

References addIntegrationPointData(), and addIntegrationPointMetaData().

◆ addPropertyToMesh()

template<typename T >
void MeshLib::addPropertyToMesh ( Mesh mesh,
std::string_view  name,
MeshItemType  item_type,
std::size_t  number_of_components,
std::vector< 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 34 of file addPropertyToMesh.h.

37{
38 if (item_type == MeshItemType::Node)
39 {
40 if (mesh.getNumberOfNodes() != values.size() / number_of_components)
41 {
43 "Error number of nodes ({:d}) does not match the number of "
44 "tuples ({:d}).",
45 mesh.getNumberOfNodes(), values.size() / number_of_components);
46 }
47 }
48 if (item_type == MeshItemType::Cell)
49 {
50 if (mesh.getNumberOfElements() != values.size() / number_of_components)
51 {
53 "Error number of elements ({:d}) does not match the number of "
54 "tuples ({:d}).",
56 values.size() / number_of_components);
57 }
58 }
59
60 auto* const property = mesh.getProperties().createNewPropertyVector<T>(
61 name, item_type, number_of_components);
62 if (!property)
63 {
64 OGS_FATAL("Error while creating PropertyVector '{:s}'.", name);
65 }
66 property->reserve(values.size());
67 std::copy(values.cbegin(), values.cend(), std::back_inserter(*property));
68}
#define OGS_FATAL(...)
Definition: Error.h:26
Properties & getProperties()
Definition: Mesh.h:130
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition: Mesh.h:96
std::size_t getNumberOfElements() const
Get the number of elements.
Definition: Mesh.h:93
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(), 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.

◆ 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 106 of file Element.cpp.

107{
108 unsigned nNeighbors(element->getNumberOfNeighbors());
109 for (unsigned i = 0; i < nNeighbors; i++)
110 {
111 if (element->getNeighbor(i) == other)
112 {
113 return true;
114 }
115 }
116 return false;
117}

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

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

◆ bulkElementIDs()

PropertyVector< std::size_t > const * MeshLib::bulkElementIDs ( Mesh const &  mesh)

Definition at line 290 of file Mesh.cpp.

291{
292 auto const& properties = mesh.getProperties();
293 return properties.getPropertyVector<std::size_t>(
296}
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
Definition: Properties.h:188

References Cell, getBulkIDString(), MeshLib::Mesh::getProperties(), and MeshLib::Properties::getPropertyVector().

Referenced by ProcessLib::ConstraintDirichletBoundaryCondition::ConstraintDirichletBoundaryCondition(), and ProcessLib::DeactivatedSubdomainDirichlet::getEssentialBCValues().

◆ 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(),
328 idsComparator<Node*>);
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:45

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

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 42 of file Utils.h.

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

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)

Given a MeshElemType this returns the appropriate string.

Definition at line 157 of file MeshEnums.cpp.

158{
159#define RETURN_CELL_TYPE_STR(t, type) \
160 if ((t) == CellType::type) \
161 return #type;
162
163 RETURN_CELL_TYPE_STR(t, POINT1);
164 RETURN_CELL_TYPE_STR(t, LINE2);
165 RETURN_CELL_TYPE_STR(t, LINE3);
166 RETURN_CELL_TYPE_STR(t, QUAD4);
167 RETURN_CELL_TYPE_STR(t, QUAD8);
168 RETURN_CELL_TYPE_STR(t, QUAD9);
169 RETURN_CELL_TYPE_STR(t, HEX8);
170 RETURN_CELL_TYPE_STR(t, HEX20);
171 RETURN_CELL_TYPE_STR(t, HEX27);
172 RETURN_CELL_TYPE_STR(t, TRI3);
173 RETURN_CELL_TYPE_STR(t, TRI6);
174 RETURN_CELL_TYPE_STR(t, TET4);
175 RETURN_CELL_TYPE_STR(t, TET10);
176 RETURN_CELL_TYPE_STR(t, PRISM6);
177 RETURN_CELL_TYPE_STR(t, PRISM15);
178 RETURN_CELL_TYPE_STR(t, PYRAMID5);
179 RETURN_CELL_TYPE_STR(t, PYRAMID13);
180
181 return "none";
182
183#undef RETURN_CELL_TYPE_STR
184}
#define RETURN_CELL_TYPE_STR(t, type)

References HEX20, HEX27, HEX8, LINE2, LINE3, POINT1, PRISM15, PRISM6, PYRAMID13, PYRAMID5, QUAD4, QUAD8, QUAD9, RETURN_CELL_TYPE_STR, TET10, TET4, TRI3, and TRI6.

Referenced by MeshToolsLib::computeElementVolumeNumerically(), computePointCloudNodes(), MeshToolsLib::convertToLinearMesh(), createElementCoordInterpolatorsForAllElementTypes(), createQuadraticElement(), getBulkElementPoint(), and MeshToolsLib::getNumberOfElementIntegrationPoints().

◆ cloneElements()

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

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

Definition at line 117 of file DuplicateMeshComponents.cpp.

118{
119 std::vector<Element*> cloned_elements;
120 cloned_elements.reserve(elements.size());
121 std::transform(begin(elements), end(elements),
122 std::back_inserter(cloned_elements),
123 [](Element const* const e) { return e->clone(); });
124 return cloned_elements;
125}
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 172 of file transformMeshToNodePartitionedMesh.cpp.

176{
177 // in the following information exchange with other ranks is required
178 MPI_Comm const mpi_comm = MPI_COMM_WORLD;
179 auto const [mpi_comm_rank, mpi_comm_size] = getMPIRankAndSize(mpi_comm);
180
181 // count regular nodes that is the offset in the mapping
182 auto const local_bulk_node_ids_for_subdomain =
183 *bulkNodeIDs(*subdomain_mesh);
184
185 // compute mapping subdomain ghost node id <-> bulk ghost node id
186 std::vector<std::size_t> subdomain_node_id_to_bulk_node_id;
187 for (auto const id : subdomain_mesh->getNodes() | MeshLib::views::ids)
188 {
189 if (!isRegularNode(*bulk_mesh, local_bulk_node_ids_for_subdomain, id))
190 {
191 auto const bulk_node_id = local_bulk_node_ids_for_subdomain[id];
192 // this puts the global bulk node id at pos:
193 // subdomain_node->getID() - number_of_regular_nodes
194 subdomain_node_id_to_bulk_node_id.push_back(
195 bulk_mesh->getGlobalNodeID(bulk_node_id));
196 }
197 }
198
199 // send ids of bulk ghost nodes belonging to the subdomain mesh to all
200 // other ranks and at the same time receive from all other ranks
201 // first send the sizes to all other to are able to allocate buffer
202 auto const size = subdomain_node_id_to_bulk_node_id.size();
203 std::size_t global_number_of_subdomain_node_id_to_bulk_node_id = 0;
204 MPI_Allreduce(&size, &global_number_of_subdomain_node_id_to_bulk_node_id, 1,
205 MPI_UNSIGNED_LONG, MPI_SUM, mpi_comm);
206
207 DBUG("[{}] global_number_of_subdomain_node_id_to_bulk_node_id: '{}' ",
208 subdomain_mesh->getName(),
209 global_number_of_subdomain_node_id_to_bulk_node_id);
210
211 std::vector<int> numbers_of_ids_at_ranks(mpi_comm_size);
212 MPI_Allgather(&size, 1, MPI_INT, numbers_of_ids_at_ranks.data(), 1, MPI_INT,
213 mpi_comm);
214 std::vector<int> offsets;
215 offsets.push_back(0);
216 std::partial_sum(begin(numbers_of_ids_at_ranks),
217 end(numbers_of_ids_at_ranks), back_inserter(offsets));
218 std::vector<std::size_t> ghost_node_ids_of_all_ranks(
219 global_number_of_subdomain_node_id_to_bulk_node_id);
220 MPI_Allgatherv(subdomain_node_id_to_bulk_node_id.data(), /* sendbuf */
221 size, /* sendcount */
222 MPI_UNSIGNED_LONG, /* sendtype */
223 ghost_node_ids_of_all_ranks.data(), /* recvbuf (out) */
224 numbers_of_ids_at_ranks.data(), /* recvcounts */
225 offsets.data(), /* displs */
226 MPI_UNSIGNED_LONG, /* recvtype */
227 mpi_comm);
228
229 // construct a map for fast search of local bulk node ids
230 std::map<std::size_t, std::size_t> global_to_local_bulk_node_ids;
231 for (auto const id : bulk_mesh->getNodes() | MeshLib::views::ids)
232 {
233 if (!bulk_mesh->isGhostNode(id))
234 {
235 global_to_local_bulk_node_ids[bulk_mesh->getGlobalNodeID(id)] = id;
236 }
237 }
238
239 // construct a map for fast search of local sub-domain node ids
240 std::map<std::size_t, std::size_t> local_subdomain_node_ids;
241 for (auto const id : subdomain_mesh->getNodes() | MeshLib::views::ids)
242 {
243 local_subdomain_node_ids[local_bulk_node_ids_for_subdomain[id]] = id;
244 }
245
246 std::vector<std::size_t> local_subdomain_node_ids_of_all_ranks(
247 global_number_of_subdomain_node_id_to_bulk_node_id,
248 std::numeric_limits<std::size_t>::max());
249 // search in all ranks within the bulk ids for the corresponding id
250 for (int rank = 0; rank < mpi_comm_size; ++rank)
251 {
252 if (rank == mpi_comm_rank)
253 {
254 continue;
255 }
256 for (int i = offsets[rank]; i < offsets[rank + 1]; ++i)
257 {
258 auto it = global_to_local_bulk_node_ids.find(
259 ghost_node_ids_of_all_ranks[i]);
260 if (it == global_to_local_bulk_node_ids.end())
261 {
262 continue;
263 }
264 auto const local_bulk_node_id = it->second;
265 local_subdomain_node_ids_of_all_ranks[i] =
266 global_regular_base_node_ids
267 [local_subdomain_node_ids.find(local_bulk_node_id)->second];
268 DBUG(
269 "[{}] found global subdomain node id: '{}' for global bulk "
270 "node id {} ",
271 subdomain_mesh->getName(),
272 local_subdomain_node_ids_of_all_ranks[i],
273 ghost_node_ids_of_all_ranks[i]);
274 }
275 }
276
277 // send the computed ids back
278 std::vector<std::size_t> computed_global_ids_for_subdomain_ghost_nodes(
279 global_number_of_subdomain_node_id_to_bulk_node_id);
280 MPI_Allreduce(
281 local_subdomain_node_ids_of_all_ranks.data(), /* sendbuf */
282 computed_global_ids_for_subdomain_ghost_nodes
283 .data(), /* recvbuf (out) */
284 global_number_of_subdomain_node_id_to_bulk_node_id, /* sendcount */
285 MPI_UNSIGNED_LONG, /* sendtype */
286 MPI_MAX, /* operation */
287 mpi_comm);
288
289 std::vector<std::size_t> global_ids_for_subdomain_ghost_nodes(
290 computed_global_ids_for_subdomain_ghost_nodes.begin() +
291 offsets[mpi_comm_rank],
292 computed_global_ids_for_subdomain_ghost_nodes.begin() +
293 offsets[mpi_comm_rank + 1]);
294 return global_ids_for_subdomain_ghost_nodes;
295}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition: Logging.h:30
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition: Mesh.h:217
std::pair< int, int > getMPIRankAndSize(MPI_Comm const &mpi_comm)
PropertyVector< std::size_t > const * bulkNodeIDs(Mesh const &mesh)
Definition: Mesh.cpp:282
bool isRegularNode(MeshLib::NodePartitionedMesh const &bulk_mesh, std::vector< std::size_t > const &local_bulk_node_ids_for_subdomain, std::size_t const subdomain_node_id)

References bulkNodeIDs(), DBUG(), MeshLib::NodePartitionedMesh::getGlobalNodeID(), getMPIRankAndSize(), MeshLib::Mesh::getName(), MeshLib::Mesh::getNodes(), MeshLib::views::ids, and MeshLib::NodePartitionedMesh::isGhostNode().

Referenced by computeGlobalNodeIDsOfSubDomainPartition().

◆ computeGlobalNodeIDsOfSubDomainPartition()

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

Definition at line 350 of file transformMeshToNodePartitionedMesh.cpp.

352{
353 auto global_regular_base_node_ids =
355 subdomain_mesh);
356 auto const local_ids_for_subdomain_ghost_nodes =
358 bulk_mesh, subdomain_mesh, global_regular_base_node_ids);
359
360 // At the moment higher order bulk meshes aren't handled correctly.
361 // If it should become necessary in the future, the necessary things must be
362 // implemented at this point.
363 /*
364 auto const regular_higher_order_node_global_node_ids =
365 computeRegularHigherOrderNodeGlobalNodeIDsofSubDomainPartition(
366 bulk_mesh, subdomain_mesh);
367 auto const ghost_higher_order_node_global_node_ids =
368 computeGhostHigherOrderNodeGlobalNodeIDsofSubDomainPartition(
369 bulk_mesh, subdomain_mesh);
370 */
371
372 std::vector<std::size_t> global_node_ids(
373 std::move(global_regular_base_node_ids));
374 global_node_ids.insert(global_node_ids.end(),
375 local_ids_for_subdomain_ghost_nodes.begin(),
376 local_ids_for_subdomain_ghost_nodes.end());
377
378 return global_node_ids;
379}
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 297 of file transformMeshToNodePartitionedMesh.cpp.

299{
300 auto const number_of_regular_base_nodes =
301 subdomain_mesh->computeNumberOfBaseNodes();
302
303 MPI_Comm const mpi_comm = MPI_COMM_WORLD;
304 auto const [mpi_comm_rank, mpi_comm_size] = getMPIRankAndSize(mpi_comm);
305
306 std::vector<std::size_t> gathered_number_of_regular_base_nodes(
307 mpi_comm_size);
308 MPI_Allgather(&number_of_regular_base_nodes, 1, MPI_UNSIGNED_LONG,
309 gathered_number_of_regular_base_nodes.data(), 1,
310 MPI_UNSIGNED_LONG, mpi_comm);
311
312 std::vector<std::size_t> numbers_of_regular_base_nodes_at_rank;
313 numbers_of_regular_base_nodes_at_rank.push_back(0);
314 std::partial_sum(begin(gathered_number_of_regular_base_nodes),
315 end(gathered_number_of_regular_base_nodes),
316 back_inserter(numbers_of_regular_base_nodes_at_rank));
317
318 return numbers_of_regular_base_nodes_at_rank;
319}

References MeshLib::Mesh::computeNumberOfBaseNodes(), and getMPIRankAndSize().

Referenced by transformMeshToNodePartitionedMesh().

◆ computeNumberOfRegularHigherOrderNodesAtRank()

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

Definition at line 322 of file transformMeshToNodePartitionedMesh.cpp.

324{
325 // in the following information exchange with other ranks is required
326 MPI_Comm const mpi_comm = MPI_COMM_WORLD;
327 auto [mpi_comm_rank, mpi_comm_size] = getMPIRankAndSize(mpi_comm);
328
329 auto const number_of_regular_base_nodes =
330 subdomain_mesh->computeNumberOfBaseNodes();
331
332 std::vector<std::size_t> gathered_number_of_regular_higher_order_nodes(
333 mpi_comm_size);
334 auto const number_of_regular_higher_order_nodes =
335 subdomain_mesh->getNumberOfNodes() - number_of_regular_base_nodes;
336 MPI_Allgather(&number_of_regular_higher_order_nodes, 1, MPI_UNSIGNED_LONG,
337 gathered_number_of_regular_higher_order_nodes.data(), 1,
338 MPI_UNSIGNED_LONG, mpi_comm);
339
340 std::vector<std::size_t> numbers_of_regular_higher_order_nodes_at_rank;
341 numbers_of_regular_higher_order_nodes_at_rank.push_back(0);
342 std::partial_sum(
343 begin(gathered_number_of_regular_higher_order_nodes),
344 end(gathered_number_of_regular_higher_order_nodes),
345 back_inserter(numbers_of_regular_higher_order_nodes_at_rank));
346
347 return numbers_of_regular_higher_order_nodes_at_rank;
348}

References MeshLib::Mesh::computeNumberOfBaseNodes(), getMPIRankAndSize(), and MeshLib::Mesh::getNumberOfNodes().

Referenced by transformMeshToNodePartitionedMesh().

◆ computeNumberOfRegularNodes()

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

Definition at line 97 of file transformMeshToNodePartitionedMesh.cpp.

99{
100 auto const subdomain_nodes = subdomain_mesh->getNodes();
101 auto const local_bulk_node_ids_for_subdomain =
102 *bulkNodeIDs(*subdomain_mesh);
103 auto const subdomain_node_ids =
104 subdomain_nodes | MeshLib::views::ids | ranges::to<std::vector>;
105 unsigned long const number_of_regular_nodes =
106 std::count_if(subdomain_node_ids.begin(), subdomain_node_ids.end(),
107 std::bind_front(isRegularNode, *bulk_mesh,
108 local_bulk_node_ids_for_subdomain));
109
110 DBUG("[{}] number of regular nodes: {}", subdomain_mesh->getName(),
111 number_of_regular_nodes);
112 return number_of_regular_nodes;
113}

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 116 of file transformMeshToNodePartitionedMesh.cpp.

118{
119 // create/fill global nodes information of the sub-domain partition
120 auto const subdomain_nodes = subdomain_mesh->getNodes();
121 auto const local_bulk_node_ids_for_subdomain =
122 *bulkNodeIDs(*subdomain_mesh);
123
124 // global node ids for the sub-domain:
125 // | regular base node ids | ghost base node ids | regular higher
126 // order node ids | ghost higher order node ids |
127 // | partition offset + local ids | regular node ids from other
128 // partitions |
129
130 // In order to compute the global node ids for the subdomain mesh nodes the
131 // sum of the number of regular nodes of the previous partitions is required
132 // first.
133 // Count the local regular base nodes to compute offset for other subsequent
134 // partitions
135 std::size_t const number_of_regular_nodes =
136 computeNumberOfRegularNodes(bulk_mesh, subdomain_mesh);
137
138 // in the following information exchange with other ranks is required
139 MPI_Comm mpi_comm = MPI_COMM_WORLD;
140 auto const [mpi_comm_rank, mpi_comm_size] = getMPIRankAndSize(mpi_comm);
141
142 // send own number of regular nodes to all others
143 std::vector<std::size_t> gathered_number_of_regular_nodes(mpi_comm_size);
144 MPI_Allgather(&number_of_regular_nodes, 1, MPI_UNSIGNED_LONG,
145 gathered_number_of_regular_nodes.data(), 1, MPI_UNSIGNED_LONG,
146 mpi_comm);
147 // compute the 'offset' in the global_node_ids
148 std::vector<std::size_t> numbers_of_regular_nodes_at_rank;
149 numbers_of_regular_nodes_at_rank.push_back(0);
150 std::partial_sum(begin(gathered_number_of_regular_nodes),
151 end(gathered_number_of_regular_nodes),
152 back_inserter(numbers_of_regular_nodes_at_rank));
153
154 // add the offset to the partitioned-owned subdomain
155 std::vector<std::size_t> subdomain_global_node_ids;
156 subdomain_global_node_ids.reserve(subdomain_nodes.size());
157 auto const partition_offset =
158 numbers_of_regular_nodes_at_rank[mpi_comm_rank];
159 DBUG("[{}] partition offset: {}", subdomain_mesh->getName(),
160 partition_offset);
161 // set the global id for the regular base nodes
162 for (auto const id : subdomain_nodes | MeshLib::views::ids)
163 {
164 if (isRegularNode(*bulk_mesh, local_bulk_node_ids_for_subdomain, id))
165 {
166 subdomain_global_node_ids.emplace_back(partition_offset + id);
167 }
168 }
169 return subdomain_global_node_ids;
170}
unsigned long computeNumberOfRegularNodes(NodePartitionedMesh const *bulk_mesh, Mesh const *subdomain_mesh)

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

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 156 of file Element.cpp.

157{
158 double min = std::numeric_limits<double>::max();
159 double max = 0;
160 const unsigned nEdges(element.getNumberOfEdges());
161 for (unsigned i = 0; i < nEdges; i++)
162 {
163 const double dist(MathLib::sqrDist(*element.getEdgeNode(i, 0),
164 *element.getEdgeNode(i, 1)));
165 min = std::min(dist, min);
166 max = std::max(dist, max);
167 }
168 return {min, max};
169}
double sqrDist(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition: Point3d.cpp:26

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 136 of file Element.cpp.

138{
139 double min = std::numeric_limits<double>::max();
140 double max = 0;
141 const unsigned nnodes = check_allnodes ? element.getNumberOfNodes()
142 : element.getNumberOfBaseNodes();
143 for (unsigned i = 0; i < nnodes; i++)
144 {
145 for (unsigned j = i + 1; j < nnodes; j++)
146 {
147 const double dist(
148 MathLib::sqrDist(*element.getNode(i), *element.getNode(j)));
149 min = std::min(dist, min);
150 max = std::max(dist, max);
151 }
152 }
153 return {min, max};
154}

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 50 of file DuplicateMeshComponents.cpp.

53{
54 unsigned const number_of_element_nodes(element->getNumberOfNodes());
55 auto** new_nodes = new Node*[number_of_element_nodes];
56 if (id_map)
57 {
58 for (unsigned i = 0; i < number_of_element_nodes; ++i)
59 {
60 new_nodes[i] = nodes[(*id_map)[element->getNode(i)->getID()]];
61 }
62 }
63 else
64 {
65 for (unsigned i = 0; i < number_of_element_nodes; ++i)
66 {
67 new_nodes[i] = nodes[element->getNode(i)->getID()];
68 }
69 }
70 return new E(new_nodes);
71}

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

Referenced by 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 73 of file DuplicateMeshComponents.cpp.

76{
77 switch (element->getCellType())
78 {
79 case CellType::LINE2:
80 return copyElement<Line>(element, nodes, id_map);
81 case CellType::LINE3:
82 return copyElement<Line3>(element, nodes, id_map);
83 case CellType::TRI3:
84 return copyElement<Tri>(element, nodes, id_map);
85 case CellType::TRI6:
86 return copyElement<Tri6>(element, nodes, id_map);
87 case CellType::QUAD4:
88 return copyElement<Quad>(element, nodes, id_map);
89 case CellType::QUAD8:
90 return copyElement<Quad8>(element, nodes, id_map);
91 case CellType::QUAD9:
92 return copyElement<Quad9>(element, nodes, id_map);
93 case CellType::TET4:
94 return copyElement<Tet>(element, nodes, id_map);
95 case CellType::TET10:
96 return copyElement<Tet10>(element, nodes, id_map);
97 case CellType::HEX8:
98 return copyElement<Hex>(element, nodes, id_map);
99 case CellType::HEX20:
100 return copyElement<Hex20>(element, nodes, id_map);
101 case CellType::PYRAMID5:
102 return copyElement<Pyramid>(element, nodes, id_map);
103 case CellType::PYRAMID13:
104 return copyElement<Pyramid13>(element, nodes, id_map);
105 case CellType::PRISM6:
106 return copyElement<Prism>(element, nodes, id_map);
107 case CellType::PRISM15:
108 return copyElement<Prism15>(element, nodes, id_map);
109 default:
110 {
111 ERR("Error: Unknown cell type.");
112 return nullptr;
113 }
114 }
115}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition: Logging.h:45

References 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 33 of file DuplicateMeshComponents.cpp.

37{
38 std::vector<Element*> new_elements;
39 new_elements.reserve(elements.size());
40 std::transform(elements.begin(), elements.end(),
41 std::back_inserter(new_elements),
42 [&new_nodes, &node_id_map](auto const& element)
43 { return copyElement(element, new_nodes, node_id_map); });
44 return new_elements;
45}

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 53 of file transformMeshToNodePartitionedMesh.cpp.

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

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

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 21 of file DuplicateMeshComponents.cpp.

22{
23 const std::size_t nNodes(nodes.size());
24 std::vector<Node*> new_nodes;
25 new_nodes.reserve(nNodes);
26 for (std::size_t k = 0; k < nNodes; ++k)
27 {
28 new_nodes.push_back(new Node(nodes[k]->data(), new_nodes.size()));
29 }
30 return new_nodes;
31}

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 24 of file createMaterialIDsBasedSubMesh.cpp.

27{
28 auto const elements =
31 name_for_created_mesh, MeshLib::cloneElements(elements));
32}
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.

Definition at line 28 of file createMeshFromElementSelection.cpp.

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

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

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

◆ createMeshFromElementSelection() [2/2]

std::unique_ptr< MeshLib::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.

Definition at line 28 of file createMeshFromElementSelection.cpp.

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

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 27 of file ElementSearch.cpp.

28{
29 return ranges::views::filter(container, p) | views::ids |
30 ranges::to<std::vector>;
31}

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 45 of file Mesh.cpp.

47{
48 std::vector<std::vector<Element const*>> elements_connected_to_nodes;
49 auto const& nodes = mesh.getNodes();
50 elements_connected_to_nodes.resize(nodes.size());
51
52 for (auto const* element : mesh.getElements())
53 {
54 for (auto const node_id : element->nodes() | views::ids)
55 {
56 elements_connected_to_nodes[node_id].push_back(element);
57 }
58 }
59 return elements_connected_to_nodes;
60}

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

Referenced by 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 23 of file findElementsWithinRadius.cpp.

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

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

Referenced by ProcessLib::SmallDeformationNonlocal::SmallDeformationNonlocalLocalAssembler< ShapeFunction, DisplacementDim >::nonlocal().

◆ 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 26 of file Utils.h.

27{
28 std::vector<Node*> base_nodes;
29 base_nodes.reserve(elements.size() * 2); // Save some of the realloctions.
30
31 for (auto* const e : elements)
32 {
33 std::copy(e->getNodes(), e->getNodes() + e->getNumberOfBaseNodes(),
34 std::back_inserter(base_nodes));
35 }
36
37 BaseLib::makeVectorUnique(base_nodes, MeshLib::idsComparator<Node*>);
38
39 return base_nodes;
40}
void makeVectorUnique(std::vector< T > &v)
Definition: Algorithm.h:165

References BaseLib::makeVectorUnique().

Referenced by ProcessLib::HydroMechanics::HydroMechanicsProcess< DisplacementDim >::constructDofTable(), ProcessLib::LIE::HydroMechanics::HydroMechanicsProcess< GlobalDim >::constructDofTable(), ProcessLib::RichardsMechanics::RichardsMechanicsProcess< DisplacementDim >::constructDofTable(), ProcessLib::StokesFlow::StokesFlowProcess< GlobalDim >::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 219 of file MapBulkElementPoint.cpp.

223{
224 if (point_on_face.getDimension() == 3)
225 {
226 // TODO disable the 3d elements in the local assembler creator
227 return MathLib::ORIGIN;
228 }
229
230 switch (bulk_element_cell_type)
231 {
232 // 3D bulk elements
233 case CellType::HEX8:
234 return getBulkElementPointHex(bulk_face_id, point_on_face);
235 case CellType::PRISM6:
236 return getBulkElementPointPrism(bulk_face_id, point_on_face);
237 case CellType::PYRAMID5:
238 return getBulkElementPointPyramid(bulk_face_id, point_on_face);
239 case CellType::TET4:
240 return getBulkElementPointTet(bulk_face_id, point_on_face);
241 // 2D bulk elements
242 case CellType::QUAD4:
243 return getBulkElementPointQuad(bulk_face_id, point_on_face);
244 case CellType::TRI3:
245 return getBulkElementPointTri(bulk_face_id, point_on_face);
246 // 1D bulk elements
247 case CellType::LINE2:
248 return getBulkElementPointLine(bulk_face_id);
249 default:
250 OGS_FATAL(
251 "Wrong cell type '{:s}' or functionality not yet implemented.",
252 CellType2String(bulk_element_cell_type));
253 }
254}
const Point3d ORIGIN
Definition: Point3d.h:101
MathLib::Point3d getBulkElementPointLine(std::size_t const face_id)
MathLib::Point3d getBulkElementPointTri(std::size_t const face_id, MathLib::WeightedPoint const &wp)
MathLib::Point3d getBulkElementPointTet(std::size_t const face_id, MathLib::WeightedPoint const &wp)
MathLib::Point3d getBulkElementPointQuad(std::size_t const face_id, MathLib::WeightedPoint const &wp)
MathLib::Point3d getBulkElementPointPrism(std::size_t const face_id, MathLib::WeightedPoint const &wp)
MathLib::Point3d getBulkElementPointHex(std::size_t const face_id, MathLib::WeightedPoint const &wp)
MathLib::Point3d getBulkElementPointPyramid(std::size_t const face_id, MathLib::WeightedPoint const &wp)

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 36 of file MapBulkElementPoint.h.

40{
42 bulk_element.getCellType(), bulk_face_id, point_on_face);
43}
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()

constexpr 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 188 of file Properties.h.

189{
190 switch (mesh_item_type)
191 {
192 case MeshItemType::Node:
193 return "bulk_node_ids";
194 break;
195 case MeshItemType::Cell:
196 return "bulk_element_ids";
197 break;
198 case MeshItemType::Edge:
199 return "bulk_edge_ids";
200 break;
201 case MeshItemType::Face:
202 return "bulk_face_ids";
203 break;
204 case MeshItemType::IntegrationPoint:
205 OGS_FATAL("MeshItemType::IntegrationPoint is not handled.");
206 return "";
207 break;
208 default:
209 OGS_FATAL(
210 "Unknown mesh item type. At the moment only for mesh item "
211 "types 'Node', 'Cell', and 'Face' mapping names are "
212 "specified.");
213 return "";
214 }
215}

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(), MeshLib::IO::isVariableAttribute(), main(), ApplicationUtils::NodeWiseMeshPartitioner::partitionOtherMesh(), and ApplicationUtils::NodeWiseMeshPartitioner::renumberBulkIdsProperty().

◆ getCenterOfGravity()

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

Calculates the center of gravity for the mesh element.

Definition at line 124 of file Element.cpp.

125{
126 const unsigned nNodes(element.getNumberOfBaseNodes());
127 MathLib::Point3d center{{0, 0, 0}};
128 for (unsigned i = 0; i < nNodes; ++i)
129 {
130 center.asEigenVector3d() += element.getNode(i)->asEigenVector3d();
131 }
132 center.asEigenVector3d() /= nNodes;
133 return center;
134}
Eigen::Vector3d const & asEigenVector3d() const
Definition: Point3d.h:67

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

Referenced by MeshToolsLib::MeshGenerator::AddFaultToVoxelGrid::addFaultToVoxelGrid(), ProcessLib::LIE::HydroMechanics::HydroMechanicsProcess< GlobalDim >::initializeConcreteProcess(), 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 21 of file GetElementRotationMatrices.cpp.

24{
25 std::vector<Eigen::MatrixXd> element_rotation_matrices;
26 element_rotation_matrices.reserve(elements.size());
27 for (auto const* const element : elements)
28 {
29 int const element_dimension = static_cast<int>(element->getDimension());
30 if (element_dimension == space_dimension)
31 {
32 element_rotation_matrices.emplace_back(Eigen::MatrixXd::Identity(
33 element_dimension, element_dimension));
34 }
35 else
36 {
38 *element, mesh_dimension);
39
40 element_rotation_matrices.emplace_back(
41 coordinates_mapping.getRotationMatrixToGlobal().topLeftCorner(
42 space_dimension, element_dimension));
43 }
44 }
45
46 return element_rotation_matrices;
47}

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 16 of file NodePartitionedMesh.cpp.

20{
21 std::vector<int> data;
22
23 std::transform(n_regular_base_nodes_at_rank.begin() + 1,
24 n_regular_base_nodes_at_rank.end(),
25 n_regular_high_order_nodes_at_rank.begin() + 1,
26 std::back_inserter(data), std::plus<int>());
27
28 data.push_back(n_global_nodes);
29
30 return data;
31}

◆ getIntegrationPointMetaData()

IntegrationPointMetaData MeshLib::getIntegrationPointMetaData ( MeshLib::Properties const &  properties,
std::string const &  name 
)

Returns integration point meta data for the given field name.

The data is read from a JSON encoded string stored in field data array.

Definition at line 109 of file IntegrationPointWriter.cpp.

111{
112 if (!properties.existsPropertyVector<char>("IntegrationPointMetaData"))
113 {
114 OGS_FATAL(
115 "Integration point data '{:s}' is present in the vtk field data "
116 "but the required 'IntegrationPointMetaData' array is not "
117 "available.",
118 name);
119 }
120 auto const& mesh_property_ip_meta_data =
121 *properties.template getPropertyVector<char>(
122 "IntegrationPointMetaData");
123
124 if (mesh_property_ip_meta_data.getMeshItemType() !=
126 {
127 OGS_FATAL("IntegrationPointMetaData array must be field data.");
128 }
129
130 // Find the current integration point data entry and extract the
131 // meta data.
132 auto const ip_meta_data = extractIntegrationPointMetaData(
133 json::parse(mesh_property_ip_meta_data.begin(),
134 mesh_property_ip_meta_data.end()),
135 name);
136
137 return ip_meta_data;
138}
static MeshLib::IntegrationPointMetaData extractIntegrationPointMetaData(json const &meta_data, std::string const &name)

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

Referenced by ApplicationUtils::checkFieldPropertyVectorSize(), ApplicationUtils::copyFieldPropertyDataToPartitions(), 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 19 of file getMaxiumElementEdgeLengths.cpp.

21{
22 std::vector<double> element_edge_lengths(elements.size());
23 for (auto const element : elements)
24 {
25 assert(element->getGeomType() != MeshElemType::POINT);
26
27 auto const& [min_edge_length, max_edge_length] =
29 (void)min_edge_length;
30
31 element_edge_lengths[element->getID()] = std::sqrt(max_edge_length);
32 }
33
34 return element_edge_lengths;
35}
std::pair< double, double > computeSqrEdgeLengthRange(Element const &element)
Compute the minimum and maximum squared edge length for this element.
Definition: Element.cpp:156

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 21 of file getMeshElementsForMaterialIDs.cpp.

23{
24 auto const material_ids = *materialIDs(mesh);
25 auto const& elements = mesh.getElements();
26 std::vector<MeshLib::Element*> selected_elements;
27
28 for (std::size_t i = 0; i < material_ids.size(); ++i)
29 {
30 if (ranges::contains(selected_material_ids, material_ids[i]))
31 {
32 selected_elements.push_back(elements[i]);
33 }
34 }
35 return selected_elements;
36}
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 132 of file MeshEnums.cpp.

133{
134 std::vector<MeshElemType> vec;
135 vec.push_back(MeshElemType::POINT);
136 vec.push_back(MeshElemType::LINE);
137 vec.push_back(MeshElemType::QUAD);
138 vec.push_back(MeshElemType::HEXAHEDRON);
139 vec.push_back(MeshElemType::TRIANGLE);
140 vec.push_back(MeshElemType::TETRAHEDRON);
141 vec.push_back(MeshElemType::PRISM);
142 vec.push_back(MeshElemType::PYRAMID);
143 return vec;
144}

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 146 of file MeshEnums.cpp.

147{
148 std::vector<std::string> vec;
149 auto const& mesh_elem_types = getMeshElemTypes();
150 std::transform(mesh_elem_types.begin(), mesh_elem_types.end(),
151 std::back_inserter(vec),
152 [](auto const& element_type)
153 { return MeshElemType2StringShort(element_type); });
154 return vec;
155}
std::vector< MeshElemType > getMeshElemTypes()
Returns a vector of all mesh element types.
Definition: MeshEnums.cpp:132

References getMeshElemTypes().

Referenced by main().

◆ getMPIRankAndSize()

std::pair< int, int > MeshLib::getMPIRankAndSize ( MPI_Comm const &  mpi_comm)

Definition at line 44 of file transformMeshToNodePartitionedMesh.cpp.

45{
46 int mpi_comm_size;
47 MPI_Comm_size(mpi_comm, &mpi_comm_size);
48 int mpi_comm_rank;
49 MPI_Comm_rank(mpi_comm, &mpi_comm_rank);
50 return {mpi_comm_rank, mpi_comm_size};
51}

Referenced by computeGhostBaseNodeGlobalNodeIDsOfSubDomainPartition(), computeNumberOfRegularBaseNodesAtRank(), computeNumberOfRegularHigherOrderNodesAtRank(), and computeRegularBaseNodeGlobalNodeIDsOfSubDomainPartition().

◆ 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 206 of file Element.cpp.

207{
208 const unsigned nNodes(element.getNumberOfNodes());
209 for (unsigned i(0); i < nNodes; i++)
210 {
211 if (node == element.getNode(i))
212 {
213 return i;
214 }
215 }
216 return std::numeric_limits<unsigned>::max();
217}

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

Referenced by isBaseNode().

◆ 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 219 of file Element.cpp.

220{
221#ifndef NDEBUG
222 if (idx >= element.getNumberOfNodes())
223 {
224 ERR("Error in MeshLib::getNodeIndex() - Index does not "
225 "exist.");
226 return std::numeric_limits<std::size_t>::max();
227 }
228#endif
229 return element.getNode(idx)->getID();
230}

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 381 of file transformMeshToNodePartitionedMesh.cpp.

382{
383 // sum all nodes over all partitions in number_of_global_nodes
384 unsigned long number_of_local_nodes = subdomain_mesh->getNodes().size();
385 unsigned long number_of_global_nodes = 0;
386
387 MPI_Comm mpi_comm = MPI_COMM_WORLD;
388
389 MPI_Allreduce(&number_of_local_nodes, &number_of_global_nodes, 1,
390 MPI_UNSIGNED_LONG, MPI_SUM, mpi_comm);
391 DBUG("[{}] number_of_global_nodes: {}'", subdomain_mesh->getName(),
392 number_of_global_nodes);
393 return number_of_global_nodes;
394}

References 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 25 of file getOrCreateMeshProperty.h.

29{
30 if (property_name.empty())
31 {
33 "Trying to get or to create a mesh property with empty name.");
34 }
35
36 auto numberOfMeshItems = [&mesh, &item_type]() -> std::size_t
37 {
38 switch (item_type)
39 {
40 case MeshItemType::Cell:
41 return mesh.getNumberOfElements();
42 case MeshItemType::Node:
43 return mesh.getNumberOfNodes();
44 case MeshItemType::IntegrationPoint:
45 return 0; // For the integration point data the size is
46 // variable
47 default:
49 "getOrCreateMeshProperty cannot handle other "
50 "types than Node, Cell, or IntegrationPoint.");
51 }
52 return 0;
53 };
54
55 if (mesh.getProperties().existsPropertyVector<T>(property_name))
56 {
57 auto result =
58 mesh.getProperties().template getPropertyVector<T>(property_name);
59 assert(result);
60 if (item_type != MeshItemType::IntegrationPoint)
61 {
62 // Test the size if number of mesh items is known, which is not the
63 // case for the integration point data.
64 assert(result->size() ==
65 numberOfMeshItems() * number_of_components);
66 }
67 return result;
68 }
69
70 auto result = mesh.getProperties().template createNewPropertyVector<T>(
71 property_name, item_type, number_of_components);
72 assert(result);
73 result->resize(numberOfMeshItems() * number_of_components);
74 return result;
75}
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.

◆ 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 23 of file GetSpaceDimension.cpp.

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

Referenced by ProcessLib::ComponentTransport::createComponentTransportProcess(), ProcessLib::HeatConduction::createHeatConductionProcess(), ProcessLib::HT::createHTProcess(), ProcessLib::LiquidFlow::createLiquidFlowProcess(), 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 163 of file NodeSearch.cpp.

164{
165 std::set<Node*> nodes_set;
166 for (auto e : elements)
167 {
168 Node* const* nodes = e->getNodes();
169 unsigned const nnodes = e->getNumberOfNodes();
170 nodes_set.insert(nodes, nodes + nnodes);
171 }
172
173 std::vector<Node*> nodes;
174 nodes.reserve(nodes_set.size());
175
176 std::move(nodes_set.cbegin(), nodes_set.cend(), std::back_inserter(nodes));
177
178 return nodes;
179}

◆ hasZeroVolume()

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

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

Definition at line 119 of file Element.cpp.

120{
121 return element.getContent() < std::numeric_limits<double>::epsilon();
122}

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 201 of file Mesh.h.

202{
203 if constexpr (std::is_pointer_v<T>)
204 {
205 return a->getID() < b->getID();
206 }
207 else
208 {
209 return a.getID() < b.getID();
210 }
211}

◆ is2DMeshOnRotatedVerticalPlane()

bool MeshLib::is2DMeshOnRotatedVerticalPlane ( Mesh const &  mesh)

Definition at line 24 of file Is2DMeshOnRotatedVerticalPlane.cpp.

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

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 return local_index < n_base_nodes;
351}

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 171 of file Element.cpp.

172{
173 for (std::size_t i(0); i < e.getNumberOfBaseNodes(); ++i)
174 {
175 if (MathLib::sqrDist2d(p, *e.getNode(i)) <
176 std::numeric_limits<double>::epsilon())
177 {
178 return true;
179 }
180 }
181
182 if (e.getGeomType() == MeshElemType::TRIANGLE)
183 {
184 MathLib::Point3d const& n0(*e.getNode(0));
185 MathLib::Point3d const& n1(*e.getNode(1));
186 MathLib::Point3d const& n2(*e.getNode(2));
187
188 return MathLib::isPointInTriangleXY(p, n0, n1, n2);
189 }
190 if (e.getGeomType() == MeshElemType::QUAD)
191 {
192 MathLib::Point3d const& n0(*e.getNode(0));
193 MathLib::Point3d const& n1(*e.getNode(1));
194 MathLib::Point3d const& n2(*e.getNode(2));
195 MathLib::Point3d const& n3(*e.getNode(3));
196
197 return MathLib::isPointInTriangleXY(p, n0, n1, n2) ||
198 MathLib::isPointInTriangleXY(p, n0, n2, n3);
199 }
200
201 WARN("isPointInElementXY: element type '{:s}' is not supported.",
202 MeshLib::MeshElemType2String(e.getGeomType()));
203 return false;
204}
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition: Logging.h:40
double sqrDist2d(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition: Point3d.h:126
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:21

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(), MeshLib::Properties::getPropertyVector(), and WARN().

Referenced by ProcessLib::HeatTransportBHE::HeatTransportBHEProcess::HeatTransportBHEProcess(), 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 21 of file MeshEnums.cpp.

22{
23 if (t == MeshElemType::POINT)
24 {
25 return "Point";
26 }
27 if (t == MeshElemType::LINE)
28 {
29 return "Line";
30 }
31 if (t == MeshElemType::QUAD)
32 {
33 return "Quad";
34 }
35 if (t == MeshElemType::HEXAHEDRON)
36 {
37 return "Hexahedron";
38 }
39 if (t == MeshElemType::TRIANGLE)
40 {
41 return "Triangle";
42 }
43 if (t == MeshElemType::TETRAHEDRON)
44 {
45 return "Tetrahedron";
46 }
47 if (t == MeshElemType::PRISM)
48 {
49 return "Prism";
50 }
51 if (t == MeshElemType::PYRAMID)
52 {
53 return "Pyramid";
54 }
55 return "none";
56}

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

Referenced by MeshModel::createMeshElemTypeMap(), MeshLib::TemplateElement< ELEMENT_RULE >::getNode(), isPointInElementXY(), 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 58 of file MeshEnums.cpp.

59{
60 if (t == MeshElemType::POINT)
61 {
62 return "point";
63 }
64 if (t == MeshElemType::LINE)
65 {
66 return "line";
67 }
68 if (t == MeshElemType::QUAD)
69 {
70 return "quad";
71 }
72 if (t == MeshElemType::HEXAHEDRON)
73 {
74 return "hex";
75 }
76 if (t == MeshElemType::TRIANGLE)
77 {
78 return "tri";
79 }
80 if (t == MeshElemType::TETRAHEDRON)
81 {
82 return "tet";
83 }
84 if (t == MeshElemType::PRISM)
85 {
86 return "pris";
87 }
88 if (t == MeshElemType::PYRAMID)
89 {
90 return "pyra";
91 }
92 return "none";
93}

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

◆ MeshQualityType2String()

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

Definition at line 186 of file MeshEnums.cpp.

187{
188 if (t == MeshQualityType::ELEMENTSIZE)
189 {
190 return "ElementSize";
191 }
192 if (t == MeshQualityType::EDGERATIO)
193 {
194 return "EdgeRatio";
195 }
196 if (t == MeshQualityType::EQUIANGLESKEW)
197 {
198 return "EquiAngleSkew";
199 }
200 if (t == MeshQualityType::RADIUSEDGERATIO)
201 {
202 return "RadiusEdgeRatio";
203 }
204 if (t == MeshQualityType::SIZEDIFFERENCE)
205 {
206 return "SizeDifference";
207 }
208 return "none";
209}

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 174 of file Mesh.h.

175{
176 return !(a == b);
177}

◆ operator<()

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

Lexicographic order of Location.

Definition at line 51 of file Location.h.

52{
53 if (left.mesh_id != right.mesh_id)
54 {
55 return left.mesh_id < right.mesh_id;
56 }
57 if (left.item_type != right.item_type)
58 {
59 return left.item_type < right.item_type;
60 }
61 return left.item_id < right.item_id;
62}
std::size_t item_id
Definition: Location.h:43
std::size_t mesh_id
Definition: Location.h:41
MeshItemType item_type
Definition: Location.h:42

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

◆ operator<<() [1/3]

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

Definition at line 88 of file Element.cpp.

89{
90 os << "Element #" << e._id << " @ " << &e << " with "
91 << e.getNumberOfNeighbors() << " neighbours\n";
92
93 unsigned const nnodes = e.getNumberOfNodes();
94 MeshLib::Node* const* const nodes = e.getNodes();
95 os << "MeshElemType: "
96 << static_cast<std::underlying_type<MeshElemType>::type>(e.getGeomType())
97 << " with " << nnodes << " nodes: {\n";
98 for (unsigned n = 0; n < nnodes; ++n)
99 {
100 os << " #" << nodes[n]->getID() << " @ " << nodes[n] << " coords ["
101 << *nodes[n] << "]\n";
102 }
103 return os << '}';
104}

◆ operator<<() [2/3]

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

Definition at line 35 of file Location.cpp.

36{
37 return os << "(" << l.mesh_id << ", " << l.item_type << ", " << l.item_id
38 << ")";
39}

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

◆ operator<<() [3/3]

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

Definition at line 17 of file Location.cpp.

18{
19 switch (t)
20 {
21 case MeshItemType::Node:
22 return os << "N";
23 case MeshItemType::Edge:
24 return os << "E";
25 case MeshItemType::Face:
26 return os << "F";
27 case MeshItemType::Cell:
28 return os << "C";
29 case MeshItemType::IntegrationPoint:
30 return os << "I";
31 };
32 return os;
33}

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

◆ operator==()

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

Meshes are equal if their id's are equal.

Definition at line 169 of file Mesh.h.

170{
171 return a.getID() == b.getID();
172}

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 18 of file scaleMeshPropertyVector.cpp.

21{
22 if (!mesh.getProperties().existsPropertyVector<double>(property_name))
23 {
24 WARN("Did not find PropertyVector '{:s}' for scaling.", property_name);
25 return;
26 }
27 auto& pv = *mesh.getProperties().getPropertyVector<double>(property_name);
28 std::transform(pv.begin(), pv.end(), pv.begin(),
29 [factor](auto const& v) { return v * factor; });
30}
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 22 of file SetMeshSpaceDimension.cpp.

23{
24 // Get the space dimension from the bulk mesh:
25 auto const d = getSpaceDimension(meshes[0]->getNodes());
26 for (auto const& mesh : meshes)
27 {
28 ranges::for_each(mesh->getElements(),
29 [d](Element* const e) { e->space_dimension_ = d; });
30 }
31}
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 95 of file MeshEnums.cpp.

96{
97 if (boost::iequals(s, "point"))
98 {
99 return MeshElemType::POINT;
100 }
101 if (boost::iequals(s, "line"))
102 {
103 return MeshElemType::LINE;
104 }
105 if (boost::iequals(s, "quad") || boost::iequals(s, "Quadrilateral"))
106 {
107 return MeshElemType::QUAD;
108 }
109 if (boost::iequals(s, "hex") || boost::iequals(s, "Hexahedron"))
110 {
111 return MeshElemType::HEXAHEDRON;
112 }
113 if (boost::iequals(s, "tri") || boost::iequals(s, "Triangle"))
114 {
115 return MeshElemType::TRIANGLE;
116 }
117 if (boost::iequals(s, "tet") || boost::iequals(s, "Tetrahedron"))
118 {
119 return MeshElemType::TETRAHEDRON;
120 }
121 if (boost::iequals(s, "pris") || boost::iequals(s, "Prism"))
122 {
123 return MeshElemType::PRISM;
124 }
125 if (boost::iequals(s, "pyra") || boost::iequals(s, "Pyramid"))
126 {
127 return MeshElemType::PYRAMID;
128 }
129 return MeshElemType::INVALID;
130}

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 211 of file MeshEnums.cpp.

212{
213 if (boost::iequals(s, "ElementSize"))
214 {
215 return MeshQualityType::ELEMENTSIZE;
216 }
217 if (boost::iequals(s, "EdgeRatio"))
218 {
219 return MeshQualityType::EDGERATIO;
220 }
221 if (boost::iequals(s, "EquiAngleSkew"))
222 {
223 return MeshQualityType::EQUIANGLESKEW;
224 }
225 if (boost::iequals(s, "RadiusEdgeRatio"))
226 {
227 return MeshQualityType::RADIUSEDGERATIO;
228 }
229 if (boost::iequals(s, "SizeDifference"))
230 {
231 return MeshQualityType::SIZEDIFFERENCE;
232 }
233 return MeshQualityType::INVALID;
234}

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

Referenced by main().

◆ toString()

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

Returns a char array for a specific MeshItemType.

Definition at line 28 of file Location.h.

29{
30 return mesh_item_type_strings[static_cast<int>(t)];
31}

References mesh_item_type_strings.

Referenced by MeshLib::IO::NodePartitionedMeshReader::readProperties().

◆ 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 396 of file transformMeshToNodePartitionedMesh.cpp.

399{
400 DBUG("Creating NodePartitionedMesh from '{}'", subdomain_mesh->getName());
401
402 auto const subdomain_global_node_ids =
403 computeGlobalNodeIDsOfSubDomainPartition(bulk_mesh, subdomain_mesh);
404
405 // according to comment in struct PartitionedMeshInfo this value
406 // is unused
407 unsigned long number_of_global_base_nodes = 0;
408
409 unsigned long const number_of_global_nodes =
410 getNumberOfGlobalNodes(subdomain_mesh);
411 auto numbers_of_regular_base_nodes_at_rank =
413 auto numbers_of_regular_higher_order_nodes_at_rank =
415
416 auto const number_of_regular_nodes =
417 computeNumberOfRegularNodes(bulk_mesh, subdomain_mesh);
418 DBUG("[{}] number_of_regular_nodes: {}", subdomain_mesh->getName(),
419 number_of_regular_nodes);
420 auto const [nodes, elements] =
421 copyNodesAndElements(subdomain_mesh->getElements());
422
423 return std::make_unique<NodePartitionedMesh>(
424 subdomain_mesh->getName(), nodes, subdomain_global_node_ids, elements,
425 subdomain_mesh->getProperties(), number_of_global_base_nodes,
426 number_of_global_nodes, number_of_regular_nodes,
427 std::move(numbers_of_regular_base_nodes_at_rank),
428 std::move(numbers_of_regular_higher_order_nodes_at_rank));
429}
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 32 of file VtkMappedMeshSource.cpp.

35{
36 this->Superclass::PrintSelf(os, indent);
37 os << indent << "Mesh: " << (_mesh ? _mesh->getName() : "(none)") << endl;
38}

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

Variable Documentation

◆ mesh_item_type_strings

constexpr 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 24 of file Location.h.

Referenced by toString().