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 <boost/serialization/access.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 #include <boost/serialization/export.hpp>
00048
00050
00054 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00055 class TetrahedralMesh : public AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM>
00056 {
00057 friend class TestTetrahedralMesh;
00058 friend class TestCryptSimulation2d;
00059
00060 private:
00062 friend class boost::serialization::access;
00069 template<class Archive>
00070 void serialize(Archive & archive, const unsigned int version)
00071 {
00072 archive & boost::serialization::base_object<AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
00073 }
00074
00075 protected:
00076
00082 unsigned SolveNodeMapping(unsigned index) const;
00083
00089 unsigned SolveElementMapping(unsigned index) const;
00090
00096 unsigned SolveBoundaryElementMapping(unsigned index) const;
00097
00099 std::vector< c_vector<double, SPACE_DIM> > mElementWeightedDirections;
00100
00102 std::vector< c_matrix<double, SPACE_DIM, ELEMENT_DIM> > mElementJacobians;
00103
00105 std::vector< c_matrix<double, ELEMENT_DIM, SPACE_DIM> > mElementInverseJacobians;
00106
00108 std::vector<double> mElementJacobianDeterminants;
00109
00111 std::vector< c_vector<double, SPACE_DIM> > mBoundaryElementWeightedDirections;
00112
00114 std::vector<double> mBoundaryElementJacobianDeterminants;
00115
00116 public:
00117
00121 TetrahedralMesh();
00122
00128 TetrahedralMesh(unsigned numElements);
00129
00130
00131
00132
00139 void ConstructFromMeshReader(AbstractMeshReader<ELEMENT_DIM,SPACE_DIM>& rMeshReader,
00140 bool cullInternalFaces=false);
00141
00147 void ReadNodesPerProcessorFile(const std::string& rNodesPerProcessorFile);
00148
00153 double GetVolume();
00154
00158 double GetSurfaceArea();
00159
00167 void Translate(c_vector<double, SPACE_DIM> displacement);
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
00253 void ConstructLinearMesh(unsigned width);
00254
00265 void ConstructRectangularMesh(unsigned width, unsigned height, bool stagger=true);
00266
00278 void ConstructCuboid(unsigned width, unsigned height, unsigned depth, bool stagger=false);
00279
00289 unsigned GetContainingElementIndex(ChastePoint<SPACE_DIM> testPoint, bool strict=false, std::set<unsigned> testElements=std::set<unsigned>());
00290
00299 unsigned GetNearestElementIndex(ChastePoint<SPACE_DIM> testPoint);
00300
00306 std::vector<unsigned> GetContainingElementIndices(ChastePoint<SPACE_DIM> testPoint);
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00321 virtual void Clear();
00322
00326 std::set<unsigned> CalculateBoundaryOfFlaggedRegion();
00327
00335 double GetAngleBetweenNodes(unsigned indexA, unsigned indexB);
00336
00340 void UnflagAllElements();
00341
00348 void FlagElementsNotContainingNodes(std::set<unsigned> nodes);
00349
00351 virtual void RefreshJacobianCachedData();
00352
00360 virtual void GetJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, SPACE_DIM>& rJacobian, double& rJacobianDeterminant) const;
00361
00370 virtual void GetInverseJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, ELEMENT_DIM>& rJacobian, double& rJacobianDeterminant, c_matrix<double, ELEMENT_DIM, SPACE_DIM>& rInverseJacobian) const;
00371
00379 virtual void GetWeightedDirectionForElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00380
00388 virtual void GetWeightedDirectionForBoundaryElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00389
00395 class EdgeIterator
00396 {
00397 public:
00401 Node<SPACE_DIM>* GetNodeA();
00405 Node<SPACE_DIM>* GetNodeB();
00406
00412 bool operator!=(const TetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::EdgeIterator& rOther);
00413
00417 EdgeIterator& operator++();
00418
00425 EdgeIterator(TetrahedralMesh& rMesh, unsigned elemIndex);
00426
00427 private:
00429 std::set<std::set<unsigned> > mEdgesVisited;
00430
00431 TetrahedralMesh& mrMesh;
00433 unsigned mElemIndex;
00434 unsigned mNodeALocalIndex;
00435 unsigned mNodeBLocalIndex;
00436 unsigned mCellIndex;
00437 unsigned mNodeIndex;
00439 };
00440
00444 EdgeIterator EdgesBegin();
00445
00450 EdgeIterator EdgesEnd();
00451 };
00452
00453 #include "TemplatedExport.hpp"
00454 EXPORT_TEMPLATE_CLASS_ALL_DIMS(TetrahedralMesh);
00455
00456 #endif //_TETRAHEDRALMESH_HPP_