OGS 6.2.0-244-g47b8a9a9d
MeshLib Namespace Reference

Detailed Description

Interface for heuristic search length strategy.

Defines functions that are shared by DirichletBoundaryCondition and DirichletBoundaryConditionWithinTimeInterval, which avoid the way of inheritance for reducing source code duplication.

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
Author
Norihiro Watanabe
Date
2013-04-16

File: DirichletBoundaryConditionAuxiliaryFunctions.h

Created on November 28, 2018, 11:26 AM

Namespaces

 anonymous_namespace{ConvertToLinearMesh.cpp}
 
 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 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::MeshaddBottomLayerToMesh (MeshLib::Mesh const &mesh, double thickness, std::string const &name)
 Adds a layer at the bottom 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 (const std::vector< MeshLib::Element *> &elements, const std::vector< MeshLib::Node *> &nodes)
 
MeshLib::ElementcopyElement (MeshLib::Element const *const element, const std::vector< MeshLib::Node * > &nodes)
 Copies an element without change, using the nodes vector from the result mesh. More...
 
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)
 
const std::string MeshElemType2String (const MeshElemType t)
 Given a MeshElemType this returns the appropriate string. More...
 
const 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...
 
const std::string CellType2String (const CellType t)
 Given a MeshElemType this returns the appropriate string. More...
 
const std::string MeshQualityType2String (const MeshQualityType t)
 
std::unique_ptr< MeshcreateQuadraticOrderMesh (Mesh const &linear_order_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)
 
void getGridGeometry (MeshElementGrid const &grid, GeoLib::GEOObjects &geometries, std::string &geometry_name)
 
std::vector< Node * > getUniqueNodes (std::vector< Element * > const &elements)
 Create a vector of unique nodes used by given elements. More...
 
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 19 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 22 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

◆ addBottomLayerToMesh()

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

Adds a layer at the bottom of the mesh.

Definition at line 94 of file AddLayerToMesh.cpp.

References addLayerToMesh().

97 {
98  return addLayerToMesh(mesh, thickness, name, false);
99 }
MeshLib::Mesh * addLayerToMesh(MeshLib::Mesh const &mesh, double thickness, std::string const &name, bool on_top)

◆ 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 101 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 addBottomLayerToMesh(), addTopLayerToMesh(), LayeredVolume::getAttributePoints(), and MeshView::openAddLayerDialog().

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

223 {
224  if (item_type == MeshLib::MeshItemType::Node)
225  {
226  if (mesh.getNumberOfNodes() != values.size() / number_of_components)
227  {
228  OGS_FATAL(
229  "Error number of nodes (%u) does not match the number of "
230  "tuples (%u).",
231  mesh.getNumberOfNodes(), values.size() / number_of_components);
232  }
233  }
234  if (item_type == MeshLib::MeshItemType::Cell)
235  {
236  if (mesh.getNumberOfElements() != values.size() / number_of_components)
237  {
238  OGS_FATAL(
239  "Error number of elements (%u) does not match the number of "
240  "tuples (%u).",
241  mesh.getNumberOfElements(),
242  values.size() / number_of_components);
243  }
244  }
245 
246  auto* const property = mesh.getProperties().createNewPropertyVector<T>(
247  name, item_type, number_of_components);
248  if (!property)
249  {
250  OGS_FATAL("Error while creating PropertyVector '%s'.", name.c_str());
251  }
252  property->reserve(values.size());
253  std::copy(values.cbegin(), values.cend(), std::back_inserter(*property));
254 }
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition: Mesh.h:99
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:134
std::size_t getNumberOfElements() const
Get the number of elements.
Definition: Mesh.h:96
#define OGS_FATAL(fmt,...)
Definition: Error.h:63
void copy(MatrixOrVector const &x, MatrixOrVector &y)
Copies x to y.
Definition: LinAlg.h:36

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

References addLayerToMesh().

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

90 {
91  return addLayerToMesh(mesh, thickness, name, true);
92 }
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 43 of file Utils.h.

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

46 {
47  MathLib::Vector3 surface_element_normal;
48  if (surface_element.getDimension() < 2)
49  {
50  auto const bulk_element_normal = MeshLib::FaceRule::getSurfaceNormal(
51  &bulk_element);
52  MathLib::Vector3 const edge_vector(*surface_element.getNode(0),
53  *surface_element.getNode(1));
54  surface_element_normal =
55  MathLib::crossProduct(bulk_element_normal, edge_vector);
56  }
57  else
58  {
59  surface_element_normal =
60  MeshLib::FaceRule::getSurfaceNormal(&surface_element);
61  }
62 
63  surface_element_normal.normalize();
64  // At the moment (2018-04-26) the surface normal is not oriented
65  // according to the right hand rule
66  // for correct results it is necessary to multiply the normal with
67  // -1
68  surface_element_normal *= -1;
69 
70  return surface_element_normal;
71 }
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:35

◆ CellType2String()

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

Given a MeshElemType this returns the appropriate string.

Definition at line 154 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().

155 {
156 #define RETURN_CELL_TYPE_STR(t, type)\
157  if ((t) == CellType::type)\
158  return #type;
159 
160  RETURN_CELL_TYPE_STR(t, POINT1);
161  RETURN_CELL_TYPE_STR(t, LINE2);
162  RETURN_CELL_TYPE_STR(t, LINE3);
163  RETURN_CELL_TYPE_STR(t, QUAD4);
164  RETURN_CELL_TYPE_STR(t, QUAD8);
165  RETURN_CELL_TYPE_STR(t, QUAD9);
166  RETURN_CELL_TYPE_STR(t, HEX8);
167  RETURN_CELL_TYPE_STR(t, HEX20);
168  RETURN_CELL_TYPE_STR(t, HEX27);
169  RETURN_CELL_TYPE_STR(t, TRI3);
170  RETURN_CELL_TYPE_STR(t, TRI6);
171  RETURN_CELL_TYPE_STR(t, TET4);
172  RETURN_CELL_TYPE_STR(t, TET10);
173  RETURN_CELL_TYPE_STR(t, PRISM6);
174  RETURN_CELL_TYPE_STR(t, PRISM15);
175  RETURN_CELL_TYPE_STR(t, PYRAMID5);
176  RETURN_CELL_TYPE_STR(t, PYRAMID13);
177 
178  return "none";
179 
180 #undef RETURN_CELL_TYPE_STR
181 }
#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 94 of file DuplicateMeshComponents.cpp.

References MeshLib::Element::clone().

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

96 {
97  std::vector<MeshLib::Element*> cloned_elements;
98  cloned_elements.reserve(elements.size());
99  std::transform(begin(elements), end(elements),
100  std::back_inserter(cloned_elements),
101  [](MeshLib::Element* const e) { return e->clone(); });
102  return cloned_elements;
103 }
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 31 of file convertMeshToGeo.cpp.

References GeoLib::GEOObjects::addPointVec(), GeoLib::GEOObjects::addSurfaceVec(), MeshLib::Properties::existsPropertyVector(), MeshLib::Mesh::getDimension(), MeshLib::Mesh::getElements(), MeshLib::Element::getGeomType(), GeoLib::PointVec::getIDMap(), MeshLib::Mesh::getName(), MeshLib::Element::getNodeIndex(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getNumberOfElements(), MeshLib::Mesh::getNumberOfNodes(), GeoLib::GEOObjects::getPointVec(), GeoLib::GEOObjects::getPointVecObj(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), QUAD, and TRIANGLE.

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

32 {
33  if (mesh.getDimension() != 2)
34  {
35  ERR ("Mesh to geometry conversion is only working for 2D meshes.");
36  return false;
37  }
38 
39  // nodes to points conversion
40  std::string mesh_name(mesh.getName());
41  {
42  auto points = std::make_unique<std::vector<GeoLib::Point*>>();
43  points->reserve(mesh.getNumberOfNodes());
44 
45  for (auto node_ptr : mesh.getNodes())
46  {
47  points->push_back(new GeoLib::Point(*node_ptr, node_ptr->getID()));
48  }
49 
50  geo_objects.addPointVec(std::move(points), mesh_name, nullptr, eps);
51  }
52  const std::vector<std::size_t> id_map (geo_objects.getPointVecObj(mesh_name)->getIDMap());
53 
54  // elements to surface triangles conversion
55  std::string const mat_name ("MaterialIDs");
56  auto bounds (MeshInformation::getValueBounds<int>(mesh, mat_name));
57  const unsigned nMatGroups(bounds.second-bounds.first+1);
58  auto sfcs = std::make_unique<std::vector<GeoLib::Surface*>>();
59  sfcs->reserve(nMatGroups);
60  auto const& points = *geo_objects.getPointVec(mesh_name);
61  for (unsigned i = 0; i < nMatGroups; ++i)
62  {
63  sfcs->push_back(new GeoLib::Surface(points));
64  }
65 
66  const std::vector<MeshLib::Element*> &elements = mesh.getElements();
67  const std::size_t nElems (mesh.getNumberOfElements());
68 
69  MeshLib::PropertyVector<int> const*const materialIds =
70  mesh.getProperties().existsPropertyVector<int>("MaterialIDs")
71  ? mesh.getProperties().getPropertyVector<int>("MaterialIDs")
72  : nullptr;
73 
74  for (unsigned i=0; i<nElems; ++i)
75  {
76  auto surfaceId = !materialIds ? 0 : ((*materialIds)[i] - bounds.first);
77  MeshLib::Element* e (elements[i]);
78  if (e->getGeomType() == MeshElemType::TRIANGLE)
79  {
80  (*sfcs)[surfaceId]->addTriangle(id_map[e->getNodeIndex(0)],
81  id_map[e->getNodeIndex(1)],
82  id_map[e->getNodeIndex(2)]);
83  }
84  if (e->getGeomType() == MeshElemType::QUAD)
85  {
86  (*sfcs)[surfaceId]->addTriangle(id_map[e->getNodeIndex(0)], id_map[e->getNodeIndex(1)], id_map[e->getNodeIndex(2)]);
87  (*sfcs)[surfaceId]->addTriangle(id_map[e->getNodeIndex(0)], id_map[e->getNodeIndex(2)], id_map[e->getNodeIndex(3)]);
88  }
89  // all other element types are ignored (i.e. lines)
90  }
91 
92  std::for_each(sfcs->begin(), sfcs->end(), [](GeoLib::Surface* sfc) {
93  if (sfc->getNumberOfTriangles() == 0)
94  {
95  delete sfc;
96  }
97  sfc = nullptr;
98  });
99  auto sfcs_end = std::remove(sfcs->begin(), sfcs->end(), nullptr);
100  sfcs->erase(sfcs_end, sfcs->end());
101 
102  geo_objects.addSurfaceVec(std::move(sfcs), mesh_name);
103  return true;
104 }
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition: Mesh.h:99
void addPointVec(std::unique_ptr< std::vector< Point *>> points, std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> pnt_names=nullptr, double eps=sqrt(std::numeric_limits< double >::epsilon()))
Definition: GEOObjects.cpp:45
void addSurfaceVec(std::unique_ptr< std::vector< Surface *>> surfaces, const std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> sfc_names=nullptr)
Definition: GEOObjects.cpp:246
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:105
MeshLib::Properties & getProperties()
Definition: Mesh.h:134
const std::string getName() const
Get name of the mesh.
Definition: Mesh.h:102
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:99
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
Definition: Surface.h:34
PropertyVector< T > const * getPropertyVector(std::string const &name) const
Definition: Properties.h:119
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:108
bool existsPropertyVector(std::string const &name) const
Definition: Properties.h:79
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition: Mesh.h:81
std::size_t getNumberOfElements() const
Get the number of elements.
Definition: Mesh.h:96

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

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

Referenced by main().

107 {
108  // convert to a mesh including duplicated nodes
109  std::vector<MeshLib::Node*> nodes;
110  std::vector<MeshLib::Element*> elements;
111  std::size_t nodeId = 0;
112  for (std::size_t i=0; i<sfc.getNumberOfTriangles(); i++)
113  {
114  auto* tri = sfc[i];
115  auto** tri_nodes = new MeshLib::Node*[3];
116  for (unsigned j = 0; j < 3; j++)
117  {
118  tri_nodes[j] =
119  new MeshLib::Node(tri->getPoint(j)->getCoords(), nodeId++);
120  }
121  elements.push_back(new MeshLib::Tri(tri_nodes, i));
122  for (unsigned j = 0; j < 3; j++)
123  {
124  nodes.push_back(tri_nodes[j]);
125  }
126  }
127  MeshLib::Mesh mesh_with_duplicated_nodes(mesh_name, nodes, elements);
128 
129  // remove duplicated nodes
130  MeshLib::MeshRevision rev(mesh_with_duplicated_nodes);
131  return rev.simplifyMesh(mesh_with_duplicated_nodes.getName(), eps);
132 }
std::size_t getNumberOfTriangles() const
Definition: Surface.cpp:90

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

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

◆ copyElement()

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

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

Definition at line 48 of file DuplicateMeshComponents.cpp.

References MeshLib::Element::getGeomType(), MathLib::Point3dWithID::getID(), MeshLib::Element::getNode(), MeshLib::Element::getNumberOfNodes(), HEXAHEDRON, LINE, PRISM, PYRAMID, QUAD, TETRAHEDRON, and TRIANGLE.

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

49 {
50  if (element->getGeomType() == MeshElemType::LINE)
51  {
52  return copyElement<MeshLib::Line>(element, nodes);
53  }
54  if (element->getGeomType() == MeshElemType::TRIANGLE)
55  {
56  return copyElement<MeshLib::Tri>(element, nodes);
57  }
58  if (element->getGeomType() == MeshElemType::QUAD)
59  {
60  return copyElement<MeshLib::Quad>(element, nodes);
61  }
62  if (element->getGeomType() == MeshElemType::TETRAHEDRON)
63  {
64  return copyElement<MeshLib::Tet>(element, nodes);
65  }
66  if (element->getGeomType() == MeshElemType::HEXAHEDRON)
67  {
68  return copyElement<MeshLib::Hex>(element, nodes);
69  }
70  if (element->getGeomType() == MeshElemType::PYRAMID)
71  {
72  return copyElement<MeshLib::Pyramid>(element, nodes);
73  }
74  if (element->getGeomType() == MeshElemType::PRISM)
75  {
76  return copyElement<MeshLib::Prism>(element, nodes);
77  }
78 
79  ERR ("Error: Unknown element type.");
80  return nullptr;
81 }

◆ copyElementVector()

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

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

Parameters
elementsThe element vector that should be duplicated.
nodesThe new node vector used for the duplicated element vector. 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(), MeshLib::MeshRevision::collapseNodes(), LayeredVolume::createRasterLayers(), ProcessLib::LIE::PostProcessTool::PostProcessTool(), projectMeshOntoPlane(), removeElements(), and removeNodes().

37 {
38  const std::size_t nElements(elements.size());
39  std::vector<MeshLib::Element*> new_elements;
40  new_elements.reserve(nElements);
41  for (std::size_t k = 0; k < nElements; ++k)
42  {
43  new_elements.push_back(copyElement(elements[k], nodes));
44  }
45  return new_elements;
46 }
MeshLib::Element * copyElement(MeshLib::Element const *const element, const std::vector< MeshLib::Node *> &nodes)
Copies an element without change, using the nodes vector from the result mesh.

◆ copyNodeVector()

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

Creates a deep copy of a Node vector.

Definition at line 23 of file DuplicateMeshComponents.cpp.

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

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 }

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

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

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

57 {
58  if (mesh.getDimension() > 2)
59  {
60  return nullptr;
61  }
62 
63  std::vector<MeshLib::Node*> new_nodes (MeshLib::copyNodeVector(mesh.getNodes()));
64  std::vector<MeshLib::Element*> const& elems (mesh.getElements());
65  std::vector<MeshLib::Element*> new_elems;
66  std::size_t n_elems (mesh.getNumberOfElements());
67  new_elems.reserve(n_elems);
68 
69  for (std::size_t i = 0; i < n_elems; ++i)
70  {
71  new_elems.push_back(
72  createFlippedElement(*elems[i], new_nodes).release());
73  }
74 
75  return std::make_unique<MeshLib::Mesh>("FlippedElementMesh", new_nodes,
76  new_elems, mesh.getProperties());
77 }
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 413 of file Mesh.cpp.

References addPropertyToMesh(), Cell, and Node.

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

415 {
416  DBUG("Found %d elements in the mesh", elements.size());
417 
418  // Store bulk element ids for each of the new elements.
419  std::vector<std::size_t> bulk_element_ids;
420  bulk_element_ids.reserve(elements.size());
421  std::transform(begin(elements), end(elements),
422  std::back_inserter(bulk_element_ids),
423  [&](auto const& e) { return e->getID(); });
424 
425  // original node pointers to newly created nodes.
426  std::unordered_map<const MeshLib::Node*, MeshLib::Node*> nodes_map;
427  nodes_map.reserve(
428  elements.size()); // There will be at least one node per element.
429 
430  for (auto& e : elements)
431  {
432  // For each node find a cloned node in map or create if there is none.
433  unsigned const n_nodes = e->getNumberOfNodes();
434  for (unsigned i = 0; i < n_nodes; ++i)
435  {
436  const MeshLib::Node* n = e->getNode(i);
437  auto const it = nodes_map.find(n);
438  if (it == nodes_map.end())
439  {
440  auto new_node_in_map = nodes_map[n] = new MeshLib::Node(*n);
441  e->setNode(i, new_node_in_map);
442  }
443  else
444  {
445  e->setNode(i, it->second);
446  }
447  }
448  }
449 
450  // Copy the unique nodes pointers.
451  std::vector<MeshLib::Node*> element_nodes;
452  element_nodes.reserve(nodes_map.size());
453  std::transform(begin(nodes_map), end(nodes_map),
454  std::back_inserter(element_nodes),
455  [](auto const& pair) { return pair.second; });
456 
457  // Store bulk node ids for each of the new nodes.
458  std::vector<std::size_t> bulk_node_ids;
459  bulk_node_ids.reserve(nodes_map.size());
460  std::transform(begin(nodes_map), end(nodes_map),
461  std::back_inserter(bulk_node_ids),
462  [](auto const& pair) { return pair.first->getID(); });
463 
464  auto mesh = std::make_unique<MeshLib::Mesh>(
465  std::move(mesh_name), std::move(element_nodes), std::move(elements));
466  assert(mesh != nullptr);
467 
468  addPropertyToMesh(*mesh, "bulk_element_ids", MeshLib::MeshItemType::Cell, 1,
469  bulk_element_ids);
470  addPropertyToMesh(*mesh, "bulk_node_ids", MeshLib::MeshItemType::Node, 1,
471  bulk_node_ids);
472 
473  return mesh;
474 }
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:219

◆ createQuadraticOrderMesh()

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

create a quadratic order mesh from the linear order mesh

Definition at line 91 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().

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

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

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

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

◆ findElementsWithinRadius()

std::vector< std::size_t > MeshLib::findElementsWithinRadius ( Element const &  e,
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:83

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

26 {
27  std::vector<Node*> base_nodes;
28  base_nodes.reserve(elements.size() * 2); // Save some of the realloctions.
29 
30  for (auto* const e : elements)
31  {
32  std::copy(e->getNodes(), e->getNodes() + e->getNumberOfBaseNodes(),
33  std::back_inserter(base_nodes));
34  }
35 
36  BaseLib::makeVectorUnique(base_nodes, [](Node const* a, Node* b) {
37  return a->getID() < b->getID();
38  });
39 
40  return base_nodes;
41 }
void makeVectorUnique(std::vector< T > &v)
Definition: Algorithm.h:177
void copy(MatrixOrVector const &x, MatrixOrVector &y)
Copies x to y.
Definition: LinAlg.h:36

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

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

◆ 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 prism face also in local coordinates.

Definition at line 34 of file MapBulkElementPoint.cpp.

References getBulkElementPoint(), and OGS_FATAL.

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

◆ 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 87 of file MapBulkElementPoint.cpp.

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

91 {
92  auto const* element = mesh.getElement(bulk_element_id);
93  if (element->getCellType() == MeshLib::CellType::QUAD4)
94  {
95  MeshLib::Quad const& quad(*dynamic_cast<MeshLib::Quad const*>(element));
96  return getBulkElementPoint(quad, bulk_face_id, wp);
97  }
98  OGS_FATAL("Wrong cell type '%s' or functionality not yet implemented.",
99  MeshLib::CellType2String(element->getCellType()).c_str());
100 }
const std::string CellType2String(const CellType t)
Given a MeshElemType this returns the appropriate string.
Definition: MeshEnums.cpp:154
MathLib::Point3d getBulkElementPoint(MeshLib::Mesh const &, std::size_t, std::size_t, MathLib::WeightedPoint3D const &)
#define OGS_FATAL(fmt,...)
Definition: Error.h:63

◆ 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 102 of file MapBulkElementPoint.cpp.

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

106 {
107  auto const* element = mesh.getElement(bulk_element_id);
108  if (element->getCellType() == MeshLib::CellType::HEX8)
109  {
110  MeshLib::Hex const& hex(*dynamic_cast<MeshLib::Hex const*>(element));
111  return getBulkElementPoint(hex, bulk_face_id, wp);
112  }
113  if (element->getCellType() == MeshLib::CellType::PRISM6)
114  {
115  MeshLib::Prism const& prism(
116  *dynamic_cast<MeshLib::Prism const*>(element));
117  return getBulkElementPoint(prism, bulk_face_id, wp);
118  }
119  OGS_FATAL("Wrong cell type '%s' or functionality not yet implemented.",
120  MeshLib::CellType2String(element->getCellType()).c_str());
121 }
const std::string CellType2String(const CellType t)
Given a MeshElemType this returns the appropriate string.
Definition: MeshEnums.cpp:154
MathLib::Point3d getBulkElementPoint(MeshLib::Mesh const &, std::size_t, std::size_t, MathLib::WeightedPoint3D const &)
#define OGS_FATAL(fmt,...)
Definition: Error.h:63

◆ getBulkElementPoint() [5/5]

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

Definition at line 124 of file MapBulkElementPoint.cpp.

References MathLib::ORIGIN.

128 {
129  return MathLib::ORIGIN;
130 }
const Point3d ORIGIN
Definition: Point3d.h:27

◆ getGridGeometry()

void MeshLib::getGridGeometry ( MeshLib::MeshElementGrid const &  grid,
GeoLib::GEOObjects geometries,
std::string &  geometry_name 
)

Transfers the grid cells to a geometry. The grid-geometry can be viewed using the DataExplorer. The visualization can be used to explain the algorithm or to find bugs in the algorithm.

Definition at line 206 of file MeshElementGrid.cpp.

References MeshLib::MeshElementGrid::_aabb, MeshLib::MeshElementGrid::_n_steps, MeshLib::MeshElementGrid::_step_sizes, GeoLib::GEOObjects::addPointVec(), GeoLib::GEOObjects::addPolylineVec(), anonymous_namespace{Density100MPa.cpp}::c, GeoLib::AABB::getMinPoint(), GeoLib::GEOObjects::getPointVec(), GeoLib::GEOObjects::mergeGeometries(), and MaterialPropertyLib::name.

209 {
210  std::vector<std::string> cell_names;
211 
212  auto addPoints = [&geometries](
213  MathLib::Point3d const& p, std::array<double, 3> const& d,
214  std::array<std::size_t, 3> const& c, std::string& name) {
215  auto pnts = std::make_unique<std::vector<GeoLib::Point*>>();
216  pnts->push_back(new GeoLib::Point(p[0]+c[0]*d[0], p[1]+c[1]*d[1], p[2]+c[2]*d[2]));
217  pnts->push_back(new GeoLib::Point(p[0]+c[0]*d[0], p[1]+(c[1]+1)*d[1], p[2]+c[2]*d[2]));
218  pnts->push_back(new GeoLib::Point(p[0]+(c[0]+1)*d[0], p[1]+(c[1]+1)*d[1], p[2]+c[2]*d[2]));
219  pnts->push_back(new GeoLib::Point(p[0]+(c[0]+1)*d[0], p[1]+c[1]*d[1], p[2]+c[2]*d[2]));
220  pnts->push_back(new GeoLib::Point(p[0]+c[0]*d[0], p[1]+c[1]*d[1], p[2]+(c[2]+1)*d[2]));
221  pnts->push_back(new GeoLib::Point(p[0]+c[0]*d[0], p[1]+(c[1]+1)*d[1], p[2]+(c[2]+1)*d[2]));
222  pnts->push_back(new GeoLib::Point(p[0]+(c[0]+1)*d[0], p[1]+(c[1]+1)*d[1], p[2]+(c[2]+1)*d[2]));
223  pnts->push_back(new GeoLib::Point(p[0]+(c[0]+1)*d[0], p[1]+c[1]*d[1], p[2]+(c[2]+1)*d[2]));
224  std::array<double,3> ulps; // unit in the last place
225  double const towards(std::numeric_limits<double>::max());
226  ulps[0] = std::nextafter(d[0], towards)-d[0];
227  ulps[1] = std::nextafter(d[1], towards)-d[1];
228  ulps[2] = std::nextafter(d[2], towards)-d[2];
229  double const tolerance(std::min(std::min(ulps[0], ulps[1]), ulps[2]));
230  geometries.addPointVec(std::move(pnts), name, nullptr, tolerance);
231  };
232 
233  for (std::size_t i(0); i<grid._n_steps[0]; ++i) {
234  for (std::size_t j(0); j<grid._n_steps[1]; ++j) {
235  for (std::size_t k(0); k<grid._n_steps[2]; ++k) {
236  cell_names.emplace_back("Grid-"+std::to_string(i)+"-"
237  +std::to_string(j)+"-"+std::to_string(k));
238  addPoints(grid._aabb.getMinPoint(), grid._step_sizes,
239  {{i, j, k}}, cell_names.back());
240  auto plys = std::make_unique<std::vector<GeoLib::Polyline*>>();
241  auto & points = *geometries.getPointVec(cell_names.back());
242 
243  auto* ply_bottom(new GeoLib::Polyline(points));
244  for (std::size_t l(0); l < 4; ++l)
245  ply_bottom->addPoint(l);
246  ply_bottom->addPoint(0); // close to bottom surface
247  plys->push_back(ply_bottom);
248 
249  auto* ply_top(new GeoLib::Polyline(points));
250  for (std::size_t l(4); l<8; ++l)
251  ply_top->addPoint(l);
252  ply_top->addPoint(4); // close to top surface
253  plys->push_back(ply_top);
254 
255  auto* ply_04(new GeoLib::Polyline(points));
256  ply_04->addPoint(0);
257  ply_04->addPoint(4);
258  plys->push_back(ply_04);
259 
260  auto* ply_15(new GeoLib::Polyline(points));
261  ply_15->addPoint(1);
262  ply_15->addPoint(5);
263  plys->push_back(ply_15);
264 
265  auto* ply_26(new GeoLib::Polyline(points));
266  ply_26->addPoint(2);
267  ply_26->addPoint(6);
268  plys->push_back(ply_26);
269 
270  auto* ply_37(new GeoLib::Polyline(points));
271  ply_37->addPoint(3);
272  ply_37->addPoint(7);
273  plys->push_back(ply_37);
274 
275  geometries.addPolylineVec(std::move(plys), cell_names.back(),
276  nullptr);
277  }
278  }
279  }
280  if (geometries.mergeGeometries(cell_names, geometry_name) == 2)
281  geometry_name = cell_names.front();
282 }
void addPointVec(std::unique_ptr< std::vector< Point *>> points, std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> pnt_names=nullptr, double eps=sqrt(std::numeric_limits< double >::epsilon()))
Definition: GEOObjects.cpp:45
void addPolylineVec(std::unique_ptr< std::vector< Polyline *>> lines, const std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> ply_names=nullptr)
Definition: GEOObjects.cpp:136
const std::vector< Point * > * getPointVec(const std::string &name) const
Definition: GEOObjects.cpp:63
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition: Polyline.h:50
static const double p
int mergeGeometries(std::vector< std::string > const &names, std::string &merged_geo_name)
Definition: GEOObjects.cpp:443

◆ getMeshElemTypes()

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

Returns a vector of all mesh element types.

Definition at line 130 of file MeshEnums.cpp.

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

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

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

◆ getMeshElemTypeStringsShort()

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

Returns a vector of strings of mesh element types.

Definition at line 144 of file MeshEnums.cpp.

References getMeshElemTypes(), and MeshElemType2StringShort().

Referenced by main().

145 {
146  std::vector<std::string> vec;
147  for (MeshElemType eleType : getMeshElemTypes())
148  {
149  vec.push_back(MeshElemType2StringShort(eleType));
150  }
151  return vec;
152 }
std::vector< MeshElemType > getMeshElemTypes()
Returns a vector of all mesh element types.
Definition: MeshEnums.cpp:130
const std::string MeshElemType2StringShort(const MeshElemType t)
Given a MeshElemType this returns the appropriate string with a short name.
Definition: MeshEnums.cpp:56
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 261 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.

265 {
266  if (property_name.empty())
267  {
268  OGS_FATAL(
269  "Trying to get or to create a mesh property with empty name.");
270  }
271 
272  auto numberOfMeshItems = [&mesh, &item_type]() -> std::size_t {
273  switch (item_type)
274  {
276  return mesh.getNumberOfElements();
278  return mesh.getNumberOfNodes();
280  return 0; // For the integration point data the size is
281  // variable
282  default:
283  OGS_FATAL(
284  "MeshLib::getOrCreateMeshProperty cannot handle other "
285  "types than Node, Cell, or IntegrationPoint.");
286  }
287  return 0;
288  };
289 
290  if (mesh.getProperties().existsPropertyVector<T>(property_name))
291  {
292  auto result =
293  mesh.getProperties().template getPropertyVector<T>(property_name);
294  assert(result);
295  if (item_type != MeshItemType::IntegrationPoint)
296  {
297  // Test the size if number of mesh items is known, which is not the
298  // case for the integration point data.
299  assert(result->size() ==
300  numberOfMeshItems() * number_of_components);
301  }
302  return result;
303  }
304 
305  auto result = mesh.getProperties().template createNewPropertyVector<T>(
306  property_name, item_type, number_of_components);
307  assert(result);
308  result->resize(numberOfMeshItems() * number_of_components);
309  return result;
310 }
#define OGS_FATAL(fmt,...)
Definition: Error.h:63

◆ getUniqueNodes()

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

Create a vector of unique nodes used by given elements.

Definition at line 164 of file NodeSearch.cpp.

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

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

226 {
227  for(std::size_t i(0); i<e.getNumberOfBaseNodes(); ++i) {
228  if (MathLib::sqrDist2d(p, *e.getNode(i)) <
229  std::numeric_limits<double>::epsilon())
230  {
231  return true;
232  }
233  }
234 
235  if (e.getGeomType() == MeshElemType::TRIANGLE)
236  {
237  MathLib::Point3d const& n0(*e.getNode(0));
238  MathLib::Point3d const& n1(*e.getNode(1));
239  MathLib::Point3d const& n2(*e.getNode(2));
240 
241  return MathLib::isPointInTriangleXY(p, n0, n1, n2);
242  }
243  if (e.getGeomType() == MeshElemType::QUAD)
244  {
245  MathLib::Point3d const& n0(*e.getNode(0));
246  MathLib::Point3d const& n1(*e.getNode(1));
247  MathLib::Point3d const& n2(*e.getNode(2));
248  MathLib::Point3d const& n3(*e.getNode(3));
249 
250  return MathLib::isPointInTriangleXY(p, n0, n1, n2) ||
251  MathLib::isPointInTriangleXY(p, n0, n2, n3);
252  }
253 
254  WARN("isPointInElementXY: element type '%s' is not supported.",
255  MeshLib::MeshElemType2String(e.getGeomType()).c_str());
256  return false;
257 }
double sqrDist2d(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition: Point3d.h:58
const std::string MeshElemType2String(const MeshElemType t)
Given a MeshElemType this returns the appropriate string.
Definition: MeshEnums.cpp:19
static const double p
bool isPointInTriangleXY(MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c)

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

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

Referenced by MeshGeoToolsLib::appendLinesAlongPolylines(), ProcessLib::createDeactivatedSubdomain(), ProcessLib::HydroMechanics::createHydroMechanicsProcess(), ProcessLib::LIE::HydroMechanics::createHydroMechanicsProcess(), ProcessLib::LiquidFlow::createLiquidFlowProcess(), MaterialPropertyLib::createMaterialSpatialDistributionMap(), ProcessLib::PhaseField::createPhaseFieldProcess(), MaterialLib::PorousMedium::createPorousMediaProperties(), ProcessLib::RichardsFlow::createRichardsFlowProcess(), 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().

404 {
405  auto const& properties = mesh.getProperties();
406  return properties.existsPropertyVector<int>("MaterialIDs",
408  ? properties.getPropertyVector<int>(
409  "MaterialIDs", MeshLib::MeshItemType::Cell, 1)
410  : nullptr;
411 }

◆ MeshElemType2String()

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

Given a MeshElemType this returns the appropriate string.

Definition at line 19 of file MeshEnums.cpp.

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

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

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

◆ MeshElemType2StringShort()

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

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

Definition at line 56 of file MeshEnums.cpp.

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

Referenced by getMeshElemTypeStringsShort().

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

◆ MeshQualityType2String()

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

Definition at line 183 of file MeshEnums.cpp.

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

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

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

◆ 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 31 of file moveMeshNodes.h.

Referenced by main().

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

◆ operator!=()

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

Definition at line 197 of file Mesh.h.

References scaleMeshPropertyVector().

198 {
199  return !(a == b);
200 }

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

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

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

◆ operator<<() [2/3]

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

Definition at line 29 of file Location.cpp.

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

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

◆ operator<<() [3/3]

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

Definition at line 208 of file Element.cpp.

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

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

209 {
210  os << "Element #" << e._id << " @ " << &e << " with " << e.getNumberOfNeighbors()
211  << " neighbours\n";
212 
213  unsigned const nnodes = e.getNumberOfNodes();
214  MeshLib::Node* const* const nodes = e.getNodes();
215  os << "MeshElemType: "
216  << static_cast<std::underlying_type<MeshElemType>::type>(e.getGeomType())
217  << " with " << nnodes << " nodes: { ";
218  for (unsigned n = 0; n < nnodes; ++n)
219  os << nodes[n]->getID() << " @ " << nodes[n] << " ";
220  os << "}\n";
221  return os;
222 }

◆ operator==()

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

Meshes are equal if their id's are equal.

Definition at line 192 of file Mesh.h.

References MeshLib::Mesh::getID().

193 {
194  return a.getID() == b.getID();
195 }

◆ 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(const std::vector< MeshLib::Element *> &elements, const std::vector< MeshLib::Node *> &nodes)
T scalarProduct(T const *const v0, T const *const v1)
Definition: MathTools.h:28

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

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

◆ removeNodes()

MeshLib::Mesh * MeshLib::removeNodes ( const MeshLib::Mesh mesh,
const std::vector< std::size_t > &  removed_node_ids,
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
removed_node_idsa vector of node indices to be removed
new_mesh_namea new mesh name
Returns
a new mesh object

Definition at line 96 of file RemoveMeshComponents.cpp.

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

Referenced by LayeredMeshGenerator::getMesh(), and MeshLib::MeshSurfaceExtraction::getMeshBoundary().

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

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

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

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

389 {
390  if (!mesh.getProperties().existsPropertyVector<double>(property_name))
391  {
392  WARN("Did not find PropertyVector '%s' for scaling.",
393  property_name.c_str());
394  return;
395  }
396  for (auto& v :
397  *mesh.getProperties().getPropertyVector<double>(property_name))
398  {
399  v *= factor;
400  }
401 }
MeshLib::Properties & getProperties()
Definition: Mesh.h:134
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 93 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().

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

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