OGS
MeshLib::ElementStatus Class Referencefinal

Detailed Description

Definition at line 14 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.
 ElementStatus (MeshLib::Mesh const *const mesh, std::vector< int > const &vec_inactive_matIDs)
 Constructor taking a vector of inactive material IDs.
std::vector< MeshLib::Element * > const & getActiveElements () const
 Returns a vector of active element IDs.
std::vector< MeshLib::Node * > const & getActiveNodes () const
 Returns a vector of active node IDs.
bool isActive (std::size_t i) const
 Returns the status of element i.
bool isActiveNode (MeshLib::Node const *node) const
 Returns the status of the given node.
std::size_t getNumberOfActiveNodes () const
 Returns the total number of active nodes.
std::size_t getNumberOfActiveElements () const
 Returns the total number of active elements.

Private Member Functions

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

Private Attributes

MeshLib::Mesh const *const _mesh
 The mesh for which the element status is administrated.
std::vector< bool > _element_status
 Element status for each mesh element (active/inactive = true/false)
std::vector< unsigned char > _active_nodes
 Node status for each mesh node (value = number of active elements connected to node, 0 means inactive)
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 12 of file ElementStatus.cpp.

13 : _mesh(mesh),
14 _element_status(mesh->getNumberOfElements(), true),
15 _hasAnyInactive(hasAnyInactive)
16{
17 const std::vector<MeshLib::Node*>& nodes(_mesh->getNodes());
18 std::transform(begin(nodes), end(nodes), back_inserter(_active_nodes),
19 [this](Node const* const n)
20 { return _mesh->getElementsConnectedToNode(*n).size(); });
21}
MeshLib::Mesh const *const _mesh
The mesh for which the element status is administrated.
std::vector< bool > _element_status
Element status for each mesh element (active/inactive = true/false)
std::vector< unsigned char > _active_nodes
Node status for each mesh node (value = number of active elements connected to node,...

References _active_nodes, _element_status, _hasAnyInactive, and _mesh.

Referenced by ElementStatus().

◆ 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 23 of file ElementStatus.cpp.

25 : ElementStatus(mesh, !vec_inactive_matIDs.empty())
26{
27 if (mesh->getProperties().existsPropertyVector<int>("MaterialIDs"))
28 {
29 auto* const materialIds =
30 mesh->getProperties().getPropertyVector<int>("MaterialIDs");
31 for (auto material_id : vec_inactive_matIDs)
32 {
33 for (auto e : _mesh->getElements())
34 {
35 if ((*materialIds)[e->getID()] == material_id)
36 {
37 setElementStatus(e->getID(), false);
38 }
39 }
40 }
41 }
42
44 const std::size_t nElems(_mesh->getNumberOfElements());
45 for (std::size_t i = 0; i < nElems; ++i)
46 {
47 if (_element_status[i])
48 {
49 _vec_active_eles.push_back(
50 const_cast<MeshLib::Element*>(_mesh->getElement(i)));
51 }
52 }
53
55 const std::size_t nNodes(_mesh->getNumberOfNodes());
56 for (std::size_t i = 0; i < nNodes; ++i)
57 {
58 if (_active_nodes[i] > 0)
59 {
60 _vec_active_nodes.push_back(
61 const_cast<MeshLib::Node*>(_mesh->getNode(i)));
62 }
63 }
64
65 DBUG(
66 "Deactivated {:d} materials and resulting active {:d} nodes and {:d} "
67 "elements",
68 vec_inactive_matIDs.size(),
69 _vec_active_nodes.size(),
70 _vec_active_eles.size());
71}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
std::vector< MeshLib::Element * > _vec_active_eles
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

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

Member Function Documentation

◆ getActiveElements()

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

Returns a vector of active element IDs.

Definition at line 73 of file ElementStatus.cpp.

74{
76 {
77 return _vec_active_eles;
78 }
79
80 return _mesh->getElements();
81}

References _hasAnyInactive, _mesh, _vec_active_eles, and getActiveElements().

Referenced by getActiveElements().

◆ getActiveNodes()

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

Returns a vector of active node IDs.

Definition at line 83 of file ElementStatus.cpp.

84{
86 {
87 return _vec_active_nodes;
88 }
89
90 return _mesh->getNodes();
91}

References _hasAnyInactive, _mesh, _vec_active_nodes, and getActiveNodes().

Referenced by getActiveNodes().

◆ getNumberOfActiveElements()

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

Returns the total number of active elements.

Definition at line 99 of file ElementStatus.cpp.

100{
101 return static_cast<std::size_t>(
102 std::count(_element_status.cbegin(), _element_status.cend(), true));
103}

References _element_status, and getNumberOfActiveElements().

Referenced by getNumberOfActiveElements().

◆ getNumberOfActiveNodes()

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

Returns the total number of active nodes.

Definition at line 93 of file ElementStatus.cpp.

94{
95 return _active_nodes.size() -
96 std::count(_active_nodes.cbegin(), _active_nodes.cend(), 0);
97}

References _active_nodes, and getNumberOfActiveNodes().

Referenced by getNumberOfActiveNodes().

◆ isActive()

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

Returns the status of element i.

Definition at line 33 of file ElementStatus.h.

33{ 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 124 of file ElementStatus.cpp.

125{
126 return _active_nodes[node->getID()] > 0;
127}

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

Referenced by isActiveNode().

◆ setElementStatus()

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

Sets the status of element i.

Definition at line 105 of file ElementStatus.cpp.

106{
107 if (_element_status[i] != status)
108 {
109 const int change = (status) ? 1 : -1;
110 _element_status[i] = status;
111 const unsigned nElemNodes(_mesh->getElement(i)->getNumberOfNodes());
112 MeshLib::Node const* const* const nodes =
113 _mesh->getElement(i)->getNodes();
114 for (unsigned j = 0; j < nElemNodes; ++j)
115 {
116 assert(_active_nodes[j] < 255); // if one node has >255 connected
117 // elements the data type is too
118 // small
119 _active_nodes[nodes[j]->getID()] += change;
120 }
121 }
122}
std::size_t getID() const

References _active_nodes, _element_status, _mesh, MathLib::Point3dWithID::getID(), and setElementStatus().

Referenced by setElementStatus().

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 53 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 51 of file ElementStatus.h.

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

◆ _hasAnyInactive

bool const MeshLib::ElementStatus::_hasAnyInactive
private

Definition at line 55 of file ElementStatus.h.

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

◆ _mesh

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

The mesh for which the element status is administrated.

Definition at line 49 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 57 of file ElementStatus.h.

Referenced by getActiveElements().

◆ _vec_active_nodes

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

Definition at line 56 of file ElementStatus.h.

Referenced by getActiveNodes().


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