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
00047
00049
00053 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00054 class TetrahedralMesh : public AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM>
00055 {
00056 friend class TestTetrahedralMesh;
00057 friend class TestCryptSimulation2d;
00058
00059 private:
00061 friend class boost::serialization::access;
00068 template<class Archive>
00069 void serialize(Archive & archive, const unsigned int version)
00070 {
00071 archive & boost::serialization::base_object<AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
00072 }
00073
00074 protected:
00075
00081 unsigned SolveNodeMapping(unsigned index) const;
00082
00088 unsigned SolveElementMapping(unsigned index) const;
00089
00095 unsigned SolveBoundaryElementMapping(unsigned index) const;
00096
00098 std::vector< c_vector<double, SPACE_DIM> > mElementWeightedDirections;
00099
00101 std::vector< c_matrix<double, SPACE_DIM, ELEMENT_DIM> > mElementJacobians;
00102
00104 std::vector< c_matrix<double, ELEMENT_DIM, SPACE_DIM> > mElementInverseJacobians;
00105
00107 std::vector<double> mElementJacobianDeterminants;
00108
00110 std::vector< c_vector<double, SPACE_DIM> > mBoundaryElementWeightedDirections;
00111
00113 std::vector<double> mBoundaryElementJacobianDeterminants;
00114
00115 public:
00116
00120 TetrahedralMesh();
00121
00127 void ConstructFromMeshReader(AbstractMeshReader<ELEMENT_DIM,SPACE_DIM>& rMeshReader);
00128
00134 void ReadNodesPerProcessorFile(const std::string& rNodesPerProcessorFile);
00135
00148 bool CheckIsConforming();
00149
00154 double GetVolume();
00155
00159 double GetSurfaceArea();
00160
00167 void Translate(const c_vector<double, SPACE_DIM>& rDisplacement);
00168
00176 void Translate(const double xMovement=0.0, const double yMovement=0.0, const double zMovement=0.0);
00177
00184 void Rotate(c_matrix<double , SPACE_DIM, SPACE_DIM> rotationMatrix);
00185
00192 void Rotate(c_vector<double,3> axis, double angle);
00193
00199 void RotateX(const double theta);
00200
00206 void RotateY(const double theta);
00207
00213 void RotateZ(const double theta);
00214
00220 void Rotate(double theta);
00221
00225 void RefreshMesh();
00226
00231 void PermuteNodes();
00232
00239 void PermuteNodesWithMetisBinaries(unsigned numProcs);
00240
00246 void PermuteNodes(std::vector<unsigned>& perm);
00247
00260 unsigned GetContainingElementIndex(ChastePoint<SPACE_DIM> testPoint,
00261 bool strict=false,
00262 std::set<unsigned> testElements=std::set<unsigned>(),
00263 bool onlyTryWithTestElements = false);
00264
00265
00275 unsigned GetContainingElementIndexWithInitialGuess(ChastePoint<SPACE_DIM> testPoint, unsigned startingElementGuess, bool strict=false);
00276
00285 unsigned GetNearestElementIndex(ChastePoint<SPACE_DIM> testPoint);
00286
00291 unsigned GetNearestElementIndexFromTestElements(ChastePoint<SPACE_DIM> testPoint,
00292 std::set<unsigned> testElements);
00293
00294
00300 std::vector<unsigned> GetContainingElementIndices(ChastePoint<SPACE_DIM> testPoint);
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00315 virtual void Clear();
00316
00320 std::set<unsigned> CalculateBoundaryOfFlaggedRegion();
00321
00329 double GetAngleBetweenNodes(unsigned indexA, unsigned indexB);
00330
00334 void UnflagAllElements();
00335
00341 void FlagElementsNotContainingNodes(const std::set<unsigned> rNodes);
00342
00344 virtual void RefreshJacobianCachedData();
00345
00353 virtual void GetJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, SPACE_DIM>& rJacobian, double& rJacobianDeterminant) const;
00354
00363 virtual void GetInverseJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, ELEMENT_DIM>& rJacobian, double& rJacobianDeterminant, c_matrix<double, ELEMENT_DIM, SPACE_DIM>& rInverseJacobian) const;
00364
00372 virtual void GetWeightedDirectionForElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00373
00381 virtual void GetWeightedDirectionForBoundaryElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00382
00388 class EdgeIterator
00389 {
00390 public:
00394 Node<SPACE_DIM>* GetNodeA();
00398 Node<SPACE_DIM>* GetNodeB();
00399
00405 bool operator!=(const TetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::EdgeIterator& rOther);
00406
00410 EdgeIterator& operator++();
00411
00418 EdgeIterator(TetrahedralMesh& rMesh, unsigned elemIndex);
00419
00420 private:
00422 std::set<std::set<unsigned> > mEdgesVisited;
00423
00424 TetrahedralMesh& mrMesh;
00426 unsigned mElemIndex;
00427 unsigned mNodeALocalIndex;
00428 unsigned mNodeBLocalIndex;
00430 };
00431
00435 EdgeIterator EdgesBegin();
00436
00441 EdgeIterator EdgesEnd();
00442 };
00443
00444 #include "SerializationExportWrapper.hpp"
00445 EXPORT_TEMPLATE_CLASS_ALL_DIMS(TetrahedralMesh);
00446
00447 #endif //_TETRAHEDRALMESH_HPP_