AbstractElement.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
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);
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 /*
00087  * Note for future reference: this used to return a reference to a c_vector, in which case a
00088  * weird error arose where it compiled, ran and passed on some machines but failed the tests
00089  * (bad_size errors) on another machine.  So be careful if you think about changing it!
00090  */
00091 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00092 c_vector<double, SPACE_DIM> AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetNodeLocation(unsigned localIndex) const
00093 {
00094     assert((unsigned)localIndex < mNodes.size());
00095     return mNodes[localIndex]->rGetLocation();
00096 }
00097 
00098 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00099 unsigned AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetNodeGlobalIndex(unsigned localIndex) const
00100 {
00101     assert((unsigned)localIndex < mNodes.size());
00102     return mNodes[localIndex]->GetIndex();
00103 }
00104 
00105 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00106 Node<SPACE_DIM>* AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetNode(unsigned localIndex) const
00107 {
00108     assert((unsigned)localIndex < mNodes.size());
00109     return mNodes[localIndex];
00110 }
00111 
00112 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00113 unsigned AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetNumNodes() const
00114 {
00115     return mNodes.size();
00116 }
00117 
00118 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00119 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::AddNode(Node<SPACE_DIM>* pNode)
00120 {
00121     mNodes.push_back(pNode);
00122 }
00123 
00124 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00125 bool AbstractElement<ELEMENT_DIM, SPACE_DIM>::IsDeleted() const
00126 {
00127     return mIsDeleted;
00128 }
00129 
00130 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00131 unsigned AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetIndex() const
00132 {
00133     return mIndex;
00134 }
00135 
00136 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00137 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::SetIndex(unsigned index)
00138 {
00139     mIndex = index;
00140 }
00141 
00142 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00143 bool AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetOwnership() const
00144 {
00145     return mOwnership;
00146 }
00147 
00148 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00149 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::SetOwnership(bool ownership)
00150 {
00151     mOwnership = ownership;
00152 }
00153 
00154 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00155 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::Flag()
00156 {
00157     mFlag = true;
00158 }
00159 
00160 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00161 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::Unflag()
00162 {
00163     mFlag = false;
00164 }
00165 
00166 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00167 bool AbstractElement<ELEMENT_DIM, SPACE_DIM>::IsFlagged() const
00168 {
00169     return mFlag;
00170 }
00171 
00172 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00173 void AbstractElement<ELEMENT_DIM, SPACE_DIM>::SetRegion(unsigned region)
00174 {
00175     mRegion = region;
00176 }
00177 
00178 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00179 unsigned AbstractElement<ELEMENT_DIM, SPACE_DIM>::GetRegion()
00180 {
00181     return mRegion;
00182 }
00183 
00184 
00186 // Explicit instantiation
00188 
00189 template class AbstractElement<0,1>;
00190 template class AbstractElement<1,1>;
00191 template class AbstractElement<0,2>;
00192 template class AbstractElement<1,2>;
00193 template class AbstractElement<2,2>;
00194 template class AbstractElement<0,3>;
00195 template class AbstractElement<1,3>;
00196 template class AbstractElement<2,3>;
00197 template class AbstractElement<3,3>;

Generated on Mon Nov 1 12:35:23 2010 for Chaste by  doxygen 1.5.5