35#include "MutableElement.hpp"
36#include "RandomNumberGenerator.hpp"
40template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
47template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
53 if (SPACE_DIM == ELEMENT_DIM)
59template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
64template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
67 for (
unsigned i=0; i<this->mNodes.size(); i++)
69 this->mNodes[i]->AddElement(this->mIndex);
73template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
77 this->mIsDeleted =
true;
80 for (
unsigned i=0; i<this->GetNumNodes(); i++)
82 this->mNodes[i]->RemoveElement(this->mIndex);
85 for (
unsigned i=0; i< GetNumEdges(); i++)
87 this->mEdges[i]->RemoveElement(this->mIndex);
91template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
94 for (
unsigned i=0; i<this->GetNumNodes(); i++)
96 this->mNodes[i]->RemoveElement(this->mIndex);
99 for (
unsigned i=0; i<this->GetNumEdges(); i++)
101 this->mEdges[i]->RemoveElement(this->mIndex);
104 this->mIndex = index;
109template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
112 assert(rIndex < this->mNodes.size());
115 if (SPACE_DIM == 2 && this->mEdgeHelper !=
nullptr)
117 auto pOldNode = this->mNodes[rIndex];
118 unsigned rPrevIndex = (rIndex-1) % this->mEdges.size();
120 rPrevIndex = this->mEdges.size()-1;
121 this->mEdges[rPrevIndex]->ReplaceNode(pOldNode, pNode);
122 this->mEdges[rIndex]->ReplaceNode(pOldNode, pNode);
126 this->mNodes[rIndex]->RemoveElement(this->mIndex);
129 this->mNodes[rIndex] = pNode;
132 this->mNodes[rIndex]->
AddElement(this->mIndex);
135template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
138 assert(rIndex < this->mNodes.size());
141 if (SPACE_DIM == 2 && this->mEdgeHelper !=
nullptr)
149 unsigned rPrevIndex = ((int)rIndex-1) % this->mEdges.size();
150 unsigned rNextIndex = (rIndex+1) % this->mEdges.size();
152 rPrevIndex = this->mEdges.size()-1;
153 auto prevNode = this->mNodes[rPrevIndex];
154 auto nextNode = this->mNodes[rNextIndex];
157 this->mEdges[rPrevIndex]->RemoveElement(this->GetIndex());
158 this->mEdges[rPrevIndex] = this->mEdgeHelper->GetEdgeFromNodes(this->GetIndex(), prevNode, nextNode);
161 this->mEdges[rIndex]->RemoveElement(this->GetIndex());
162 this->mEdges.erase(this->mEdges.begin() + rIndex);
167 this->mNodes[rIndex]->RemoveElement(this->mIndex);
169 this->mNodes.erase(this->mNodes.begin() + rIndex);
172template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
181 if (SPACE_DIM == 2 && this->mEdgeHelper !=
nullptr && !this->mEdges.empty())
190 unsigned rNextIndex = (rIndex+1) % this->mEdges.size();
192 auto prevNode = this->mNodes[rIndex];
193 auto currentNode = pNode;
194 auto nextNode = this->mNodes[rNextIndex];
197 this->mEdges[rIndex] = this->mEdgeHelper->GetEdgeFromNodes(this->mIndex, prevNode, currentNode);
199 auto edge = this->mEdgeHelper->GetEdgeFromNodes(this->mIndex, currentNode, nextNode);
200 this->mEdges.insert(this->mEdges.begin() + rIndex+1, edge);
204 if (this->mNodes.empty())
207 this->mNodes.push_back(pNode);
210 this->mNodes[0]->AddElement(this->mIndex);
214 assert(rIndex < this->mNodes.size());
217 this->mNodes.insert(this->mNodes.begin() + rIndex+1, pNode);
220 this->mNodes[rIndex+1]->AddElement(this->mIndex);
224template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
227 unsigned local_index = UINT_MAX;
228 for (
unsigned i=0; i<this->mNodes.size(); i++)
230 if (this->GetNodeGlobalIndex(i) == globalIndex)
238template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
241 for (
auto edge : this->mEdges)
243 edge->AddElement(this->mIndex);
247template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
254template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
257 bool is_element_on_boundary =
false;
258 for (
unsigned i=0; i<this->mNodes.size(); i++)
260 if (this->GetNode(i)->IsBoundaryNode())
262 is_element_on_boundary =
true;
266 return is_element_on_boundary;
269template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
272 this->mEdgeHelper = pEdgeHelper;
275template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
278 for (
auto edge: mEdges)
280 edge->RemoveElement(this->mIndex);
285template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
288 assert(mEdgeHelper !=
nullptr);
296 for (
unsigned i = 0; i < this->mNodes.size(); i++)
298 unsigned i_next = (i+1) % this->mNodes.size();
299 mEdges.push_back(mEdgeHelper->GetEdgeFromNodes(this->mIndex, this->mNodes[i], this->mNodes[i_next]));
304template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
307 assert(localIndex < mEdges.size());
308 return mEdges[localIndex]->GetIndex();
311template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
314 assert(localIndex < mEdges.size());
315 return mEdges[localIndex];
318template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
320 return mEdges.size();
323template<
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
326 assert(localIndex < mEdges.size());
327 return mEdges[localIndex]->GetOtherElements(this->mIndex);
330template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
333 for (
unsigned i=0; i<mEdges.size(); ++i)
335 if ((*mEdges[i]) == (*pEdge))
343template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
347 for (
unsigned i=0; i<mEdges.size(); ++i)
349 if ((*mEdges[i]) == (*pEdge))
367template<
unsigned SPACE_DIM>
373 assert(SPACE_DIM > 0);
376template<
unsigned SPACE_DIM>
381template<
unsigned SPACE_DIM>
384 for (
unsigned i=0; i<this->mNodes.size(); i++)
386 this->mNodes[i]->AddElement(this->mIndex);
390template<
unsigned SPACE_DIM>
394 this->mIsDeleted =
true;
397 for (
unsigned i=0; i<this->GetNumNodes(); i++)
399 this->mNodes[i]->RemoveElement(this->mIndex);
403template <
unsigned SPACE_DIM>
406 for (
unsigned i=0; i<this->GetNumNodes(); i++)
408 this->mNodes[i]->RemoveElement(this->mIndex);
410 this->mIndex = index;
416template<
unsigned SPACE_DIM>
418 return mEdges.size();
421template<
unsigned SPACE_DIM>
424 assert(localIndex < mEdges.size());
425 return mEdges[localIndex];
428template <
unsigned SPACE_DIM>
431 for (
unsigned i=0; i<mEdges.size(); ++i)
433 if ((*mEdges[i]) == (*pEdge))
441template<
unsigned SPACE_DIM>
444 this->mEdgeHelper = pEdgeHelper;
447template<
unsigned SPACE_DIM>
450 assert(mEdgeHelper !=
nullptr);
458 for (
unsigned i = 0; i < this->mNodes.size(); i++)
460 unsigned i_next = (i+1) % this->mNodes.size();
461 mEdges.push_back(mEdgeHelper->GetEdgeFromNodes(this->mIndex, this->mNodes[i], this->mNodes[i_next]));
466template<
unsigned SPACE_DIM>
469 for (
auto p_edge : mEdges)
471 p_edge->RemoveElement(this->mIndex);
476template <
unsigned SPACE_DIM>
480 for (
unsigned i=0; i<mEdges.size(); ++i)
482 if ((*mEdges[i]) == (*pEdge))
490template<
unsigned SPACE_DIM>
493 assert(localIndex < mEdges.size());
494 return mEdges[localIndex]->GetIndex();
497template<
unsigned SPACE_DIM>
500 assert(localIndex < mEdges.size());
501 return mEdges[localIndex]->GetOtherElements(this->mIndex);
504template<
unsigned SPACE_DIM>
507 assert(rIndex < this->mNodes.size());
510 this->mNodes[rIndex]->RemoveElement(this->mIndex);
513 this->mNodes[rIndex] = pNode;
516 this->mNodes[rIndex]->
AddElement(this->mIndex);
519template<
unsigned SPACE_DIM>
522 assert(rIndex < this->mNodes.size());
525 this->mNodes[rIndex]->RemoveElement(this->mIndex);
528 this->mNodes.erase(this->mNodes.begin() + rIndex);
531template<
unsigned SPACE_DIM>
534 assert(rIndex < this->mNodes.size());
537 this->mNodes.insert(this->mNodes.begin() + rIndex+1, pNode);
540 this->mNodes[rIndex+1]->AddElement(this->mIndex);
543template<
unsigned SPACE_DIM>
546 unsigned local_index = UINT_MAX;
547 for (
unsigned i=0; i<this->mNodes.size(); i++)
549 if (this->GetNodeGlobalIndex(i) == globalIndex)
558template<
unsigned SPACE_DIM>
563template<
unsigned SPACE_DIM>
568template<
unsigned SPACE_DIM>
571 bool is_element_on_boundary =
false;
572 for (
unsigned i=0; i<this->mNodes.size(); i++)
574 if (this->GetNode(i)->IsBoundaryNode())
576 is_element_on_boundary =
true;
580 return is_element_on_boundary;
MutableElement(unsigned index)
std::set< unsigned > GetNeighbouringElementAtEdgeIndex(unsigned localIndex)
unsigned GetEdgeGlobalIndex(unsigned localIndex) const
void ResetIndex(unsigned index)
virtual bool IsElementOnBoundary() const
long GetLocalEdgeIndex(const Edge< SPACE_DIM > *pEdge) const
void DeleteNode(const unsigned &rIndex)
virtual ~MutableElement()
bool ContainsEdge(const Edge< SPACE_DIM > *pEdge) const
void UpdateNode(const unsigned &rIndex, Node< SPACE_DIM > *pNode)
Edge< SPACE_DIM > * GetEdge(unsigned localIndex) const
void SetEdgeHelper(EdgeHelper< SPACE_DIM > *pEdgeHelper)
unsigned GetNodeLocalIndex(unsigned globalIndex) const
void AddNode(Node< SPACE_DIM > *pNode, const unsigned &rIndex)
unsigned GetNumEdges() const
void AddElement(unsigned index)
void RemoveElement(unsigned index)