-
Notifications
You must be signed in to change notification settings - Fork 239
/
Copy pathElementStatus.cpp
135 lines (117 loc) · 4.24 KB
/
ElementStatus.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
* \file ElementStatus.cpp
* \author Karsten Rink
* \date 2012-12-18
* \brief Implementation of the ElementStatus class.
*
* \copyright
* Copyright (c) 2012-2018, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include "ElementStatus.h"
#include "Mesh.h"
#include "MeshLib/Node.h"
#include "Elements/Element.h"
namespace MeshLib {
ElementStatus::ElementStatus(Mesh const* const mesh, bool hasAnyInactive)
: _mesh(mesh),
_element_status(mesh->getNumberOfElements(), true),
_hasAnyInactive(hasAnyInactive)
{
const std::vector<MeshLib::Node*>& nodes(_mesh->getNodes());
for (auto node : nodes)
_active_nodes.push_back(node->getNumberOfElements());
}
ElementStatus::ElementStatus(Mesh const* const mesh,
std::vector<int> const& vec_inactive_matIDs)
: ElementStatus(mesh, !vec_inactive_matIDs.empty())
{
if (mesh->getProperties().existsPropertyVector<int>("MaterialIDs"))
{
auto* const materialIds =
mesh->getProperties().getPropertyVector<int>("MaterialIDs");
for (auto material_id : vec_inactive_matIDs) {
for (auto e : _mesh->getElements()) {
if ((*materialIds)[e->getID()] == material_id) {
setElementStatus(e->getID(), false);
}
}
}
}
_vec_active_eles.reserve(getNumberOfActiveElements());
const std::size_t nElems (_mesh->getNumberOfElements());
for (std::size_t i=0; i<nElems; ++i)
if (_element_status[i])
_vec_active_eles.push_back(const_cast<MeshLib::Element*>(_mesh->getElement(i)));
_vec_active_nodes.reserve(this->getNumberOfActiveNodes());
const std::size_t nNodes (_mesh->getNumberOfNodes());
for (std::size_t i=0; i<nNodes; ++i)
if (_active_nodes[i]>0)
_vec_active_nodes.push_back(const_cast<MeshLib::Node*>(_mesh->getNode(i)));
DBUG(
"Deactivated %d materials and resulting active %d nodes and %d "
"elements",
vec_inactive_matIDs.size(),
_vec_active_nodes.size(),
_vec_active_eles.size());
}
std::vector<MeshLib::Element*> const& ElementStatus::getActiveElements() const
{
if (_hasAnyInactive)
return _vec_active_eles;
return _mesh->getElements();
}
std::vector<MeshLib::Node*> const& ElementStatus::getActiveNodes() const
{
if (_hasAnyInactive)
return _vec_active_nodes;
return _mesh->getNodes();
}
std::vector<MeshLib::Element*> ElementStatus::getActiveElementsAtNode(std::size_t node_id) const
{
const std::size_t nActiveElements (_active_nodes[node_id]);
std::vector<MeshLib::Element*> active_elements;
active_elements.reserve(nActiveElements);
for (auto elem : _mesh->getNode(node_id)->getElements())
{
if (active_elements.size() == nActiveElements)
return active_elements;
if (_element_status[elem->getID()])
active_elements.push_back(elem);
}
return active_elements;
}
std::size_t ElementStatus::getNumberOfActiveNodes() const
{
return _active_nodes.size() - std::count(_active_nodes.cbegin(), _active_nodes.cend(), 0);
}
std::size_t ElementStatus::getNumberOfActiveElements() const
{
return static_cast<std::size_t>(
std::count(_element_status.cbegin(), _element_status.cend(), true));
}
void ElementStatus::setElementStatus(std::size_t i, bool status)
{
if (_element_status[i] != status)
{
const int change = (status) ? 1 : -1;
_element_status[i] = status;
const unsigned nElemNodes (_mesh->getElement(i)->getNumberOfNodes());
MeshLib::Node const*const*const nodes = _mesh->getElement(i)->getNodes();
for (unsigned j=0; j<nElemNodes; ++j)
{
assert(_active_nodes[j] < 255); // if one node has >255 connected
// elements the data type is too
// small
_active_nodes[nodes[j]->getID()] += change;
}
}
}
bool ElementStatus::isActiveNode(MeshLib::Node const* node) const
{
return _active_nodes[node->getID()]>0;
}
}