VertexElement.cpp

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

Generated by  doxygen 1.6.2