Skip to content
Snippets Groups Projects
Commit 8f3766c9 authored by Karsten Rink's avatar Karsten Rink
Browse files

changed iterators to constant functions where possible

parent e190b065
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,7 @@ ElementStatus::ElementStatus(Mesh const*const mesh) ...@@ -24,7 +24,7 @@ ElementStatus::ElementStatus(Mesh const*const mesh)
: _mesh(mesh), _element_status(mesh->getNElements(), true) : _mesh(mesh), _element_status(mesh->getNElements(), true)
{ {
const std::vector<MeshLib::Node*> &nodes (_mesh->getNodes()); const std::vector<MeshLib::Node*> &nodes (_mesh->getNodes());
for (auto node = nodes.begin(); node != nodes.end(); ++node) for (auto node = nodes.cbegin(); node != nodes.cend(); ++node)
_active_nodes.push_back((*node)->getNElements()); _active_nodes.push_back((*node)->getNElements());
} }
...@@ -51,17 +51,17 @@ std::vector<std::size_t> ElementStatus::getActiveNodes() const ...@@ -51,17 +51,17 @@ std::vector<std::size_t> ElementStatus::getActiveNodes() const
return active_nodes; return active_nodes;
} }
std::vector<std::size_t> ElementStatus::getActiveElementsAtNode(unsigned node_id) const std::vector<std::size_t> ElementStatus::getActiveElementsAtNode(std::size_t node_id) const
{ {
const unsigned nActiveElements (_active_nodes[node_id]); const std::size_t nActiveElements (_active_nodes[node_id]);
const std::vector<Element*> &elements (_mesh->getNode(node_id)->getElements()); const std::vector<Element*> &elements (_mesh->getNode(node_id)->getElements());
std::vector<std::size_t> active_elements; std::vector<std::size_t> active_elements;
active_elements.reserve(nActiveElements); active_elements.reserve(nActiveElements);
for (auto elem = elements.begin(); elem != elements.end(); ++elem) for (auto elem = elements.cbegin(); elem != elements.cend(); ++elem)
{ {
if (active_elements.size() == nActiveElements) if (active_elements.size() == nActiveElements)
return active_elements; return active_elements;
const unsigned id ((*elem)->getID()); const std::size_t id ((*elem)->getID());
if (_element_status[id]) if (_element_status[id])
active_elements.push_back(id); active_elements.push_back(id);
} }
...@@ -70,12 +70,12 @@ std::vector<std::size_t> ElementStatus::getActiveElementsAtNode(unsigned node_id ...@@ -70,12 +70,12 @@ std::vector<std::size_t> ElementStatus::getActiveElementsAtNode(unsigned node_id
std::size_t ElementStatus::getNActiveNodes() const std::size_t ElementStatus::getNActiveNodes() const
{ {
return _active_nodes.size() - std::count(_active_nodes.begin(), _active_nodes.end(), 0); return _active_nodes.size() - std::count(_active_nodes.cbegin(), _active_nodes.cend(), 0);
} }
std::size_t ElementStatus::getNActiveElements() const std::size_t ElementStatus::getNActiveElements() const
{ {
return static_cast<unsigned>(std::count(_element_status.begin(), _element_status.end(), true)); return static_cast<std::size_t>(std::count(_element_status.cbegin(), _element_status.cend(), true));
} }
void ElementStatus::setAll(bool status) void ElementStatus::setAll(bool status)
......
...@@ -41,7 +41,7 @@ public: ...@@ -41,7 +41,7 @@ public:
bool getElementStatus(std::size_t i) const { return _element_status[i]; } bool getElementStatus(std::size_t i) const { return _element_status[i]; }
/// Returns a vector of active elements connected to a node /// Returns a vector of active elements connected to a node
std::vector<std::size_t> getActiveElementsAtNode(unsigned node_id) const; std::vector<std::size_t> getActiveElementsAtNode(std::size_t node_id) const;
/// Returns the total number of active nodes /// Returns the total number of active nodes
std::size_t getNActiveNodes() const; std::size_t getNActiveNodes() const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment