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 #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
00052
00056 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00057 class TetrahedralMesh : public AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM>
00058 {
00059 friend class TestTetrahedralMesh;
00060 friend class TestCryptSimulation2d;
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_