Node.cpp

00001 /*
00002 
00003 Copyright (c) 2005-2014, 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     mpNodeAttributes = NULL;
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 
00094 template<unsigned SPACE_DIM>
00095 Node<SPACE_DIM>::Node(unsigned index, double *location, bool isBoundaryNode)
00096 {
00097     for (unsigned i=0; i<SPACE_DIM; i++)
00098     {
00099         mLocation(i) = location[i];
00100     }
00101     CommonConstructor(index, isBoundaryNode);
00102 }
00103 
00104 template<unsigned SPACE_DIM>
00105 Node<SPACE_DIM>::~Node()
00106 {
00107     delete mpNodeAttributes;
00108 }
00109 
00111 // Methods dealing with node location
00113 
00114 template<unsigned SPACE_DIM>
00115 void Node<SPACE_DIM>::SetPoint(ChastePoint<SPACE_DIM> point)
00116 {
00117     mLocation = point.rGetLocation();
00118 }
00119 
00120 template<unsigned SPACE_DIM>
00121 void Node<SPACE_DIM>::SetIndex(unsigned index)
00122 {
00123     mIndex = index;
00124 }
00125 
00126 template<unsigned SPACE_DIM>
00127 void Node<SPACE_DIM>::SetAsBoundaryNode(bool value)
00128 {
00129     mIsBoundaryNode = value;
00130 }
00131 
00132 
00133 template<unsigned SPACE_DIM>
00134 ChastePoint<SPACE_DIM> Node<SPACE_DIM>::GetPoint() const
00135 {
00136     return ChastePoint<SPACE_DIM>(mLocation);
00137 }
00138 
00139 template<unsigned SPACE_DIM>
00140 const c_vector<double, SPACE_DIM>& Node<SPACE_DIM>::rGetLocation() const
00141 {
00142     assert(!mIsDeleted);
00143     return mLocation;
00144 }
00145 
00146 template<unsigned SPACE_DIM>
00147 c_vector<double, SPACE_DIM>& Node<SPACE_DIM>::rGetModifiableLocation()
00148 {
00149     assert(!mIsDeleted);
00150     return mLocation;
00151 }
00152 
00153 template<unsigned SPACE_DIM>
00154 unsigned Node<SPACE_DIM>::GetIndex() const
00155 {
00156     return mIndex;
00157 }
00158 
00159 template<unsigned SPACE_DIM>
00160 bool Node<SPACE_DIM>::IsBoundaryNode() const
00161 {
00162     return mIsBoundaryNode;
00163 }
00164 
00165 template<unsigned SPACE_DIM>
00166 void Node<SPACE_DIM>::AddNodeAttribute(double attribute)
00167 {
00168     ConstructNodeAttributes();
00169 
00170     mpNodeAttributes->AddAttribute(attribute);
00171 }
00172 
00173 template<unsigned SPACE_DIM>
00174 std::vector<double>& Node<SPACE_DIM>::rGetNodeAttributes()
00175 {
00176     CheckForNodeAttributes();
00177 
00178     return mpNodeAttributes->rGetAttributes();
00179 }
00180 
00181 template<unsigned SPACE_DIM>
00182 unsigned Node<SPACE_DIM>::GetNumNodeAttributes()
00183 {
00184     unsigned num_attributes;
00185     if (!mpNodeAttributes)
00186     {
00187         num_attributes = 0u;
00188     }
00189     else
00190     {
00191         num_attributes = mpNodeAttributes->rGetAttributes().size();
00192     }
00193 
00194     return num_attributes;
00195 }
00196 
00197 template<unsigned SPACE_DIM>
00198 bool Node<SPACE_DIM>::HasNodeAttributes()
00199 {
00200     return (mpNodeAttributes != NULL);
00201 }
00202 
00203 template<unsigned SPACE_DIM>
00204 c_vector<double, SPACE_DIM>& Node<SPACE_DIM>::rGetAppliedForce()
00205 {
00206     CheckForNodeAttributes();
00207 
00208     return mpNodeAttributes->rGetAppliedForce();
00209 }
00210 
00211 template<unsigned SPACE_DIM>
00212 void Node<SPACE_DIM>::ClearAppliedForce()
00213 {
00214     ConstructNodeAttributes();
00215 
00216     mpNodeAttributes->ClearAppliedForce();
00217 }
00218 
00219 template<unsigned SPACE_DIM>
00220 void Node<SPACE_DIM>::AddAppliedForceContribution(c_vector<double, SPACE_DIM>& forceContribution)
00221 {
00222     ConstructNodeAttributes();
00223 
00224     mpNodeAttributes->AddAppliedForceContribution(forceContribution);
00225 }
00226 
00227 template<unsigned SPACE_DIM>
00228 bool Node<SPACE_DIM>::IsParticle()
00229 {
00230     CheckForNodeAttributes();
00231 
00232     return mpNodeAttributes->IsParticle();
00233 }
00234 
00235 template<unsigned SPACE_DIM>
00236 void Node<SPACE_DIM>::SetIsParticle(bool isParticle)
00237 {
00238     ConstructNodeAttributes();
00239 
00240     mpNodeAttributes->SetIsParticle(isParticle);
00241 }
00242 
00243 template<unsigned SPACE_DIM>
00244 double Node<SPACE_DIM>::GetRadius()
00245 {
00246     CheckForNodeAttributes();
00247 
00248     return mpNodeAttributes->GetRadius();
00249 }
00250 
00251 template<unsigned SPACE_DIM>
00252 void Node<SPACE_DIM>::SetRadius(double radius)
00253 {
00254     ConstructNodeAttributes();
00255 
00256     mpNodeAttributes->SetRadius(radius);
00257 }
00258 
00260 // Tracking (boundary) elements which contain this node as a vertex
00262 
00263 template<unsigned SPACE_DIM>
00264 void Node<SPACE_DIM>::AddElement(unsigned index)
00265 {
00266     mElementIndices.insert(index);
00267 }
00268 
00269 template<unsigned SPACE_DIM>
00270 void Node<SPACE_DIM>::RemoveElement(unsigned index)
00271 {
00272     unsigned count = mElementIndices.erase(index);
00273     if (count == 0)
00274     {
00275         EXCEPTION("Tried to remove an index which was not in the set");
00276     }
00277 }
00278 
00279 template<unsigned SPACE_DIM>
00280 void Node<SPACE_DIM>::RemoveBoundaryElement(unsigned index)
00281 {
00282     unsigned count = mBoundaryElementIndices.erase(index);
00283     if (count == 0)
00284     {
00285         EXCEPTION("Tried to remove an index which was not in the set");
00286     }
00287 }
00288 
00289 template<unsigned SPACE_DIM>
00290 void Node<SPACE_DIM>::AddBoundaryElement(unsigned index)
00291 {
00292     mBoundaryElementIndices.insert(index);
00293 }
00294 
00295 template<unsigned SPACE_DIM>
00296 std::set<unsigned>& Node<SPACE_DIM>::rGetContainingElementIndices()
00297 {
00298     return mElementIndices;
00299 }
00300 
00301 template<unsigned SPACE_DIM>
00302 std::set<unsigned>& Node<SPACE_DIM>::rGetContainingBoundaryElementIndices()
00303 {
00304     return mBoundaryElementIndices;
00305 }
00306 
00307 template<unsigned SPACE_DIM>
00308 unsigned Node<SPACE_DIM>::GetNumContainingElements() const
00309 {
00310     return mElementIndices.size();
00311 }
00312 
00313 template<unsigned SPACE_DIM>
00314 unsigned Node<SPACE_DIM>::GetNumBoundaryElements() const
00315 {
00316     return mBoundaryElementIndices.size();
00317 }
00318 
00320 // Methods dealing with some node flags (deleted, region)
00322 
00323 template<unsigned SPACE_DIM>
00324 void Node<SPACE_DIM>::CheckForNodeAttributes() const
00325 {
00326     if (mpNodeAttributes == NULL)
00327     {
00328         EXCEPTION("Node has no attributes associated with it. Construct attributes first");
00329     }
00330 }
00331 
00332 template<unsigned SPACE_DIM>
00333 void Node<SPACE_DIM>::ConstructNodeAttributes()
00334 {
00335     if (mpNodeAttributes == NULL)
00336     {
00337         mpNodeAttributes = new NodeAttributes<SPACE_DIM>();
00338     }
00339 }
00340 
00341 template<unsigned SPACE_DIM>
00342 void Node<SPACE_DIM>::MarkAsDeleted()
00343 {
00344     mIsDeleted = true;
00345 }
00346 
00347 template<unsigned SPACE_DIM>
00348 bool Node<SPACE_DIM>::IsDeleted() const
00349 {
00350     return mIsDeleted;
00351 }
00352 
00353 template<unsigned SPACE_DIM>
00354 void Node<SPACE_DIM>::MarkAsInternal()
00355 {
00356     mIsInternal = true;
00357 }
00358 
00359 template<unsigned SPACE_DIM>
00360 bool Node<SPACE_DIM>::IsInternal() const
00361 {
00362     return mIsInternal;
00363 }
00364 
00365 template<unsigned SPACE_DIM>
00366 void Node<SPACE_DIM>::SetRegion(unsigned region)
00367 {
00368     ConstructNodeAttributes();
00369     mpNodeAttributes->SetRegion(region);
00370 }
00371 
00372 template<unsigned SPACE_DIM>
00373 unsigned Node<SPACE_DIM>::GetRegion() const
00374 {
00375     unsigned region = 0;
00376 
00377     if (mpNodeAttributes)
00378     {
00379         region = mpNodeAttributes->GetRegion();
00380     }
00381 
00382     return region;
00383 }
00384 
00385 
00387 // Explicit instantiation
00389 
00390 template class Node<1>;
00391 template class Node<2>;
00392 template class Node<3>;

Generated by  doxygen 1.6.2