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

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