Chaste Release::3.1
VertexElement.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 #include "VertexElement.hpp"
00036 #include "RandomNumberGenerator.hpp"
00037 #include <cassert>
00038 
00039 
00040 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00041 VertexElement<ELEMENT_DIM, SPACE_DIM>::VertexElement(unsigned index,
00042                                                      const std::vector<VertexElement<ELEMENT_DIM-1,SPACE_DIM>*>& rFaces,
00043                                                      const std::vector<bool>& rOrientations,
00044                                                      const std::vector<Node<SPACE_DIM>*>& rNodes)
00045     : MutableElement<ELEMENT_DIM, SPACE_DIM>(index, rNodes),
00046       mFaces(rFaces),
00047       mOrientations(rOrientations)
00048 {
00049     // This constructor should only be used in 3D
00050     assert(SPACE_DIM == 3);
00051 
00052     // Each face must have an associated orientation
00053     assert(mFaces.size() == mOrientations.size());
00054 
00055     if (SPACE_DIM == ELEMENT_DIM)
00056     {
00057         // Register element with nodes
00058         this->RegisterWithNodes();
00059     }
00060 }
00061 
00062 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00063 VertexElement<ELEMENT_DIM, SPACE_DIM>::VertexElement(unsigned index,
00064                                                      const std::vector<VertexElement<ELEMENT_DIM-1,SPACE_DIM>*>& rFaces,
00065                                                      const std::vector<bool>& rOrientations)
00066     : MutableElement<ELEMENT_DIM, SPACE_DIM>(index),
00067       mFaces(rFaces),
00068       mOrientations(rOrientations)
00069 {
00070     // Each face must have an associated orientation
00071     assert(mFaces.size() == mOrientations.size());
00072 
00073     // Make a set of nodes with mFaces
00074     std::set<Node<SPACE_DIM>* > nodes_set;
00075     for (unsigned face_index=0; face_index<mFaces.size(); face_index++)
00076     {
00077         for (unsigned node_index=0; node_index<mFaces[face_index]->GetNumNodes(); node_index++)
00078         {
00079             nodes_set.insert(mFaces[face_index]->GetNode(node_index));
00080         }
00081     }
00082 
00083     // Populate mNodes
00084     for (typename std::set< Node<SPACE_DIM>* >::iterator node_iter = nodes_set.begin();
00085          node_iter != nodes_set.end();
00086          ++node_iter)
00087     {
00088          this->mNodes.push_back(*node_iter);
00089     }
00090 
00091     // Register element with nodes
00092     this->RegisterWithNodes();
00093 }
00094 
00095 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00096 VertexElement<ELEMENT_DIM, SPACE_DIM>::VertexElement(unsigned index)
00097     : MutableElement<ELEMENT_DIM, SPACE_DIM>(index)
00098 {
00099 }
00100 
00101 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00102 VertexElement<ELEMENT_DIM, SPACE_DIM>::VertexElement(unsigned index,
00103                                                      const std::vector<Node<SPACE_DIM>*>& rNodes)
00104     : MutableElement<ELEMENT_DIM, SPACE_DIM>(index, rNodes)
00105 {
00106 }
00107 
00108 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00109 VertexElement<ELEMENT_DIM, SPACE_DIM>::~VertexElement()
00110 {
00111 }
00112 
00113 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00114 unsigned VertexElement<ELEMENT_DIM, SPACE_DIM>::GetNumFaces() const
00115 {
00116     return mFaces.size();
00117 }
00118 
00119 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00120 void VertexElement<ELEMENT_DIM, SPACE_DIM>::AddFace(VertexElement<ELEMENT_DIM-1,SPACE_DIM>* pFace)
00121 {
00122     // Add pFace to the end of mFaces
00123     this->mFaces.push_back(pFace);
00124 
00125     // Create a set of indices of nodes currently owned by this element
00126     std::set<unsigned> node_indices;
00127     for (unsigned local_index=0; local_index<this->GetNumNodes(); local_index++)
00128     {
00129         node_indices.insert(this->GetNodeGlobalIndex(local_index));
00130     }
00131 
00132     // Loop over nodes owned by pFace
00133     unsigned end_index = this->GetNumNodes()-1;
00134     for (unsigned local_index=0; local_index<pFace->GetNumNodes(); local_index++)
00135     {
00136         // If this node is not already owned by this element...
00137         unsigned global_index = pFace->GetNodeGlobalIndex(local_index);
00138         if (node_indices.find(global_index) == node_indices.end())
00139         {
00140             // ... then add it to the element (and vice versa)
00141             this->AddNode(pFace->GetNode(local_index), end_index);
00142             end_index++;
00143         }
00144     }
00145 }
00146 
00147 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00148 VertexElement<ELEMENT_DIM-1,  SPACE_DIM>* VertexElement<ELEMENT_DIM, SPACE_DIM>::GetFace(unsigned index) const
00149 {
00150     assert(index < mFaces.size());
00151     return mFaces[index];
00152 }
00153 
00154 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00155 bool VertexElement<ELEMENT_DIM, SPACE_DIM>::FaceIsOrientatedClockwise(unsigned index) const
00156 {
00157     assert(index < mOrientations.size());
00158     return mOrientations[index];
00159 }
00160 
00162 //                  Specialization for 1d elements                  //
00163 //                                                                  //
00164 //                 1d elements are just edges (lines)               //
00166 
00171 template<unsigned SPACE_DIM>
00172 VertexElement<1, SPACE_DIM>::VertexElement(unsigned index, const std::vector<Node<SPACE_DIM>*>& rNodes)
00173     : MutableElement<1, SPACE_DIM>(index, rNodes)
00174 {
00175 }
00176 
00177 template<unsigned SPACE_DIM>
00178 unsigned VertexElement<1, SPACE_DIM>::GetNumFaces() const
00179 {
00180     return 0;
00181 }
00182 
00183 template<unsigned SPACE_DIM>
00184 VertexElement<0, SPACE_DIM>* VertexElement<1, SPACE_DIM>::GetFace(unsigned index) const
00185 {
00186     return NULL;
00187 }
00188 
00189 template<unsigned SPACE_DIM>
00190 bool VertexElement<1, SPACE_DIM>::FaceIsOrientatedClockwise(unsigned index) const
00191 {
00192     return false;
00193 }
00194 
00195 
00197 // Explicit instantiation
00199 
00200 template class VertexElement<1,1>;
00201 template class VertexElement<1,2>;
00202 template class VertexElement<1,3>;
00203 template class VertexElement<2,2>;
00204 template class VertexElement<2,3>;
00205 template class VertexElement<3,3>;