Node.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 <cassert>
00030 
00031 #include "Node.hpp"
00032 #include "Exception.hpp"
00033 
00035 // Constructors
00037 
00038 template<unsigned SPACE_DIM>
00039 void Node<SPACE_DIM>::CommonConstructor(unsigned index, bool isBoundaryNode)
00040 {
00041     mIndex = index;
00042     mIsBoundaryNode = isBoundaryNode;
00043     mIsInternal = false;
00044     mIsDeleted = false;
00045     mRegion = 0;
00046 }
00047 
00048 template<unsigned SPACE_DIM>
00049 Node<SPACE_DIM>::Node(unsigned index, ChastePoint<SPACE_DIM> point, bool isBoundaryNode)
00050 {
00051     mLocation = point.rGetLocation();
00052     CommonConstructor(index, isBoundaryNode);
00053 }
00054 
00055 template<unsigned SPACE_DIM>
00056 Node<SPACE_DIM>::Node(unsigned index, std::vector<double> coords, bool isBoundaryNode)
00057 {
00058     for (unsigned i=0; i<SPACE_DIM; i++)
00059     {
00060         mLocation(i) = coords.at(i);
00061     }
00062     CommonConstructor(index, isBoundaryNode);
00063 }
00064 
00065 template<unsigned SPACE_DIM>
00066 Node<SPACE_DIM>::Node(unsigned index, c_vector<double, SPACE_DIM> location, bool isBoundaryNode)
00067 {
00068     mLocation = location;
00069     CommonConstructor(index, isBoundaryNode);
00070 }
00071 
00072 template<unsigned SPACE_DIM>
00073 Node<SPACE_DIM>::Node(unsigned index, bool isBoundaryNode, double v1, double v2, double v3)
00074 {
00075     mLocation[0] = v1;
00076     if (SPACE_DIM > 1)
00077     {
00078         mLocation[1] = v2;
00079         if (SPACE_DIM > 2)
00080         {
00081             mLocation[2] = v3;
00082         }
00083     }
00084     CommonConstructor(index, isBoundaryNode);
00085 }
00086 template<unsigned SPACE_DIM>
00087 Node<SPACE_DIM>::Node(unsigned index, double *location, bool isBoundaryNode)
00088 {
00089     for (unsigned i=0; i<SPACE_DIM; i++)
00090     {
00091         mLocation(i) = location[i];
00092     }
00093     CommonConstructor(index, isBoundaryNode);
00094     
00095 }
00097 // Methods dealing with node location
00099 
00100 template<unsigned SPACE_DIM>
00101 void Node<SPACE_DIM>::SetPoint(ChastePoint<SPACE_DIM> point)
00102 {
00103     mLocation = point.rGetLocation();
00104 }
00105 
00106 template<unsigned SPACE_DIM>
00107 void Node<SPACE_DIM>::SetIndex(unsigned index)
00108 {
00109     mIndex = index;
00110 }
00111 
00112 template<unsigned SPACE_DIM>
00113 void Node<SPACE_DIM>::SetAsBoundaryNode(bool value)
00114 {
00115     mIsBoundaryNode = value;
00116 }
00117 
00118 
00119 template<unsigned SPACE_DIM>
00120 ChastePoint<SPACE_DIM> Node<SPACE_DIM>::GetPoint() const
00121 {
00122     return ChastePoint<SPACE_DIM>(mLocation);
00123 }
00124 
00125 template<unsigned SPACE_DIM>
00126 const c_vector<double, SPACE_DIM>& Node<SPACE_DIM>::rGetLocation() const
00127 {
00128     assert(!mIsDeleted);
00129     return mLocation;
00130 }
00131 
00132 template<unsigned SPACE_DIM>
00133 c_vector<double, SPACE_DIM>& Node<SPACE_DIM>::rGetModifiableLocation()
00134 {
00135     assert(!mIsDeleted);
00136     return mLocation;
00137 }
00138 
00139 template<unsigned SPACE_DIM>
00140 unsigned Node<SPACE_DIM>::GetIndex() const
00141 {
00142     return mIndex;
00143 }
00144 
00145 template<unsigned SPACE_DIM>
00146 bool Node<SPACE_DIM>::IsBoundaryNode() const
00147 {
00148     return mIsBoundaryNode;
00149 }
00150 
00151 
00152 
00154 // Tracking (boundary) elements which contain this node as a vertex
00156 
00157 template<unsigned SPACE_DIM>
00158 void Node<SPACE_DIM>::AddElement(unsigned index)
00159 {
00160     mElementIndices.insert(index);
00161 }
00162 
00163 template<unsigned SPACE_DIM>
00164 void Node<SPACE_DIM>::RemoveElement(unsigned index)
00165 {
00166     unsigned count = mElementIndices.erase(index);
00167     if (count == 0)
00168     {
00169         EXCEPTION("Tried to remove an index which was not in the set");
00170     }
00171 }
00172 
00173 template<unsigned SPACE_DIM>
00174 void Node<SPACE_DIM>::RemoveBoundaryElement(unsigned index)
00175 {
00176     unsigned count = mBoundaryElementIndices.erase(index);
00177     if (count == 0)
00178     {
00179         EXCEPTION("Tried to remove an index which was not in the set");
00180     }
00181 }
00182 
00183 template<unsigned SPACE_DIM>
00184 void Node<SPACE_DIM>::AddBoundaryElement(unsigned index)
00185 {
00186     mBoundaryElementIndices.insert(index);
00187 }
00188 
00189 template<unsigned SPACE_DIM>
00190 std::set<unsigned>& Node<SPACE_DIM>::rGetContainingElementIndices()
00191 {
00192     return mElementIndices;
00193 }
00194 
00195 template<unsigned SPACE_DIM>
00196 std::set<unsigned>& Node<SPACE_DIM>::rGetContainingBoundaryElementIndices()
00197 {
00198     return mBoundaryElementIndices;
00199 }
00200 
00201 template<unsigned SPACE_DIM>
00202 unsigned Node<SPACE_DIM>::GetNumContainingElements() const
00203 {
00204     return mElementIndices.size();
00205 }
00206 
00207 template<unsigned SPACE_DIM>
00208 unsigned Node<SPACE_DIM>::GetNumBoundaryElements() const
00209 {
00210     return mBoundaryElementIndices.size();
00211 }
00212 
00214 // Methods dealing with some node flags (deleted, region)
00216 
00217 template<unsigned SPACE_DIM>
00218 void Node<SPACE_DIM>::MarkAsDeleted()
00219 {
00220     mIsDeleted = true;
00221 }
00222 
00223 template<unsigned SPACE_DIM>
00224 bool Node<SPACE_DIM>::IsDeleted() const
00225 {
00226     return mIsDeleted;
00227 }
00228 
00229 template<unsigned SPACE_DIM>
00230 void Node<SPACE_DIM>::MarkAsInternal()
00231 {
00232     mIsInternal = true;
00233 }
00234 
00235 template<unsigned SPACE_DIM>
00236 bool Node<SPACE_DIM>::IsInternal() const
00237 {
00238     return mIsInternal;
00239 }
00240 
00241 template<unsigned SPACE_DIM>
00242 void Node<SPACE_DIM>::SetRegion(unsigned region)
00243 {
00244     mRegion = region;
00245 }
00246 
00247 template<unsigned SPACE_DIM>
00248 unsigned Node<SPACE_DIM>::GetRegion() const
00249 {
00250     return mRegion;
00251 }
00252 
00253 
00255 // Explicit instantiation
00257 
00258 template class Node<1>;
00259 template class Node<2>;
00260 template class Node<3>;

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