DistributedTetrahedralMesh.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
00030
00031
00032
00033
00034
00035
00036 #ifndef DISTRIBUTEDTETRAHEDRALMESH_HPP_
00037 #define DISTRIBUTEDTETRAHEDRALMESH_HPP_
00038
00039 #include <map>
00040 #include <vector>
00041 #include <set>
00042
00043 #include "ChasteSerialization.hpp"
00044 #include <boost/serialization/base_object.hpp>
00045
00046 #include "AbstractTetrahedralMesh.hpp"
00047 #include "Node.hpp"
00048 #include "AbstractMeshReader.hpp"
00049 #include "DistributedTetrahedralMeshPartitionType.hpp"
00050
00051 #define UNASSIGNED_NODE UINT_MAX
00052
00053
00061 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00062 class DistributedTetrahedralMesh : public AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM>
00063 {
00064 friend class TestDistributedTetrahedralMesh;
00065 friend class TestDistributedQuadraticMesh;
00066 private:
00067
00069 unsigned mTotalNumElements;
00070
00072 unsigned mTotalNumBoundaryElements;
00073
00075 unsigned mTotalNumNodes;
00076
00078 std::vector<Node<SPACE_DIM>* > mHaloNodes;
00079
00081 std::map<unsigned, unsigned> mNodesMapping;
00082
00084 std::map<unsigned, unsigned> mHaloNodesMapping;
00085
00087 std::map<unsigned, unsigned> mElementsMapping;
00088
00090 std::map<unsigned, unsigned> mBoundaryElementsMapping;
00091
00093 ChasteCuboid<SPACE_DIM>* mpSpaceRegion;
00094
00096 DistributedTetrahedralMeshPartitionType::type mMetisPartitioning;
00097
00099 friend class boost::serialization::access;
00106 template<class Archive>
00107 void serialize(Archive & archive, const unsigned int version)
00108 {
00109 archive & boost::serialization::base_object<AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
00110 }
00111
00112
00120 void SetElementOwnerships();
00121
00122
00123 public:
00124
00130 DistributedTetrahedralMesh(DistributedTetrahedralMeshPartitionType::type partitioningMethod=DistributedTetrahedralMeshPartitionType::PARMETIS_LIBRARY);
00131
00135 virtual ~DistributedTetrahedralMesh();
00136
00143 void SetDistributedVectorFactory(DistributedVectorFactory* pFactory);
00144
00150 virtual void ConstructFromMeshReader(AbstractMeshReader<ELEMENT_DIM,SPACE_DIM>& rMeshReader);
00151
00156 unsigned GetNumLocalNodes() const;
00157
00161 unsigned GetNumHaloNodes() const;
00162
00167 unsigned GetNumLocalElements() const;
00168
00173 unsigned GetNumLocalBoundaryElements() const;
00174
00178 unsigned GetNumNodes() const;
00179
00183 unsigned GetNumAllNodes() const;
00184
00188 unsigned GetNumElements() const;
00189
00195 DistributedTetrahedralMeshPartitionType::type GetPartitionType() const;
00196
00200 unsigned GetNumBoundaryElements() const;
00201
00206 void GetHaloNodeIndices(std::vector<unsigned>& rHaloIndices) const;
00207
00213 void SetProcessRegion(ChasteCuboid<SPACE_DIM>* pRegion);
00214
00220 ChasteCuboid<SPACE_DIM>* GetProcessRegion();
00221
00229 bool CalculateDesignatedOwnershipOfElement( unsigned elementIndex );
00230
00237 bool CalculateDesignatedOwnershipOfBoundaryElement( unsigned faceIndex );
00238
00246 void ConstructLinearMesh(unsigned width);
00247
00261 void ConstructRectangularMesh(unsigned width, unsigned height, bool stagger=true);
00262
00273 void ConstructCuboid(unsigned width, unsigned height, unsigned depth);
00282 virtual void Scale(const double xFactor=1.0, const double yFactor=1.0, const double zFactor=1.0);
00283
00293 Node<SPACE_DIM>* GetNodeOrHaloNode(unsigned index) const;
00294
00302 virtual ChasteCuboid<SPACE_DIM> CalculateBoundingBox() const;
00303
00312 virtual c_vector<double, 2> CalculateMinMaxEdgeLengths();
00313
00314
00315 protected:
00322 unsigned SolveNodeMapping(unsigned index) const;
00323
00330 unsigned SolveElementMapping(unsigned index) const;
00331
00338 unsigned SolveBoundaryElementMapping(unsigned index) const;
00339 private:
00340
00346 void RegisterNode(unsigned index);
00347
00353 void RegisterHaloNode(unsigned index);
00354
00360 void RegisterElement(unsigned index);
00361
00367 void RegisterBoundaryElement(unsigned index);
00368
00369
00381 void ComputeMeshPartitioning(AbstractMeshReader<ELEMENT_DIM, SPACE_DIM>& rMeshReader,
00382 std::set<unsigned>& rNodesOwned,
00383 std::set<unsigned>& rHaloNodesOwned,
00384 std::set<unsigned>& rElementsOwned,
00385 std::vector<unsigned>& rProcessorsOffset);
00386
00398 void ParMetisLibraryNodeAndElementPartitioning(AbstractMeshReader<ELEMENT_DIM, SPACE_DIM>& rMeshReader,
00399 std::set<unsigned>& rElementsOwned,
00400 std::set<unsigned>& rNodesOwned,
00401 std::set<unsigned>& rHaloNodesOwned,
00402 std::vector<unsigned>& rProcessorsOffset);
00403
00410 void ReorderNodes();
00411
00413
00415
00416 public:
00418
00419
00421 typedef typename std::vector<Node<SPACE_DIM> *>::const_iterator HaloNodeIterator;
00422
00426 HaloNodeIterator GetHaloNodeIteratorBegin() const;
00427
00431 HaloNodeIterator GetHaloNodeIteratorEnd() const;
00432 };
00433
00434 #include "SerializationExportWrapper.hpp"
00435 EXPORT_TEMPLATE_CLASS_ALL_DIMS(DistributedTetrahedralMesh)
00436
00437 namespace boost
00438 {
00439 namespace serialization
00440 {
00444 template<class Archive, unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00445 inline void save_construct_data(
00446 Archive & ar, const DistributedTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> * t, const BOOST_PFTO unsigned int file_version)
00447 {
00448 unsigned num_procs = PetscTools::GetNumProcs();
00449 const DistributedTetrahedralMeshPartitionType::type partition_type = t->GetPartitionType();
00450 ar << num_procs;
00451 ar << partition_type;
00452 }
00453
00458 template<class Archive, unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00459 inline void load_construct_data(
00460 Archive & ar, DistributedTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> * t, const unsigned int file_version)
00461 {
00462 unsigned num_procs;
00463 DistributedTetrahedralMeshPartitionType::type partition_type;
00464
00465 ar >> num_procs;
00466 ar >> partition_type;
00467
00468
00470
00471 ::new(t)DistributedTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>(DistributedTetrahedralMeshPartitionType::DUMB);
00472
00473
00474
00475
00476
00477 if (DistributedVectorFactory::CheckNumberOfProcessesOnLoad() &&
00478 num_procs != PetscTools::GetNumProcs())
00479 {
00480 EXCEPTION("This archive was written for a different number of processors");
00481 }
00482
00483 }
00484 }
00485 }
00486
00487 #endif