Chaste Release::3.1
Node.cpp
00001 /*
00002 
00003 Copyright (c) 2005-2012, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #include <cassert>
00037 
00038 #include "Node.hpp"
00039 #include "Exception.hpp"
00040 
00042 // Constructors
00044 
00045 template<unsigned SPACE_DIM>
00046 void Node<SPACE_DIM>::CommonConstructor(unsigned index, bool isBoundaryNode)
00047 {
00048     mIndex = index;
00049     mIsBoundaryNode = isBoundaryNode;
00050     mIsInternal = false;
00051     mIsDeleted = false;
00052     mRegion = 0;
00053 }
00054 
00055 template<unsigned SPACE_DIM>
00056 Node<SPACE_DIM>::Node(unsigned index, ChastePoint<SPACE_DIM> point, bool isBoundaryNode)
00057 {
00058     mLocation = point.rGetLocation();
00059     CommonConstructor(index, isBoundaryNode);
00060 }
00061 
00062 template<unsigned SPACE_DIM>
00063 Node<SPACE_DIM>::Node(unsigned index, std::vector<double> coords, bool isBoundaryNode)
00064 {
00065     for (unsigned i=0; i<SPACE_DIM; i++)
00066     {
00067         mLocation(i) = coords.at(i);
00068     }
00069     CommonConstructor(index, isBoundaryNode);
00070 }
00071 
00072 template<unsigned SPACE_DIM>
00073 Node<SPACE_DIM>::Node(unsigned index, c_vector<double, SPACE_DIM> location, bool isBoundaryNode)
00074 {
00075     mLocation = location;
00076     CommonConstructor(index, isBoundaryNode);
00077 }
00078 
00079 template<unsigned SPACE_DIM>
00080 Node<SPACE_DIM>::Node(unsigned index, bool isBoundaryNode, double v1, double v2, double v3)
00081 {
00082     mLocation[0] = v1;
00083     if (SPACE_DIM > 1)
00084     {
00085         mLocation[1] = v2;
00086         if (SPACE_DIM > 2)
00087         {
00088             mLocation[2] = v3;
00089         }
00090     }
00091     CommonConstructor(index, isBoundaryNode);
00092 }
00093 template<unsigned SPACE_DIM>
00094 Node<SPACE_DIM>::Node(unsigned index, double *location, bool isBoundaryNode)
00095 {
00096     for (unsigned i=0; i<SPACE_DIM; i++)
00097     {
00098         mLocation(i) = location[i];
00099     }
00100     CommonConstructor(index, isBoundaryNode);
00101 
00102 }
00104 // Methods dealing with node location
00106 
00107 template<unsigned SPACE_DIM>
00108 void Node<SPACE_DIM>::SetPoint(ChastePoint<SPACE_DIM> point)
00109 {
00110     mLocation = point.rGetLocation();
00111 }
00112 
00113 template<unsigned SPACE_DIM>
00114 void Node<SPACE_DIM>::SetIndex(unsigned index)
00115 {
00116     mIndex = index;
00117 }
00118 
00119 template<unsigned SPACE_DIM>
00120 void Node<SPACE_DIM>::SetAsBoundaryNode(bool value)
00121 {
00122     mIsBoundaryNode = value;
00123 }
00124 
00125 
00126 template<unsigned SPACE_DIM>
00127 ChastePoint<SPACE_DIM> Node<SPACE_DIM>::GetPoint() const
00128 {
00129     return ChastePoint<SPACE_DIM>(mLocation);
00130 }
00131 
00132 template<unsigned SPACE_DIM>
00133 const c_vector<double, SPACE_DIM>& Node<SPACE_DIM>::rGetLocation() const
00134 {
00135     assert(!mIsDeleted);
00136     return mLocation;
00137 }
00138 
00139 template<unsigned SPACE_DIM>
00140 c_vector<double, SPACE_DIM>& Node<SPACE_DIM>::rGetModifiableLocation()
00141 {
00142     assert(!mIsDeleted);
00143     return mLocation;
00144 }
00145 
00146 template<unsigned SPACE_DIM>
00147 unsigned Node<SPACE_DIM>::GetIndex() const
00148 {
00149     return mIndex;
00150 }
00151 
00152 template<unsigned SPACE_DIM>
00153 bool Node<SPACE_DIM>::IsBoundaryNode() const
00154 {
00155     return mIsBoundaryNode;
00156 }
00157 
00158 
00159 template<unsigned SPACE_DIM>
00160 void Node<SPACE_DIM>::AddNodeAttribute(double attribute)
00161 {
00162     mNodeAttributes.push_back(attribute);
00163 }
00164 
00165 template<unsigned SPACE_DIM>
00166 std::vector<double>& Node<SPACE_DIM>::rGetNodeAttributes()
00167 {
00168     return mNodeAttributes;
00169 }
00170 
00172 // Tracking (boundary) elements which contain this node as a vertex
00174 
00175 template<unsigned SPACE_DIM>
00176 void Node<SPACE_DIM>::AddElement(unsigned index)
00177 {
00178     mElementIndices.insert(index);
00179 }
00180 
00181 template<unsigned SPACE_DIM>
00182 void Node<SPACE_DIM>::RemoveElement(unsigned index)
00183 {
00184     unsigned count = mElementIndices.erase(index);
00185     if (count == 0)
00186     {
00187         EXCEPTION("Tried to remove an index which was not in the set");
00188     }
00189 }
00190 
00191 template<unsigned SPACE_DIM>
00192 void Node<SPACE_DIM>::RemoveBoundaryElement(unsigned index)
00193 {
00194     unsigned count = mBoundaryElementIndices.erase(index);
00195     if (count == 0)
00196     {
00197         EXCEPTION("Tried to remove an index which was not in the set");
00198     }
00199 }
00200 
00201 template<unsigned SPACE_DIM>
00202 void Node<SPACE_DIM>::AddBoundaryElement(unsigned index)
00203 {
00204     mBoundaryElementIndices.insert(index);
00205 }
00206 
00207 template<unsigned SPACE_DIM>
00208 std::set<unsigned>& Node<SPACE_DIM>::rGetContainingElementIndices()
00209 {
00210     return mElementIndices;
00211 }
00212 
00213 template<unsigned SPACE_DIM>
00214 std::set<unsigned>& Node<SPACE_DIM>::rGetContainingBoundaryElementIndices()
00215 {
00216     return mBoundaryElementIndices;
00217 }
00218 
00219 template<unsigned SPACE_DIM>
00220 unsigned Node<SPACE_DIM>::GetNumContainingElements() const
00221 {
00222     return mElementIndices.size();
00223 }
00224 
00225 template<unsigned SPACE_DIM>
00226 unsigned Node<SPACE_DIM>::GetNumBoundaryElements() const
00227 {
00228     return mBoundaryElementIndices.size();
00229 }
00230 
00232 // Methods dealing with some node flags (deleted, region)
00234 
00235 template<unsigned SPACE_DIM>
00236 void Node<SPACE_DIM>::MarkAsDeleted()
00237 {
00238     mIsDeleted = true;
00239 }
00240 
00241 template<unsigned SPACE_DIM>
00242 bool Node<SPACE_DIM>::IsDeleted() const
00243 {
00244     return mIsDeleted;
00245 }
00246 
00247 template<unsigned SPACE_DIM>
00248 void Node<SPACE_DIM>::MarkAsInternal()
00249 {
00250     mIsInternal = true;
00251 }
00252 
00253 template<unsigned SPACE_DIM>
00254 bool Node<SPACE_DIM>::IsInternal() const
00255 {
00256     return mIsInternal;
00257 }
00258 
00259 template<unsigned SPACE_DIM>
00260 void Node<SPACE_DIM>::SetRegion(unsigned region)
00261 {
00262     mRegion = region;
00263 }
00264 
00265 template<unsigned SPACE_DIM>
00266 unsigned Node<SPACE_DIM>::GetRegion() const
00267 {
00268     return mRegion;
00269 }
00270 
00271 
00273 // Explicit instantiation
00275 
00276 template class Node<1>;
00277 template class Node<2>;
00278 template class Node<3>;