From d37f686d065f8b374cb4cab41cf01ed659719b8a Mon Sep 17 00:00:00 2001 From: Karsten Rink <karsten.rink@ufz.de> Date: Thu, 13 Mar 2014 16:13:10 +0100 Subject: [PATCH] setting element status and getting total numbers of nodes and elems --- MeshLib/ElementStatus.cpp | 29 +++++++++++++++++++++++++++++ MeshLib/ElementStatus.h | 15 +++++++++------ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/MeshLib/ElementStatus.cpp b/MeshLib/ElementStatus.cpp index 8c96512ed27..7e103977860 100644 --- a/MeshLib/ElementStatus.cpp +++ b/MeshLib/ElementStatus.cpp @@ -14,13 +14,42 @@ #include "ElementStatus.h" +#include "Mesh.h" +#include "Node.h" +#include "Elements/Element.h" + namespace MeshLib { ElementStatus::ElementStatus(Mesh const*const mesh) : _mesh(mesh), _element_status(mesh->getNElements(), true) { + const std::vector<MeshLib::Node*> &nodes (_mesh->getNodes()); + for (auto node = nodes.begin(); node != nodes.end(); ++node) + _active_nodes.push_back((*node)->getNElements()); } +unsigned ElementStatus::getNActiveNodes() const +{ + return _active_nodes.size() - std::count(_active_nodes.begin(), _active_nodes.end(), 0); +} + +unsigned ElementStatus::getNActiveElements() const +{ + return static_cast<unsigned>(std::count(_element_status.begin(), _element_status.end(), true)); +} + +void ElementStatus::setElementStatus(unsigned i, bool status) +{ + if (_element_status[i] != status) + { + const int change = (status) ? 1 : -1; + _element_status[i] = status; + const unsigned nElemNodes (_mesh->getElement(i)->getNNodes()); + MeshLib::Node const*const*const nodes = _mesh->getElement(i)->getNodes(); + for (unsigned i=0; i<nElemNodes; ++i) + _active_nodes[nodes[i]->getID()] += change; + } +} } diff --git a/MeshLib/ElementStatus.h b/MeshLib/ElementStatus.h index beee191bde9..ecfb694331f 100644 --- a/MeshLib/ElementStatus.h +++ b/MeshLib/ElementStatus.h @@ -15,9 +15,11 @@ #ifndef ELEMENTSTATUS_H_ #define ELEMENTSTATUS_H_ -#include "Mesh.h" +#include <vector> namespace MeshLib { + class Mesh; + class Element; /** * Manages active/inactive mesh elements and their nodes @@ -27,7 +29,7 @@ class ElementStatus public: /// Constructor - ElementStatus(Mesh const*const mesh); + ElementStatus(MeshLib::Mesh const*const mesh); /// Returns a vector of active element IDs std::vector<unsigned> getActiveElements() const {}; @@ -42,16 +44,16 @@ public: std::vector<MeshLib::Element*> getActiveElements(unsigned node_id) const {}; /// Returns the total number of active nodes - unsigned getNActiveNodes() const {}; + unsigned getNActiveNodes() const; /// Returns the total number of active elements - unsigned getNActiveElements() const {}; + unsigned getNActiveElements() const; /// Returns the status of element bool isActive(unsigned i) const { return _element_status[i]; } /// Sets the status of element i - void setElementStatus(unsigned i, bool status) { _element_status[i] = status; } + void setElementStatus(unsigned i, bool status); /// Sets the status of material group i void setMaterialStatus(unsigned i, bool status) {}; @@ -59,8 +61,9 @@ public: ~ElementStatus() {}; protected: - Mesh const*const _mesh; + MeshLib::Mesh const*const _mesh; std::vector<bool> _element_status; + std::vector<char> _active_nodes; }; /* class */ -- GitLab