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

setting status based on mat id and returning active elements for a node

parent 5b187888
No related branches found
No related tags found
No related merge requests found
......@@ -51,6 +51,34 @@ std::vector<unsigned> ElementStatus::getActiveNodes() const
return active_nodes;
}
std::vector<MeshLib::Element*> ElementStatus::getActiveElementsAtNode(unsigned node_id) const
{
const unsigned nElems (_mesh->getNode(node_id)->getNElements());
const unsigned nActiveElements (_active_nodes[node_id]);
const std::vector<Element*> &elements (_mesh->getNode(node_id)->getElements());
std::vector<MeshLib::Element*> active_elements;
active_elements.reserve(nActiveElements);
for (unsigned i=0; i<nElems; ++i)
{
// if all active elements are found, the test can be cancelled for the rest of the connected elements
if (active_elements.size() == nActiveElements)
return active_elements;
const unsigned nElemNodes (elements[i]->getNNodes());
MeshLib::Node const*const*const nodes = elements[i]->getNodes();
bool isActive (true);
for (unsigned j=0; j<nElemNodes; ++j)
if (_active_nodes[nodes[j]->getID()]==0)
{
isActive = false;
break;
}
if (isActive)
active_elements.push_back(elements[i]);
}
return active_elements;
}
unsigned ElementStatus::getNActiveNodes() const
{
return _active_nodes.size() - std::count(_active_nodes.begin(), _active_nodes.end(), 0);
......@@ -74,5 +102,13 @@ void ElementStatus::setElementStatus(unsigned i, bool status)
}
}
void ElementStatus::setMaterialStatus(unsigned material_id, bool status)
{
const std::size_t nElems (_mesh->getNElements());
for (std::size_t i=0; i<nElems; ++i)
if (_mesh->getElement(i)->getValue() == material_id)
this->setElementStatus(i, status);
}
}
......@@ -41,7 +41,7 @@ public:
bool getElementStatus(unsigned i) const { return _element_status[i]; }
/// Returns a vector of active elements connected to a node
std::vector<MeshLib::Element*> getActiveElements(unsigned node_id) const {};
std::vector<MeshLib::Element*> getActiveElementsAtNode(unsigned node_id) const;
/// Returns the total number of active nodes
unsigned getNActiveNodes() const;
......@@ -56,7 +56,7 @@ public:
void setElementStatus(unsigned i, bool status);
/// Sets the status of material group i
void setMaterialStatus(unsigned i, bool status) {};
void setMaterialStatus(unsigned material_id, bool status);
~ElementStatus() {};
......
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