TetrahedralMesh.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
00059
00063 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00064 class TetrahedralMesh : public AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM>
00065 {
00066 friend class TestTetrahedralMesh;
00067 friend class TestCryptSimulation2d;
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_