AbstractElement.cpp

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 #include "AbstractElement.hpp"
00030 
00031 #include "Exception.hpp"
00032 
00033 #include <cassert>
00034 
00036 // Implementation
00038 
00039 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00040 AbstractElement<ELEMENT_DIM, SPACE_DIM>::AbstractElement(unsigned index, const std::vector<Node<SPACE_DIM>*>& rNodes)
00041     : mNodes(rNodes),
00042       mIndex(index),
00043       mRegion(0),
00044       mIsDeleted(false),
00045       mOwnership(true),
00046       mFlag(false)
00047 {
00048     // Sanity checking
00049     assert(ELEMENT_DIM <= SPACE_DIM);
00050 
00051     // Flags must be initialised before the Jacobian calculations, or assertions trip
00052 }
00053 
00054 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00055 AbstractElement<ELEMENT_DIM, SPACE_DIM>::AbstractElement(unsigned index)
00056     : mIndex(index),
00057       mRegion(0),
00058       mIsDeleted(false),
00059       mOwnership(true),
00060       mFlag(false)
00061 {}
00062 
00063 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00064 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::ReplaceNode(Node<SPACE_DIM>* pOldNode, Node<SPACE_DIM>* pNewNode)
00065 {
00066     //assert(pOldNode != pNewNode); /// \todo this will sometimes trip; is it a logic error?
00067     for (unsigned i=0; i<this->mNodes.size(); i++)
00068     {
00069         if (this->mNodes[i] == pOldNode)
00070         {
00071             UpdateNode(i, pNewNode);
00072             return;
00073         }
00074     }
00075     EXCEPTION("You didn't have that node to start with.");
00076 }
00077 
00078 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00079 double AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetNodeLocation(unsigned localIndex, unsigned dimension) const
00080 {
00081     assert(dimension < SPACE_DIM);
00082     assert((unsigned)localIndex < mNodes.size());
00083     return mNodes[localIndex]->rGetLocation()[dimension];
00084 }
00085 
00086 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00087 c_vector<double, SPACE_DIM> AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetNodeLocation(unsigned localIndex) const
00088 {
00089     assert((unsigned)localIndex < mNodes.size());
00090     return mNodes[localIndex]->rGetLocation();
00091 }
00092 
00093 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00094 unsigned AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetNodeGlobalIndex(unsigned localIndex) const
00095 {
00096     assert((unsigned)localIndex < mNodes.size());
00097     return mNodes[localIndex]->GetIndex();
00098 }
00099 
00100 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00101 Node<SPACE_DIM>* AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetNode(unsigned localIndex) const
00102 {
00103     assert((unsigned)localIndex < mNodes.size());
00104     return mNodes[localIndex];
00105 }
00106 
00107 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00108 unsigned AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetNumNodes() const
00109 {
00110     return mNodes.size();
00111 }
00112 
00113 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00114 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::AddNode(Node<SPACE_DIM>* pNode)
00115 {
00116     mNodes.push_back(pNode);
00117 }
00118 
00119 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00120 bool AbstractElement<ELEMENT_DIM, SPACE_DIM>::IsDeleted() const
00121 {
00122     return mIsDeleted;
00123 }
00124 
00125 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00126 unsigned AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetIndex() const
00127 {
00128     return mIndex;
00129 }
00130 
00131 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00132 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::SetIndex(unsigned index)
00133 {
00134     mIndex = index;
00135 }
00136 
00137 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00138 bool AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetOwnership() const
00139 {
00140     return mOwnership;
00141 }
00142 
00143 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00144 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::SetOwnership(bool ownership)
00145 {
00146     mOwnership = ownership;
00147 }
00148 
00149 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00150 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::Flag()
00151 {
00152     mFlag = true;
00153 }
00154 
00155 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00156 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::Unflag()
00157 {
00158     mFlag = false;
00159 }
00160 
00161 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00162 bool AbstractElement<ELEMENT_DIM, SPACE_DIM>::IsFlagged() const
00163 {
00164     return mFlag;
00165 }
00166 
00167 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00168 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::SetRegion(unsigned region)
00169 {
00170     mRegion = region;
00171 }
00172 
00173 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00174 unsigned AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetRegion()
00175 {
00176     return mRegion;
00177 }
00178 
00179 
00181 // Explicit instantiation
00183 
00184 template class AbstractElement<0,1>;
00185 template class AbstractElement<1,1>;
00186 template class AbstractElement<0,2>;
00187 template class AbstractElement<1,2>;
00188 template class AbstractElement<2,2>;
00189 template class AbstractElement<0,3>;
00190 template class AbstractElement<1,3>;
00191 template class AbstractElement<2,3>;
00192 template class AbstractElement<3,3>;

Generated on Tue Aug 4 16:10:22 2009 for Chaste by  doxygen 1.5.5