Skip to content
Snippets Groups Projects
Commit d63a82e6 authored by Tom Fischer's avatar Tom Fischer
Browse files

[class Element]

- optimized addNeighbor()

[Mesh]
- optimized setNeighborInformationForElements()
parent 110cbb82
No related branches found
No related tags found
No related merge requests found
...@@ -52,12 +52,13 @@ bool Element::addNeighbor(Element* e) ...@@ -52,12 +52,13 @@ bool Element::addNeighbor(Element* e)
const unsigned eNodes (e->getNNodes()); const unsigned eNodes (e->getNNodes());
const Node* const* e_nodes = e->getNodes(); const Node* const* e_nodes = e->getNodes();
unsigned count(0); unsigned count(0);
const unsigned dim (this->getDimension());
for (unsigned i(0); i<nNodes; i++) for (unsigned i(0); i<nNodes; i++)
for (unsigned j(0); j<eNodes; j++) for (unsigned j(0); j<eNodes; j++)
if (_nodes[i] == e_nodes[j]) if (_nodes[i] == e_nodes[j])
//std::cout << _nodes[i]->getID() << " == " << e_nodes[j]->getID() << std::endl; //std::cout << _nodes[i]->getID() << " == " << e_nodes[j]->getID() << std::endl;
// increment shared nodes counter and check if enough nodes are similar to be sure e is a neighbour of this // increment shared nodes counter and check if enough nodes are similar to be sure e is a neighbour of this
if ((++count)>=this->getDimension()) if ((++count)>=dim)
{ {
_neighbors[n]=e; _neighbors[n]=e;
return true; return true;
......
...@@ -112,34 +112,24 @@ void Mesh::setNeighborInformationForElements() ...@@ -112,34 +112,24 @@ void Mesh::setNeighborInformationForElements()
{ {
// create vector with all elements connected to current element (includes lots of doubles!) // create vector with all elements connected to current element (includes lots of doubles!)
std::vector<Element*> neighbors; std::vector<Element*> neighbors;
const size_t nNodes (_elements[m]->getNNodes()); Element *const element (_elements[m]);
const size_t nNodes (element->getNNodes());
for (unsigned n(0); n<nNodes; n++) for (unsigned n(0); n<nNodes; n++)
{ {
const std::vector<Element*> conn_elems (_elements[m]->getNode(n)->getElements()); std::vector<Element*> const& conn_elems ((element->getNode(n)->getElements()));
neighbors.insert(neighbors.end(), conn_elems.begin(), conn_elems.end()); neighbors.insert(neighbors.end(), conn_elems.begin(), conn_elems.end());
} }
const unsigned nNeighbors ( neighbors.size() ); const unsigned nNeighbors ( neighbors.size() );
/*std::vector<bool> done (nNeighbors, false);
// mark off the element itself
for (unsigned j(0); j<nNeighbors; j++)
if (neighbors[j] == _elements[m])
done[j] = true;
*/
// check if connected element is indeed a neighbour and mark all doubles of that element as 'done' // check if connected element is indeed a neighbour and mark all doubles of that element as 'done'
for (unsigned i(0); i<nNeighbors; i++) for (unsigned i(0); i<nNeighbors; i++)
//if (!done[i]) {
if (element->addNeighbor(neighbors[i]))
{ {
if (_elements[m]->addNeighbor(neighbors[i])) neighbors[i]->addNeighbor(element);
{
neighbors[i]->addNeighbor(_elements[m]);
}/*
for (unsigned j(0); j<nNeighbors; j++)
if (!done[j] && (neighbors[j] == neighbors[i]))
done[j] = true;
*/
} }
}
} }
} }
......
...@@ -48,7 +48,7 @@ public: ...@@ -48,7 +48,7 @@ public:
const Element* getElement(unsigned idx) const { return _elements[idx]; }; const Element* getElement(unsigned idx) const { return _elements[idx]; };
/// Get all elements the node is part of. /// Get all elements the node is part of.
const std::vector<Element*> getElements() const { return _elements; }; const std::vector<Element*>& getElements() const { return _elements; };
/// Get number of elements the node is part of. /// Get number of elements the node is part of.
size_t getNElements() const { return _elements.size(); }; size_t getNElements() const { return _elements.size(); };
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
// BaseLib/logog // BaseLib/logog
#include "logog.hpp" #include "logog.hpp"
// MeshLib // MeshLib
#include "Node.h" #include "Node.h"
#include "Elements/Element.h" #include "Elements/Element.h"
......
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