OGS
MeshLib::MeshSubset Class Reference

Detailed Description

A subset of nodes on a single mesh.

Definition at line 25 of file MeshSubset.h.

#include <MeshSubset.h>

Collaboration diagram for MeshLib::MeshSubset:
[legend]

Public Member Functions

 MeshSubset (const Mesh &msh, std::vector< Node * > const &vec_items, const bool use_taylor_hood_elements=false)
 
std::size_t getMeshID () const
 return this mesh ID More...
 
std::size_t getNumberOfNodes () const
 return the number of registered nodes More...
 
std::size_t getNodeID (std::size_t const i) const
 
bool useTaylorHoodElements () const
 
std::vector< Element * >::const_iterator elementsBegin () const
 
std::vector< Element * >::const_iterator elementsEnd () const
 
std::vector< Node * > const & getNodes () const
 
Mesh const & getMesh () const
 

Private Attributes

Mesh const & _msh
 
std::vector< Node * > const & _nodes
 
bool const _use_taylor_hood_elements
 

Constructor & Destructor Documentation

◆ MeshSubset()

MeshLib::MeshSubset::MeshSubset ( const Mesh msh,
std::vector< Node * > const &  vec_items,
const bool  use_taylor_hood_elements = false 
)
inline

Construct a mesh subset from vector of nodes on the given mesh.

Parameters
mshMesh
vec_itemsVector of Node pointers.
use_taylor_hood_elementsFlag to indicate whether the Taylor-Hood elements are used.

Definition at line 33 of file MeshSubset.h.

35  : _msh(msh),
36  _nodes(vec_items),
37  _use_taylor_hood_elements(use_taylor_hood_elements)
38  {
39  // If the mesh nodes and the given nodes point to the same vector, they
40  // must be equal.
41  if (&_msh.getNodes() == &_nodes)
42  {
43  return;
44  }
45 
46  //
47  // Testing if the given nodes belong to the mesh.
48  //
49  {
50  // Need sorted version of the large vector.
51  auto sorted_nodes = _msh.getNodes(); // full copy of pointers.
52  sort(begin(sorted_nodes), end(sorted_nodes));
53 
54  // Then proceed with the search function.
55  auto node_is_part_of_mesh =
56  [&mesh_nodes = sorted_nodes](MeshLib::Node* const& n)
57  {
58  auto it = lower_bound(begin(mesh_nodes), end(mesh_nodes), n);
59  if (it == end(mesh_nodes))
60  {
61  ERR("A node {:d} ({:g}, {:g}, {:g}) in mesh subset is not "
62  "a part of the mesh.",
63  n->getID(), (*n)[0], (*n)[1], (*n)[2]);
64  return false;
65  }
66  return true;
67  };
68  if (!std::all_of(begin(_nodes), end(_nodes), node_is_part_of_mesh))
69  {
70  OGS_FATAL("The mesh subset construction failed.");
71  }
72  }
73  }
#define OGS_FATAL(...)
Definition: Error.h:26
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
std::vector< Node * > const & _nodes
Definition: MeshSubset.h:108
Mesh const & _msh
Definition: MeshSubset.h:107
bool const _use_taylor_hood_elements
Definition: MeshSubset.h:109
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:95
constexpr bool all_of(List const &values)
Checks if all of the elements in the given list are true.
Definition: Algorithm.h:341

References _msh, _nodes, BaseLib::all_of(), ERR(), MeshLib::Mesh::getNodes(), and OGS_FATAL.

Member Function Documentation

◆ elementsBegin()

std::vector<Element*>::const_iterator MeshLib::MeshSubset::elementsBegin ( ) const
inline

Definition at line 92 of file MeshSubset.h.

93  {
94  return _msh.getElements().cbegin();
95  }
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:98

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

◆ elementsEnd()

std::vector<Element*>::const_iterator MeshLib::MeshSubset::elementsEnd ( ) const
inline

Definition at line 97 of file MeshSubset.h.

98  {
99  return _msh.getElements().cend();
100  }

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

◆ getMesh()

Mesh const& MeshLib::MeshSubset::getMesh ( ) const
inline

Definition at line 104 of file MeshSubset.h.

104 { return _msh; }

References _msh.

Referenced by ProcessLib::createSourceTerm(), and NumLib::MeshComponentMap::getSubset().

◆ getMeshID()

◆ getNodeID()

std::size_t MeshLib::MeshSubset::getNodeID ( std::size_t const  i) const
inline

Returns the global node id Node::getID() of i-th node in the mesh subset.

Precondition
The _nodes vector must be of size > i.

Definition at line 84 of file MeshSubset.h.

85  {
86  assert(i < _nodes.size());
87  return _nodes[i]->getID();
88  }

References _nodes.

◆ getNodes()

std::vector<Node*> const& MeshLib::MeshSubset::getNodes ( ) const
inline

Definition at line 102 of file MeshSubset.h.

102 { return _nodes; }

References _nodes.

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

◆ getNumberOfNodes()

std::size_t MeshLib::MeshSubset::getNumberOfNodes ( ) const
inline

return the number of registered nodes

Definition at line 79 of file MeshSubset.h.

79 { return _nodes.size(); }

References _nodes.

◆ useTaylorHoodElements()

bool MeshLib::MeshSubset::useTaylorHoodElements ( ) const
inline

Definition at line 90 of file MeshSubset.h.

90 { return _use_taylor_hood_elements; }

References _use_taylor_hood_elements.

Member Data Documentation

◆ _msh

Mesh const& MeshLib::MeshSubset::_msh
private

Definition at line 107 of file MeshSubset.h.

Referenced by MeshSubset(), elementsBegin(), elementsEnd(), getMesh(), and getMeshID().

◆ _nodes

std::vector<Node*> const& MeshLib::MeshSubset::_nodes
private

Definition at line 108 of file MeshSubset.h.

Referenced by MeshSubset(), getNodeID(), getNodes(), and getNumberOfNodes().

◆ _use_taylor_hood_elements

bool const MeshLib::MeshSubset::_use_taylor_hood_elements
private

Definition at line 109 of file MeshSubset.h.

Referenced by useTaylorHoodElements().


The documentation for this class was generated from the following file: