AbstractTetrahedralMesh.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
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 "AbstractTetrahedralMesh.hpp"
00030 
00032 // Implementation
00034 
00035 
00036 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00037 void AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::SetElementOwnerships(unsigned lo, unsigned hi)
00038 {
00039     assert(hi >= lo);
00040     for (unsigned element_index=0; element_index<mElements.size(); element_index++)
00041     {
00042         Element<ELEMENT_DIM, SPACE_DIM> *p_element = mElements[element_index];
00043         p_element->SetOwnership(false);
00044         for (unsigned local_node_index=0; local_node_index< p_element->GetNumNodes(); local_node_index++)
00045         {
00046             unsigned global_node_index = p_element->GetNodeGlobalIndex(local_node_index);
00047             if (lo<=global_node_index && global_node_index<hi)
00048             {
00049                 p_element->SetOwnership(true);
00050                 break;
00051             }
00052         }
00053     }
00054 }
00055 
00056 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00057 AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::AbstractTetrahedralMesh()
00058 {
00059 }
00060 
00061 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00062 AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::~AbstractTetrahedralMesh()
00063 {
00064     // Iterate over elements and free the memory
00065     for (unsigned i=0; i<mElements.size(); i++)
00066     {
00067         delete mElements[i];
00068     }
00069     // Iterate over boundary elements and free the memory
00070     for (unsigned i=0; i<mBoundaryElements.size(); i++)
00071     {
00072         delete mBoundaryElements[i];
00073     }
00074 }
00075 
00076 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00077 unsigned AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::GetNumElements() const
00078 {
00079     return mElements.size();
00080 }
00081 
00082 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00083 unsigned AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::GetNumAllElements() const
00084 {
00085     return mElements.size();
00086 }
00087 
00088 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00089 unsigned AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::GetNumAllBoundaryElements() const
00090 {
00091     return mBoundaryElements.size();
00092 }
00093 
00094 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00095 unsigned AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::GetNumBoundaryElements() const
00096 {
00097     return mBoundaryElements.size();
00098 }
00099 
00100 
00101 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00102 Element<ELEMENT_DIM, SPACE_DIM>* AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::GetElement(unsigned index) const
00103 {
00104     unsigned local_index = SolveElementMapping(index);
00105     return mElements[local_index];
00106 }
00107 
00108 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00109 BoundaryElement<ELEMENT_DIM-1, SPACE_DIM>* AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::GetBoundaryElement(unsigned index) const
00110 {
00111     unsigned local_index = SolveBoundaryElementMapping(index);
00112     return mBoundaryElements[local_index];
00113 }
00114 
00115 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00116 typename AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::BoundaryElementIterator AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::GetBoundaryElementIteratorBegin() const
00117 {
00118     return mBoundaryElements.begin();
00119 }
00120 
00121 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00122 typename AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::BoundaryElementIterator AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::GetBoundaryElementIteratorEnd() const
00123 {
00124     return mBoundaryElements.end();
00125 }
00126 
00127 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00128 void AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::GetInverseJacobianForElement(
00129         unsigned elementIndex,
00130         c_matrix<double, SPACE_DIM, ELEMENT_DIM>& rJacobian,
00131         double& rJacobianDeterminant,
00132         c_matrix<double, ELEMENT_DIM, SPACE_DIM>& rInverseJacobian) const
00133 {
00134     mElements[SolveElementMapping(elementIndex)]->CalculateInverseJacobian(rJacobian, rJacobianDeterminant, rInverseJacobian);
00135 }
00136 
00137 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00138 void AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::GetWeightedDirectionForBoundaryElement(
00139         unsigned elementIndex,
00140         c_vector<double, SPACE_DIM>& rWeightedDirection,
00141         double& rJacobianDeterminant) const
00142 {
00143     mBoundaryElements[SolveBoundaryElementMapping(elementIndex)]->CalculateWeightedDirection(rWeightedDirection, rJacobianDeterminant );
00144 }
00145 
00147 // Explicit instantiation
00149 
00150 template class AbstractTetrahedralMesh<1,1>;
00151 template class AbstractTetrahedralMesh<1,2>;
00152 template class AbstractTetrahedralMesh<1,3>;
00153 template class AbstractTetrahedralMesh<2,2>;
00154 template class AbstractTetrahedralMesh<2,3>;
00155 template class AbstractTetrahedralMesh<3,3>;

Generated on Tue Aug 4 16:10:22 2009 for Chaste by  doxygen 1.5.5