TetrahedralMesh.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 #ifndef _TETRAHEDRALMESH_HPP_
00030 #define _TETRAHEDRALMESH_HPP_
00031 
00032 #include "ChasteSerialization.hpp"
00033 #include <boost/serialization/base_object.hpp>
00034 
00035 #include "UblasVectorInclude.hpp"
00036 #include "UblasMatrixInclude.hpp"
00037 
00038 #include <vector>
00039 #include <string>
00040 #include <set>
00041 
00042 #include "AbstractTetrahedralMesh.hpp"
00043 #include "AbstractMeshReader.hpp"
00044 #include "ChastePoint.hpp"
00045 
00046 
00047 class triangulateio; 
00049 
00050 //   DECLARATION
00052 
00056 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00057 class TetrahedralMesh : public AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM>
00058 {
00059     friend class TestTetrahedralMesh; // to give access to private methods (not variables)
00060     friend class TestCryptSimulation2d; // to give access to private methods (not variables)
00061 
00062 private:
00064     friend class boost::serialization::access;
00071     template<class Archive>
00072     void serialize(Archive & archive, const unsigned int version)
00073     {
00074        archive & boost::serialization::base_object<AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
00075     }
00076 
00077 protected:
00078 
00084     unsigned SolveNodeMapping(unsigned index) const;
00085 
00091     unsigned SolveElementMapping(unsigned index) const;
00092 
00098     unsigned SolveBoundaryElementMapping(unsigned index) const;
00099 
00101     std::vector< c_vector<double, SPACE_DIM> > mElementWeightedDirections;
00102 
00104     std::vector< c_matrix<double, SPACE_DIM, ELEMENT_DIM> > mElementJacobians;
00105 
00107     std::vector< c_matrix<double, ELEMENT_DIM, SPACE_DIM> > mElementInverseJacobians;
00108 
00110     std::vector<double> mElementJacobianDeterminants;
00111 
00113     std::vector< c_vector<double, SPACE_DIM> > mBoundaryElementWeightedDirections;
00114 
00116     std::vector<double> mBoundaryElementJacobianDeterminants;
00117     
00134     template <class MESHER_IO>
00135     void ExportToMesher(NodeMap& map, MESHER_IO& mesherInput, int *elementList=NULL);
00136 
00153     template <class MESHER_IO>
00154     void ImportFromMesher(MESHER_IO& mesherOutput, unsigned numberOfElements, int *elementList, unsigned numberOfFaces, int *faceList, int *edgeMarkerList);
00155 
00156 
00161     void InitialiseTriangulateIo(triangulateio& mesherIo);
00162     
00167     void FreeTriangulateIo(triangulateio& mesherIo);
00168 
00169 public:
00170 
00174     TetrahedralMesh();
00175 
00181     void ConstructFromMeshReader(AbstractMeshReader<ELEMENT_DIM,SPACE_DIM>& rMeshReader);
00182 
00190     void ConstructNodesWithoutMesh(const std::vector< Node<SPACE_DIM>*> & rNodes);
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 
00254     unsigned GetContainingElementIndex(const ChastePoint<SPACE_DIM>& rTestPoint,
00255                                        bool strict=false,
00256                                        std::set<unsigned> testElements=std::set<unsigned>(),
00257                                        bool onlyTryWithTestElements = false);
00258 
00259 
00269     unsigned GetContainingElementIndexWithInitialGuess(const ChastePoint<SPACE_DIM>& rTestPoint, unsigned startingElementGuess, bool strict=false);
00270 
00279     unsigned GetNearestElementIndex(const ChastePoint<SPACE_DIM>& rTestPoint);
00280 
00285     unsigned GetNearestElementIndexFromTestElements(const ChastePoint<SPACE_DIM>& rTestPoint,
00286                                                     std::set<unsigned> testElements);
00287 
00288 
00294     std::vector<unsigned> GetContainingElementIndices(const ChastePoint<SPACE_DIM>& rTestPoint);
00295 
00299     virtual void Clear();
00300 
00304     std::set<unsigned> CalculateBoundaryOfFlaggedRegion();
00305 
00313     double GetAngleBetweenNodes(unsigned indexA, unsigned indexB);
00314 
00318     void UnflagAllElements();
00319 
00325     void FlagElementsNotContainingNodes(const std::set<unsigned> rNodes);
00326 
00328     virtual void RefreshJacobianCachedData();
00329 
00337     virtual void GetJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, SPACE_DIM>& rJacobian, double& rJacobianDeterminant) const;
00338 
00347     virtual void GetInverseJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, ELEMENT_DIM>& rJacobian, double& rJacobianDeterminant, c_matrix<double, ELEMENT_DIM, SPACE_DIM>& rInverseJacobian) const;
00348 
00356     virtual void GetWeightedDirectionForElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00357 
00365     virtual void GetWeightedDirectionForBoundaryElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00366 
00373     class EdgeIterator
00374     {
00375     public:
00379         Node<SPACE_DIM>* GetNodeA();
00383         Node<SPACE_DIM>* GetNodeB();
00384 
00390         bool operator!=(const TetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::EdgeIterator& rOther);
00391 
00395         EdgeIterator& operator++();
00396 
00403         EdgeIterator(TetrahedralMesh& rMesh, unsigned elemIndex);
00404         
00405         
00406         
00407 
00408     private:
00412         std::set< std::pair<unsigned, unsigned> > mEdgesVisited;
00413 
00414         TetrahedralMesh& mrMesh;   
00416         unsigned mElemIndex;       
00417         unsigned mNodeALocalIndex; 
00418         unsigned mNodeBLocalIndex; 
00420     };
00421 
00425     EdgeIterator EdgesBegin();
00426 
00431     EdgeIterator EdgesEnd();
00432 };
00433 
00434 #include "SerializationExportWrapper.hpp"
00435 EXPORT_TEMPLATE_CLASS_ALL_DIMS(TetrahedralMesh)
00436 
00437 #endif //_TETRAHEDRALMESH_HPP_

Generated on Mon Apr 18 11:35:35 2011 for Chaste by  doxygen 1.5.5