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

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