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 template <unsigned A_DIMENSION> friend class NodesOnlyMesh;
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
00188 void ReadNodesPerProcessorFile(const std::string& rNodesPerProcessorFile);
00189
00202 bool CheckIsConforming();
00203
00208 double GetVolume();
00209
00213 double GetSurfaceArea();
00214
00218 void RefreshMesh();
00219
00224 void PermuteNodes();
00225
00231 void PermuteNodes(const std::vector<unsigned>& perm);
00232
00245 unsigned GetContainingElementIndex(const ChastePoint<SPACE_DIM>& rTestPoint,
00246 bool strict=false,
00247 std::set<unsigned> testElements=std::set<unsigned>(),
00248 bool onlyTryWithTestElements = false);
00249
00250
00260 unsigned GetContainingElementIndexWithInitialGuess(const ChastePoint<SPACE_DIM>& rTestPoint, unsigned startingElementGuess, bool strict=false);
00261
00270 unsigned GetNearestElementIndex(const ChastePoint<SPACE_DIM>& rTestPoint);
00271
00276 unsigned GetNearestElementIndexFromTestElements(const ChastePoint<SPACE_DIM>& rTestPoint,
00277 std::set<unsigned> testElements);
00278
00279
00285 std::vector<unsigned> GetContainingElementIndices(const ChastePoint<SPACE_DIM>& rTestPoint);
00286
00290 virtual void Clear();
00291
00295 std::set<unsigned> CalculateBoundaryOfFlaggedRegion();
00296
00304 double GetAngleBetweenNodes(unsigned indexA, unsigned indexB);
00305
00309 void UnflagAllElements();
00310
00316 void FlagElementsNotContainingNodes(const std::set<unsigned> rNodes);
00317
00319 virtual void RefreshJacobianCachedData();
00320
00328 virtual void GetJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, SPACE_DIM>& rJacobian, double& rJacobianDeterminant) const;
00329
00338 virtual void GetInverseJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, ELEMENT_DIM>& rJacobian, double& rJacobianDeterminant, c_matrix<double, ELEMENT_DIM, SPACE_DIM>& rInverseJacobian) const;
00339
00347 virtual void GetWeightedDirectionForElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00348
00356 virtual void GetWeightedDirectionForBoundaryElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00357
00364 class EdgeIterator
00365 {
00366 public:
00370 Node<SPACE_DIM>* GetNodeA();
00374 Node<SPACE_DIM>* GetNodeB();
00375
00381 bool operator!=(const TetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::EdgeIterator& rOther);
00382
00386 EdgeIterator& operator++();
00387
00394 EdgeIterator(TetrahedralMesh& rMesh, unsigned elemIndex);
00395
00396
00397
00398
00399 private:
00403 std::set< std::pair<unsigned, unsigned> > mEdgesVisited;
00404
00405 TetrahedralMesh& mrMesh;
00407 unsigned mElemIndex;
00408 unsigned mNodeALocalIndex;
00409 unsigned mNodeBLocalIndex;
00411 };
00412
00416 EdgeIterator EdgesBegin();
00417
00422 EdgeIterator EdgesEnd();
00423 };
00424
00425 #include "SerializationExportWrapper.hpp"
00426 EXPORT_TEMPLATE_CLASS_ALL_DIMS(TetrahedralMesh)
00427
00428 #endif //_TETRAHEDRALMESH_HPP_