PottsElement.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 #include "PottsElement.hpp"
00029 #include "RandomNumberGenerator.hpp"
00030 #include <cassert>
00031 
00032 
00033 template<unsigned DIM>
00034 PottsElement<DIM>::PottsElement(unsigned index, const std::vector<Node<DIM>*>& rNodes)
00035     : AbstractElement<DIM,DIM>(index, rNodes)
00036 {
00037     RegisterWithNodes();
00038 }
00039 
00040 template<unsigned DIM>
00041 PottsElement<DIM>::~PottsElement()
00042 {
00043 }
00044 
00045 template<unsigned DIM>
00046 void PottsElement<DIM>::RegisterWithNodes()
00047 {
00048     for (unsigned i=0; i<this->mNodes.size(); i++)
00049     {
00050         this->mNodes[i]->AddElement(this->mIndex);
00051     }
00052 }
00053 
00054 template<unsigned DIM>
00055 void PottsElement<DIM>::MarkAsDeleted()
00056 {
00057     // Mark element as deleted
00058     this->mIsDeleted = true;
00059 
00060     // Update nodes in the element so they know they are not contained by it
00061     for (unsigned i=0; i<this->GetNumNodes(); i++)
00062     {
00063         this->mNodes[i]->RemoveElement(this->mIndex);
00064     }
00065 }
00066 
00067 template<unsigned DIM>
00068 void PottsElement<DIM>::ResetIndex(unsigned index)
00069 {
00070     for (unsigned i=0; i<this->GetNumNodes(); i++)
00071     {
00072        this->mNodes[i]->RemoveElement(this->mIndex);
00073     }
00074     this->mIndex = index;
00075     RegisterWithNodes();
00076 }
00077 
00078 template<unsigned DIM>
00079 void PottsElement<DIM>::UpdateNode(const unsigned& rIndex, Node<DIM>* pNode)
00080 {
00081     assert(rIndex < this->mNodes.size());
00082 
00083     // Remove it from the node at this location
00084     this->mNodes[rIndex]->RemoveElement(this->mIndex);
00085 
00086     // Update the node at this location
00087     this->mNodes[rIndex] = pNode;
00088 
00089     // Add element to this node
00090     this->mNodes[rIndex]->AddElement(this->mIndex);
00091 }
00092 
00093 template<unsigned DIM>
00094 void PottsElement<DIM>::DeleteNode(const unsigned& rIndex)
00095 {
00096     assert(rIndex < this->mNodes.size());
00097 
00098     // Remove element from the node at this location
00099     this->mNodes[rIndex]->RemoveElement(this->mIndex);
00100 
00101     // Remove the node at rIndex (removes node from element)
00102     this->mNodes.erase(this->mNodes.begin() + rIndex);
00103 }
00104 
00105 template<unsigned DIM>
00106 void PottsElement<DIM>::AddNode(Node<DIM>* pNode)
00107 {
00108     // Add element to this node
00109     pNode->AddElement(this->mIndex);
00110 
00111     // Add pNode to mNodes
00112     this->mNodes.push_back(pNode);
00113 }
00114 
00115 template<unsigned DIM>
00116 unsigned PottsElement<DIM>::GetNodeLocalIndex(unsigned globalIndex) const
00117 {
00118     unsigned local_index = UINT_MAX;
00119     for (unsigned i=0; i<this->mNodes.size(); i++)
00120     {
00121         if (this->GetNodeGlobalIndex(i) == globalIndex)
00122         {
00123             local_index = i;
00124         }
00125     }
00126     return local_index;
00127 }
00128 
00129 template<unsigned DIM>
00130 bool PottsElement<DIM>::IsElementOnBoundary() const
00131 {
00132     bool is_element_on_boundary = false;
00133     for (unsigned i=0; i<this->mNodes.size(); i++)
00134     {
00135         if (this->GetNode(i)->IsBoundaryNode())
00136         {
00137             is_element_on_boundary = true;
00138             break;
00139         }
00140     }
00141     return is_element_on_boundary;
00142 }
00143 
00145 // Explicit instantiation
00147 
00148 template class PottsElement<1>;
00149 template class PottsElement<2>;
00150 template class PottsElement<3>;
Generated on Thu Dec 22 13:00:04 2011 for Chaste by  doxygen 1.6.3