OGS
MeshLib Namespace Reference

Detailed Description

Author
Karsten Rink
Date
2010-08-25

Contains all functionality concerned with defining and obtaining information about meshes and their components (nodes, elements). Also includes additional algorithms for generating and modifying meshes and elements.

See also
MeshGenerator

Namespaces

 anonymous_namespace{AngleSkewMetric.cpp}
 
 anonymous_namespace{ConvertToLinearMesh.cpp}
 
 BoundaryExtraction
 
 detail
 
 details
 
 IO
 
 MeshGenerator
 
 ProjectPointOnMesh
 
 RasterDataToMesh
 Adding pixel values from a raster onto nodes or cells of a mesh.
 

Classes

class  PropertyVector
 
struct  CoordinateSystemType
 Coordinate system type. More...
 
class  CoordinateSystem
 Coordinate systems. More...
 
class  ElementCoordinatesMappingLocal
 
class  CellRule
 
class  NoEdgeReturn
 Returns always null pointer. More...
 
class  LinearEdgeReturn
 Returns linear order edge. More...
 
class  QuadraticEdgeReturn
 Returns quadratic order edge. More...
 
class  EdgeRule
 
class  Element
 
class  FaceRule
 
class  HexRule20
 
class  HexRule8
 
class  LineRule2
 
class  LineRule3
 
class  PointRule1
 A 0d point element. More...
 
class  PrismRule15
 
class  PrismRule6
 
class  PyramidRule13
 
class  PyramidRule5
 
class  QuadRule4
 
class  QuadRule8
 
class  QuadRule9
 
class  TemplateElement
 
class  TetRule10
 
class  TetRule4
 
class  TriRule3
 
class  TriRule6
 
class  VertexRule
 
class  ElementStatus
 
struct  Location
 
class  Mesh
 
class  ElementValueModification
 A set of methods for manipulating mesh element values. More...
 
class  Mesh2MeshPropertyInterpolation
 
class  MeshRevision
 
class  MeshLayerMapper
 Manipulating and adding prism element layers to an existing 2D mesh. More...
 
class  RasterToMesh
 Converts raster data into an OGS mesh. More...
 
class  VtkMeshConverter
 Converter for VtkUnstructured Grids to OGS meshes. More...
 
class  MeshInformation
 A set of tools for extracting information from a mesh. More...
 
struct  AngleSkewMetric
 
struct  EdgeRatioMetric
 
class  ElementQualityInterface
 
class  ElementQualityMetric
 
class  ElementSizeMetric
 
struct  MeshValidation
 A collection of methods for testing mesh quality and correctness. More...
 
struct  RadiusEdgeRatioMetric
 
struct  SizeDifferenceMetric
 
class  ElementSearch
 Element search class. More...
 
class  MeshElementGrid
 
class  NodeSearch
 Node search class. More...
 
class  MeshSubset
 A subset of nodes on a single mesh. More...
 
class  MeshSurfaceExtraction
 A set of tools concerned with extracting nodes and elements from a mesh surface. More...
 
class  Node
 
class  NodeAdjacencyTable
 
class  NodePartitionedMesh
 A subdomain mesh. More...
 
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  PropertyVectorBase
 
class  PropertyVector< T * >
 
class  VtkMappedMeshSource
 
class  VtkMeshNodalCoordinatesTemplate
 

Typedefs

using RotationMatrix = Eigen::Matrix< double, 3u, 3u, Eigen::RowMajor >
 
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

bool convertMeshToGeo (const MeshLib::Mesh &mesh, GeoLib::GEOObjects &geo_objects, double const eps)
 
MeshLib::MeshconvertSurfaceToMesh (const GeoLib::Surface &sfc, const std::string &mesh_name, double eps)
 
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. More...
 
bool hasZeroVolume (MeshLib::Element const &element)
 Returns true if the element has zero length/area/volume. More...
 
MeshLib::Node getCenterOfGravity (MeshLib::Element const &element)
 Calculates the center of gravity for the mesh element. More...
 
std::pair< double, double > computeSqrNodeDistanceRange (MeshLib::Element const &element, bool const check_allnodes=true)
 Compute the minimum and maximum node distances for this element. More...
 
std::pair< double, double > computeSqrEdgeLengthRange (Element const &element)
 Compute the minimum and maximum squared edge length for this element. More...
 
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. More...
 
std::size_t getNodeIndex (Element const &element, unsigned const idx)
 
MathLib::Point3d getBulkElementPoint (Tri const &, std::size_t const face_id, MathLib::WeightedPoint1D const &wp)
 
MathLib::Point3d getBulkElementPoint (Hex const &, std::size_t const face_id, MathLib::WeightedPoint2D const &wp)
 
MathLib::Point3d getBulkElementPoint (Mesh const &mesh, std::size_t const bulk_element_id, std::size_t const bulk_face_id, MathLib::WeightedPoint1D const &wp)
 
MathLib::Point3d getBulkElementPoint (Mesh const &mesh, std::size_t bulk_element_id, std::size_t bulk_face_id, MathLib::WeightedPoint2D const &wp)
 
MathLib::Point3d getBulkElementPoint (Mesh const &, std::size_t, std::size_t, MathLib::WeightedPoint3D const &)
 
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. More...
 
bool operator< (const Location &left, const Location &right)
 Lexicographic order of Location. More...
 
std::vector< std::vector< Element const * > > findElementsConnectedToNodes (Mesh const &mesh)
 
void scaleMeshPropertyVector (MeshLib::Mesh &mesh, std::string const &property_name, double factor)
 
PropertyVector< int > const * materialIDs (Mesh const &mesh)
 
std::unique_ptr< MeshLib::MeshcreateMeshFromElementSelection (std::string mesh_name, std::vector< MeshLib::Element * > const &elements)
 
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. More...
 
bool operator!= (Mesh const &a, Mesh const &b)
 
template<typename T >
void addPropertyToMesh (Mesh &mesh, std::string const &name, MeshItemType item_type, std::size_t number_of_components, std::vector< T > const &values)
 
template<typename T >
PropertyVector< T > * getOrCreateMeshProperty (Mesh &mesh, std::string const &property_name, MeshItemType const item_type, int const number_of_components)
 
std::unique_ptr< MeshcreateMeshFromElementSelection (std::string mesh_name, std::vector< Element * > const &elements)
 
MeshLib::ElementextrudeElement (std::vector< MeshLib::Node * > const &subsfc_nodes, MeshLib::Element const &sfc_elem, MeshLib::PropertyVector< std::size_t > const &sfc_to_subsfc_id_map, std::map< std::size_t, std::size_t > const &subsfc_sfc_id_map)
 
MeshLib::MeshaddLayerToMesh (MeshLib::Mesh const &mesh, double thickness, std::string const &name, bool on_top, bool copy_material_ids)
 
std::unique_ptr< MeshLib::MeshconvertToLinearMesh (MeshLib::Mesh const &org_mesh, std::string const &new_mesh_name)
 
std::vector< Node * > copyNodeVector (const std::vector< Node * > &nodes)
 Creates a deep copy of a Node vector. More...
 
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)
 
std::vector< Element * > cloneElements (std::vector< Element * > const &elements)
 Clones a vector of elements using the Element::clone() function. More...
 
std::unique_ptr< ElementcreateFlippedElement (Element const &elem, std::vector< Node * > const &nodes)
 
std::unique_ptr< MeshcreateFlippedMesh (Mesh const &mesh)
 
template<typename T >
void fillNodeProperty (std::vector< T > &new_prop, std::vector< T > const &old_prop, std::vector< size_t > node_ids)
 
template<typename T >
void fillElemProperty (std::vector< T > &new_prop, std::vector< T > const &old_prop, std::vector< size_t > elem_ids)
 
template<typename Iterator >
void moveMeshNodes (Iterator begin, Iterator end, MeshLib::Node const &displacement)
 
MeshLib::MeshremoveElements (const MeshLib::Mesh &mesh, const std::vector< std::size_t > &removed_element_ids, const std::string &new_mesh_name)
 
std::vector< bool > markUnusedNodes (std::vector< Element * > const &elements, std::vector< Node * > const &nodes)
 Marks nodes not used by any of the elements. More...
 
void removeMarkedNodes (std::vector< bool > const &nodes_to_delete, std::vector< Node * > &nodes)
 Deallocates and removes nodes marked true. More...
 
MeshLib::MeshremoveNodes (const MeshLib::Mesh &mesh, const std::vector< std::size_t > &del_nodes_idx, const std::string &new_mesh_name)
 
std::string MeshElemType2String (const MeshElemType t)
 Given a MeshElemType this returns the appropriate string. More...
 
std::string MeshElemType2StringShort (const MeshElemType t)
 Given a MeshElemType this returns the appropriate string with a short name. More...
 
MeshElemType String2MeshElemType (const std::string &s)
 Given a string of the shortened name of the element type, this returns the corresponding MeshElemType. More...
 
std::vector< MeshElemTypegetMeshElemTypes ()
 Returns a vector of all mesh element types. More...
 
std::vector< std::string > getMeshElemTypeStringsShort ()
 Returns a vector of strings of mesh element types. More...
 
std::string CellType2String (const CellType t)
 Given a MeshElemType this returns the appropriate string. More...
 
std::string MeshQualityType2String (const MeshQualityType t)
 
MeshLib::MeshQualityType String2MeshQualityType (std::string const &s)
 
std::unique_ptr< MeshcreateQuadraticOrderMesh (Mesh const &linear_mesh, bool const add_centre_node)
 
static void trackSurface (MeshLib::Element const *const element, std::vector< unsigned > &sfc_idx, unsigned const current_index)
 
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. More...
 
template<typename T >
void processPropertyVector (MeshLib::PropertyVector< T > const &property, std::vector< std::size_t > const &id_map, MeshLib::Mesh &sfc_mesh)
 
bool createSfcMeshProperties (MeshLib::Mesh &sfc_mesh, MeshLib::Properties const &properties, std::vector< std::size_t > const &node_ids_map, std::vector< std::size_t > const &element_ids_map)
 
std::tuple< std::vector< MeshLib::Node * >, std::vector< std::size_t > > createNodesAndIDMapFromElements (std::vector< MeshLib::Element * > const &elements, std::size_t const n_all_nodes)
 
void createSurfaceElementsFromElement (MeshLib::Element const &surface_element, std::vector< MeshLib::Element * > &surface_elements, std::vector< std::size_t > &element_to_bulk_element_id_map, std::vector< std::size_t > &element_to_bulk_face_id_map)
 
std::tuple< std::vector< MeshLib::Element * >, std::vector< std::size_t >, std::vector< std::size_t > > createBoundaryElements (MeshLib::Mesh const &bulk_mesh)
 
void addBulkIDPropertiesToMesh (MeshLib::Mesh &surface_mesh, std::string const &node_to_bulk_node_id_map_name, std::vector< std::size_t > const &node_to_bulk_node_id_map, std::string const &element_to_bulk_element_id_map_name, std::vector< std::size_t > const &element_to_bulk_element_id_map, std::string const &element_to_bulk_face_id_map_name, std::vector< std::size_t > const &element_to_bulk_face_id_map)
 
std::vector< Eigen::MatrixXd > getElementRotationMatrices (int const space_dimension, int const mesh_dimension, std::vector< Element * > const &elements)
 Element rotation matrix computation. More...
 
int getSpaceDimension (std::vector< Node * > const &nodes)
 Computes dimension of the embedding space containing the set of given points. More...
 
bool is2DMeshOnRotatedVerticalPlane (Mesh const &mesh)
 
void setMeshSpaceDimension (std::vector< std::unique_ptr< Mesh >> const &meshes)
 
 vtkStandardNewMacro (VtkMappedMeshSource) void VtkMappedMeshSource
 

Variables

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

Typedef Documentation

◆ 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 23 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 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.

43 {
44  INVALID = 0,
45  POINT1 = 1,
46  LINE2 = 2,
47  LINE3 = 3,
48  TRI3 = 4,
49  TRI6 = 5,
50  QUAD4 = 6,
51  QUAD8 = 7,
52  QUAD9 = 8,
53  TET4 = 9,
54  TET10 = 10,
55  HEX8 = 11,
56  HEX20 = 12,
57  HEX27 = 13,
58  PRISM6 = 14,
59  PRISM15 = 15,
60  PRISM18 = 16,
61  PYRAMID5 = 17,
62  PYRAMID13 = 18,
64 };

◆ MeshElemType

enum 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 MeshLib::MeshItemType
strong
Enumerator
Node 
Edge 
Face 
Cell 
IntegrationPoint 

Definition at line 21 of file Location.h.

◆ MeshQualityType

Describes a mesh quality metric.

Enumerator
INVALID 
ELEMENTSIZE 
SIZEDIFFERENCE 
EDGERATIO 
EQUIANGLESKEW 
RADIUSEDGERATIO 

Definition at line 69 of file MeshEnums.h.

◆ UseIntensityAs

Selection of possible interpretations for intensities.

Enumerator
ELEVATION 
MATERIALS 
DATAVECTOR 
NONE 

Definition at line 82 of file MeshEnums.h.

Function Documentation

◆ addBulkIDPropertiesToMesh()

void MeshLib::addBulkIDPropertiesToMesh ( MeshLib::Mesh surface_mesh,
std::string const &  node_to_bulk_node_id_map_name,
std::vector< std::size_t > const &  node_to_bulk_node_id_map,
std::string const &  element_to_bulk_element_id_map_name,
std::vector< std::size_t > const &  element_to_bulk_element_id_map,
std::string const &  element_to_bulk_face_id_map_name,
std::vector< std::size_t > const &  element_to_bulk_face_id_map 
)

Definition at line 498 of file MeshSurfaceExtraction.cpp.

506 {
507  // transmit the original node ids of the bulk mesh as a property
508  if (!node_to_bulk_node_id_map_name.empty())
509  {
510  MeshLib::addPropertyToMesh(surface_mesh, node_to_bulk_node_id_map_name,
512  node_to_bulk_node_id_map);
513  }
514 
515  // transmit the original bulk element ids as a property
516  if (!element_to_bulk_element_id_map_name.empty())
517  {
519  surface_mesh, element_to_bulk_element_id_map_name,
520  MeshLib::MeshItemType::Cell, 1, element_to_bulk_element_id_map);
521  }
522 
523  // transmit the face id of the original bulk element as a property
524  if (!element_to_bulk_face_id_map_name.empty())
525  {
527  surface_mesh, element_to_bulk_face_id_map_name,
528  MeshLib::MeshItemType::Cell, 1, element_to_bulk_face_id_map);
529  }
530 }
void addPropertyToMesh(Mesh &mesh, std::string const &name, MeshItemType item_type, std::size_t number_of_components, std::vector< T > const &values)
Definition: Mesh.h:193

References addPropertyToMesh(), Cell, and Node.

Referenced by MeshLib::BoundaryExtraction::getBoundaryElementsAsMesh(), and MeshLib::MeshSurfaceExtraction::getMeshSurface().

◆ addLayerToMesh()

MeshLib::Mesh * MeshLib::addLayerToMesh ( MeshLib::Mesh const &  mesh,
double  thickness,
std::string const &  name,
bool  on_top,
bool  copy_material_ids 
)

Adds a layer to the mesh. If on_top is true, the layer is added on top, if it is false, the layer is added at the bottom.

Definition at line 85 of file AddLayerToMesh.cpp.

88 {
89  INFO("Extracting top surface of mesh '{:s}' ... ", mesh.getName());
90  double const flag = on_top ? -1.0 : 1.0;
91  Eigen::Vector3d const dir({0, 0, flag});
92  double const angle(90);
93  std::unique_ptr<MeshLib::Mesh> sfc_mesh(nullptr);
94 
95  std::string const prop_name("bulk_node_ids");
96 
97  if (mesh.getDimension() == 3)
98  {
100  mesh, dir, angle, prop_name));
101  }
102  else
103  {
104  sfc_mesh = (on_top) ? std::make_unique<MeshLib::Mesh>(mesh)
105  : std::unique_ptr<MeshLib::Mesh>(
107  // add property storing node ids
108  auto* const pv =
109  sfc_mesh->getProperties().createNewPropertyVector<std::size_t>(
110  prop_name, MeshLib::MeshItemType::Node, 1);
111  if (pv)
112  {
113  pv->resize(sfc_mesh->getNumberOfNodes());
114  std::iota(pv->begin(), pv->end(), 0);
115  }
116  else
117  {
118  ERR("Could not create and initialize property '{%s}'.", prop_name);
119  return nullptr;
120  }
121  }
122  INFO("done.");
123 
124  // *** add new surface nodes
125  std::vector<MeshLib::Node*> subsfc_nodes =
126  MeshLib::copyNodeVector(mesh.getNodes());
127  std::vector<MeshLib::Element*> subsfc_elements =
128  MeshLib::copyElementVector(mesh.getElements(), subsfc_nodes);
129 
130  std::size_t const n_subsfc_nodes(subsfc_nodes.size());
131 
132  std::vector<MeshLib::Node*> const& sfc_nodes(sfc_mesh->getNodes());
133  std::size_t const n_sfc_nodes(sfc_nodes.size());
134 
135  if (!sfc_mesh->getProperties().existsPropertyVector<std::size_t>(prop_name))
136  {
137  ERR("Need subsurface node ids, but the property '{:s}' is not "
138  "available.",
139  prop_name);
140  return nullptr;
141  }
142  // fetch subsurface node ids PropertyVector
143  auto const* const node_id_pv =
144  sfc_mesh->getProperties().getPropertyVector<std::size_t>(prop_name);
145 
146  // *** copy sfc nodes to subsfc mesh node
147  std::map<std::size_t, std::size_t> subsfc_sfc_id_map;
148  for (std::size_t k(0); k < n_sfc_nodes; ++k)
149  {
150  std::size_t const subsfc_id((*node_id_pv)[k]);
151  std::size_t const sfc_id(k + n_subsfc_nodes);
152  subsfc_sfc_id_map.insert(std::make_pair(subsfc_id, sfc_id));
153  MeshLib::Node const& node(*sfc_nodes[k]);
154  subsfc_nodes.push_back(new MeshLib::Node(
155  node[0], node[1], node[2] - (flag * thickness), sfc_id));
156  }
157 
158  // *** insert new layer elements into subsfc_mesh
159  std::vector<MeshLib::Element*> const& sfc_elements(sfc_mesh->getElements());
160  std::size_t const n_sfc_elements(sfc_elements.size());
161  for (std::size_t k(0); k < n_sfc_elements; ++k)
162  {
163  subsfc_elements.push_back(extrudeElement(
164  subsfc_nodes, *sfc_elements[k], *node_id_pv, subsfc_sfc_id_map));
165  }
166 
167  auto new_mesh = new MeshLib::Mesh(name, subsfc_nodes, subsfc_elements);
168 
169  if (!mesh.getProperties().existsPropertyVector<int>("MaterialIDs"))
170  {
171  ERR("Could not copy the property 'MaterialIDs' since the original mesh "
172  "does not contain such a property.");
173  return new_mesh;
174  }
175  auto const* const materials =
176  mesh.getProperties().getPropertyVector<int>("MaterialIDs");
177 
178  auto* const new_materials =
179  new_mesh->getProperties().createNewPropertyVector<int>(
180  "MaterialIDs", MeshLib::MeshItemType::Cell, 1);
181  if (!new_materials)
182  {
183  ERR("Can not set material properties for new layer");
184  return new_mesh;
185  }
186 
187  new_materials->reserve(subsfc_elements.size());
188  std::copy(materials->cbegin(), materials->cend(),
189  std::back_inserter(*new_materials));
190 
191  if (copy_material_ids &&
192  sfc_mesh->getProperties().existsPropertyVector<int>("MaterialIDs"))
193  {
194  auto const& sfc_material_ids =
195  *sfc_mesh->getProperties().getPropertyVector<int>("MaterialIDs");
196  std::copy(sfc_material_ids.cbegin(), sfc_material_ids.cend(),
197  std::back_inserter(*new_materials));
198  }
199  else
200  {
201  int const new_layer_id(
202  *(std::max_element(materials->cbegin(), materials->cend())) + 1);
203  auto const n_new_props(subsfc_elements.size() -
204  mesh.getNumberOfElements());
205  std::fill_n(std::back_inserter(*new_materials), n_new_props,
206  new_layer_id);
207  }
208 
209  return new_mesh;
210 }
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
static MeshLib::Mesh * getMeshSurface(const MeshLib::Mesh &subsfc_mesh, Eigen::Vector3d const &dir, double angle, std::string const &subsfc_node_id_prop_name="", std::string const &subsfc_element_id_prop_name="", std::string const &face_id_prop_name="")
void copy(PETScVector const &x, PETScVector &y)
Definition: LinAlg.cpp:37
std::vector< Node * > copyNodeVector(const std::vector< Node * > &nodes)
Creates a deep copy of a Node vector.
MeshLib::Element * extrudeElement(std::vector< MeshLib::Node * > const &subsfc_nodes, MeshLib::Element const &sfc_elem, MeshLib::PropertyVector< std::size_t > const &sfc_to_subsfc_id_map, std::map< std::size_t, std::size_t > const &subsfc_sfc_id_map)
std::unique_ptr< Mesh > createFlippedMesh(Mesh const &mesh)
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)

References Cell, MathLib::LinAlg::copy(), copyElementVector(), copyNodeVector(), createFlippedMesh(), ERR(), MeshLib::Properties::existsPropertyVector(), extrudeElement(), MeshLib::Mesh::getDimension(), MeshLib::Mesh::getElements(), MeshLib::MeshSurfaceExtraction::getMeshSurface(), MeshLib::Mesh::getName(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getNumberOfElements(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), INFO(), MaterialPropertyLib::name, and Node.

Referenced by MeshLib::MeshGenerator::generateRegularPrismMesh(), main(), and MeshView::openAddLayerDialog().

◆ addPropertyToMesh()

template<typename T >
void MeshLib::addPropertyToMesh ( Mesh mesh,
std::string const &  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 193 of file Mesh.h.

196 {
197  if (item_type == MeshItemType::Node)
198  {
199  if (mesh.getNumberOfNodes() != values.size() / number_of_components)
200  {
201  OGS_FATAL(
202  "Error number of nodes ({:d}) does not match the number of "
203  "tuples ({:d}).",
204  mesh.getNumberOfNodes(), values.size() / number_of_components);
205  }
206  }
207  if (item_type == MeshItemType::Cell)
208  {
209  if (mesh.getNumberOfElements() != values.size() / number_of_components)
210  {
211  OGS_FATAL(
212  "Error number of elements ({:d}) does not match the number of "
213  "tuples ({:d}).",
214  mesh.getNumberOfElements(),
215  values.size() / number_of_components);
216  }
217  }
218 
219  auto* const property = mesh.getProperties().createNewPropertyVector<T>(
220  name, item_type, number_of_components);
221  if (!property)
222  {
223  OGS_FATAL("Error while creating PropertyVector '{:s}'.", name);
224  }
225  property->reserve(values.size());
226  std::copy(values.cbegin(), values.cend(), std::back_inserter(*property));
227 }
#define OGS_FATAL(...)
Definition: Error.h:26

References Cell, MathLib::LinAlg::copy(), MeshLib::Properties::createNewPropertyVector(), MeshLib::Mesh::getNumberOfElements(), MeshLib::Mesh::getNumberOfNodes(), MeshLib::Mesh::getProperties(), ApplicationUtils::NodeWiseMeshPartitioner::mesh(), MaterialPropertyLib::name, Node, and OGS_FATAL.

Referenced by addBulkIDPropertiesToMesh(), createMeshFromElementSelection(), ParameterLib::createRandomFieldMeshElementParameter(), main(), and anonymous_namespace{IdentifySubdomainMesh.cpp}::updateOrCheckExistingSubdomainProperty().

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

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

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

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

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

333 {
334  auto const elements_connected_to_nodes = findElementsConnectedToNodes(mesh);
335 
336  std::vector<std::vector<Node*>> nodes_connected_by_elements;
337  auto const& nodes = mesh.getNodes();
338  nodes_connected_by_elements.resize(nodes.size());
339  for (std::size_t i = 0; i < nodes.size(); ++i)
340  {
341  auto& adjacent_nodes = nodes_connected_by_elements[i];
342  auto const* node = nodes[i];
343 
344  // Get all elements, to which this node is connected.
345  auto const& connected_elements =
346  elements_connected_to_nodes[node->getID()];
347 
348  // And collect all elements' nodes.
349  for (Element const* const element : connected_elements)
350  {
351  Node* const* const single_elem_nodes = element->getNodes();
352  std::size_t const nnodes = element->getNumberOfNodes();
353  for (std::size_t n = 0; n < nnodes; n++)
354  {
355  adjacent_nodes.push_back(single_elem_nodes[n]);
356  }
357  }
358 
359  // Make nodes unique and sorted by their ids.
360  // This relies on the node's id being equivalent to it's address.
361  std::sort(adjacent_nodes.begin(), adjacent_nodes.end(),
362  [](Node* a, Node* b) { return a->getID() < b->getID(); });
363  auto const last =
364  std::unique(adjacent_nodes.begin(), adjacent_nodes.end());
365  adjacent_nodes.erase(last, adjacent_nodes.end());
366  }
367  return nodes_connected_by_elements;
368 }
std::vector< std::vector< Element const * > > findElementsConnectedToNodes(Mesh const &mesh)
Definition: Mesh.cpp:35

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

47 {
48  Eigen::Vector3d surface_element_normal;
49  if (surface_element.getDimension() < 2)
50  {
51  auto const bulk_element_normal =
53  auto const v0 = Eigen::Map<Eigen::Vector3d const>(
54  surface_element.getNode(0)->getCoords());
55  auto const v1 = Eigen::Map<Eigen::Vector3d const>(
56  surface_element.getNode(1)->getCoords());
57  Eigen::Vector3d const edge_vector = v1 - v0;
58  surface_element_normal = bulk_element_normal.cross(edge_vector);
59  }
60  else
61  {
62  surface_element_normal =
63  MeshLib::FaceRule::getSurfaceNormal(surface_element);
64  }
65 
66  surface_element_normal.normalize();
67  // At the moment (2018-04-26) the surface normal is not oriented
68  // according to the right hand rule
69  // for correct results it is necessary to multiply the normal with
70  // -1
71  surface_element_normal *= -1;
72 
73  return surface_element_normal;
74 }
static Eigen::Vector3d getSurfaceNormal(Element const &e)
Returns the surface normal of a 2D element.
Definition: FaceRule.cpp:40

References MathLib::TemplatePoint< T, DIM >::getCoords(), MeshLib::Element::getDimension(), MeshLib::Element::getNode(), and MeshLib::FaceRule::getSurfaceNormal().

◆ 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 convertToLinearMesh(), createQuadraticElement(), getBulkElementPoint(), and main().

◆ cloneElements()

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

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

Definition at line 118 of file DuplicateMeshComponents.cpp.

119 {
120  std::vector<Element*> cloned_elements;
121  cloned_elements.reserve(elements.size());
122  std::transform(begin(elements), end(elements),
123  std::back_inserter(cloned_elements),
124  [](Element* const e) { return e->clone(); });
125  return cloned_elements;
126 }

References MeshLib::Element::clone().

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

◆ computeSqrEdgeLengthRange()

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

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

Definition at line 162 of file Element.cpp.

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

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

Referenced by MeshLib::Mesh::calcEdgeLengthRange(), and MeshLib::RadiusEdgeRatioMetric::calculateQuality().

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

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

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

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

◆ convertMeshToGeo()

bool MeshLib::convertMeshToGeo ( const MeshLib::Mesh mesh,
GeoLib::GEOObjects geo_objects,
double  eps = std::numeric_limits< double >::epsilon() 
)

Converts a 2D mesh into a geometry. A new geometry with the name of the mesh will be inserted into geo_objects, consisting of points identical with mesh nodes and one surface representing the mesh. Triangles are converted to geometric triangles, quads are split into two triangles, all other elements are ignored.

Definition at line 77 of file convertMeshToGeo.cpp.

80 {
81  if (mesh.getDimension() != 2)
82  {
83  ERR("Mesh to geometry conversion is only working for 2D meshes.");
84  return false;
85  }
86 
87  // Special handling of the bounds in case there are no materialIDs present.
88  auto get_material_ids_and_bounds = [&]()
89  -> std::tuple<MeshLib::PropertyVector<int> const*, std::pair<int, int>>
90  {
91  auto const materialIds = materialIDs(mesh);
92  if (!materialIds)
93  {
94  return std::make_tuple(nullptr, std::make_pair(0, 0));
95  }
96 
97  auto const bounds = MeshInformation::getValueBounds(*materialIds);
98  if (!bounds)
99  {
100  OGS_FATAL(
101  "Could not get minimum/maximum ranges values for the "
102  "MaterialIDs property in the mesh '{:s}'.",
103  mesh.getName());
104  }
105  return std::make_tuple(materialIds, *bounds);
106  };
107 
108  auto const [materialIds, bounds] = get_material_ids_and_bounds();
109  // elements to surface triangles conversion
110  const unsigned nMatGroups(bounds.second - bounds.first + 1);
111  auto sfcs = std::make_unique<std::vector<GeoLib::Surface*>>();
112  sfcs->reserve(nMatGroups);
113  std::string const geoobject_name =
114  convertMeshNodesToGeoPoints(mesh, eps, geo_objects);
115  auto const& points = *geo_objects.getPointVec(geoobject_name);
116  for (unsigned i = 0; i < nMatGroups; ++i)
117  {
118  sfcs->push_back(new GeoLib::Surface(points));
119  }
120 
121  const std::vector<std::size_t>& id_map(
122  geo_objects.getPointVecObj(geoobject_name)->getIDMap());
123  const std::vector<MeshLib::Element*>& elements = mesh.getElements();
124  const std::size_t nElems(mesh.getNumberOfElements());
125 
126  for (unsigned i = 0; i < nElems; ++i)
127  {
128  auto surfaceId = !materialIds ? 0 : ((*materialIds)[i] - bounds.first);
129  addElementToSurface(*elements[i], id_map, *(*sfcs)[surfaceId]);
130  }
131 
132  std::for_each(sfcs->begin(), sfcs->end(),
133  [](GeoLib::Surface*& sfc)
134  {
135  if (sfc->getNumberOfTriangles() == 0)
136  {
137  delete sfc;
138  sfc = nullptr;
139  }
140  });
141  auto sfcs_end = std::remove(sfcs->begin(), sfcs->end(), nullptr);
142  sfcs->erase(sfcs_end, sfcs->end());
143 
144  geo_objects.addSurfaceVec(std::move(sfcs), geoobject_name);
145  return true;
146 }
void addSurfaceVec(std::unique_ptr< std::vector< Surface * >> sfc, const std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> sfc_names=nullptr)
Definition: GEOObjects.cpp:261
const std::vector< Point * > * getPointVec(const std::string &name) const
Definition: GEOObjects.cpp:71
const PointVec * getPointVecObj(const std::string &name) const
Definition: GEOObjects.cpp:84
const std::vector< std::size_t > & getIDMap() const
Definition: PointVec.h:97
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
Definition: Surface.h:34
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition: Mesh.h:71
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:98
const std::string getName() const
Get name of the mesh.
Definition: Mesh.h:92
std::size_t getNumberOfElements() const
Get the number of elements.
Definition: Mesh.h:86
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition: Mesh.cpp:258
void addElementToSurface(MeshLib::Element const &e, std::vector< std::size_t > const &id_map, GeoLib::Surface &surface)
std::string convertMeshNodesToGeoPoints(MeshLib::Mesh const &mesh, double const eps, GeoLib::GEOObjects &geo_objects)

References anonymous_namespace{convertMeshToGeo.cpp}::addElementToSurface(), anonymous_namespace{convertMeshToGeo.cpp}::convertMeshNodesToGeoPoints(), ERR(), MeshLib::Mesh::getDimension(), MeshLib::Mesh::getElements(), GeoLib::PointVec::getIDMap(), MeshLib::Mesh::getName(), MeshLib::Mesh::getNumberOfElements(), GeoLib::GEOObjects::getPointVec(), GeoLib::GEOObjects::getPointVecObj(), MeshLib::MeshInformation::getValueBounds(), materialIDs(), and OGS_FATAL.

Referenced by MainWindow::convertMeshToGeometry(), FileIO::createSurface(), and main().

◆ convertSurfaceToMesh()

MeshLib::Mesh * MeshLib::convertSurfaceToMesh ( const GeoLib::Surface sfc,
const std::string &  mesh_name,
double  eps = std::numeric_limits< double >::epsilon() 
)

Converts a surface into a triangular mesh

Parameters
sfcSurface object
mesh_nameNew mesh name
epsMinimum distance for nodes not to be collapsed
Returns
a pointer to a converted mesh object. nullptr is returned if the conversion fails.

Definition at line 148 of file convertMeshToGeo.cpp.

151 {
152  // convert to a mesh including duplicated nodes
153  std::vector<MeshLib::Node*> nodes;
154  std::vector<MeshLib::Element*> elements;
155  std::size_t nodeId = 0;
156  for (std::size_t i = 0; i < sfc.getNumberOfTriangles(); i++)
157  {
158  auto* tri = sfc[i];
159  auto** tri_nodes = new MeshLib::Node*[3];
160  for (unsigned j = 0; j < 3; j++)
161  {
162  tri_nodes[j] =
163  new MeshLib::Node(tri->getPoint(j)->getCoords(), nodeId++);
164  }
165  elements.push_back(new MeshLib::Tri(tri_nodes, i));
166  for (unsigned j = 0; j < 3; j++)
167  {
168  nodes.push_back(tri_nodes[j]);
169  }
170  }
171  MeshLib::Mesh mesh_with_duplicated_nodes(mesh_name, nodes, elements);
172 
173  // remove duplicated nodes
174  MeshLib::MeshRevision rev(mesh_with_duplicated_nodes);
175  return rev.simplifyMesh(mesh_with_duplicated_nodes.getName(), eps);
176 }
std::size_t getNumberOfTriangles() const
Definition: Surface.cpp:82

References MeshLib::Mesh::getName(), GeoLib::Surface::getNumberOfTriangles(), and MeshLib::MeshRevision::simplifyMesh().

Referenced by main().

◆ convertToLinearMesh()

std::unique_ptr< MeshLib::Mesh > MeshLib::convertToLinearMesh ( const MeshLib::Mesh mesh,
const std::string &  new_mesh_name 
)

Converts a non-linear mesh to a linear mesh. All the mesh properties will be copied except for entries for non-linear nodes.

Definition at line 59 of file ConvertToLinearMesh.cpp.

61 {
62  std::vector<MeshLib::Node*> vec_new_nodes =
63  MeshLib::copyNodeVector(MeshLib::getBaseNodes(org_mesh.getElements()));
64 
65  // create new elements with the quadratic nodes
66  std::vector<MeshLib::Element*> vec_new_eles;
67  for (MeshLib::Element const* e : org_mesh.getElements())
68  {
69  if (e->getCellType() == MeshLib::CellType::LINE3)
70  {
71  vec_new_eles.push_back(
72  createLinearElement<MeshLib::Line>(e, vec_new_nodes));
73  }
74  else if (e->getCellType() == MeshLib::CellType::QUAD8)
75  {
76  vec_new_eles.push_back(
77  createLinearElement<MeshLib::Quad>(e, vec_new_nodes));
78  }
79  else if (e->getCellType() == MeshLib::CellType::TRI6)
80  {
81  vec_new_eles.push_back(
82  createLinearElement<MeshLib::Tri>(e, vec_new_nodes));
83  }
84  else if (e->getCellType() == MeshLib::CellType::HEX20)
85  {
86  vec_new_eles.push_back(
87  createLinearElement<MeshLib::Hex>(e, vec_new_nodes));
88  }
89  else if (e->getCellType() == MeshLib::CellType::TET10)
90  {
91  vec_new_eles.push_back(
92  createLinearElement<MeshLib::Tet>(e, vec_new_nodes));
93  }
94  else
95  {
96  OGS_FATAL("Mesh element type {:s} is not supported",
97  MeshLib::CellType2String(e->getCellType()));
98  }
99  }
100 
101  auto new_mesh = std::make_unique<MeshLib::Mesh>(
102  new_mesh_name, vec_new_nodes, vec_new_eles,
103  org_mesh.getProperties().excludeCopyProperties(
104  std::vector<MeshLib::MeshItemType>(1,
106 
107  // copy property vectors for nodes
108  for (auto [name, property] : org_mesh.getProperties())
109  {
110  if (property->getMeshItemType() != MeshLib::MeshItemType::Node)
111  {
112  continue;
113  }
114  auto double_property = dynamic_cast<PropertyVector<double>*>(property);
115  if (double_property == nullptr)
116  {
117  continue;
118  }
119  auto const n_src_comp = double_property->getNumberOfGlobalComponents();
120  auto new_prop =
121  new_mesh->getProperties().createNewPropertyVector<double>(
122  name, MeshLib::MeshItemType::Node, n_src_comp);
123  new_prop->resize(new_mesh->getNumberOfNodes() * n_src_comp);
124 
125  // copy only base node values
126  for (unsigned i = 0; i < org_mesh.getNumberOfBaseNodes(); i++)
127  {
128  for (int j = 0; j < n_src_comp; j++)
129  {
130  (*new_prop)[i * n_src_comp + j] =
131  (*double_property)[i * n_src_comp + j];
132  }
133  }
134  }
135 
136  return new_mesh;
137 }
std::string CellType2String(const CellType t)
Given a MeshElemType this returns the appropriate string.
Definition: MeshEnums.cpp:157
std::vector< Node * > getBaseNodes(std::vector< Element * > const &elements)
Definition: Utils.h:26

References CellType2String(), copyNodeVector(), MeshLib::Properties::excludeCopyProperties(), getBaseNodes(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getNumberOfBaseNodes(), MeshLib::PropertyVectorBase::getNumberOfGlobalComponents(), MeshLib::Mesh::getProperties(), HEX20, LINE3, MaterialPropertyLib::name, Node, OGS_FATAL, QUAD8, TET10, and TRI6.

Referenced by main(), and anonymous_namespace{postLIE.cpp}::postVTU().

◆ copyElement()

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

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

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

Referenced by MeshLib::MeshRevision::simplifyMesh().

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

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

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

◆ copyNodeVector()

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

Creates a deep copy of a Node vector.

Definition at line 22 of file DuplicateMeshComponents.cpp.

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

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

◆ createBoundaryElements()

std::tuple<std::vector<MeshLib::Element*>, std::vector<std::size_t>, std::vector<std::size_t> > MeshLib::createBoundaryElements ( MeshLib::Mesh const &  bulk_mesh)

Definition at line 413 of file MeshSurfaceExtraction.cpp.

414 {
415  std::vector<std::size_t> element_to_bulk_element_id_map;
416  std::vector<std::size_t> element_to_bulk_face_id_map;
417  std::vector<MeshLib::Element*> surface_elements;
418 
419  auto const& bulk_elements = bulk_mesh.getElements();
420  auto const mesh_dimension = bulk_mesh.getDimension();
421 
422  for (auto const* elem : bulk_elements)
423  {
424  const unsigned element_dimension(elem->getDimension());
425  if (element_dimension < mesh_dimension)
426  {
427  continue;
428  }
429 
430  if (!elem->isBoundaryElement())
431  {
432  continue;
433  }
434  createSurfaceElementsFromElement(*elem, surface_elements,
435  element_to_bulk_element_id_map,
436  element_to_bulk_face_id_map);
437  }
438  return {surface_elements, element_to_bulk_element_id_map,
439  element_to_bulk_face_id_map};
440 }
void createSurfaceElementsFromElement(MeshLib::Element const &surface_element, std::vector< MeshLib::Element * > &surface_elements, std::vector< std::size_t > &element_to_bulk_element_id_map, std::vector< std::size_t > &element_to_bulk_face_id_map)

References createSurfaceElementsFromElement(), MeshLib::Mesh::getDimension(), and MeshLib::Mesh::getElements().

Referenced by MeshLib::BoundaryExtraction::getBoundaryElementsAsMesh().

◆ createFlippedElement()

std::unique_ptr< Element > MeshLib::createFlippedElement ( Element const &  elem,
std::vector< Node * > const &  nodes 
)

Creates a copy of an 1d / 2d element where the node order is reversed, such that the direction of a line changes and normals of 2D elements changes its sign.

Parameters
elemoriginal element
nodesnode vector used for the copy of the element
Returns
a flipped copy of the element

Definition at line 22 of file FlipElements.cpp.

24 {
25  if (elem.getDimension() > 2)
26  {
27  return nullptr;
28  }
29 
30  unsigned const n_nodes(elem.getNumberOfNodes());
31  auto elem_nodes = std::make_unique<Node*[]>(n_nodes);
32  for (unsigned i = 0; i < n_nodes; ++i)
33  {
34  elem_nodes[i] = nodes[elem.getNode(i)->getID()];
35  }
36  std::swap(elem_nodes[0], elem_nodes[1]);
37 
38  if (elem.getGeomType() == MeshElemType::LINE)
39  {
40  return std::make_unique<Line>(elem_nodes.release(), elem.getID());
41  }
42  if (elem.getGeomType() == MeshElemType::TRIANGLE)
43  {
44  return std::make_unique<Tri>(elem_nodes.release(), elem.getID());
45  }
46  if (elem.getGeomType() == MeshElemType::QUAD)
47  {
48  std::swap(elem_nodes[2], elem_nodes[3]);
49  return std::make_unique<Quad>(elem_nodes.release(), elem.getID());
50  }
51  return nullptr;
52 }

References MeshLib::Element::getDimension(), MeshLib::Element::getGeomType(), MathLib::Point3dWithID::getID(), MeshLib::Element::getID(), MeshLib::Element::getNode(), MeshLib::Element::getNumberOfNodes(), LINE, QUAD, and TRIANGLE.

Referenced by createFlippedMesh().

◆ createFlippedMesh()

std::unique_ptr< Mesh > MeshLib::createFlippedMesh ( Mesh const &  mesh)

Creates a copy of a 1d / 2d mesh where the node order of all elements is reversed such that the direction of lines changes and normals of 2D elements changes their sign.

Parameters
meshinput mesh
Returns
a flipped copy of the input mesh

Definition at line 54 of file FlipElements.cpp.

55 {
56  if (mesh.getDimension() > 2)
57  {
58  return nullptr;
59  }
60 
61  std::vector<Node*> new_nodes(copyNodeVector(mesh.getNodes()));
62  std::vector<Element*> const& elems(mesh.getElements());
63  std::vector<Element*> new_elems;
64  std::size_t n_elems(mesh.getNumberOfElements());
65  new_elems.reserve(n_elems);
66 
67  for (std::size_t i = 0; i < n_elems; ++i)
68  {
69  new_elems.push_back(
70  createFlippedElement(*elems[i], new_nodes).release());
71  }
72 
73  return std::make_unique<Mesh>("FlippedElementMesh", new_nodes, new_elems,
74  mesh.getProperties());
75 }
std::unique_ptr< Element > createFlippedElement(Element const &elem, std::vector< Node * > const &nodes)

References copyNodeVector(), createFlippedElement(), MeshLib::Mesh::getDimension(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getNumberOfElements(), and MeshLib::Mesh::getProperties().

Referenced by addLayerToMesh().

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

270 {
271  DBUG("Found {:d} elements in the mesh", elements.size());
272 
273  // Store bulk element ids for each of the new elements.
274  std::vector<std::size_t> bulk_element_ids;
275  bulk_element_ids.reserve(elements.size());
276  std::transform(begin(elements), end(elements),
277  std::back_inserter(bulk_element_ids),
278  [&](auto const& e) { return e->getID(); });
279 
280  // original node pointers to newly created nodes.
281  std::unordered_map<const MeshLib::Node*, MeshLib::Node*> nodes_map;
282  nodes_map.reserve(
283  elements.size()); // There will be at least one node per element.
284 
285  for (auto& e : elements)
286  {
287  // For each node find a cloned node in map or create if there is none.
288  unsigned const n_nodes = e->getNumberOfNodes();
289  for (unsigned i = 0; i < n_nodes; ++i)
290  {
291  const MeshLib::Node* n = e->getNode(i);
292  auto const it = nodes_map.find(n);
293  if (it == nodes_map.end())
294  {
295  auto new_node_in_map = nodes_map[n] = new MeshLib::Node(*n);
296  e->setNode(i, new_node_in_map);
297  }
298  else
299  {
300  e->setNode(i, it->second);
301  }
302  }
303  }
304 
305  // Copy the unique nodes pointers.
306  std::vector<MeshLib::Node*> element_nodes;
307  element_nodes.reserve(nodes_map.size());
308  std::transform(begin(nodes_map), end(nodes_map),
309  std::back_inserter(element_nodes),
310  [](auto const& pair) { return pair.second; });
311 
312  // Store bulk node ids for each of the new nodes.
313  std::vector<std::size_t> bulk_node_ids;
314  bulk_node_ids.reserve(nodes_map.size());
315  std::transform(begin(nodes_map), end(nodes_map),
316  std::back_inserter(bulk_node_ids),
317  [](auto const& pair) { return pair.first->getID(); });
318 
319  auto mesh = std::make_unique<MeshLib::Mesh>(
320  std::move(mesh_name), std::move(element_nodes), std::move(elements));
321  assert(mesh != nullptr);
322 
323  addPropertyToMesh(*mesh, "bulk_element_ids", MeshLib::MeshItemType::Cell, 1,
324  bulk_element_ids);
325  addPropertyToMesh(*mesh, "bulk_node_ids", MeshLib::MeshItemType::Node, 1,
326  bulk_node_ids);
327 
328  return mesh;
329 }
void DBUG(char const *fmt, Args const &... args)
Definition: Logging.h:27

References addPropertyToMesh(), Cell, DBUG(), and Node.

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

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

270 {
271  DBUG("Found {:d} elements in the mesh", elements.size());
272 
273  // Store bulk element ids for each of the new elements.
274  std::vector<std::size_t> bulk_element_ids;
275  bulk_element_ids.reserve(elements.size());
276  std::transform(begin(elements), end(elements),
277  std::back_inserter(bulk_element_ids),
278  [&](auto const& e) { return e->getID(); });
279 
280  // original node pointers to newly created nodes.
281  std::unordered_map<const MeshLib::Node*, MeshLib::Node*> nodes_map;
282  nodes_map.reserve(
283  elements.size()); // There will be at least one node per element.
284 
285  for (auto& e : elements)
286  {
287  // For each node find a cloned node in map or create if there is none.
288  unsigned const n_nodes = e->getNumberOfNodes();
289  for (unsigned i = 0; i < n_nodes; ++i)
290  {
291  const MeshLib::Node* n = e->getNode(i);
292  auto const it = nodes_map.find(n);
293  if (it == nodes_map.end())
294  {
295  auto new_node_in_map = nodes_map[n] = new MeshLib::Node(*n);
296  e->setNode(i, new_node_in_map);
297  }
298  else
299  {
300  e->setNode(i, it->second);
301  }
302  }
303  }
304 
305  // Copy the unique nodes pointers.
306  std::vector<MeshLib::Node*> element_nodes;
307  element_nodes.reserve(nodes_map.size());
308  std::transform(begin(nodes_map), end(nodes_map),
309  std::back_inserter(element_nodes),
310  [](auto const& pair) { return pair.second; });
311 
312  // Store bulk node ids for each of the new nodes.
313  std::vector<std::size_t> bulk_node_ids;
314  bulk_node_ids.reserve(nodes_map.size());
315  std::transform(begin(nodes_map), end(nodes_map),
316  std::back_inserter(bulk_node_ids),
317  [](auto const& pair) { return pair.first->getID(); });
318 
319  auto mesh = std::make_unique<MeshLib::Mesh>(
320  std::move(mesh_name), std::move(element_nodes), std::move(elements));
321  assert(mesh != nullptr);
322 
323  addPropertyToMesh(*mesh, "bulk_element_ids", MeshLib::MeshItemType::Cell, 1,
324  bulk_element_ids);
325  addPropertyToMesh(*mesh, "bulk_node_ids", MeshLib::MeshItemType::Node, 1,
326  bulk_node_ids);
327 
328  return mesh;
329 }

References addPropertyToMesh(), Cell, DBUG(), and Node.

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

◆ createNodesAndIDMapFromElements()

std::tuple<std::vector<MeshLib::Node*>, std::vector<std::size_t> > MeshLib::createNodesAndIDMapFromElements ( std::vector< MeshLib::Element * > const &  elements,
std::size_t const  n_all_nodes 
)

Definition at line 161 of file MeshSurfaceExtraction.cpp.

163 {
164  std::vector<MeshLib::Node const*> tmp_nodes(n_all_nodes, nullptr);
165  for (auto const* elem : elements)
166  {
167  auto const n_nodes = elem->getNumberOfNodes();
168  for (unsigned j = 0; j < n_nodes; ++j)
169  {
170  const MeshLib::Node* node(elem->getNode(j));
171  tmp_nodes[node->getID()] = node;
172  }
173  }
174 
175  std::vector<MeshLib::Node*> nodes;
176  std::vector<std::size_t> node_id_map(n_all_nodes);
177  for (unsigned i = 0; i < n_all_nodes; ++i)
178  {
179  if (tmp_nodes[i])
180  {
181  node_id_map[i] = nodes.size();
182  nodes.push_back(new MeshLib::Node(*tmp_nodes[i]));
183  }
184  }
185  return {nodes, node_id_map};
186 }

References MathLib::Point3dWithID::getID().

Referenced by MeshLib::BoundaryExtraction::getBoundaryElementsAsMesh(), MeshLib::MeshSurfaceExtraction::getMeshSurface(), and MeshLib::MeshSurfaceExtraction::getSurfaceNodes().

◆ createQuadraticOrderMesh()

std::unique_ptr< Mesh > MeshLib::createQuadraticOrderMesh ( Mesh const &  linear_mesh,
bool const  add_centre_node 
)

Create a quadratic order mesh from the linear order mesh. For some element types like Quad-4, a centre node might be added if the add_centre_node flag is set, yielding a Quad-9.

Definition at line 139 of file QuadraticMeshGenerator.cpp.

141 {
142  // Clone the linear mesh nodes.
143  auto quadratic_mesh_nodes = MeshLib::copyNodeVector(linear_mesh.getNodes());
144 
145  // Temporary container for unique quadratic nodes with O(log(n)) search.
146  std::set<MeshLib::Node*, nodeByCoordinatesComparator> unique_nodes;
147 
148  // Create new elements with the quadratic nodes
149  std::vector<MeshLib::Element*> quadratic_elements;
150  auto const& linear_mesh_elements = linear_mesh.getElements();
151  for (MeshLib::Element const* e : linear_mesh_elements)
152  {
153  auto quadratic_element = createQuadraticElement(*e, add_centre_node);
154 
155  // Replace the base nodes with cloned linear nodes.
156  int const number_base_nodes = quadratic_element->getNumberOfBaseNodes();
157  for (int i = 0; i < number_base_nodes; ++i)
158  {
159  quadratic_element->setNode(
160  i, quadratic_mesh_nodes[getNodeIndex(*quadratic_element, i)]);
161  }
162 
163  // Make the new (middle-edge) nodes unique.
164  int const number_all_nodes = quadratic_element->getNumberOfNodes();
165  for (int i = number_base_nodes; i < number_all_nodes; ++i)
166  {
167  Node* original_node =
168  const_cast<Node*>(quadratic_element->getNode(i));
169 
170  auto it = unique_nodes.insert(original_node);
171  if (!it.second) // same node was already inserted before, no
172  // insertion
173  {
174  // Replace the element's node with the unique node.
175  quadratic_element->setNode(i, *it.first);
176  // And delete the original node
177  delete original_node;
178  }
179  }
180 
181  quadratic_elements.push_back(quadratic_element.release());
182  }
183 
184  // Add the unique quadratic nodes to the cloned linear nodes.
185  quadratic_mesh_nodes.reserve(linear_mesh.getNodes().size() +
186  unique_nodes.size());
187  std::copy(unique_nodes.begin(), unique_nodes.end(),
188  std::back_inserter(quadratic_mesh_nodes));
189 
190  return std::make_unique<MeshLib::Mesh>(
191  linear_mesh.getName(), quadratic_mesh_nodes, quadratic_elements,
192  linear_mesh.getProperties().excludeCopyProperties(
193  std::vector<MeshLib::MeshItemType>(1,
195 }
std::unique_ptr< MeshLib::Element > createQuadraticElement(MeshLib::Element const &e, bool const add_centre_node)
Return a new quadratic element corresponding to the linear element's type.
std::size_t getNodeIndex(Element const &element, unsigned const idx)
Definition: Element.cpp:225

References MathLib::LinAlg::copy(), copyNodeVector(), createQuadraticElement(), MeshLib::Properties::excludeCopyProperties(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getName(), getNodeIndex(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getProperties(), and Node.

Referenced by main().

◆ createSfcMeshProperties()

bool MeshLib::createSfcMeshProperties ( MeshLib::Mesh sfc_mesh,
MeshLib::Properties const &  properties,
std::vector< std::size_t > const &  node_ids_map,
std::vector< std::size_t > const &  element_ids_map 
)

Definition at line 52 of file MeshSurfaceExtraction.cpp.

56 {
57  std::size_t const n_elems(sfc_mesh.getNumberOfElements());
58  std::size_t const n_nodes(sfc_mesh.getNumberOfNodes());
59  if (node_ids_map.size() != n_nodes)
60  {
61  ERR("createSfcMeshProperties() - Incorrect number of node IDs ({:d}) "
62  "compared to actual number of surface nodes ({:d}).",
63  node_ids_map.size(), n_nodes);
64  return false;
65  }
66 
67  if (element_ids_map.size() != n_elems)
68  {
69  ERR("createSfcMeshProperties() - Incorrect number of element IDs "
70  "({:d}) compared to actual number of surface elements ({:d}).",
71  element_ids_map.size(), n_elems);
72  return false;
73  }
74  std::map<MeshLib::MeshItemType, std::vector<std::size_t> const*> const
75  id_maps = {{MeshItemType::Cell, &element_ids_map},
76  {MeshItemType::Node, &node_ids_map}};
77 
78  std::size_t vectors_copied(0);
79  std::size_t vectors_skipped(0);
80  for (auto [name, property] : properties)
81  {
82  if (property->getMeshItemType() != MeshItemType::Cell &&
83  property->getMeshItemType() != MeshItemType::Node)
84  {
85  WARN(
86  "Skipping property vector '{:s}' - not defined on cells or "
87  "nodes.",
88  name);
89  vectors_skipped++;
90  continue;
91  }
92 
93  auto const& id_map = *id_maps.at(property->getMeshItemType());
94  if (auto p = dynamic_cast<PropertyVector<double>*>(property))
95  {
96  processPropertyVector(*p, id_map, sfc_mesh);
97  vectors_copied++;
98  }
99  else if (auto p = dynamic_cast<PropertyVector<float>*>(property))
100  {
101  processPropertyVector(*p, id_map, sfc_mesh);
102  vectors_copied++;
103  }
104  else if (auto p = dynamic_cast<PropertyVector<int>*>(property))
105  {
106  processPropertyVector(*p, id_map, sfc_mesh);
107  vectors_copied++;
108  }
109  else if (auto p = dynamic_cast<PropertyVector<unsigned>*>(property))
110  {
111  processPropertyVector(*p, id_map, sfc_mesh);
112  vectors_copied++;
113  }
114  else if (auto p = dynamic_cast<PropertyVector<long>*>(property))
115  {
116  processPropertyVector(*p, id_map, sfc_mesh);
117  vectors_copied++;
118  }
119  else if (auto p = dynamic_cast<PropertyVector<long long>*>(property))
120  {
121  processPropertyVector(*p, id_map, sfc_mesh);
122  vectors_copied++;
123  }
124  else if (auto p =
125  dynamic_cast<PropertyVector<unsigned long>*>(property))
126  {
127  processPropertyVector(*p, id_map, sfc_mesh);
128  vectors_copied++;
129  }
130  else if (auto p = dynamic_cast<PropertyVector<unsigned long long>*>(
131  property))
132  {
133  processPropertyVector(*p, id_map, sfc_mesh);
134  vectors_copied++;
135  }
136  else if (auto p = dynamic_cast<PropertyVector<std::size_t>*>(property))
137  {
138  processPropertyVector(*p, id_map, sfc_mesh);
139  vectors_copied++;
140  }
141  else if (auto p = dynamic_cast<PropertyVector<char>*>(property))
142  {
143  processPropertyVector(*p, id_map, sfc_mesh);
144  vectors_copied++;
145  }
146  else
147  {
148  WARN(
149  "Skipping property vector '{:s}' - no matching data type "
150  "'{:s}' found.",
151  name, typeid(*property).name());
152  vectors_skipped++;
153  }
154  }
155  INFO("{:d} property vectors copied, {:d} vectors skipped.", vectors_copied,
156  vectors_skipped);
157  return true;
158 }
void WARN(char const *fmt, Args const &... args)
Definition: Logging.h:37
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition: Mesh.h:89
static const double p
void processPropertyVector(MeshLib::PropertyVector< T > const &property, std::vector< std::size_t > const &id_map, MeshLib::Mesh &sfc_mesh)

References Cell, ERR(), MeshLib::Mesh::getNumberOfElements(), MeshLib::Mesh::getNumberOfNodes(), INFO(), MaterialPropertyLib::name, Node, processPropertyVector(), and WARN().

Referenced by MeshLib::BoundaryExtraction::getBoundaryElementsAsMesh(), and MeshLib::MeshSurfaceExtraction::getMeshSurface().

◆ createSurfaceElementsFromElement()

void MeshLib::createSurfaceElementsFromElement ( MeshLib::Element const &  surface_element,
std::vector< MeshLib::Element * > &  surface_elements,
std::vector< std::size_t > &  element_to_bulk_element_id_map,
std::vector< std::size_t > &  element_to_bulk_face_id_map 
)

Definition at line 390 of file MeshSurfaceExtraction.cpp.

395 {
396  const unsigned n_faces(surface_element.getNumberOfBoundaries());
397  for (unsigned j = 0; j < n_faces; ++j)
398  {
399  if (surface_element.getNeighbor(j) != nullptr)
400  {
401  continue;
402  }
403 
404  surface_elements.push_back(
405  const_cast<MeshLib::Element*>(surface_element.getBoundary(j)));
406  element_to_bulk_face_id_map.push_back(j);
407  element_to_bulk_element_id_map.push_back(surface_element.getID());
408  }
409 }

References MeshLib::Element::getBoundary(), MeshLib::Element::getID(), MeshLib::Element::getNeighbor(), and MeshLib::Element::getNumberOfBoundaries().

Referenced by createBoundaryElements().

◆ extrudeElement()

MeshLib::Element* MeshLib::extrudeElement ( std::vector< MeshLib::Node * > const &  subsfc_nodes,
MeshLib::Element const &  sfc_elem,
MeshLib::PropertyVector< std::size_t > const &  sfc_to_subsfc_id_map,
std::map< std::size_t, std::size_t > const &  subsfc_sfc_id_map 
)

Extrudes point, line, triangle or quad elements to its higher dimensional versions, i.e. line, quad, prism, hexahedron.

Parameters
subsfc_nodesthe nodes the elements are based on
sfc_elemthe element of the surface that will be extruded
sfc_to_subsfc_id_maprelation between the surface nodes of the surface element and the ids of the nodes of the subsurface mesh
subsfc_sfc_id_mapmapping of the surface nodes of the current mesh to the surface nodes of the extruded mesh
Returns
extruded element (point -> line, line -> quad, tri -> prism, quad -> hexahedron)

Definition at line 44 of file AddLayerToMesh.cpp.

49 {
50  if (sfc_elem.getDimension() > 2)
51  {
52  return nullptr;
53  }
54 
55  const unsigned nElemNodes(sfc_elem.getNumberOfBaseNodes());
56  auto new_nodes = std::unique_ptr<MeshLib::Node* []> {
57  new MeshLib::Node*[2 * nElemNodes]
58  };
59 
60  for (unsigned j = 0; j < nElemNodes; ++j)
61  {
62  std::size_t const subsfc_id(
63  sfc_to_subsfc_id_map[sfc_elem.getNode(j)->getID()]);
64  new_nodes[j] = subsfc_nodes[subsfc_id];
65  std::size_t new_idx = (nElemNodes == 2) ? (3 - j) : (nElemNodes + j);
66  new_nodes[new_idx] = subsfc_nodes[subsfc_sfc_id_map.at(subsfc_id)];
67  }
68 
69  if (sfc_elem.getGeomType() == MeshLib::MeshElemType::LINE)
70  {
71  return new MeshLib::Quad(new_nodes.release());
72  }
73  if (sfc_elem.getGeomType() == MeshLib::MeshElemType::TRIANGLE)
74  {
75  return new MeshLib::Prism(new_nodes.release());
76  }
77  if (sfc_elem.getGeomType() == MeshLib::MeshElemType::QUAD)
78  {
79  return new MeshLib::Hex(new_nodes.release());
80  }
81 
82  return nullptr;
83 }
TemplateElement< MeshLib::PrismRule6 > Prism
Definition: Prism.h:25
TemplateElement< MeshLib::HexRule8 > Hex
Definition: Hex.h:25
TemplateElement< MeshLib::QuadRule4 > Quad
Definition: Quad.h:28

References MeshLib::Element::getDimension(), MeshLib::Element::getGeomType(), MathLib::Point3dWithID::getID(), MeshLib::Element::getNode(), MeshLib::Element::getNumberOfBaseNodes(), LINE, QUAD, and TRIANGLE.

Referenced by addLayerToMesh().

◆ fillElemProperty()

template<typename T >
void MeshLib::fillElemProperty ( std::vector< T > &  new_prop,
std::vector< T > const &  old_prop,
std::vector< size_t >  elem_ids 
)

Definition at line 242 of file MeshRevision.cpp.

246 {
247  std::transform(elem_ids.cbegin(), elem_ids.cend(),
248  std::back_inserter(new_prop),
249  [&](std::size_t const i) { return old_prop[i]; });
250 }

Referenced by MeshLib::MeshRevision::copyProperties().

◆ fillNodeProperty()

template<typename T >
void MeshLib::fillNodeProperty ( std::vector< T > &  new_prop,
std::vector< T > const &  old_prop,
std::vector< size_t >  node_ids 
)

Definition at line 225 of file MeshRevision.cpp.

229 {
230  std::size_t const n_nodes = node_ids.size();
231  for (std::size_t i = 0; i < n_nodes; ++i)
232  {
233  if (node_ids[i] != i)
234  {
235  continue;
236  }
237  new_prop.push_back(old_prop[i]);
238  }
239 }

Referenced by MeshLib::MeshRevision::copyProperties().

◆ filter()

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

Definition at line 22 of file ElementSearch.cpp.

23 {
24  std::vector<std::size_t> matchedIDs;
25  std::size_t i = 0;
26  for (auto value : container)
27  {
28  if (p(value))
29  {
30  matchedIDs.push_back(i);
31  }
32  i++;
33  }
34  return matchedIDs;
35 }

Referenced by VtkAddFilterDialog::VtkAddFilterDialog(), VtkVisPipeline::highlightGeoObject(), VtkVisPipeline::highlightMeshComponent(), VtkAddFilterDialog::on_buttonBox_accepted(), VtkAddFilterDialog::on_filterListWidget_currentRowChanged(), MeshLib::ElementSearch::searchByBoundingBox(), MeshLib::ElementSearch::searchByContent(), MeshLib::ElementSearch::searchByElementType(), and VtkVisPipeline::showMeshElementQuality().

◆ findElementsConnectedToNodes()

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

Definition at line 35 of file Mesh.cpp.

37 {
38  std::vector<std::vector<Element const*>> elements_connected_to_nodes;
39  auto const& nodes = mesh.getNodes();
40  elements_connected_to_nodes.resize(nodes.size());
41 
42  for (auto const* element : mesh.getElements())
43  {
44  unsigned const number_nodes(element->getNumberOfNodes());
45  for (unsigned j = 0; j < number_nodes; ++j)
46  {
47  auto const node_id = element->getNode(j)->getID();
48  elements_connected_to_nodes[node_id].push_back(element);
49  }
50  }
51  return elements_connected_to_nodes;
52 }

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

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  for (auto const& n : start_element_nodes)
50  {
51  if (MathLib::sqrDist(*test_node, n) <= radius_squared)
52  {
53  return true;
54  }
55  }
56  return false;
57  };
58 
59  // Returns true if any of the test element's nodes is inside the start
60  // element's radius.
61  auto element_in_radius = [&node_inside_radius](Element const& element)
62  {
63  auto const n_nodes = element.getNumberOfNodes();
64  for (unsigned i = 0; i < n_nodes; ++i)
65  {
66  if (node_inside_radius(element.getNode(i)))
67  {
68  return true;
69  }
70  }
71  return false;
72  };
73 
74  std::set<std::size_t> found_elements;
75  std::vector<Element const*> neighbors_to_visit;
76  std::unordered_set<std::size_t> visited_elements;
77 
78  auto mark_visited_and_add_neighbors =
79  [&found_elements, &neighbors_to_visit, &visited_elements](
80  Element const& element)
81  {
82  found_elements.insert(element.getID());
83  visited_elements.insert(element.getID());
84  auto const n_neighbors = element.getNumberOfNeighbors();
85  for (unsigned n = 0; n < n_neighbors; ++n)
86  {
87  auto neighbor = element.getNeighbor(n);
88  if (neighbor == nullptr)
89  {
90  continue;
91  }
92  auto x = visited_elements.find(neighbor->getID());
93  if (x != visited_elements.end())
94  {
95  continue;
96  }
97 
98  neighbors_to_visit.push_back(neighbor);
99 
100  visited_elements.insert(neighbor->getID());
101  }
102  };
103 
104  // The result always contains the starting element.
105  mark_visited_and_add_neighbors(start_element);
106 
107  while (!neighbors_to_visit.empty())
108  {
109  auto const& current_element = *neighbors_to_visit.back();
110  neighbors_to_visit.pop_back();
111 
112  // If any node is inside the radius, all neighbors are visited.
113  if (element_in_radius(current_element))
114  {
115  mark_visited_and_add_neighbors(current_element);
116  }
117  }
118 
119  return {std::begin(found_elements), std::end(found_elements)};
120 }

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

Referenced by ProcessLib::SmallDeformationNonlocal::SmallDeformationNonlocalLocalAssembler< ShapeFunction, IntegrationMethod, 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, [](Node const* a, Node* b) {
38  return a->getID() < b->getID();
39  });
40 
41  return base_nodes;
42 }
void makeVectorUnique(std::vector< T > &v)
Definition: Algorithm.h:209

References MathLib::LinAlg::copy(), MathLib::Point3dWithID::getID(), and 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(), ProcessLib::ThermoRichardsMechanics::ThermoRichardsMechanicsProcess< DisplacementDim >::constructDofTable(), and convertToLinearMesh().

◆ getBulkElementPoint() [1/5]

MathLib::Point3d MeshLib::getBulkElementPoint ( Hex const &  hex,
std::size_t const  face_id,
MathLib::WeightedPoint2D const &  wp 
)

Maps the given 2d boundary point wp of a quad face, given in local coordinates of the quad, to 3d point existing on a hexahedron face also in local coordinates.

Maps the given lower dimensional 2d boundary point wp of a quad or triangle element, given in local coordinates of the quad or triangle, to a 3d point existing on a tet face also in local coordinates.

Maps the given lower dimensional 2d boundary point wp of a quad or triangle element, given in local coordinates of the quad or triangle, to a 3d point existing on a prism face also in local coordinates.

Maps the given lower dimensional 2d boundary point wp of a quad or triangle element, given in local coordinates of the quad or triangle, to a 3d point existing on a pyramid face also in local coordinates.

Definition at line 57 of file MapBulkElementPoint.cpp.

60 {
61  switch (face_id)
62  {
63  case 0:
64  return MathLib::Point3d{
65  std::array<double, 3>{{wp[1], wp[0], -1.0}}};
66  case 1:
67  return MathLib::Point3d{
68  std::array<double, 3>{{wp[0], -1.0, wp[1]}}};
69  case 2:
70  return MathLib::Point3d{std::array<double, 3>{{1.0, wp[0], wp[1]}}};
71  case 3:
72  return MathLib::Point3d{
73  std::array<double, 3>{{-wp[0], -1.0, wp[1]}}};
74  case 4:
75  return MathLib::Point3d{
76  std::array<double, 3>{{-1.0, -wp[0], -wp[1]}}};
77  case 5:
78  return MathLib::Point3d{std::array<double, 3>{{wp[0], wp[1], 1.0}}};
79  default:
80  OGS_FATAL("Invalid face id '{:d}' for the hexahedron.", face_id);
81  }
82 }

References OGS_FATAL.

◆ getBulkElementPoint() [2/5]

MathLib::Point3d MeshLib::getBulkElementPoint ( Mesh const &  ,
std::size_t  ,
std::size_t  ,
MathLib::WeightedPoint3D const &   
)

Definition at line 206 of file MapBulkElementPoint.cpp.

210 {
211  return MathLib::ORIGIN;
212 }
const Point3d ORIGIN
Definition: Point3d.h:26

References MathLib::ORIGIN.

◆ getBulkElementPoint() [3/5]

MathLib::Point3d MeshLib::getBulkElementPoint ( Mesh const &  mesh,
std::size_t  bulk_element_id,
std::size_t  bulk_face_id,
MathLib::WeightedPoint2D const &  wp 
)

Maps the given 2d boundary point wp of a boundary element, given in local coordinates of the boundary element, to 3d point existing on a bulk element also in local coordinates.

Definition at line 175 of file MapBulkElementPoint.cpp.

179 {
180  auto const* element = mesh.getElement(bulk_element_id);
181  if (element->getCellType() == CellType::HEX8)
182  {
183  Hex const& hex = *static_cast<Hex const*>(element);
184  return getBulkElementPoint(hex, bulk_face_id, wp);
185  }
186  if (element->getCellType() == CellType::PRISM6)
187  {
188  Prism const& prism = *static_cast<Prism const*>(element);
189  return getBulkElementPoint(prism, bulk_face_id, wp);
190  }
191  if (element->getCellType() == CellType::PYRAMID5)
192  {
193  Pyramid const& pyramid = *static_cast<Pyramid const*>(element);
194  return getBulkElementPoint(pyramid, bulk_face_id, wp);
195  }
196  if (element->getCellType() == CellType::TET4)
197  {
198  Tet const& tet = *static_cast<Tet const*>(element);
199  return getBulkElementPoint(tet, bulk_face_id, wp);
200  }
201  OGS_FATAL("Wrong cell type '{:s}' or functionality not yet implemented.",
202  CellType2String(element->getCellType()));
203 }
TemplateElement< MeshLib::TetRule4 > Tet
Definition: Tet.h:25
MathLib::Point3d getBulkElementPoint(Mesh const &, std::size_t, std::size_t, MathLib::WeightedPoint3D const &)
TemplateElement< MeshLib::PyramidRule5 > Pyramid
Definition: Pyramid.h:25

References CellType2String(), getBulkElementPoint(), MeshLib::Mesh::getElement(), HEX8, OGS_FATAL, PRISM6, PYRAMID5, and TET4.

◆ getBulkElementPoint() [4/5]

MathLib::Point3d MeshLib::getBulkElementPoint ( Mesh const &  mesh,
std::size_t const  bulk_element_id,
std::size_t const  bulk_face_id,
MathLib::WeightedPoint1D const &  wp 
)

Maps the given 1d boundary point wp of a boundary element, given in local coordinates of the boundary element, to 3d point existing on a bulk element also in local coordinates.

Definition at line 155 of file MapBulkElementPoint.cpp.

159 {
160  auto const* element = mesh.getElement(bulk_element_id);
161  if (element->getCellType() == CellType::QUAD4)
162  {
163  Quad const& quad(*dynamic_cast<Quad const*>(element));
164  return getBulkElementPoint(quad, bulk_face_id, wp);
165  }
166  if (element->getCellType() == CellType::TRI3)
167  {
168  Tri const& tri = *static_cast<Tri const*>(element);
169  return getBulkElementPoint(tri, bulk_face_id, wp);
170  }
171  OGS_FATAL("Wrong cell type '{:s}' or functionality not yet implemented.",
172  CellType2String(element->getCellType()));
173 }
TemplateElement< MeshLib::TriRule3 > Tri
Definition: Tri.h:26

References CellType2String(), getBulkElementPoint(), MeshLib::Mesh::getElement(), OGS_FATAL, QUAD4, and TRI3.

◆ getBulkElementPoint() [5/5]

MathLib::Point3d MeshLib::getBulkElementPoint ( Tri const &  tri,
std::size_t const  face_id,
MathLib::WeightedPoint1D const &  wp 
)

Maps the given lower dimensional boundary point wp of a line, i.e. the 1d integration point given in local coordinates of a line, to higher dimensional point of the triangle face (defined by the triangle element and the face id) also in local coordinates of the triangle element.

Parameters
trithe triangle element
face_idthe id of the triangle face the point will be mapped on
wpthe integration point of the lower dimensional element
Returns
the mapped point

Maps the given lower dimensional boundary point wp of a line, i.e. the 1d integration point given in local coordinates of a line, to higher dimensional point of the quad face (defined by the quad element and the face id) also in local coordinates of the quad face.

Parameters
quadthe quad element
face_idthe id of the quad face the point will be mapped on
wpthe integration point of the lower dimensional element
Returns
the mapped point

Definition at line 17 of file MapBulkElementPoint.cpp.

20 {
21  switch (face_id)
22  {
23  case 0:
24  return MathLib::Point3d{std::array<double, 3>{{wp[0], 0.0, 0.0}}};
25  case 1:
26  return MathLib::Point3d{
27  std::array<double, 3>{{1 - wp[0], wp[0], 0.0}}};
28  case 2:
29  return MathLib::Point3d{
30  std::array<double, 3>{{0.0, 1 - wp[0], 0.0}}};
31  default:
32  OGS_FATAL("Invalid face id '{:d}' for the tri.", face_id);
33  }
34 }

References OGS_FATAL.

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

◆ getCenterOfGravity()

MeshLib::Node MeshLib::getCenterOfGravity ( Element const &  element)

Calculates the center of gravity for the mesh element.

Definition at line 126 of file Element.cpp.

127 {
128  const unsigned nNodes(element.getNumberOfBaseNodes());
129  MeshLib::Node center(0, 0, 0);
130  for (unsigned i = 0; i < nNodes; ++i)
131  {
132  center[0] += (*element.getNode(i))[0];
133  center[1] += (*element.getNode(i))[1];
134  center[2] += (*element.getNode(i))[2];
135  }
136  center[0] /= nNodes;
137  center[1] /= nNodes;
138  center[2] /= nNodes;
139  return center;
140 }

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

Referenced by ProcessLib::LIE::HydroMechanics::HydroMechanicsProcess< GlobalDim >::initializeConcreteProcess(), ProcessLib::LIE::SmallDeformation::SmallDeformationProcess< DisplacementDim >::initializeConcreteProcess(), main(), markFaults(), LayeredVolume::removeCongruentElements(), ProcessLib::LIE::setFractureProperty(), FileIO::FEFLOWMeshInterface::setMaterialIDs(), setMaterialIDs(), MeshLib::CellRule::testElementNodeOrder(), ProcessLib::ProcessVariable::updateDeactivatedSubdomains(), 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& 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  {
37  MeshLib::ElementCoordinatesMappingLocal coordinates_mapping(
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::LiquidFlow::createLiquidFlowProcess().

◆ 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().

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

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

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

Referenced by isBaseNode(), and MeshLib::MeshRevision::reduceHex().

◆ getNodeIndex()

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

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

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

Definition at line 225 of file Element.cpp.

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

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

Referenced by MeshGeoToolsLib::BoundaryElementsAlongPolyline::BoundaryElementsAlongPolyline(), MeshGeoToolsLib::BoundaryElementsOnSurface::BoundaryElementsOnSurface(), ProcessLib::LIE::PostProcessTool::PostProcessTool(), anonymous_namespace{convertMeshToGeo.cpp}::addElementToSurface(), LayeredVolume::addLayerBoundaries(), LayeredVolume::addLayerToMesh(), MeshLib::MeshLayerMapper::addLayerToMesh(), ProcessLib::LIE::PostProcessTool::calculateTotalDisplacement(), MeshLib::RasterToMesh::convert(), createQuadraticOrderMesh(), FileIO::SwmmInterface::getLinkPointIds(), anonymous_namespace{IdentifySubdomainMesh.cpp}::identifySubdomainMeshElements(), MeshGeoToolsLib::BoundaryElementsAlongPolyline::includesAllEdgeNodeIDs(), NumLib::interpolateToHigherOrderNodes(), markUnusedNodes(), ProcessLib::LIE::HydroMechanics::LocalDataInitializer< LocalAssemblerInterface, LocalAssemblerDataMatrix, LocalAssemblerDataMatrixNearFracture, LocalAssemblerDataFracture, GlobalDim, ConstructorArgs >::operator()(), ProcessLib::LIE::SmallDeformation::LocalDataInitializer< LocalAssemblerInterface, LocalAssemblerDataMatrix, LocalAssemblerDataMatrixNearFracture, LocalAssemblerDataFracture, GlobalDim, ConstructorArgs >::operator()(), LayeredVolume::removeCongruentElements(), MeshLib::NodeSearch::searchNodesConnectedToOnlyGivenElements(), FileIO::FEFLOWMeshInterface::setMaterialIDs(), ProcessLib::LIE::HydroMechanics::HydroMechanicsLocalAssemblerMatrix< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, GlobalDim >::setPressureOfInactiveNodes(), FileIO::TetGenInterface::writeElementToFacets(), and ApplicationUtils::writeMETIS().

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

238 {
239  if (property_name.empty())
240  {
241  OGS_FATAL(
242  "Trying to get or to create a mesh property with empty name.");
243  }
244 
245  auto numberOfMeshItems = [&mesh, &item_type]() -> std::size_t {
246  switch (item_type)
247  {
248  case MeshItemType::Cell:
249  return mesh.getNumberOfElements();
250  case MeshItemType::Node:
251  return mesh.getNumberOfNodes();
252  case MeshItemType::IntegrationPoint:
253  return 0; // For the integration point data the size is
254  // variable
255  default:
256  OGS_FATAL(
257  "getOrCreateMeshProperty cannot handle other "
258  "types than Node, Cell, or IntegrationPoint.");
259  }
260  return 0;
261  };
262 
263  if (mesh.getProperties().existsPropertyVector<T>(property_name))
264  {
265  auto result =
266  mesh.getProperties().template getPropertyVector<T>(property_name);
267  assert(result);
268  if (item_type != MeshItemType::IntegrationPoint)
269  {
270  // Test the size if number of mesh items is known, which is not the
271  // case for the integration point data.
272  assert(result->size() ==
273  numberOfMeshItems() * number_of_components);
274  }
275  return result;
276  }
277 
278  auto result = mesh.getProperties().template createNewPropertyVector<T>(
279  property_name, item_type, number_of_components);
280  assert(result);
281  result->resize(numberOfMeshItems() * number_of_components);
282  return result;
283 }

References Cell, MeshLib::Properties::existsPropertyVector(), MeshLib::Mesh::getNumberOfElements(), MeshLib::Mesh::getNumberOfNodes(), MeshLib::Mesh::getProperties(), IntegrationPoint, ApplicationUtils::NodeWiseMeshPartitioner::mesh(), 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 of a mesh is:

  • 1, if the mesh is 1D and and the mesh is parallel either to \(x\), \(y\) or to \(z\) axis.
  • 2, if the mesh is 1D but it contains inclined elements on the origin coordinate plane of \(x-y,\, y-z,\, \text{or }\, x-z\). That means the coordinates of all nodes are \((x, y, 0)\), \((x, 0, z)\) or \((0, y, z)\).
  • 3, if the mesh is 1D and but it is not on any origin coordinate plane of \(x-y,\, y-z,\, \text{or }\, x-z\).
  • 2, if the mesh is 2D and it is on the origin coordinate plane of \(x-y,\, y-z,\, \text{or }\, x-z\).
  • 2, if the mesh is 2D and it is on vertical or horizontal plane that is parallel to the the origin coordinate plane of \(x-y,\, y-z,\, \text{or }\, x-z\) but with an offset.
  • 3, if the mesh contains inclined 2D elements.
  • 3, if the mesh contains 3D elements.

Definition at line 23 of file GetSpaceDimension.cpp.

24 {
25  std::array x_magnitude = {0.0, 0.0, 0.0};
26 
27  double const* const x_ref = nodes[0]->getCoords();
28  for (auto const& node : nodes)
29  {
30  auto const x = node->getCoords();
31  for (int i = 0; i < 3; i++)
32  {
33  x_magnitude[i] += std::fabs(x[i] - x_ref[i]);
34  }
35  }
36 
37  return static_cast<int>(std::count_if(
38  x_magnitude.begin(), x_magnitude.end(),
39  [](const double x_i_magnitude)
40  { return x_i_magnitude > std::numeric_limits<double>::epsilon(); }));
41 }

Referenced by 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 121 of file Element.cpp.

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

References MeshLib::Element::getContent().

Referenced by MeshLib::HexRule8::validate(), MeshLib::LineRule2::validate(), MeshLib::PointRule1::validate(), MeshLib::PrismRule6::validate(), MeshLib::PyramidRule5::validate(), MeshLib::QuadRule4::validate(), MeshLib::TetRule4::validate(), and MeshLib::TriRule3::validate().

◆ 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  {
29  OGS_FATAL(
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)->getCoords();
53  auto const x2 = element->getNode(1)->getCoords();
54  auto const x3 = element->getNode(2)->getCoords();
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)->getCoords();
72  auto const x2 = element->getNode(1)->getCoords();
73  auto const x3 = element->getNode(2)->getCoords();
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  {
87  OGS_FATAL(
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 370 of file Mesh.cpp.

372 {
373  // Check if node is connected.
374  if (elements_connected_to_node.empty())
375  {
376  return true;
377  }
378 
379  // In a mesh a node always belongs to at least one element.
380  auto const e = elements_connected_to_node[0];
381 
382  auto const n_base_nodes = e->getNumberOfBaseNodes();
383  auto const local_index = getNodeIDinElement(*e, &node);
384  return local_index < n_base_nodes;
385 }
unsigned getNodeIDinElement(Element const &element, const MeshLib::Node *node)
Returns the position of the given node in the node array of this element.
Definition: Element.cpp:212

References getNodeIDinElement().

Referenced by MeshGeoToolsLib::MeshNodesOnPoint::MeshNodesOnPoint(), ApplicationUtils::findGhostNodesInPartition(), ApplicationUtils::findRegularNodesInPartition(), MeshLib::Mesh::getNumberOfBaseNodes(), NumLib::MeshComponentMap::getSubset(), MeshLib::NodePartitionedMesh::isGhostNode(), and ProcessLib::LIE::anonymous_namespace{MeshUtils.cpp}::IsCrackTip::operator()().

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

178 {
179  for (std::size_t i(0); i < e.getNumberOfBaseNodes(); ++i)
180  {
181  if (MathLib::sqrDist2d(p, *e.getNode(i)) <
182  std::numeric_limits<double>::epsilon())
183  {
184  return true;
185  }
186  }
187 
188  if (e.getGeomType() == MeshElemType::TRIANGLE)
189  {
190  MathLib::Point3d const& n0(*e.getNode(0));
191  MathLib::Point3d const& n1(*e.getNode(1));
192  MathLib::Point3d const& n2(*e.getNode(2));
193 
194  return MathLib::isPointInTriangleXY(p, n0, n1, n2);
195  }
196  if (e.getGeomType() == MeshElemType::QUAD)
197  {
198  MathLib::Point3d const& n0(*e.getNode(0));
199  MathLib::Point3d const& n1(*e.getNode(1));
200  MathLib::Point3d const& n2(*e.getNode(2));
201  MathLib::Point3d const& n3(*e.getNode(3));
202 
203  return MathLib::isPointInTriangleXY(p, n0, n1, n2) ||
204  MathLib::isPointInTriangleXY(p, n0, n2, n3);
205  }
206 
207  WARN("isPointInElementXY: element type '{:s}' is not supported.",
208  MeshLib::MeshElemType2String(e.getGeomType()));
209  return false;
210 }
double sqrDist2d(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition: Point3d.h:58
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 MeshLib::Mesh2MeshPropertyInterpolation::interpolatePropertiesForMesh().

◆ markUnusedNodes()

std::vector< bool > MeshLib::markUnusedNodes ( std::vector< Element * > const &  elements,
std::vector< Node * > const &  nodes 
)

Marks nodes not used by any of the elements.

Definition at line 100 of file RemoveMeshComponents.cpp.

102 {
103  std::vector<bool> unused_nodes(nodes.size(), true);
104  for (auto e : elements)
105  {
106  for (unsigned i = 0; i < e->getNumberOfNodes(); i++)
107  {
108  unused_nodes[getNodeIndex(*e, i)] = false;
109  }
110  }
111 
112  return unused_nodes;
113 }

References getNodeIndex().

Referenced by createMeshFromElements(), and removeNodes().

◆ materialIDs()

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  return properties.existsPropertyVector<int>("MaterialIDs",
263  ? properties.getPropertyVector<int>(
264  "MaterialIDs", MeshLib::MeshItemType::Cell, 1)
265  : nullptr;
266 }

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

Referenced by ProcessLib::HeatTransportBHE::HeatTransportBHEProcess::HeatTransportBHEProcess(), ProcessLib::LIE::HydroMechanics::HydroMechanicsProcess< GlobalDim >::HydroMechanicsProcess(), MeshGeoToolsLib::appendLinesAlongPolylines(), convertMeshToGeo(), ProcessLib::createDeactivatedSubdomain(), ProcessLib::createDeactivatedSubdomainMesh(), ProcessLib::LIE::HydroMechanics::createHydroMechanicsProcess(), ProcessLib::HydroMechanics::createHydroMechanicsProcess(), MaterialPropertyLib::createMaterialSpatialDistributionMap(), ProcessLib::PhaseField::createPhaseFieldProcess(), MaterialLib::PorousMedium::createPorousMediaProperties(), ProcessLib::RichardsMechanics::createRichardsMechanicsProcess(), ProcessLib::SmallDeformationNonlocal::createSmallDeformationNonlocalProcess(), ProcessLib::LIE::SmallDeformation::createSmallDeformationProcess(), ProcessLib::SmallDeformation::createSmallDeformationProcess(), ProcessLib::TH2M::createTH2MProcess(), ProcessLib::ThermalTwoPhaseFlowWithPP::createThermalTwoPhaseFlowWithPPProcess(), ProcessLib::ThermoHydroMechanics::createThermoHydroMechanicsProcess(), ProcessLib::ThermoMechanicalPhaseField::createThermoMechanicalPhaseFieldProcess(), ProcessLib::ThermoMechanics::createThermoMechanicsProcess(), ProcessLib::ThermoRichardsMechanics::createThermoRichardsMechanicsProcess(), ProcessLib::TwoPhaseFlowWithPP::createTwoPhaseFlowWithPPProcess(), ProcessLib::TwoPhaseFlowWithPrho::createTwoPhaseFlowWithPrhoProcess(), extractBoundaryMeshes(), ProcessLib::LIE::anonymous_namespace{MeshUtils.cpp}::findFracutreIntersections(), ProcessLib::HeatTransportBHE::getBHEDataInMesh(), ProcessLib::LIE::getFractureMatrixDataInMesh(), ProcessLib::LIE::HydroMechanics::HydroMechanicsProcess< GlobalDim >::initializeConcreteProcess(), main(), removeUnusedElements(), ElementTreeModel::setElement(), and ProcessLib::ProcessVariable::updateDeactivatedSubdomains().

◆ 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::setElement(), ElementTreeModel::setMesh(), and MeshLib::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.

Referenced by VtkVisPipeline::showMeshElementQuality(), and MeshLib::ElementQualityInterface::writeHistogram().

◆ moveMeshNodes()

template<typename Iterator >
void MeshLib::moveMeshNodes ( Iterator  begin,
Iterator  end,
MeshLib::Node const &  displacement 
)

Function that moves mesh nodes.

The function iterates over all mesh nodes between the begin and the end iterator and moves them using the given displacement.

Parameters
beginbegin iterator
endend iterator
displacementthe displacement to use

Definition at line 32 of file moveMeshNodes.h.

36 {
37  std::for_each(begin, end, [&displacement](MeshLib::Node* node)
38  {
39  (*node)[0] += displacement[0];
40  (*node)[1] += displacement[1];
41  (*node)[2] += displacement[2];
42  }
43  );
44 };

Referenced by main().

◆ operator!=()

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

Definition at line 171 of file Mesh.h.

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

◆ 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 }

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

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

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

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

References MeshLib::Mesh::getID().

◆ processPropertyVector()

template<typename T >
void MeshLib::processPropertyVector ( MeshLib::PropertyVector< T > const &  property,
std::vector< std::size_t > const &  id_map,
MeshLib::Mesh sfc_mesh 
)

Definition at line 33 of file MeshSurfaceExtraction.cpp.

36 {
37  auto const number_of_components = property.getNumberOfGlobalComponents();
38 
39  auto sfc_prop = getOrCreateMeshProperty<T>(
40  sfc_mesh, property.getPropertyName(), property.getMeshItemType(),
41  number_of_components);
42  sfc_prop->clear();
43  sfc_prop->reserve(id_map.size());
44 
45  for (auto bulk_id : id_map)
46  {
47  std::copy_n(&property.getComponent(bulk_id, 0 /*component_id*/),
48  number_of_components, back_inserter(*sfc_prop));
49  }
50 }
std::string const & getPropertyName() const
MeshItemType getMeshItemType() const
PROP_VAL_TYPE & getComponent(std::size_t tuple_index, int component)
Returns the value for the given component stored in the given tuple.

References MeshLib::PropertyVector< PROP_VAL_TYPE >::getComponent(), MeshLib::PropertyVectorBase::getMeshItemType(), and MeshLib::PropertyVectorBase::getPropertyName().

Referenced by createSfcMeshProperties().

◆ removeElements()

MeshLib::Mesh * MeshLib::removeElements ( const MeshLib::Mesh mesh,
const std::vector< std::size_t > &  removed_element_ids,
const std::string &  new_mesh_name 
)

Removes mesh elements and returns a new mesh object. The original mesh is kept unchanged.

Parameters
meshan original mesh whose elements are removed
removed_element_idsa vector of element indices to be removed
new_mesh_namea new mesh name
Returns
a new mesh object

Definition at line 52 of file RemoveMeshComponents.cpp.

56 {
57  if (removed_element_ids.empty())
58  {
59  INFO("No elements to remove");
60  return nullptr;
61  }
62 
63  INFO("Removing total {:d} elements...", removed_element_ids.size());
64  std::vector<MeshLib::Element*> tmp_elems =
65  details::excludeElementCopy(mesh.getElements(), removed_element_ids);
66  INFO("{:d} elements remain in mesh.", tmp_elems.size());
67 
68  // copy node and element objects
69  std::vector<MeshLib::Node*> new_nodes =
71  std::vector<MeshLib::Element*> new_elems =
72  MeshLib::copyElementVector(tmp_elems, new_nodes);
73 
74  // delete unused nodes
75  NodeSearch ns(mesh);
76  ns.searchNodesConnectedToOnlyGivenElements(removed_element_ids);
77  auto& removed_node_ids(ns.getSearchedNodeIDs());
78  INFO("Removing total {:d} nodes...", removed_node_ids.size());
79  for (auto nodeid : removed_node_ids)
80  {
81  delete new_nodes[nodeid];
82  new_nodes[nodeid] = nullptr;
83  }
84  new_nodes.erase(std::remove(new_nodes.begin(), new_nodes.end(), nullptr),
85  new_nodes.end());
86 
87  if (!new_elems.empty())
88  {
89  MeshLib::Mesh* new_mesh =
90  new MeshLib::Mesh(new_mesh_name, new_nodes, new_elems,
92  removed_element_ids, removed_node_ids));
93  return new_mesh;
94  }
95 
96  INFO("Current selection removes all elements.");
97  return nullptr;
98 }
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:95
Properties & getProperties()
Definition: Mesh.h:123
Properties excludeCopyProperties(std::vector< std::size_t > const &exclude_elem_ids, std::vector< std::size_t > const &exclude_node_ids) const
Definition: Properties.cpp:58
std::vector< MeshLib::Element * > excludeElementCopy(std::vector< MeshLib::Element * > const &vec_src_eles, std::vector< std::size_t > const &vec_removed)

References copyElementVector(), copyNodeVector(), MeshLib::Properties::excludeCopyProperties(), MeshLib::details::excludeElementCopy(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getProperties(), MeshLib::NodeSearch::getSearchedNodeIDs(), INFO(), and MeshLib::NodeSearch::searchNodesConnectedToOnlyGivenElements().

Referenced by MeshElementRemovalDialog::accept(), MeshLib::RasterToMesh::convert(), LayeredVolume::createRasterLayers(), extractMatGroup(), MeshLib::MeshGenerator::generateRegularPrismMesh(), main(), removeUnusedElements(), removeUnusedGridCells(), and writeBoundary().

◆ removeMarkedNodes()

void MeshLib::removeMarkedNodes ( std::vector< bool > const &  nodes_to_delete,
std::vector< Node * > &  nodes 
)

Deallocates and removes nodes marked true.

Definition at line 115 of file RemoveMeshComponents.cpp.

117 {
118  assert(nodes_to_delete.size() == nodes.size());
119 
120  for (std::size_t i = 0; i < nodes.size(); i++)
121  {
122  if (nodes_to_delete[i])
123  {
124  delete nodes[i];
125  nodes[i] = nullptr;
126  }
127  }
128  nodes.erase(remove(begin(nodes), end(nodes), nullptr), end(nodes));
129 }

Referenced by createMeshFromElements(), and removeNodes().

◆ removeNodes()

MeshLib::Mesh * MeshLib::removeNodes ( const MeshLib::Mesh mesh,
const std::vector< std::size_t > &  del_nodes_idx,
const std::string &  new_mesh_name 
)

Removes the mesh nodes (and connected elements) given in the nodes-list from the mesh.

Parameters
meshan original mesh whose elements are removed
del_nodes_idxa vector of node indices to be removed
new_mesh_namea new mesh name
Returns
a new mesh object

Definition at line 131 of file RemoveMeshComponents.cpp.

134 {
135  if (del_nodes_idx.empty())
136  {
137  return nullptr;
138  }
139 
140  // copy node and element objects
141  std::vector<MeshLib::Node*> new_nodes =
143  std::vector<MeshLib::Element*> new_elems =
144  MeshLib::copyElementVector(mesh.getElements(), new_nodes);
145 
146  // delete elements
147  MeshLib::ElementSearch es(mesh);
148  es.searchByNodeIDs(del_nodes_idx);
149  auto& removed_element_ids = es.getSearchedElementIDs();
150  for (auto eid : removed_element_ids)
151  {
152  delete new_elems[eid];
153  new_elems[eid] = nullptr;
154  }
155  new_elems.erase(std::remove(new_elems.begin(), new_elems.end(), nullptr),
156  new_elems.end());
157 
158  // check unused nodes due to element deletion
159  std::vector<bool> const node_delete_flag =
160  markUnusedNodes(new_elems, new_nodes);
161 
162  // delete unused nodes
163  removeMarkedNodes(node_delete_flag, new_nodes);
164 
165  if (!new_elems.empty())
166  {
167  MeshLib::Mesh* new_mesh =
168  new MeshLib::Mesh(new_mesh_name, new_nodes, new_elems,
170  removed_element_ids, del_nodes_idx));
171  return new_mesh;
172  }
173 
174  return nullptr;
175 }
Element search class.
Definition: ElementSearch.h:28
std::vector< bool > markUnusedNodes(std::vector< Element * > const &elements, std::vector< Node * > const &nodes)
Marks nodes not used by any of the elements.
void removeMarkedNodes(std::vector< bool > const &nodes_to_delete, std::vector< Node * > &nodes)
Deallocates and removes nodes marked true.

References copyElementVector(), copyNodeVector(), MeshLib::Properties::excludeCopyProperties(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getProperties(), MeshLib::ElementSearch::getSearchedElementIDs(), markUnusedNodes(), removeMarkedNodes(), and MeshLib::ElementSearch::searchByNodeIDs().

Referenced by LayeredMeshGenerator::getMesh().

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

247 {
248  if (!mesh.getProperties().existsPropertyVector<double>(property_name))
249  {
250  WARN("Did not find PropertyVector '{:s}' for scaling.", property_name);
251  return;
252  }
253  auto& pv = *mesh.getProperties().getPropertyVector<double>(property_name);
254  std::transform(pv.begin(), pv.end(), pv.begin(),
255  [factor](auto const& v) { return v * factor; });
256 }
PropertyVector< T > const * getPropertyVector(std::string const &name) const
bool existsPropertyVector(std::string const &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 20 of file SetMeshSpaceDimension.cpp.

21 {
22  // Get the space dimension from the bulk mesh:
23  auto const space_dimension = getSpaceDimension(meshes[0]->getNodes());
24  for (auto& mesh : meshes)
25  {
26  auto elements = mesh->getElements();
27  for (auto element : elements)
28  {
29  element->space_dimension_ = space_dimension;
30  }
31  }
32 }
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 MeshLib::IO::Legacy::MeshIO::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 }
static constexpr char const * mesh_item_type_strings[]
Char array names for all of MeshItemType values.
Definition: Location.h:24

References mesh_item_type_strings.

◆ trackSurface()

static void MeshLib::trackSurface ( MeshLib::Element const *const  element,
std::vector< unsigned > &  sfc_idx,
unsigned const  current_index 
)
static

Finds all surface elements that can be reached from element. All elements that are found in this way are marked in the global sfc_idx vector using the current_index.

Parameters
elementThe mesh element from which the search is started
sfc_idxThe global index vector notifying to which surface elements belong
current_indexThe index that all elements reachable from element will be assigned in sfc_idx

Definition at line 40 of file MeshValidation.cpp.

43 {
44  std::stack<MeshLib::Element const*> elem_stack;
45  elem_stack.push(element);
46  while (!elem_stack.empty())
47  {
48  MeshLib::Element const* const elem = elem_stack.top();
49  elem_stack.pop();
50  sfc_idx[elem->getID()] = current_index;
51  std::size_t const n_neighbors(elem->getNumberOfNeighbors());
52  for (std::size_t i = 0; i < n_neighbors; ++i)
53  {
54  MeshLib::Element const* neighbor(elem->getNeighbor(i));
55  if (neighbor != nullptr && sfc_idx[neighbor->getID()] ==
56  std::numeric_limits<unsigned>::max())
57  {
58  elem_stack.push(neighbor);
59  }
60  }
61  }
62 }
virtual const Element * getNeighbor(unsigned i) const =0
Get the specified neighbor.
virtual unsigned getNumberOfNeighbors() const =0
Get the number of neighbors for this element.
virtual std::size_t getID() const final
Returns the ID of the element.
Definition: Element.h:82

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

Referenced by MeshLib::MeshValidation::detectHoles().

◆ 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().