AbstractElement.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
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 
00029 #ifndef ABSTRACTELEMENT_HPP_
00030 #define ABSTRACTELEMENT_HPP_
00031 #include "Node.hpp"
00032 #include "ChastePoint.hpp"
00033 #include "UblasCustomFunctions.hpp"
00034 
00035 #include "Exception.hpp"
00036 
00037 #include <vector>
00038 #include <cmath>
00039 
00040 // When creating an element within a mesh one needs to specify its global index
00041 // If the element is not used within a mesh the following
00042 // constant is used instead.
00043 const unsigned INDEX_IS_NOT_USED=0;
00044 
00048 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00049 class AbstractElement
00050 {
00051 protected:
00053     std::vector<Node<SPACE_DIM>*> mNodes;
00055     unsigned mIndex;
00057     unsigned mRegion;
00058 
00063     bool mIsDeleted;
00065     bool mOwnership;
00067     bool mFlag;
00068     
00069 public:
00070     AbstractElement(unsigned index, const std::vector<Node<SPACE_DIM>*>& rNodes)
00071         : mNodes(rNodes), mIndex(index)
00072     {
00073         // Sanity checking
00074         assert(ELEMENT_DIM <= SPACE_DIM);
00075     
00076         // Initialise flags.
00077         // This must be done before the Jacobian calculations, or assertions trip.
00078         mIsDeleted = false;
00079         mFlag = false;
00080         mOwnership = true;
00081         
00082         mRegion = 0;
00083     }
00084 
00088     AbstractElement(unsigned index=INDEX_IS_NOT_USED)
00089         : mIndex(index),
00090           mRegion(0),
00091           mIsDeleted(false),
00092           mOwnership(true),
00093           mFlag(false)
00094     {}
00095 
00100     virtual ~AbstractElement()
00101     {}
00102 
00103 
00109     virtual void UpdateNode(const unsigned& rIndex, Node<SPACE_DIM>* pNode)=0;
00110 
00117     void ReplaceNode(Node<SPACE_DIM>* pOldNode, Node<SPACE_DIM>* pNewNode)
00118     {
00119         //assert(pOldNode != pNewNode); /// \todo this will sometimes trip; is it a logic error?
00120         for (unsigned i=0; i<this->mNodes.size(); i++)
00121         {
00122             if (this->mNodes[i]==pOldNode)
00123             {
00124                 UpdateNode(i,pNewNode);
00125                 return;
00126             }
00127         }
00128         EXCEPTION("You didn't have that node to start with.");
00129     }
00130 
00135     virtual void MarkAsDeleted()=0;
00136 
00137 
00141     virtual void RegisterWithNodes()=0;
00142 
00151     double GetNodeLocation(unsigned localIndex, unsigned dimension) const
00152     {
00153         assert(dimension < SPACE_DIM);
00154         assert((unsigned)localIndex < mNodes.size());
00155         return mNodes[localIndex]->rGetLocation()[dimension];
00156     }
00157 
00168     c_vector<double, SPACE_DIM> GetNodeLocation(unsigned localIndex) const
00169     {
00170         assert((unsigned)localIndex < mNodes.size());
00171         return mNodes[localIndex]->rGetLocation();
00172     }
00173     
00174     unsigned GetNodeGlobalIndex(unsigned localIndex) const
00175     {
00176         assert((unsigned)localIndex < mNodes.size());
00177         return mNodes[localIndex]->GetIndex();
00178     }
00179 
00180     Node<SPACE_DIM>* GetNode(unsigned localIndex) const
00181     {
00182         assert((unsigned)localIndex < mNodes.size());
00183         return mNodes[localIndex];
00184     }
00185 
00186     unsigned GetNumNodes() const
00187     {
00188         return mNodes.size();
00189     }
00190 
00191 
00192     void AddNode(Node<SPACE_DIM>* node)
00193     {
00194         mNodes.push_back(node);
00195     }
00196 
00197     bool IsDeleted() const
00198     {
00199         return mIsDeleted;
00200     }
00201 
00205     unsigned GetIndex(void) const
00206     {
00207         return mIndex;
00208     }
00209 
00210     void SetIndex(unsigned index)
00211     {
00212         mIndex=index;
00213     }
00214 
00215     bool GetOwnership() const
00216     {
00217         return mOwnership;
00218     }
00219 
00220     void SetOwnership(bool ownership)
00221     {
00222         mOwnership=ownership;
00223     }
00224 
00225     void Flag()
00226     {
00227         mFlag = true;
00228     }
00229 
00230     void Unflag()
00231     {
00232         mFlag = false;
00233     }
00234 
00235     bool IsFlagged() const
00236     {
00237         return mFlag;
00238     }
00239 
00240     void SetRegion(unsigned region)
00241     {
00242         mRegion = region;
00243     }
00244 
00245     unsigned GetRegion()
00246     {
00247         return mRegion;
00248     }
00249 
00250 
00251 };
00252 
00253 #endif /*ABSTRACTELEMENT_HPP_*/

Generated on Wed Mar 18 12:51:52 2009 for Chaste by  doxygen 1.5.5