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

setting element status and getting total numbers of nodes and elems

parent 276ef1e6
No related branches found
No related tags found
No related merge requests found
...@@ -14,13 +14,42 @@ ...@@ -14,13 +14,42 @@
#include "ElementStatus.h" #include "ElementStatus.h"
#include "Mesh.h"
#include "Node.h"
#include "Elements/Element.h"
namespace MeshLib { namespace MeshLib {
ElementStatus::ElementStatus(Mesh const*const mesh) 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());
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;
}
}
} }
...@@ -15,9 +15,11 @@ ...@@ -15,9 +15,11 @@
#ifndef ELEMENTSTATUS_H_ #ifndef ELEMENTSTATUS_H_
#define ELEMENTSTATUS_H_ #define ELEMENTSTATUS_H_
#include "Mesh.h" #include <vector>
namespace MeshLib { namespace MeshLib {
class Mesh;
class Element;
/** /**
* Manages active/inactive mesh elements and their nodes * Manages active/inactive mesh elements and their nodes
...@@ -27,7 +29,7 @@ class ElementStatus ...@@ -27,7 +29,7 @@ class ElementStatus
public: public:
/// Constructor /// Constructor
ElementStatus(Mesh const*const mesh); ElementStatus(MeshLib::Mesh const*const mesh);
/// Returns a vector of active element IDs /// Returns a vector of active element IDs
std::vector<unsigned> getActiveElements() const {}; std::vector<unsigned> getActiveElements() const {};
...@@ -42,16 +44,16 @@ public: ...@@ -42,16 +44,16 @@ public:
std::vector<MeshLib::Element*> getActiveElements(unsigned node_id) const {}; std::vector<MeshLib::Element*> getActiveElements(unsigned node_id) const {};
/// Returns the total number of active nodes /// Returns the total number of active nodes
unsigned getNActiveNodes() const {}; unsigned getNActiveNodes() const;
/// Returns the total number of active elements /// Returns the total number of active elements
unsigned getNActiveElements() const {}; unsigned getNActiveElements() const;
/// Returns the status of element /// Returns the status of element
bool isActive(unsigned i) const { return _element_status[i]; } bool isActive(unsigned i) const { return _element_status[i]; }
/// Sets the status of element 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 /// Sets the status of material group i
void setMaterialStatus(unsigned i, bool status) {}; void setMaterialStatus(unsigned i, bool status) {};
...@@ -59,8 +61,9 @@ public: ...@@ -59,8 +61,9 @@ public:
~ElementStatus() {}; ~ElementStatus() {};
protected: protected:
Mesh const*const _mesh; MeshLib::Mesh const*const _mesh;
std::vector<bool> _element_status; std::vector<bool> _element_status;
std::vector<char> _active_nodes;
}; /* class */ }; /* class */
......
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