OGS
ElementStatus.cpp
Go to the documentation of this file.
1
15#include "ElementStatus.h"
16
17#include "Elements/Element.h"
18#include "Mesh.h"
19#include "MeshLib/Node.h"
20
21namespace MeshLib
22{
23ElementStatus::ElementStatus(Mesh const* const mesh, bool hasAnyInactive)
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}
33
35 std::vector<int> const& vec_inactive_matIDs)
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}
83
84std::vector<MeshLib::Element*> const& ElementStatus::getActiveElements() const
85{
87 {
88 return _vec_active_eles;
89 }
90
91 return _mesh->getElements();
92}
93
94std::vector<MeshLib::Node*> const& ElementStatus::getActiveNodes() const
95{
97 {
98 return _vec_active_nodes;
99 }
100
101 return _mesh->getNodes();
102}
103
105{
106 return _active_nodes.size() -
107 std::count(_active_nodes.cbegin(), _active_nodes.cend(), 0);
108}
109
111{
112 return static_cast<std::size_t>(
113 std::count(_element_status.cbegin(), _element_status.cend(), true));
114}
115
116void ElementStatus::setElementStatus(std::size_t i, bool status)
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 =
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}
134
136{
137 return _active_nodes[node->getID()] > 0;
138}
139
140} // namespace MeshLib
Definition of the ElementStatus class.
Definition of the Element class.
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition: Logging.h:30
Definition of the Mesh class.
Definition of the Node class.
std::size_t getID() const
Definition: Point3dWithID.h:62
std::vector< MeshLib::Element * > _vec_active_eles
Definition: ElementStatus.h:68
bool isActiveNode(MeshLib::Node const *node) const
Returns the status of the given node.
void setElementStatus(std::size_t i, bool status)
Sets the status of element i.
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
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::vector< MeshLib::Node * > const & getActiveNodes() const
Returns a vector of active node IDs.
std::vector< MeshLib::Element * > const & getActiveElements() const
Returns a vector of active element IDs.
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< unsigned char > _active_nodes
Node status for each mesh node (value = number of active elements connected to node,...
Definition: ElementStatus.h:64
virtual unsigned getNumberOfNodes() const =0
virtual Node *const * getNodes() const =0
Get array of element nodes.
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:102
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:105
const Node * getNode(std::size_t idx) const
Get the node with the given index.
Definition: Mesh.h:87
Properties & getProperties()
Definition: Mesh.h:130
const Element * getElement(std::size_t idx) const
Get the element with the given index.
Definition: Mesh.h:90
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition: Mesh.h:96
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
Definition: Mesh.cpp:246
std::size_t getNumberOfElements() const
Get the number of elements.
Definition: Mesh.h:93
bool existsPropertyVector(std::string_view name) const
PropertyVector< T > const * getPropertyVector(std::string_view name) const