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
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
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00300 virtual void Clear();
00301
00305 std::set<unsigned> CalculateBoundaryOfFlaggedRegion();
00306
00314 double GetAngleBetweenNodes(unsigned indexA, unsigned indexB);
00315
00319 void UnflagAllElements();
00320
00326 void FlagElementsNotContainingNodes(const std::set<unsigned> rNodes);
00327
00329 virtual void RefreshJacobianCachedData();
00330
00338 virtual void GetJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, SPACE_DIM>& rJacobian, double& rJacobianDeterminant) const;
00339
00348 virtual void GetInverseJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, ELEMENT_DIM>& rJacobian, double& rJacobianDeterminant, c_matrix<double, ELEMENT_DIM, SPACE_DIM>& rInverseJacobian) const;
00349
00357 virtual void GetWeightedDirectionForElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00358
00366 virtual void GetWeightedDirectionForBoundaryElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00367
00374 class EdgeIterator
00375 {
00376 public:
00380 Node<SPACE_DIM>* GetNodeA();
00384 Node<SPACE_DIM>* GetNodeB();
00385
00391 bool operator!=(const TetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::EdgeIterator& rOther);
00392
00396 EdgeIterator& operator++();
00397
00404 EdgeIterator(TetrahedralMesh& rMesh, unsigned elemIndex);
00405
00406
00407
00408
00409 private:
00413 std::set< std::pair<unsigned, unsigned> > mEdgesVisited;
00414
00415 TetrahedralMesh& mrMesh;
00417 unsigned mElemIndex;
00418 unsigned mNodeALocalIndex;
00419 unsigned mNodeBLocalIndex;
00421 };
00422
00426 EdgeIterator EdgesBegin();
00427
00432 EdgeIterator EdgesEnd();
00433 };
00434
00435 #include "SerializationExportWrapper.hpp"
00436 EXPORT_TEMPLATE_CLASS_ALL_DIMS(TetrahedralMesh)
00437
00438 #endif //_TETRAHEDRALMESH_HPP_