TetrahedralMesh.hpp

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 
00036 #ifndef _TETRAHEDRALMESH_HPP_
00037 #define _TETRAHEDRALMESH_HPP_
00038 
00039 #include "ChasteSerialization.hpp"
00040 #include <boost/serialization/base_object.hpp>
00041 
00042 #include "UblasVectorInclude.hpp"
00043 #include "UblasMatrixInclude.hpp"
00044 
00045 #include <vector>
00046 #include <string>
00047 #include <set>
00048 
00049 #include "AbstractTetrahedralMesh.hpp"
00050 #include "AbstractMeshReader.hpp"
00051 #include "ChastePoint.hpp"
00052 
00053 
00054 struct triangulateio; 
00056 
00057 //   DECLARATION
00059 
00063 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00064 class TetrahedralMesh : public AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM>
00065 {
00066     friend class TestTetrahedralMesh; // to give access to private methods (not variables)
00067     friend class TestCryptSimulation2d; // to give access to private methods (not variables)
00068 private:
00070     friend class boost::serialization::access;
00077     template<class Archive>
00078     void serialize(Archive & archive, const unsigned int version)
00079     {
00080        archive & boost::serialization::base_object<AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
00081     }
00082 
00083 protected:
00084 
00091     unsigned SolveNodeMapping(unsigned index) const;
00092 
00099     unsigned SolveElementMapping(unsigned index) const;
00100 
00107     unsigned SolveBoundaryElementMapping(unsigned index) const;
00108 
00110     std::vector< c_vector<double, SPACE_DIM> > mElementWeightedDirections;
00111 
00113     std::vector< c_matrix<double, SPACE_DIM, ELEMENT_DIM> > mElementJacobians;
00114 
00116     std::vector< c_matrix<double, ELEMENT_DIM, SPACE_DIM> > mElementInverseJacobians;
00117 
00119     std::vector<double> mElementJacobianDeterminants;
00120 
00122     std::vector< c_vector<double, SPACE_DIM> > mBoundaryElementWeightedDirections;
00123 
00125     std::vector<double> mBoundaryElementJacobianDeterminants;
00126 
00143     template <class MESHER_IO>
00144     void ExportToMesher(NodeMap& map, MESHER_IO& mesherInput, int *elementList=NULL);
00145 
00162     template <class MESHER_IO>
00163     void ImportFromMesher(MESHER_IO& mesherOutput, unsigned numberOfElements, int *elementList, unsigned numberOfFaces, int *faceList, int *edgeMarkerList);
00164 
00165 
00170     void InitialiseTriangulateIo(triangulateio& mesherIo);
00171 
00176     void FreeTriangulateIo(triangulateio& mesherIo);
00177 
00178 public:
00179 
00183     TetrahedralMesh();
00184 
00190     void ConstructFromMeshReader(AbstractMeshReader<ELEMENT_DIM,SPACE_DIM>& rMeshReader);
00191 
00197     void ReadNodesPerProcessorFile(const std::string& rNodesPerProcessorFile);
00198 
00211     bool CheckIsConforming();
00212 
00217     double GetVolume();
00218 
00222     double GetSurfaceArea();
00223 
00227     void RefreshMesh();
00228 
00233     void PermuteNodes();
00234 
00240     void PermuteNodes(const std::vector<unsigned>& perm);
00241 
00251     unsigned GetContainingElementIndexWithInitialGuess(const ChastePoint<SPACE_DIM>& rTestPoint, unsigned startingElementGuess, bool strict=false);
00252 
00261     unsigned GetNearestElementIndex(const ChastePoint<SPACE_DIM>& rTestPoint);
00262 
00268     std::vector<unsigned> GetContainingElementIndices(const ChastePoint<SPACE_DIM>& rTestPoint);
00269 
00273     virtual void Clear();
00274 
00278     std::set<unsigned> CalculateBoundaryOfFlaggedRegion();
00279 
00287     double GetAngleBetweenNodes(unsigned indexA, unsigned indexB);
00288 
00292     void UnflagAllElements();
00293 
00299     void FlagElementsNotContainingNodes(const std::set<unsigned>& rNodes);
00300 
00302     virtual void RefreshJacobianCachedData();
00303 
00311     virtual void GetJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, SPACE_DIM>& rJacobian, double& rJacobianDeterminant) const;
00312 
00321     virtual void GetInverseJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, ELEMENT_DIM>& rJacobian, double& rJacobianDeterminant, c_matrix<double, ELEMENT_DIM, SPACE_DIM>& rInverseJacobian) const;
00322 
00330     virtual void GetWeightedDirectionForElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00331 
00339     virtual void GetWeightedDirectionForBoundaryElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00340 
00347     class EdgeIterator
00348     {
00349     public:
00353         Node<SPACE_DIM>* GetNodeA();
00357         Node<SPACE_DIM>* GetNodeB();
00358 
00364         bool operator!=(const typename TetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::EdgeIterator& rOther);
00365 
00370         EdgeIterator& operator++();
00371 
00378         EdgeIterator(TetrahedralMesh& rMesh, unsigned elemIndex);
00379 
00380     private:
00385         std::set< std::pair<unsigned, unsigned> > mEdgesVisited;
00386 
00387         TetrahedralMesh& mrMesh;   
00389         unsigned mElemIndex;       
00390         unsigned mNodeALocalIndex; 
00391         unsigned mNodeBLocalIndex; 
00392     };
00393 
00397     EdgeIterator EdgesBegin();
00398 
00403     EdgeIterator EdgesEnd();
00404 };
00405 
00406 #include "SerializationExportWrapper.hpp"
00407 EXPORT_TEMPLATE_CLASS_ALL_DIMS(TetrahedralMesh)
00408 
00409 #endif //_TETRAHEDRALMESH_HPP_

Generated by  doxygen 1.6.2