OGS
MeshLib::ElementStatus Class Referencefinal

Detailed Description

Definition at line 25 of file ElementStatus.h.

#include <ElementStatus.h>

Collaboration diagram for MeshLib::ElementStatus:
[legend]

Public Member Functions

 ElementStatus (MeshLib::Mesh const *const mesh, bool hasAnyInactive=false)
 Constructor assuming all nodes and elements. More...
 
 ElementStatus (MeshLib::Mesh const *const mesh, std::vector< int > const &vec_inactive_matIDs)
 Constructor taking a vector of inactive material IDs. More...
 
std::vector< MeshLib::Element * > const & getActiveElements () const
 Returns a vector of active element IDs. More...
 
std::vector< MeshLib::Node * > const & getActiveNodes () const
 Returns a vector of active node IDs. More...
 
bool isActive (std::size_t i) const
 Returns the status of element i. More...
 
bool isActiveNode (MeshLib::Node const *node) const
 Returns the status of the given node. More...
 
std::size_t getNumberOfActiveNodes () const
 Returns the total number of active nodes. More...
 
std::size_t getNumberOfActiveElements () const
 Returns the total number of active elements. More...
 

Private Member Functions

void setElementStatus (std::size_t i, bool status)
 Sets the status of element i. More...
 

Private Attributes

MeshLib::Mesh const *const _mesh
 The mesh for which the element status is administrated. More...
 
std::vector< bool > _element_status
 Element status for each mesh element (active/inactive = true/false) More...
 
std::vector< unsigned char > _active_nodes
 Node status for each mesh node (value = number of active elements connected to node, 0 means inactive) More...
 
bool const _hasAnyInactive
 
std::vector< MeshLib::Node * > _vec_active_nodes
 
std::vector< MeshLib::Element * > _vec_active_eles
 

Constructor & Destructor Documentation

◆ ElementStatus() [1/2]

MeshLib::ElementStatus::ElementStatus ( MeshLib::Mesh const *const  mesh,
bool  hasAnyInactive = false 
)
explicit

Constructor assuming all nodes and elements.

Definition at line 23 of file ElementStatus.cpp.

24  : _mesh(mesh),
25  _element_status(mesh->getNumberOfElements(), true),
26  _hasAnyInactive(hasAnyInactive)
27 {
28  const std::vector<MeshLib::Node*>& nodes(_mesh->getNodes());
29  std::transform(begin(nodes), end(nodes), back_inserter(_active_nodes),
30  [this](Node const* const n)
31  { return _mesh->getElementsConnectedToNode(*n).size(); });
32 }
MeshLib::Mesh const *const _mesh
The mesh for which the element status is administrated.
Definition: ElementStatus.h:60
bool const _hasAnyInactive
Definition: ElementStatus.h:66
std::vector< bool > _element_status
Element status for each mesh element (active/inactive = true/false)
Definition: ElementStatus.h:62
std::vector< unsigned char > _active_nodes
Node status for each mesh node (value = number of active elements connected to node,...
Definition: ElementStatus.h:64
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:95
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
Definition: Mesh.cpp:232

References _active_nodes, _mesh, MeshLib::Mesh::getElementsConnectedToNode(), and MeshLib::Mesh::getNodes().

◆ ElementStatus() [2/2]

MeshLib::ElementStatus::ElementStatus ( MeshLib::Mesh const *const  mesh,
std::vector< int > const &  vec_inactive_matIDs 
)

Constructor taking a vector of inactive material IDs.

Definition at line 34 of file ElementStatus.cpp.

36  : ElementStatus(mesh, !vec_inactive_matIDs.empty())
37 {
38  if (mesh->getProperties().existsPropertyVector<int>("MaterialIDs"))
39  {
40  auto* const materialIds =
41  mesh->getProperties().getPropertyVector<int>("MaterialIDs");
42  for (auto material_id : vec_inactive_matIDs)
43  {
44  for (auto e : _mesh->getElements())
45  {
46  if ((*materialIds)[e->getID()] == material_id)
47  {
48  setElementStatus(e->getID(), false);
49  }
50  }
51  }
52  }
53 
55  const std::size_t nElems(_mesh->getNumberOfElements());
56  for (std::size_t i = 0; i < nElems; ++i)
57  {
58  if (_element_status[i])
59  {
60  _vec_active_eles.push_back(
61  const_cast<MeshLib::Element*>(_mesh->getElement(i)));
62  }
63  }
64 
66  const std::size_t nNodes(_mesh->getNumberOfNodes());
67  for (std::size_t i = 0; i < nNodes; ++i)
68  {
69  if (_active_nodes[i] > 0)
70  {
71  _vec_active_nodes.push_back(
72  const_cast<MeshLib::Node*>(_mesh->getNode(i)));
73  }
74  }
75 
76  DBUG(
77  "Deactivated {:d} materials and resulting active {:d} nodes and {:d} "
78  "elements",
79  vec_inactive_matIDs.size(),
80  _vec_active_nodes.size(),
81  _vec_active_eles.size());
82 }
void DBUG(char const *fmt, Args const &... args)
Definition: Logging.h:27
std::vector< MeshLib::Element * > _vec_active_eles
Definition: ElementStatus.h:68
void setElementStatus(std::size_t i, bool status)
Sets the status of element i.
ElementStatus(MeshLib::Mesh const *const mesh, bool hasAnyInactive=false)
Constructor assuming all nodes and elements.
std::size_t getNumberOfActiveElements() const
Returns the total number of active elements.
std::size_t getNumberOfActiveNodes() const
Returns the total number of active nodes.
std::vector< MeshLib::Node * > _vec_active_nodes
Definition: ElementStatus.h:67
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:98
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition: Mesh.h:89
const Element * getElement(std::size_t idx) const
Get the element with the given index.
Definition: Mesh.h:77
const Node * getNode(std::size_t idx) const
Get the node with the given index.
Definition: Mesh.h:74
std::size_t getNumberOfElements() const
Get the number of elements.
Definition: Mesh.h:86

References _active_nodes, _element_status, _mesh, _vec_active_eles, _vec_active_nodes, DBUG(), MeshLib::Properties::existsPropertyVector(), MeshLib::Mesh::getElement(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getNode(), getNumberOfActiveElements(), getNumberOfActiveNodes(), MeshLib::Mesh::getNumberOfElements(), MeshLib::Mesh::getNumberOfNodes(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), and setElementStatus().

Member Function Documentation

◆ getActiveElements()

std::vector< MeshLib::Element * > const & MeshLib::ElementStatus::getActiveElements ( ) const

Returns a vector of active element IDs.

Definition at line 84 of file ElementStatus.cpp.

85 {
86  if (_hasAnyInactive)
87  {
88  return _vec_active_eles;
89  }
90 
91  return _mesh->getElements();
92 }

References _hasAnyInactive, _mesh, _vec_active_eles, and MeshLib::Mesh::getElements().

◆ getActiveNodes()

std::vector< MeshLib::Node * > const & MeshLib::ElementStatus::getActiveNodes ( ) const

Returns a vector of active node IDs.

Definition at line 94 of file ElementStatus.cpp.

95 {
96  if (_hasAnyInactive)
97  {
98  return _vec_active_nodes;
99  }
100 
101  return _mesh->getNodes();
102 }

References _hasAnyInactive, _mesh, _vec_active_nodes, and MeshLib::Mesh::getNodes().

◆ getNumberOfActiveElements()

std::size_t MeshLib::ElementStatus::getNumberOfActiveElements ( ) const

Returns the total number of active elements.

Definition at line 110 of file ElementStatus.cpp.

111 {
112  return static_cast<std::size_t>(
113  std::count(_element_status.cbegin(), _element_status.cend(), true));
114 }

References _element_status.

Referenced by ElementStatus().

◆ getNumberOfActiveNodes()

std::size_t MeshLib::ElementStatus::getNumberOfActiveNodes ( ) const

Returns the total number of active nodes.

Definition at line 104 of file ElementStatus.cpp.

105 {
106  return _active_nodes.size() -
107  std::count(_active_nodes.cbegin(), _active_nodes.cend(), 0);
108 }

References _active_nodes.

Referenced by ElementStatus().

◆ isActive()

bool MeshLib::ElementStatus::isActive ( std::size_t  i) const
inline

Returns the status of element i.

Definition at line 44 of file ElementStatus.h.

44 { return _element_status[i]; }

References _element_status.

◆ isActiveNode()

bool MeshLib::ElementStatus::isActiveNode ( MeshLib::Node const *  node) const

Returns the status of the given node.

Definition at line 135 of file ElementStatus.cpp.

136 {
137  return _active_nodes[node->getID()] > 0;
138 }

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

◆ setElementStatus()

void MeshLib::ElementStatus::setElementStatus ( std::size_t  i,
bool  status 
)
private

Sets the status of element i.

Definition at line 116 of file ElementStatus.cpp.

117 {
118  if (_element_status[i] != status)
119  {
120  const int change = (status) ? 1 : -1;
121  _element_status[i] = status;
122  const unsigned nElemNodes(_mesh->getElement(i)->getNumberOfNodes());
123  MeshLib::Node const* const* const nodes =
124  _mesh->getElement(i)->getNodes();
125  for (unsigned j = 0; j < nElemNodes; ++j)
126  {
127  assert(_active_nodes[j] < 255); // if one node has >255 connected
128  // elements the data type is too
129  // small
130  _active_nodes[nodes[j]->getID()] += change;
131  }
132  }
133 }
std::size_t getID() const
Definition: Point3dWithID.h:62
virtual Node *const * getNodes() const =0
Get array of element nodes.
virtual unsigned getNumberOfNodes() const =0

References _active_nodes, _element_status, _mesh, MeshLib::Mesh::getElement(), MathLib::Point3dWithID::getID(), MeshLib::Element::getNodes(), and MeshLib::Element::getNumberOfNodes().

Referenced by ElementStatus().

Member Data Documentation

◆ _active_nodes

std::vector<unsigned char> MeshLib::ElementStatus::_active_nodes
private

Node status for each mesh node (value = number of active elements connected to node, 0 means inactive)

Definition at line 64 of file ElementStatus.h.

Referenced by ElementStatus(), getNumberOfActiveNodes(), isActiveNode(), and setElementStatus().

◆ _element_status

std::vector<bool> MeshLib::ElementStatus::_element_status
private

Element status for each mesh element (active/inactive = true/false)

Definition at line 62 of file ElementStatus.h.

Referenced by ElementStatus(), getNumberOfActiveElements(), isActive(), and setElementStatus().

◆ _hasAnyInactive

bool const MeshLib::ElementStatus::_hasAnyInactive
private

Definition at line 66 of file ElementStatus.h.

Referenced by getActiveElements(), and getActiveNodes().

◆ _mesh

MeshLib::Mesh const* const MeshLib::ElementStatus::_mesh
private

The mesh for which the element status is administrated.

Definition at line 60 of file ElementStatus.h.

Referenced by ElementStatus(), getActiveElements(), getActiveNodes(), and setElementStatus().

◆ _vec_active_eles

std::vector<MeshLib::Element*> MeshLib::ElementStatus::_vec_active_eles
private

Definition at line 68 of file ElementStatus.h.

Referenced by ElementStatus(), and getActiveElements().

◆ _vec_active_nodes

std::vector<MeshLib::Node*> MeshLib::ElementStatus::_vec_active_nodes
private

Definition at line 67 of file ElementStatus.h.

Referenced by ElementStatus(), and getActiveNodes().


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