OGS 6.3.0-179-g962fdcd4e.dirty.20200403132553
MeshLib Namespace Reference

Detailed Description

Interface for heuristic search length strategy.

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
Date
2014-09-19

Namespaces

 anonymous_namespace{ConvertToLinearMesh.cpp}
 
 BoundaryExtraction
 
 detail
 
 details
 
 IO
 
 MeshGenerator
 
 ProjectPointOnMesh
 

Classes

class  AngleSkewMetric
 
class  CellRule
 
class  CoordinateSystem
 Coordinate systems. More...
 
struct  CoordinateSystemType
 Coordinate system type. More...
 
class  EdgeRatioMetric
 
class  EdgeRule
 
class  Element
 
class  ElementCoordinatesMappingLocal
 
class  ElementQualityInterface
 
class  ElementQualityMetric
 
class  ElementSearch
 Element search class. More...
 
class  ElementSizeMetric
 
class  ElementStatus
 
class  ElementValueModification
 A set of methods for manipulating mesh element values. More...
 
class  FaceRule
 
class  HexRule20
 
class  HexRule8
 
class  LinearEdgeReturn
 Returns linear order edge. More...
 
class  LineRule2
 
class  LineRule3
 
struct  Location
 
class  Mesh
 
class  Mesh2MeshPropertyInterpolation
 
class  MeshElementGrid
 
class  MeshInformation
 A set of tools for extracting information from a mesh. More...
 
class  MeshLayerMapper
 Manipulating and adding prism element layers to an existing 2D mesh. More...
 
class  MeshRevision
 
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  MeshValidation
 A collection of methods for testing mesh quality and correctness. More...
 
class  Node
 
class  NodeAdjacencyTable
 
class  NodePartitionedMesh
 A subdomain mesh. More...
 
class  NodeSearch
 Node search class. More...
 
class  NoEdgeReturn
 Returns always null pointer. More...
 
class  PointRule1
 A 0d point element. More...
 
class  PrismRule15
 
class  PrismRule6
 
class  Properties
 Property manager on mesh items. Class Properties manages scalar, vector or matrix properties. For instance in groundwater flow porosity is a scalar property and permeabilty can be stored as a tensor property. Properties are assigned to mesh items, i.e. Node or Element objects. The createNewPropertyVector() method first creates a PropertyVector of template type T (scalar, vector or matrix). This class stores the PropertyVector, accessible by a combination of the name and the type of the mesh item (Node or Element). More...
 
class  PropertyVector
 
class  PropertyVector< T *>
 
class  PropertyVectorBase
 
class  PyramidRule13
 
class  PyramidRule5
 
class  QuadraticEdgeReturn
 Returns quadratic order edge. More...
 
class  QuadRule4
 
class  QuadRule8
 
class  QuadRule9
 
class  RadiusEdgeRatioMetric
 
class  RasterToMesh
 Converts raster data into an OGS mesh. More...
 
class  SizeDifferenceMetric
 
class  TemplateElement
 
class  TetRule10
 
class  TetRule4
 
class  TriRule3
 
class  TriRule6
 
class  VertexRule
 
class  VtkMappedMeshSource
 
class  VtkMeshConverter
 Converter for VtkUnstructured Grids to OGS meshes. More...
 
class  VtkMeshNodalCoordinatesTemplate
 

Typedefs

using RotationMatrix = Eigen::Matrix< double, 3u, 3u, Eigen::RowMajor >
 
using 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  MeshItemType {
  MeshItemType::Node, MeshItemType::Edge, MeshItemType::Face, MeshItemType::Cell,
  MeshItemType::IntegrationPoint
}
 
enum  MeshElemType {
  MeshElemType::INVALID = 0, MeshElemType::POINT = 1, MeshElemType::LINE = 3, MeshElemType::QUAD = 9,
  MeshElemType::HEXAHEDRON = 12, MeshElemType::TRIANGLE = 5, MeshElemType::TETRAHEDRON = 10, MeshElemType::PRISM = 16,
  MeshElemType::PYRAMID = 14
}
 Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum. More...
 
enum  CellType {
  CellType::INVALID = 0, CellType::POINT1 = 1, CellType::LINE2 = 2, CellType::LINE3 = 3,
  CellType::TRI3 = 4, CellType::TRI6 = 5, CellType::QUAD4 = 6, CellType::QUAD8 = 7,
  CellType::QUAD9 = 8, CellType::TET4 = 9, CellType::TET10 = 10, CellType::HEX8 = 11,
  CellType::HEX20 = 12, CellType::HEX27 = 13, CellType::PRISM6 = 14, CellType::PRISM15 = 15,
  CellType::PRISM18 = 16, CellType::PYRAMID5 = 17, CellType::PYRAMID13 = 18
}
 Types of mesh elements supported by OpenGeoSys. More...
 
enum  MeshQualityType {
  MeshQualityType::INVALID = 0, MeshQualityType::ELEMENTSIZE, MeshQualityType::SIZEDIFFERENCE, MeshQualityType::EDGERATIO,
  MeshQualityType::EQUIANGLESKEW, MeshQualityType::RADIUSEDGERATIO
}
 Describes a mesh quality metric. More...
 
enum  UseIntensityAs { UseIntensityAs::ELEVATION, UseIntensityAs::MATERIALS, UseIntensityAs::DATAVECTOR, UseIntensityAs::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 isPointInElementXY (MathLib::Point3d const &p, Element const &e)
 
MathLib::Point3d getBulkElementPoint (MeshLib::Quad const &, std::size_t const face_id, MathLib::WeightedPoint1D const &wp)
 
MathLib::Point3d getBulkElementPoint (MeshLib::Hex const &, std::size_t const face_id, MathLib::WeightedPoint2D const &wp)
 
MathLib::Point3d getBulkElementPoint (MeshLib::Mesh const &mesh, std::size_t const bulk_element_id, std::size_t const bulk_face_id, MathLib::WeightedPoint1D const &wp)
 
MathLib::Point3d getBulkElementPoint (MeshLib::Mesh const &mesh, std::size_t bulk_element_id, std::size_t bulk_face_id, MathLib::WeightedPoint2D const &wp)
 
MathLib::Point3d getBulkElementPoint (MeshLib::Mesh const &, std::size_t, std::size_t, MathLib::WeightedPoint3D const &)
 
std::vector< Node * > getBaseNodes (std::vector< Element *> const &elements)
 
MathLib::Vector3 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...
 
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)
 
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 (MeshLib::Mesh &mesh, std::string const &name, MeshLib::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, MeshLib::MeshItemType const item_type, int const number_of_components)
 
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::MeshaddTopLayerToMesh (MeshLib::Mesh const &mesh, double thickness, std::string const &name)
 Adds a layer on top of the mesh. More...
 
MeshLib::MeshaddLayerToMesh (MeshLib::Mesh const &mesh, double thickness, std::string const &name, bool on_top)
 
std::unique_ptr< MeshLib::MeshconvertToLinearMesh (MeshLib::Mesh const &org_mesh, std::string const &new_mesh_name)
 
std::vector< MeshLib::Node * > copyNodeVector (const std::vector< MeshLib::Node * > &nodes)
 Creates a deep copy of a Node vector. More...
 
std::vector< MeshLib::Element * > copyElementVector (std::vector< MeshLib::Element *> const &elements, std::vector< MeshLib::Node *> const &new_nodes, std::vector< std::size_t > const *const node_id_map)
 
template<typename E >
MeshLib::ElementcopyElement (MeshLib::Element const *const element, const std::vector< MeshLib::Node *> &nodes, std::vector< std::size_t > const *const id_map)
 
std::vector< MeshLib::Element * > cloneElements (std::vector< MeshLib::Element * > const &elements)
 Clones a vector of elements using the Element::clone() function. More...
 
std::unique_ptr< MeshLib::ElementcreateFlippedElement (MeshLib::Element const &elem, std::vector< MeshLib::Node *> const &nodes)
 
std::unique_ptr< MeshLib::MeshcreateFlippedMesh (MeshLib::Mesh const &mesh)
 
template<typename Iterator >
void moveMeshNodes (Iterator begin, Iterator end, MeshLib::Node const &displacement)
 
MeshLib::MeshprojectMeshOntoPlane (MeshLib::Mesh const &mesh, MathLib::Point3d const &plane_origin, MathLib::Vector3 const &plane_normal)
 
MeshLib::MeshremoveElements (const MeshLib::Mesh &mesh, const std::vector< std::size_t > &removed_element_ids, const std::string &new_mesh_name)
 
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)
 
std::unique_ptr< MeshcreateQuadraticOrderMesh (Mesh const &linear_mesh)
 create a quadratic order mesh from the linear order mesh More...
 
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 >
bool processPropertyVector (std::string const &name, MeshLib::MeshItemType const type, MeshLib::Properties const &properties, std::size_t const, 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)
 
bool isBaseNode (Node const &node)
 
 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 

Definition at line 42 of file MeshEnums.h.

◆ 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

◆ MeshQualityType

Describes a mesh quality metric.

Enumerator
INVALID 
ELEMENTSIZE 
SIZEDIFFERENCE 
EDGERATIO 
EQUIANGLESKEW 
RADIUSEDGERATIO 

Definition at line 68 of file MeshEnums.h.

◆ UseIntensityAs

Selection of possible interpretations for intensities.

Enumerator
ELEVATION 
MATERIALS 
DATAVECTOR 
NONE 

Definition at line 81 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 464 of file MeshSurfaceExtraction.cpp.

References addPropertyToMesh(), Cell, and Node.

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

472 {
473  // transmit the original node ids of the bulk mesh as a property
474  if (!node_to_bulk_node_id_map_name.empty())
475  {
476  MeshLib::addPropertyToMesh(surface_mesh, node_to_bulk_node_id_map_name,
478  node_to_bulk_node_id_map);
479  }
480 
481  // transmit the original bulk element ids as a property
482  if (!element_to_bulk_element_id_map_name.empty())
483  {
485  surface_mesh, element_to_bulk_element_id_map_name,
486  MeshLib::MeshItemType::Cell, 1, element_to_bulk_element_id_map);
487  }
488 
489  // transmit the face id of the original bulk element as a property
490  if (!element_to_bulk_face_id_map_name.empty())
491  {
493  surface_mesh, element_to_bulk_face_id_map_name,
494  MeshLib::MeshItemType::Cell, 1, element_to_bulk_face_id_map);
495  }
496 }
void addPropertyToMesh(MeshLib::Mesh &mesh, std::string const &name, MeshLib::MeshItemType item_type, std::size_t number_of_components, std::vector< T > const &values)
Definition: Mesh.h:207

◆ addLayerToMesh()

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

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 93 of file AddLayerToMesh.cpp.

References Cell, MathLib::LinAlg::copy(), copyElementVector(), copyNodeVector(), createFlippedMesh(), 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(), and Node.

Referenced by addTopLayerToMesh(), LayeredVolume::getAttributePoints(), and MeshView::openAddLayerDialog().

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

◆ addPropertyToMesh()

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

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

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

211 {
212  if (item_type == MeshLib::MeshItemType::Node)
213  {
214  if (mesh.getNumberOfNodes() != values.size() / number_of_components)
215  {
216  OGS_FATAL(
217  "Error number of nodes (%u) does not match the number of "
218  "tuples (%u).",
219  mesh.getNumberOfNodes(), values.size() / number_of_components);
220  }
221  }
222  if (item_type == MeshLib::MeshItemType::Cell)
223  {
224  if (mesh.getNumberOfElements() != values.size() / number_of_components)
225  {
226  OGS_FATAL(
227  "Error number of elements (%u) does not match the number of "
228  "tuples (%u).",
229  mesh.getNumberOfElements(),
230  values.size() / number_of_components);
231  }
232  }
233 
234  auto* const property = mesh.getProperties().createNewPropertyVector<T>(
235  name, item_type, number_of_components);
236  if (!property)
237  {
238  OGS_FATAL("Error while creating PropertyVector '%s'.", name.c_str());
239  }
240  property->reserve(values.size());
241  std::copy(values.cbegin(), values.cend(), std::back_inserter(*property));
242 }
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition: Mesh.h:96
PropertyVector< T > * createNewPropertyVector(std::string const &name, MeshItemType mesh_item_type, std::size_t n_components=1)
Definition: Properties.h:15
MeshLib::Properties & getProperties()
Definition: Mesh.h:131
std::size_t getNumberOfElements() const
Get the number of elements.
Definition: Mesh.h:93
#define OGS_FATAL(fmt,...)
Definition: Error.h:64
void copy(MatrixOrVector const &x, MatrixOrVector &y)
Copies x to y.
Definition: LinAlg.h:37

◆ addTopLayerToMesh()

MeshLib::Mesh * MeshLib::addTopLayerToMesh ( MeshLib::Mesh const &  mesh,
double  thickness,
std::string const &  name 
)

Adds a layer on top of the mesh.

Definition at line 86 of file AddLayerToMesh.cpp.

References addLayerToMesh().

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

89 {
90  return addLayerToMesh(mesh, thickness, name, true);
91 }
MeshLib::Mesh * addLayerToMesh(MeshLib::Mesh const &mesh, double thickness, std::string const &name, bool on_top)

◆ calculateNormalizedSurfaceNormal()

MathLib::Vector3 MeshLib::calculateNormalizedSurfaceNormal ( MeshLib::Element const &  surface_element,
MeshLib::Element const &  bulk_element 
)
inline

Definition at line 44 of file Utils.h.

References MathLib::crossProduct(), MeshLib::Element::getDimension(), MeshLib::Element::getNode(), MeshLib::FaceRule::getSurfaceNormal(), and MathLib::TemplateVector3< T >::normalize().

47 {
48  MathLib::Vector3 surface_element_normal;
49  if (surface_element.getDimension() < 2)
50  {
51  auto const bulk_element_normal = MeshLib::FaceRule::getSurfaceNormal(
52  &bulk_element);
53  MathLib::Vector3 const edge_vector(*surface_element.getNode(0),
54  *surface_element.getNode(1));
55  surface_element_normal =
56  MathLib::crossProduct(bulk_element_normal, edge_vector);
57  }
58  else
59  {
60  surface_element_normal =
61  MeshLib::FaceRule::getSurfaceNormal(&surface_element);
62  }
63 
64  surface_element_normal.normalize();
65  // At the moment (2018-04-26) the surface normal is not oriented
66  // according to the right hand rule
67  // for correct results it is necessary to multiply the normal with
68  // -1
69  surface_element_normal *= -1;
70 
71  return surface_element_normal;
72 }
TemplateVector3< T1 > crossProduct(TemplateVector3< T1 > const &v, TemplateVector3< T1 > const &w)
Definition: Vector3.h:173
static MathLib::Vector3 getSurfaceNormal(const Element *e)
Returns the surface normal of a 2D element.
Definition: FaceRule.cpp:36

◆ CellType2String()

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

Given a MeshElemType this returns the appropriate string.

Definition at line 153 of file MeshEnums.cpp.

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

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

◆ cloneElements()

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

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

Definition at line 121 of file DuplicateMeshComponents.cpp.

References MeshLib::Element::clone().

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

123 {
124  std::vector<MeshLib::Element*> cloned_elements;
125  cloned_elements.reserve(elements.size());
126  std::transform(begin(elements), end(elements),
127  std::back_inserter(cloned_elements),
128  [](MeshLib::Element* const e) { return e->clone(); });
129  return cloned_elements;
130 }
virtual Element * clone() const =0

◆ 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 80 of file convertMeshToGeo.cpp.

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

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

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

◆ 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 150 of file convertMeshToGeo.cpp.

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

Referenced by main().

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

◆ 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 58 of file ConvertToLinearMesh.cpp.

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

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

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

◆ copyElement()

template<typename E >
MeshLib::Element * MeshLib::copyElement ( MeshLib::Element const *const  element,
const std::vector< MeshLib::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 53 of file DuplicateMeshComponents.cpp.

References MeshLib::Element::getCellType(), MathLib::Point3dWithID::getID(), MeshLib::Element::getNode(), MeshLib::Element::getNumberOfNodes(), HEX20, HEX8, LINE2, LINE3, PRISM15, PRISM6, PYRAMID13, PYRAMID5, QUAD4, QUAD8, QUAD9, TET10, TET4, TRI3, and TRI6.

Referenced by copyElementVector(), and MeshLib::MeshRevision::simplifyMesh().

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

◆ copyElementVector()

std::vector< MeshLib::Element * > MeshLib::copyElementVector ( std::vector< MeshLib::Element * > const &  elements,
std::vector< MeshLib::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 36 of file DuplicateMeshComponents.cpp.

References copyElement().

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

40 {
41  std::vector<MeshLib::Element*> new_elements;
42  new_elements.reserve(elements.size());
43  for (auto element : elements)
44  {
45  new_elements.push_back(copyElement(element, new_nodes, node_id_map));
46  }
47  return new_elements;
48 }
MeshLib::Element * copyElement(MeshLib::Element const *const element, const std::vector< MeshLib::Node *> &nodes, std::vector< std::size_t > const *const id_map)

◆ copyNodeVector()

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

Creates a deep copy of a Node vector.

Definition at line 22 of file DuplicateMeshComponents.cpp.

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

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

◆ 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 379 of file MeshSurfaceExtraction.cpp.

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

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

380 {
381  std::vector<std::size_t> element_to_bulk_element_id_map;
382  std::vector<std::size_t> element_to_bulk_face_id_map;
383  std::vector<MeshLib::Element*> surface_elements;
384 
385  auto const& bulk_elements = bulk_mesh.getElements();
386  auto const mesh_dimension = bulk_mesh.getDimension();
387 
388  for (auto const* elem : bulk_elements)
389  {
390  const unsigned element_dimension(elem->getDimension());
391  if (element_dimension < mesh_dimension)
392  {
393  continue;
394  }
395 
396  if (!elem->isBoundaryElement())
397  {
398  continue;
399  }
400  createSurfaceElementsFromElement(*elem, surface_elements,
401  element_to_bulk_element_id_map,
402  element_to_bulk_face_id_map);
403  }
404  return {surface_elements, element_to_bulk_element_id_map,
405  element_to_bulk_face_id_map};
406 }
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)

◆ createFlippedElement()

std::unique_ptr< MeshLib::Element > MeshLib::createFlippedElement ( MeshLib::Element const &  elem,
std::vector< MeshLib::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.

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

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<MeshLib::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<MeshLib::Line>(elem_nodes.release(),
41  elem.getID());
42  }
43  if (elem.getGeomType() == MeshElemType::TRIANGLE)
44  {
45  return std::make_unique<MeshLib::Tri>(elem_nodes.release(),
46  elem.getID());
47  }
48  if (elem.getGeomType() == MeshElemType::QUAD)
49  {
50  std::swap(elem_nodes[2], elem_nodes[3]);
51  return std::make_unique<MeshLib::Quad>(elem_nodes.release(),
52  elem.getID());
53  }
54  return nullptr;
55 }

◆ createFlippedMesh()

std::unique_ptr< MeshLib::Mesh > MeshLib::createFlippedMesh ( MeshLib::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 57 of file FlipElements.cpp.

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

Referenced by addLayerToMesh().

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

◆ createMeshFromElementSelection()

std::unique_ptr< MeshLib::Mesh > MeshLib::createMeshFromElementSelection ( std::string  mesh_name,
std::vector< MeshLib::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 320 of file Mesh.cpp.

References addPropertyToMesh(), Cell, and Node.

Referenced by MeshGeoToolsLib::constructAdditionalMeshesFromGeometries(), ProcessLib::createDeactivatedSubdomain(), and getOrCreateMeshProperty().

322 {
323  DBUG("Found %d elements in the mesh", elements.size());
324 
325  // Store bulk element ids for each of the new elements.
326  std::vector<std::size_t> bulk_element_ids;
327  bulk_element_ids.reserve(elements.size());
328  std::transform(begin(elements), end(elements),
329  std::back_inserter(bulk_element_ids),
330  [&](auto const& e) { return e->getID(); });
331 
332  // original node pointers to newly created nodes.
333  std::unordered_map<const MeshLib::Node*, MeshLib::Node*> nodes_map;
334  nodes_map.reserve(
335  elements.size()); // There will be at least one node per element.
336 
337  for (auto& e : elements)
338  {
339  // For each node find a cloned node in map or create if there is none.
340  unsigned const n_nodes = e->getNumberOfNodes();
341  for (unsigned i = 0; i < n_nodes; ++i)
342  {
343  const MeshLib::Node* n = e->getNode(i);
344  auto const it = nodes_map.find(n);
345  if (it == nodes_map.end())
346  {
347  auto new_node_in_map = nodes_map[n] = new MeshLib::Node(*n);
348  e->setNode(i, new_node_in_map);
349  }
350  else
351  {
352  e->setNode(i, it->second);
353  }
354  }
355  }
356 
357  // Copy the unique nodes pointers.
358  std::vector<MeshLib::Node*> element_nodes;
359  element_nodes.reserve(nodes_map.size());
360  std::transform(begin(nodes_map), end(nodes_map),
361  std::back_inserter(element_nodes),
362  [](auto const& pair) { return pair.second; });
363 
364  // Store bulk node ids for each of the new nodes.
365  std::vector<std::size_t> bulk_node_ids;
366  bulk_node_ids.reserve(nodes_map.size());
367  std::transform(begin(nodes_map), end(nodes_map),
368  std::back_inserter(bulk_node_ids),
369  [](auto const& pair) { return pair.first->getID(); });
370 
371  auto mesh = std::make_unique<MeshLib::Mesh>(
372  std::move(mesh_name), std::move(element_nodes), std::move(elements));
373  assert(mesh != nullptr);
374 
375  addPropertyToMesh(*mesh, "bulk_element_ids", MeshLib::MeshItemType::Cell, 1,
376  bulk_element_ids);
377  addPropertyToMesh(*mesh, "bulk_node_ids", MeshLib::MeshItemType::Node, 1,
378  bulk_node_ids);
379 
380  return mesh;
381 }
void addPropertyToMesh(MeshLib::Mesh &mesh, std::string const &name, MeshLib::MeshItemType item_type, std::size_t number_of_components, std::vector< T > const &values)
Definition: Mesh.h:207

◆ 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 126 of file MeshSurfaceExtraction.cpp.

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

128 {
129  std::vector<MeshLib::Node const*> tmp_nodes(n_all_nodes, nullptr);
130  for (auto const* elem : elements)
131  {
132  auto const n_nodes = elem->getNumberOfNodes();
133  for (unsigned j = 0; j < n_nodes; ++j)
134  {
135  const MeshLib::Node* node(elem->getNode(j));
136  tmp_nodes[node->getID()] = node;
137  }
138  }
139 
140  std::vector<MeshLib::Node*> nodes;
141  std::vector<std::size_t> node_id_map(n_all_nodes);
142  for (unsigned i = 0; i < n_all_nodes; ++i)
143  {
144  if (tmp_nodes[i])
145  {
146  node_id_map[i] = nodes.size();
147  nodes.push_back(new MeshLib::Node(*tmp_nodes[i]));
148  }
149  }
150  return {nodes, node_id_map};
151 }

◆ createQuadraticOrderMesh()

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

create a quadratic order mesh from the linear order mesh

Definition at line 93 of file QuadraticMeshGenerator.cpp.

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

Referenced by main().

94 {
95  // Clone the linear mesh nodes.
96  auto quadratic_mesh_nodes = MeshLib::copyNodeVector(linear_mesh.getNodes());
97 
98  // Temporary container for unique quadratic nodes with O(log(n)) search.
99  std::set<MeshLib::Node*, nodeByCoordinatesComparator> unique_nodes;
100 
101  // Create new elements with the quadratic nodes
102  std::vector<MeshLib::Element*> quadratic_elements;
103  auto const& linear_mesh_elements = linear_mesh.getElements();
104  for (MeshLib::Element const* e : linear_mesh_elements)
105  {
106  auto quadratic_element = createQuadraticElement(*e);
107 
108  // Replace the base nodes with cloned linear nodes.
109  int const number_base_nodes = quadratic_element->getNumberOfBaseNodes();
110  for (int i = 0; i < number_base_nodes; ++i)
111  {
112  quadratic_element->setNode(
113  i, quadratic_mesh_nodes[quadratic_element->getNodeIndex(i)]);
114  }
115 
116  // Make the new (middle-edge) nodes unique.
117  int const number_all_nodes = quadratic_element->getNumberOfNodes();
118  for (int i = number_base_nodes; i < number_all_nodes; ++i)
119  {
120  Node* original_node =
121  const_cast<Node*>(quadratic_element->getNode(i));
122 
123  auto it = unique_nodes.insert(original_node);
124  if (!it.second) // same node was already inserted before, no
125  // insertion
126  {
127  // Replace the element's node with the unique node.
128  quadratic_element->setNode(i, *it.first);
129  // And delete the original node
130  delete original_node;
131  }
132  }
133 
134  quadratic_elements.push_back(quadratic_element.release());
135  }
136 
137  // Add the unique quadratic nodes to the cloned linear nodes.
138  quadratic_mesh_nodes.reserve(linear_mesh.getNodes().size() +
139  unique_nodes.size());
140  std::copy(unique_nodes.begin(), unique_nodes.end(),
141  std::back_inserter(quadratic_mesh_nodes));
142 
143  return std::make_unique<MeshLib::Mesh>(
144  linear_mesh.getName(), quadratic_mesh_nodes, quadratic_elements,
145  linear_mesh.getProperties().excludeCopyProperties(
146  std::vector<MeshLib::MeshItemType>(1, MeshLib::MeshItemType::Node)),
147  linear_mesh.getNumberOfNodes());
148 }
std::unique_ptr< MeshLib::Element > createQuadraticElement(MeshLib::Element const &e)
Return a new quadratic element corresponding to the linear element&#39;s type.
std::vector< MeshLib::Node * > copyNodeVector(const std::vector< MeshLib::Node *> &nodes)
Creates a deep copy of a Node vector.
void copy(MatrixOrVector const &x, MatrixOrVector &y)
Copies x to y.
Definition: LinAlg.h:37

◆ 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 69 of file MeshSurfaceExtraction.cpp.

References Cell, MeshLib::Mesh::getNumberOfElements(), MeshLib::Mesh::getNumberOfNodes(), MeshLib::Properties::getPropertyVectorNames(), MaterialPropertyLib::name, and Node.

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

73 {
74  std::size_t const n_elems(sfc_mesh.getNumberOfElements());
75  std::size_t const n_nodes(sfc_mesh.getNumberOfNodes());
76  if (node_ids_map.size() != n_nodes)
77  {
78  ERR("createSfcMeshProperties() - Incorrect number of node IDs (%d) "
79  "compared to actual number of surface nodes (%d).",
80  node_ids_map.size(), n_nodes);
81  return false;
82  }
83 
84  if (element_ids_map.size() != n_elems)
85  {
86  ERR("createSfcMeshProperties() - Incorrect number of element IDs (%d) "
87  "compared to actual number of surface elements (%d).",
88  element_ids_map.size(), n_elems);
89  return false;
90  }
91 
92  std::size_t vectors_copied(0);
93  std::size_t vectors_skipped(0);
94  std::vector<std::string> const& array_names =
95  properties.getPropertyVectorNames();
96  for (std::string const& name : array_names)
97  {
98  if (processPropertyVector<double>(name, MeshLib::MeshItemType::Cell,
99  properties, n_elems, element_ids_map,
100  sfc_mesh) ||
101  processPropertyVector<int>(name, MeshLib::MeshItemType::Cell,
102  properties, n_elems, element_ids_map,
103  sfc_mesh) ||
104  processPropertyVector<double>(name, MeshLib::MeshItemType::Node,
105  properties, n_nodes, node_ids_map,
106  sfc_mesh) ||
107  processPropertyVector<int>(name, MeshLib::MeshItemType::Node,
108  properties, n_nodes, node_ids_map,
109  sfc_mesh))
110  {
111  vectors_copied++;
112  }
113  else
114  {
115  WARN("Skipping property vector '%s' - no matching data type found.",
116  name.c_str());
117  vectors_skipped++;
118  }
119  }
120  INFO("%d property vectors copied, %d vectors skipped.", vectors_copied,
121  vectors_skipped);
122  return true;
123 }
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition: Mesh.h:96
std::size_t getNumberOfElements() const
Get the number of elements.
Definition: Mesh.h:93

◆ 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 356 of file MeshSurfaceExtraction.cpp.

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

Referenced by createBoundaryElements().

361 {
362  const unsigned n_faces(surface_element.getNumberOfBoundaries());
363  for (unsigned j = 0; j < n_faces; ++j)
364  {
365  if (surface_element.getNeighbor(j) != nullptr)
366  {
367  continue;
368  }
369 
370  surface_elements.push_back(
371  const_cast<MeshLib::Element*>(surface_element.getBoundary(j)));
372  element_to_bulk_face_id_map.push_back(j);
373  element_to_bulk_element_id_map.push_back(surface_element.getID());
374  }
375 }

◆ 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 46 of file AddLayerToMesh.cpp.

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

Referenced by addLayerToMesh().

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

◆ filter()

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

Definition at line 27 of file ElementSearch.cpp.

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

28 {
29  std::vector<std::size_t> matchedIDs;
30  std::size_t i = 0;
31  for (auto value : container) {
32  if (p(value))
33  {
34  matchedIDs.push_back(i);
35  }
36  i++;
37  }
38  return matchedIDs;
39 }
static const double p

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

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

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

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

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

References MathLib::LinAlg::copy(), MathLib::Point3dWithID::getID(), and BaseLib::makeVectorUnique().

Referenced by ProcessLib::LIE::HydroMechanics::HydroMechanicsProcess< GlobalDim >::constructDofTable(), ProcessLib::RichardsMechanics::RichardsMechanicsProcess< DisplacementDim >::constructDofTable(), ProcessLib::HydroMechanics::HydroMechanicsProcess< DisplacementDim >::constructDofTable(), ProcessLib::ThermoHydroMechanics::ThermoHydroMechanicsProcess< DisplacementDim >::constructDofTable(), and convertToLinearMesh().

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:196
void copy(MatrixOrVector const &x, MatrixOrVector &y)
Copies x to y.
Definition: LinAlg.h:37

◆ getBulkElementPoint() [1/5]

MathLib::Point3d MeshLib::getBulkElementPoint ( MeshLib::Quad const &  quad,
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 gauss 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 gauss point of the lower dimensional element
Returns
the mapped point

Definition at line 17 of file MapBulkElementPoint.cpp.

References OGS_FATAL.

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

20 {
21  switch (face_id) {
22  case 0:
23  return MathLib::Point3d{std::array<double, 3>{{wp[0], 0.0, 0.0}}};
24  case 1:
25  return MathLib::Point3d{std::array<double, 3>{{1.0, wp[0], 0.0}}};
26  case 2:
27  return MathLib::Point3d{std::array<double, 3>{{1.0 - wp[0], 1.0, 0.0}}};
28  case 3:
29  return MathLib::Point3d{std::array<double, 3>{{0.0, 1.0 - wp[0], 0.0}}};
30  default:
31  OGS_FATAL("Invalid face id '%u' for the quad.", face_id);
32  }
33 }
#define OGS_FATAL(fmt,...)
Definition: Error.h:64

◆ getBulkElementPoint() [2/5]

MathLib::Point3d MeshLib::getBulkElementPoint ( MeshLib::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.

Definition at line 35 of file MapBulkElementPoint.cpp.

References getBulkElementPoint(), and OGS_FATAL.

38 {
39  switch (face_id)
40  {
41  case 0:
42  return MathLib::Point3d{
43  std::array<double, 3>{{wp[1], wp[0], -1.0}}};
44  case 1:
45  return MathLib::Point3d{
46  std::array<double, 3>{{wp[0], -1.0, wp[1]}}};
47  case 2:
48  return MathLib::Point3d{std::array<double, 3>{{1.0, wp[0], wp[1]}}};
49  case 3:
50  return MathLib::Point3d{
51  std::array<double, 3>{{-wp[0], -1.0, wp[1]}}};
52  case 4:
53  return MathLib::Point3d{
54  std::array<double, 3>{{-1.0, -wp[0], -wp[1]}}};
55  case 5:
56  return MathLib::Point3d{std::array<double, 3>{{wp[0], wp[1], 1.0}}};
57  default:
58  OGS_FATAL("Invalid face id '%u' for the hexahedron.", face_id);
59  }
60 }
#define OGS_FATAL(fmt,...)
Definition: Error.h:64

◆ getBulkElementPoint() [3/5]

MathLib::Point3d MeshLib::getBulkElementPoint ( MeshLib::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 109 of file MapBulkElementPoint.cpp.

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

113 {
114  auto const* element = mesh.getElement(bulk_element_id);
115  if (element->getCellType() == MeshLib::CellType::QUAD4)
116  {
117  MeshLib::Quad const& quad(*dynamic_cast<MeshLib::Quad const*>(element));
118  return getBulkElementPoint(quad, bulk_face_id, wp);
119  }
120  OGS_FATAL("Wrong cell type '%s' or functionality not yet implemented.",
121  MeshLib::CellType2String(element->getCellType()).c_str());
122 }
MathLib::Point3d getBulkElementPoint(MeshLib::Mesh const &, std::size_t, std::size_t, MathLib::WeightedPoint3D const &)
#define OGS_FATAL(fmt,...)
Definition: Error.h:64
std::string CellType2String(const CellType t)
Given a MeshElemType this returns the appropriate string.
Definition: MeshEnums.cpp:153

◆ getBulkElementPoint() [4/5]

MathLib::Point3d MeshLib::getBulkElementPoint ( MeshLib::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 124 of file MapBulkElementPoint.cpp.

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

128 {
129  auto const* element = mesh.getElement(bulk_element_id);
130  if (element->getCellType() == MeshLib::CellType::HEX8)
131  {
132  MeshLib::Hex const& hex = *static_cast<MeshLib::Hex const*>(element);
133  return getBulkElementPoint(hex, bulk_face_id, wp);
134  }
135  if (element->getCellType() == MeshLib::CellType::PRISM6)
136  {
137  MeshLib::Prism const& prism =
138  *static_cast<MeshLib::Prism const*>(element);
139  return getBulkElementPoint(prism, bulk_face_id, wp);
140  }
141  if (element->getCellType() == MeshLib::CellType::TET4)
142  {
143  MeshLib::Tet const& tet = *static_cast<MeshLib::Tet const*>(element);
144  return getBulkElementPoint(tet, bulk_face_id, wp);
145  }
146  OGS_FATAL("Wrong cell type '%s' or functionality not yet implemented.",
147  MeshLib::CellType2String(element->getCellType()).c_str());
148 }
MathLib::Point3d getBulkElementPoint(MeshLib::Mesh const &, std::size_t, std::size_t, MathLib::WeightedPoint3D const &)
#define OGS_FATAL(fmt,...)
Definition: Error.h:64
std::string CellType2String(const CellType t)
Given a MeshElemType this returns the appropriate string.
Definition: MeshEnums.cpp:153

◆ getBulkElementPoint() [5/5]

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

Definition at line 151 of file MapBulkElementPoint.cpp.

References MathLib::ORIGIN.

155 {
156  return MathLib::ORIGIN;
157 }
const Point3d ORIGIN
Definition: Point3d.h:26

◆ getMeshElemTypes()

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

Returns a vector of all mesh element types.

Definition at line 129 of file MeshEnums.cpp.

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

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

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

◆ getMeshElemTypeStringsShort()

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

Returns a vector of strings of mesh element types.

Definition at line 143 of file MeshEnums.cpp.

References getMeshElemTypes(), and MeshElemType2StringShort().

Referenced by main().

144 {
145  std::vector<std::string> vec;
146  for (MeshElemType eleType : getMeshElemTypes())
147  {
148  vec.push_back(MeshElemType2StringShort(eleType));
149  }
150  return vec;
151 }
std::vector< MeshElemType > getMeshElemTypes()
Returns a vector of all mesh element types.
Definition: MeshEnums.cpp:129
std::string MeshElemType2StringShort(const MeshElemType t)
Given a MeshElemType this returns the appropriate string with a short name.
Definition: MeshEnums.cpp:55
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum. ...
Definition: MeshEnums.h:26

◆ getOrCreateMeshProperty()

template<typename T >
PropertyVector<T>* MeshLib::getOrCreateMeshProperty ( Mesh mesh,
std::string const &  property_name,
MeshLib::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 249 of file Mesh.h.

References Cell, createMeshFromElementSelection(), MeshLib::Properties::existsPropertyVector(), MeshLib::Mesh::getNumberOfElements(), MeshLib::Mesh::getNumberOfNodes(), MeshLib::Mesh::getProperties(), IntegrationPoint, materialIDs(), ApplicationUtils::NodeWiseMeshPartitioner::mesh(), Node, and OGS_FATAL.

253 {
254  if (property_name.empty())
255  {
256  OGS_FATAL(
257  "Trying to get or to create a mesh property with empty name.");
258  }
259 
260  auto numberOfMeshItems = [&mesh, &item_type]() -> std::size_t {
261  switch (item_type)
262  {
264  return mesh.getNumberOfElements();
266  return mesh.getNumberOfNodes();
268  return 0; // For the integration point data the size is
269  // variable
270  default:
271  OGS_FATAL(
272  "MeshLib::getOrCreateMeshProperty cannot handle other "
273  "types than Node, Cell, or IntegrationPoint.");
274  }
275  return 0;
276  };
277 
278  if (mesh.getProperties().existsPropertyVector<T>(property_name))
279  {
280  auto result =
281  mesh.getProperties().template getPropertyVector<T>(property_name);
282  assert(result);
283  if (item_type != MeshItemType::IntegrationPoint)
284  {
285  // Test the size if number of mesh items is known, which is not the
286  // case for the integration point data.
287  assert(result->size() ==
288  numberOfMeshItems() * number_of_components);
289  }
290  return result;
291  }
292 
293  auto result = mesh.getProperties().template createNewPropertyVector<T>(
294  property_name, item_type, number_of_components);
295  assert(result);
296  result->resize(numberOfMeshItems() * number_of_components);
297  return result;
298 }
#define OGS_FATAL(fmt,...)
Definition: Error.h:64

◆ getUniqueNodes()

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

Create a vector of unique nodes used by given elements.

Definition at line 165 of file NodeSearch.cpp.

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

◆ isBaseNode()

bool MeshLib::isBaseNode ( Node const &  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 54 of file Node.cpp.

References MeshLib::Node::getElement(), MeshLib::Element::getNumberOfBaseNodes(), and MeshLib::Node::getNumberOfElements().

Referenced by NumLib::MeshComponentMap::getSubset().

55 {
56  // Check if node is connected.
57  if (node.getNumberOfElements() == 0)
58  {
59  return true;
60  }
61 
62  // In a mesh a node always belongs to at least one element.
63  auto const e = node.getElement(0);
64 
65  auto const n_base_nodes = e->getNumberOfBaseNodes();
66  auto const local_index = e->getNodeIDinElement(&node);
67  return local_index < n_base_nodes;
68 }

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

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

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

236 {
237  for(std::size_t i(0); i<e.getNumberOfBaseNodes(); ++i) {
238  if (MathLib::sqrDist2d(p, *e.getNode(i)) <
239  std::numeric_limits<double>::epsilon())
240  {
241  return true;
242  }
243  }
244 
245  if (e.getGeomType() == MeshElemType::TRIANGLE)
246  {
247  MathLib::Point3d const& n0(*e.getNode(0));
248  MathLib::Point3d const& n1(*e.getNode(1));
249  MathLib::Point3d const& n2(*e.getNode(2));
250 
251  return MathLib::isPointInTriangleXY(p, n0, n1, n2);
252  }
253  if (e.getGeomType() == MeshElemType::QUAD)
254  {
255  MathLib::Point3d const& n0(*e.getNode(0));
256  MathLib::Point3d const& n1(*e.getNode(1));
257  MathLib::Point3d const& n2(*e.getNode(2));
258  MathLib::Point3d const& n3(*e.getNode(3));
259 
260  return MathLib::isPointInTriangleXY(p, n0, n1, n2) ||
261  MathLib::isPointInTriangleXY(p, n0, n2, n3);
262  }
263 
264  WARN("isPointInElementXY: element type '%s' is not supported.",
265  MeshLib::MeshElemType2String(e.getGeomType()).c_str());
266  return false;
267 }
double sqrDist2d(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition: Point3d.h:57
static const double p
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:18

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

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

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

311 {
312  auto const& properties = mesh.getProperties();
313  return properties.existsPropertyVector<int>("MaterialIDs",
315  ? properties.getPropertyVector<int>(
316  "MaterialIDs", MeshLib::MeshItemType::Cell, 1)
317  : nullptr;
318 }

◆ MeshElemType2String()

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

Given a MeshElemType this returns the appropriate string.

Definition at line 18 of file MeshEnums.cpp.

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

Referenced by MeshLib::EdgeRatioMetric::calculateQuality(), MeshModel::createMeshElemTypeMap(), MeshLib::Element::getNode(), isPointInElementXY(), and ElementTreeModel::setElement().

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

◆ MeshElemType2StringShort()

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

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

Definition at line 55 of file MeshEnums.cpp.

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

Referenced by getMeshElemTypeStringsShort().

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

◆ MeshQualityType2String()

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

Definition at line 182 of file MeshEnums.cpp.

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

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

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

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

Referenced by main().

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

◆ operator!=()

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

Definition at line 185 of file Mesh.h.

References scaleMeshPropertyVector().

186 {
187  return !(a == b);
188 }

◆ operator<()

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

Lexicographic order of Location.

Definition at line 51 of file Location.h.

References MeshLib::Location::item_id, MeshLib::Location::item_type, MeshLib::Location::mesh_id, and operator<<().

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 }

◆ operator<<() [1/3]

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

Definition at line 17 of file Location.cpp.

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

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

◆ operator<<() [2/3]

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

Definition at line 30 of file Location.cpp.

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

31 {
32  return os << "(" << l.mesh_id
33  << ", " << l.item_type
34  << ", " << l.item_id
35  << ")";
36 }

◆ operator<<() [3/3]

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

Definition at line 216 of file Element.cpp.

References MeshLib::Element::_id, MeshLib::Element::getGeomType(), MathLib::Point3dWithID::getID(), MeshLib::Element::getNodes(), MeshLib::Element::getNumberOfNeighbors(), and MeshLib::Element::getNumberOfNodes().

Referenced by operator<(), and toString().

217 {
218  os << "Element #" << e._id << " @ " << &e << " with " << e.getNumberOfNeighbors()
219  << " neighbours\n";
220 
221  unsigned const nnodes = e.getNumberOfNodes();
222  MeshLib::Node* const* const nodes = e.getNodes();
223  os << "MeshElemType: "
224  << static_cast<std::underlying_type<MeshElemType>::type>(e.getGeomType())
225  << " with " << nnodes << " nodes: { ";
226  for (unsigned n = 0; n < nnodes; ++n)
227  {
228  os << nodes[n]->getID() << " @ " << nodes[n] << " ";
229  }
230  os << "}\n";
231  return os;
232 }
std::size_t getID() const
Definition: Point3dWithID.h:61

◆ operator==()

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

Meshes are equal if their id's are equal.

Definition at line 180 of file Mesh.h.

References MeshLib::Mesh::getID().

181 {
182  return a.getID() == b.getID();
183 }

◆ processPropertyVector()

template<typename T >
bool MeshLib::processPropertyVector ( std::string const &  name,
MeshLib::MeshItemType const  type,
MeshLib::Properties const &  properties,
std::size_t  const,
std::vector< std::size_t > const &  id_map,
MeshLib::Mesh sfc_mesh 
)

Definition at line 33 of file MeshSurfaceExtraction.cpp.

References MeshLib::Properties::existsPropertyVector(), MeshLib::Properties::getPropertyVector(), and MaterialPropertyLib::name.

39 {
40  if (!properties.existsPropertyVector<T>(name))
41  {
42  return false;
43  }
44 
45  auto const& org_vec = *properties.getPropertyVector<T>(name);
46  if (type != org_vec.getMeshItemType())
47  {
48  return false;
49  }
50  auto const number_of_components = org_vec.getNumberOfComponents();
51 
52  auto sfc_prop =
53  getOrCreateMeshProperty<T>(sfc_mesh, name, type, number_of_components);
54  sfc_prop->clear();
55  sfc_prop->reserve(id_map.size());
56 
57  for (auto bulk_id : id_map)
58  {
59  for (auto component_id = 0; component_id < number_of_components;
60  ++component_id)
61  {
62  sfc_prop->push_back(org_vec.getComponent(bulk_id, component_id));
63  }
64  }
65 
66  return true;
67 }

◆ projectMeshOntoPlane()

MeshLib::Mesh* MeshLib::projectMeshOntoPlane ( MeshLib::Mesh const &  mesh,
MathLib::Point3d const &  plane_origin,
MathLib::Vector3 const &  plane_normal 
)
inline

Projects all nodes of a mesh onto a plane specified by a point of origin and a normal vector. Overlapping elements, collapsed nodes, and other issues are not handled by the method. The normal vector need not be normalized.

Definition at line 36 of file projectMeshOntoPlane.h.

References copyElementVector(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getNumberOfNodes(), and MathLib::scalarProduct().

39 {
40  std::size_t const n_nodes (mesh.getNumberOfNodes());
41  std::vector<MeshLib::Node*> const& nodes (mesh.getNodes());
42  MathLib::Vector3 normal (plane_normal);
43  normal.normalize();
44  std::vector<MeshLib::Node*> new_nodes;
45  new_nodes.reserve(n_nodes);
46  for (std::size_t i=0; i<n_nodes; ++i)
47  {
48  MeshLib::Node const& node(*nodes[i]);
49  MathLib::Vector3 const v(plane_origin, node);
50  double const dist (MathLib::scalarProduct(v,normal));
51  new_nodes.push_back(new MeshLib::Node(node - dist * normal));
52  }
53 
54  return new MeshLib::Mesh("Projected_Mesh", new_nodes,
55  MeshLib::copyElementVector(mesh.getElements(), new_nodes));
56 }
std::vector< MeshLib::Element * > copyElementVector(std::vector< MeshLib::Element *> const &elements, std::vector< MeshLib::Node *> const &new_nodes, std::vector< std::size_t > const *const node_id_map)
T scalarProduct(T const *const v0, T const *const v1)
Definition: MathTools.h:26

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

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

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

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:102
MeshLib::Properties & getProperties()
Definition: Mesh.h:131
std::vector< MeshLib::Element * > copyElementVector(std::vector< MeshLib::Element *> const &elements, std::vector< MeshLib::Node *> const &new_nodes, std::vector< std::size_t > const *const node_id_map)
std::vector< MeshLib::Element * > excludeElementCopy(std::vector< MeshLib::Element *> const &vec_src_eles, std::vector< std::size_t > const &vec_removed)
Properties excludeCopyProperties(std::vector< std::size_t > const &exclude_elem_ids, std::vector< std::size_t > const &exclude_node_ids) const
Definition: Properties.cpp:60
std::vector< MeshLib::Node * > copyNodeVector(const std::vector< MeshLib::Node *> &nodes)
Creates a deep copy of a Node vector.
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:105

◆ 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 100 of file RemoveMeshComponents.cpp.

References copyElementVector(), copyNodeVector(), MeshLib::Properties::excludeCopyProperties(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getNodes(), and MeshLib::Mesh::getProperties().

Referenced by LayeredMeshGenerator::getMesh().

103 {
104  if (del_nodes_idx.empty())
105  {
106  return nullptr;
107  }
108 
109  // copy node and element objects
110  std::vector<MeshLib::Node*> new_nodes =
112  std::vector<MeshLib::Element*> new_elems =
113  MeshLib::copyElementVector(mesh.getElements(), new_nodes);
114 
115  // delete elements
116  MeshLib::ElementSearch es(mesh);
117  es.searchByNodeIDs(del_nodes_idx);
118  auto& removed_element_ids = es.getSearchedElementIDs();
119  for (auto eid : removed_element_ids)
120  {
121  delete new_elems[eid];
122  new_elems[eid] = nullptr;
123  }
124  new_elems.erase(std::remove(new_elems.begin(), new_elems.end(), nullptr),
125  new_elems.end());
126 
127  // check unused nodes due to element deletion
128  std::vector<bool> node_delete_flag(new_nodes.size(), true);
129  for (auto e : new_elems)
130  {
131  for (unsigned i = 0; i < e->getNumberOfNodes(); i++)
132  {
133  node_delete_flag[e->getNodeIndex(i)] = false;
134  }
135  }
136 
137  // delete unused nodes
138  for (std::size_t i = 0; i < new_nodes.size(); i++)
139  {
140  if (!node_delete_flag[i])
141  {
142  continue;
143  }
144  delete new_nodes[i];
145  new_nodes[i] = nullptr;
146  }
147  new_nodes.erase(std::remove(new_nodes.begin(), new_nodes.end(), nullptr),
148  new_nodes.end());
149 
150  if (!new_elems.empty())
151  {
152  MeshLib::Mesh* new_mesh =
153  new MeshLib::Mesh(new_mesh_name, new_nodes, new_elems,
155  removed_element_ids, del_nodes_idx));
156  return new_mesh;
157  }
158 
159  return nullptr;
160 }
Element search class.
Definition: ElementSearch.h:27
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:102
MeshLib::Properties & getProperties()
Definition: Mesh.h:131
std::vector< MeshLib::Element * > copyElementVector(std::vector< MeshLib::Element *> const &elements, std::vector< MeshLib::Node *> const &new_nodes, std::vector< std::size_t > const *const node_id_map)
Properties excludeCopyProperties(std::vector< std::size_t > const &exclude_elem_ids, std::vector< std::size_t > const &exclude_node_ids) const
Definition: Properties.cpp:60
std::vector< MeshLib::Node * > copyNodeVector(const std::vector< MeshLib::Node *> &nodes)
Creates a deep copy of a Node vector.
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:105

◆ scaleMeshPropertyVector()

void MeshLib::scaleMeshPropertyVector ( MeshLib::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 293 of file Mesh.cpp.

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

Referenced by main(), and operator!=().

296 {
297  if (!mesh.getProperties().existsPropertyVector<double>(property_name))
298  {
299  WARN("Did not find PropertyVector '%s' for scaling.",
300  property_name.c_str());
301  return;
302  }
303  for (auto& v :
304  *mesh.getProperties().getPropertyVector<double>(property_name))
305  {
306  v *= factor;
307  }
308 }
MeshLib::Properties & getProperties()
Definition: Mesh.h:131
PropertyVector< T > const * getPropertyVector(std::string const &name) const
Definition: Properties.h:119
bool existsPropertyVector(std::string const &name) const
Definition: Properties.h:79

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

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

Referenced by MeshElementRemovalDialog::accept(), main(), and MeshLib::IO::Legacy::MeshIO::readElement().

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

◆ toString()

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

Returns a char array for a specific MeshItemType.

Definition at line 28 of file Location.h.

References operator<<().

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

◆ vtkStandardNewMacro()

MeshLib::vtkStandardNewMacro ( VtkMappedMeshSource  )

Definition at line 32 of file VtkMappedMeshSource.cpp.

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

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

Variable Documentation

◆ mesh_item_type_strings

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

Char array names for all of MeshItemType values.

Definition at line 24 of file Location.h.