Node.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 template<unsigned SPACE_DIM>
00153 void Node<SPACE_DIM>::AddNodeAttribute(double attribute)
00154 {
00155     mNodeAttributes.push_back(attribute);
00156 }
00157 
00158 template<unsigned SPACE_DIM>
00159 std::vector<double>& Node<SPACE_DIM>::rGetNodeAttributes()
00160 {
00161     return mNodeAttributes;
00162 }
00163 
00165 // Tracking (boundary) elements which contain this node as a vertex
00167 
00168 template<unsigned SPACE_DIM>
00169 void Node<SPACE_DIM>::AddElement(unsigned index)
00170 {
00171     mElementIndices.insert(index);
00172 }
00173 
00174 template<unsigned SPACE_DIM>
00175 void Node<SPACE_DIM>::RemoveElement(unsigned index)
00176 {
00177     unsigned count = mElementIndices.erase(index);
00178     if (count == 0)
00179     {
00180         EXCEPTION("Tried to remove an index which was not in the set");
00181     }
00182 }
00183 
00184 template<unsigned SPACE_DIM>
00185 void Node<SPACE_DIM>::RemoveBoundaryElement(unsigned index)
00186 {
00187     unsigned count = mBoundaryElementIndices.erase(index);
00188     if (count == 0)
00189     {
00190         EXCEPTION("Tried to remove an index which was not in the set");
00191     }
00192 }
00193 
00194 template<unsigned SPACE_DIM>
00195 void Node<SPACE_DIM>::AddBoundaryElement(unsigned index)
00196 {
00197     mBoundaryElementIndices.insert(index);
00198 }
00199 
00200 template<unsigned SPACE_DIM>
00201 std::set<unsigned>& Node<SPACE_DIM>::rGetContainingElementIndices()
00202 {
00203     return mElementIndices;
00204 }
00205 
00206 template<unsigned SPACE_DIM>
00207 std::set<unsigned>& Node<SPACE_DIM>::rGetContainingBoundaryElementIndices()
00208 {
00209     return mBoundaryElementIndices;
00210 }
00211 
00212 template<unsigned SPACE_DIM>
00213 unsigned Node<SPACE_DIM>::GetNumContainingElements() const
00214 {
00215     return mElementIndices.size();
00216 }
00217 
00218 template<unsigned SPACE_DIM>
00219 unsigned Node<SPACE_DIM>::GetNumBoundaryElements() const
00220 {
00221     return mBoundaryElementIndices.size();
00222 }
00223 
00225 // Methods dealing with some node flags (deleted, region)
00227 
00228 template<unsigned SPACE_DIM>
00229 void Node<SPACE_DIM>::MarkAsDeleted()
00230 {
00231     mIsDeleted = true;
00232 }
00233 
00234 template<unsigned SPACE_DIM>
00235 bool Node<SPACE_DIM>::IsDeleted() const
00236 {
00237     return mIsDeleted;
00238 }
00239 
00240 template<unsigned SPACE_DIM>
00241 void Node<SPACE_DIM>::MarkAsInternal()
00242 {
00243     mIsInternal = true;
00244 }
00245 
00246 template<unsigned SPACE_DIM>
00247 bool Node<SPACE_DIM>::IsInternal() const
00248 {
00249     return mIsInternal;
00250 }
00251 
00252 template<unsigned SPACE_DIM>
00253 void Node<SPACE_DIM>::SetRegion(unsigned region)
00254 {
00255     mRegion = region;
00256 }
00257 
00258 template<unsigned SPACE_DIM>
00259 unsigned Node<SPACE_DIM>::GetRegion() const
00260 {
00261     return mRegion;
00262 }
00263 
00264 
00266 // Explicit instantiation
00268 
00269 template class Node<1>;
00270 template class Node<2>;
00271 template class Node<3>;

Generated on Mon Apr 18 11:35:35 2011 for Chaste by  doxygen 1.5.5