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 private:
00063     friend class boost::serialization::access;
00070     template<class Archive>
00071     void serialize(Archive & archive, const unsigned int version)
00072     {
00073        archive & boost::serialization::base_object<AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
00074     }
00075 
00076 protected:
00077 
00083     unsigned SolveNodeMapping(unsigned index) const;
00084 
00090     unsigned SolveElementMapping(unsigned index) const;
00091 
00097     unsigned SolveBoundaryElementMapping(unsigned index) const;
00098 
00100     std::vector< c_vector<double, SPACE_DIM> > mElementWeightedDirections;
00101 
00103     std::vector< c_matrix<double, SPACE_DIM, ELEMENT_DIM> > mElementJacobians;
00104 
00106     std::vector< c_matrix<double, ELEMENT_DIM, SPACE_DIM> > mElementInverseJacobians;
00107 
00109     std::vector<double> mElementJacobianDeterminants;
00110 
00112     std::vector< c_vector<double, SPACE_DIM> > mBoundaryElementWeightedDirections;
00113 
00115     std::vector<double> mBoundaryElementJacobianDeterminants;
00116 
00133     template <class MESHER_IO>
00134     void ExportToMesher(NodeMap& map, MESHER_IO& mesherInput, int *elementList=NULL);
00135 
00152     template <class MESHER_IO>
00153     void ImportFromMesher(MESHER_IO& mesherOutput, unsigned numberOfElements, int *elementList, unsigned numberOfFaces, int *faceList, int *edgeMarkerList);
00154 
00155 
00160     void InitialiseTriangulateIo(triangulateio& mesherIo);
00161 
00166     void FreeTriangulateIo(triangulateio& mesherIo);
00167 
00168 public:
00169 
00173     TetrahedralMesh();
00174 
00180     void ConstructFromMeshReader(AbstractMeshReader<ELEMENT_DIM,SPACE_DIM>& rMeshReader);
00181 
00187     void ReadNodesPerProcessorFile(const std::string& rNodesPerProcessorFile);
00188 
00201     bool CheckIsConforming();
00202 
00207     double GetVolume();
00208 
00212     double GetSurfaceArea();
00213 
00217     void RefreshMesh();
00218 
00223     void PermuteNodes();
00224 
00230     void PermuteNodes(const std::vector<unsigned>& perm);
00231 
00244     unsigned GetContainingElementIndex(const ChastePoint<SPACE_DIM>& rTestPoint,
00245                                        bool strict=false,
00246                                        std::set<unsigned> testElements=std::set<unsigned>(),
00247                                        bool onlyTryWithTestElements = false);
00248 
00249 
00259     unsigned GetContainingElementIndexWithInitialGuess(const ChastePoint<SPACE_DIM>& rTestPoint, unsigned startingElementGuess, bool strict=false);
00260 
00269     unsigned GetNearestElementIndex(const ChastePoint<SPACE_DIM>& rTestPoint);
00270 
00275     unsigned GetNearestElementIndexFromTestElements(const ChastePoint<SPACE_DIM>& rTestPoint,
00276                                                     std::set<unsigned> testElements);
00277 
00278 
00284     std::vector<unsigned> GetContainingElementIndices(const ChastePoint<SPACE_DIM>& rTestPoint);
00285 
00289     virtual void Clear();
00290 
00294     std::set<unsigned> CalculateBoundaryOfFlaggedRegion();
00295 
00303     double GetAngleBetweenNodes(unsigned indexA, unsigned indexB);
00304 
00308     void UnflagAllElements();
00309 
00315     void FlagElementsNotContainingNodes(const std::set<unsigned> rNodes);
00316 
00318     virtual void RefreshJacobianCachedData();
00319 
00327     virtual void GetJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, SPACE_DIM>& rJacobian, double& rJacobianDeterminant) const;
00328 
00337     virtual void GetInverseJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, ELEMENT_DIM>& rJacobian, double& rJacobianDeterminant, c_matrix<double, ELEMENT_DIM, SPACE_DIM>& rInverseJacobian) const;
00338 
00346     virtual void GetWeightedDirectionForElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00347 
00355     virtual void GetWeightedDirectionForBoundaryElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00356 
00363     class EdgeIterator
00364     {
00365     public:
00369         Node<SPACE_DIM>* GetNodeA();
00373         Node<SPACE_DIM>* GetNodeB();
00374 
00380         bool operator!=(const TetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::EdgeIterator& rOther);
00381 
00385         EdgeIterator& operator++();
00386 
00393         EdgeIterator(TetrahedralMesh& rMesh, unsigned elemIndex);
00394 
00395 
00396 
00397 
00398     private:
00402         std::set< std::pair<unsigned, unsigned> > mEdgesVisited;
00403 
00404         TetrahedralMesh& mrMesh;   
00406         unsigned mElemIndex;       
00407         unsigned mNodeALocalIndex; 
00408         unsigned mNodeBLocalIndex; 
00410     };
00411 
00415     EdgeIterator EdgesBegin();
00416 
00421     EdgeIterator EdgesEnd();
00422 };
00423 
00424 #include "SerializationExportWrapper.hpp"
00425 EXPORT_TEMPLATE_CLASS_ALL_DIMS(TetrahedralMesh)
00426 
00427 #endif //_TETRAHEDRALMESH_HPP_
Generated on Thu Dec 22 13:00:16 2011 for Chaste by  doxygen 1.6.3