MeshPartitioner.h 6.06 KB
 Thomas Witkowski committed Jan 24, 2011 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 // ============================================================================ // == == // == AMDiS - Adaptive multidimensional simulations == // == == // == http://www.amdis-fem.org == // == == // ============================================================================ // // Software License for AMDiS // // Copyright (c) 2010 Dresden University of Technology // All rights reserved. // Authors: Simon Vey, Thomas Witkowski et al. // // This file is part of AMDiS // // See also license.opensource.txt in the distribution. /** \file MeshPartitioner.h */ #ifndef AMDIS_MESH_PARTITIONER_H #define AMDIS_MESH_PARTITIONER_H #include  Thomas Witkowski committed Jan 28, 2011 27 #include  Thomas Witkowski committed Apr 05, 2011 28 29 #include  Thomas Witkowski committed Jan 24, 2011 30 31 #include "AMDiS_fwd.h" #include "Mesh.h"  Thomas Witkowski committed Feb 09, 2012 32 #include "parallel/MpiHelper.h"  Thomas Witkowski committed Apr 18, 2012 33 #include "parallel/ParallelDofMapping.h"  Thomas Witkowski committed Jan 24, 2011 34 35   Thomas Witkowski committed Feb 09, 2012 36 namespace AMDiS {  Thomas Witkowski committed Jan 24, 2011 37 38 39 40 41 42 43 44 45 46  using namespace std; enum PartitionMode { INITIAL = 0, // initial partitioning of a unpartitioned mesh ADAPTIVE_REPART = 1, // repartitioning of a adaptively refined mesh REFINE_PART = 2 // quality improvement of the current partitioning };  Thomas Witkowski committed Feb 10, 2011 47 48 49 50 51 52  /** * Abstract class for mesh partitioning. This class provides only a function * for a random initial partitioning. A concrete partition must override the * functions \ref MeshPartitioner::partition and * \ref MeshPartitioner::createPartitionMap. */  Thomas Witkowski committed Jan 24, 2011 53 54 55 56 57 58  class MeshPartitioner { public: MeshPartitioner(MPI::Intracomm *comm) : mpiComm(comm), mesh(NULL),  Thomas Witkowski committed Jan 28, 2011 59  boxPartitioning(false),  Thomas Witkowski committed Jan 24, 2011 60 61 62 63 64  mapLocalGlobal(NULL) {} virtual ~MeshPartitioner() {}  Thomas Witkowski committed Nov 14, 2011 65 66 67  /// Creates an initial paritioning of the AMDiS mesh. This partitioning /// can be arbitrary, the only requirement is that each macro element /// must be uniquely assign to a rank.  Thomas Witkowski committed Mar 31, 2011 68  virtual void createInitialPartitioning();  Thomas Witkowski committed Jan 24, 2011 69   Thomas Witkowski committed Nov 14, 2011 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88  /** \brief * Function the takes a weighted set of macro elements and returns a * macro mesh partitioning. This function is virtual and must be implemented * for a specific algorithm or an external partitioning library. * * \param[in] elemWeights Maps to each macro element in rank's subdomain * a weight, which is usually the number of leaf * elements in this macro element. * \param[in] mode Most external partitioning libraries can make * a difference whether we want to create a * first partitioning or we alread have created * one using this library but due to some mesh * adaptivity we want to repartition the mesh. In * the later case, the libraries also consider the * time for redistribution of the new partitioning. * \return Returns a boolean value if the partitioning algorithm created * a correct partitioning. If it is so, the partitioning is * stored in \ref elementInRank and \ref partitionMap. */  Thomas Witkowski committed Jan 24, 2011 89 90 91  virtual bool partition(map &elemWeights, PartitionMode mode = INITIAL) = 0;  Thomas Witkowski committed Jan 27, 2011 92 93  virtual void createPartitionMap(map& partitionMap) = 0;  Thomas Witkowski committed Jan 24, 2011 94 95 96 97 98 99 100 101 102 103 104  /// Write partitioner state to disk. void serialize(ostream &out); /// Read partitioner state from disk. void deserialize(istream &in); void setMesh(Mesh *m) { mesh = m; }  Thomas Witkowski committed Jan 28, 2011 105 106 107 108 109  void setBoxPartitioning(bool b) { boxPartitioning = b; }  110  void setLocalGlobalDofMap(DofMap *m)  Thomas Witkowski committed Jan 24, 2011 111 112 113 114  { mapLocalGlobal = m; }  Thomas Witkowski committed Jan 24, 2011 115 116 117 118 119  Mesh *getMesh() { return mesh; }  Thomas Witkowski committed Jan 24, 2011 120 121 122 123 124 125 126 127 128 129 130 131 132 133  map& getElementInRank() { return elementInRank; } map >& getRecvElements() { return recvElements; } map >& getSendElements() { return sendElements; }  Thomas Witkowski committed Feb 09, 2012 134 135 136 137 138 139 140 141 142 143  /// After mesh repartition this function returns true if the mesh must be /// redistributed on at least one rank. bool meshChanged() { int nChanges = recvElements.size() + sendElements.size(); mpi::globalAdd(nChanges); return static_cast(nChanges); }  Thomas Witkowski committed Jan 24, 2011 144 145  protected:  Thomas Witkowski committed Nov 14, 2011 146  /// Pointer to the MPI communicator the mesh partitioner should make use of.  Thomas Witkowski committed Jan 24, 2011 147 148  MPI::Intracomm *mpiComm;  Thomas Witkowski committed Nov 14, 2011 149  /// Pointer to the AMDiS mesh.  Thomas Witkowski committed Jan 24, 2011 150 151  Mesh *mesh;  Thomas Witkowski committed Nov 14, 2011 152 153 154 155 156 157  /// The mesh partitioner can be used in to different modes, the standard /// mode and the so called "box partitioning". The standard mode assigns /// macro elements to ranks. If box partitioning is enabled, which makes /// only sence if the macro mesh results from meshconv's "lego mesher", /// then in 2D boxed (2 macro elements) and in 3D cubes (6 macro /// elements) are assigned as a uniion to ranks.  Thomas Witkowski committed Jan 28, 2011 158 159  bool boxPartitioning;  Thomas Witkowski committed Nov 14, 2011 160 161  /// In box partitioning mode this map stores for each box number the set /// of macro element indices the box consists of.  Thomas Witkowski committed Jan 28, 2011 162  map > boxSplitting;  Thomas Witkowski committed Nov 14, 2011 163 164 165  /// In box partitioning mode this map stores to each box number the set /// of neighbouring boxes.  Thomas Witkowski committed Jan 28, 2011 166 167  map > boxNeighbours;  Thomas Witkowski committed Nov 14, 2011 168 169  /// Is the reverse of the map \ref boxSplitting. Thus, it stores for each /// macro element index the box number it belongs to.  Thomas Witkowski committed Jan 28, 2011 170 171  map elInBox;  172  DofMap *mapLocalGlobal;  Thomas Witkowski committed Jan 24, 2011 173   Thomas Witkowski committed Jan 26, 2011 174 175  map > elNeighbours;  Thomas Witkowski committed Nov 14, 2011 176 177  /// Maps to each macro element index (or box index in box /// partitioning mode) if it is in rank's partition or not.  Thomas Witkowski committed Jan 24, 2011 178 179  map elementInRank;  Thomas Witkowski committed Nov 14, 2011 180 181  /// Maps to each macro element index (or box index in box /// partitiong mode) the rank number the element belongs to.  Thomas Witkowski committed Jan 26, 2011 182 183  map partitionMap;  Thomas Witkowski committed Feb 09, 2012 184 185  /// After mesh repartitioning these maps stores which elements are communicated /// from this rank to other ranks.  Thomas Witkowski committed Jan 24, 2011 186 187 188 189 190  map > recvElements, sendElements; }; } #endif