MeshPartitioner.h 3.2 KB
Newer Older
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 <map>
Thomas Witkowski's avatar
Thomas Witkowski committed
27
#include <set>
28
29
#include <mpi.h>

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "AMDiS_fwd.h"
#include "Mesh.h"

namespace AMDiS {


  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's avatar
Thomas Witkowski committed
46
47
48
49
50
51
  /**
   * 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.
   */
52
53
54
55
56
57
  class MeshPartitioner
  {
  public:
    MeshPartitioner(MPI::Intracomm *comm)
      : mpiComm(comm),
	mesh(NULL),
Thomas Witkowski's avatar
Thomas Witkowski committed
58
	boxPartitioning(false),
59
60
61
62
63
64
	mapLocalGlobal(NULL)
    {}

    virtual ~MeshPartitioner() {}

    /// Creates an initial paritioning of the AMDiS mesh.
65
    virtual void createInitialPartitioning();
66
67
68
69

    virtual bool partition(map<int, double> &elemWeights,
			   PartitionMode mode = INITIAL) = 0;

70
71
    virtual void createPartitionMap(map<int, int>& partitionMap) = 0;

72
73
74
75
76
77
78
79
80
81
82
    /// 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's avatar
Thomas Witkowski committed
83
84
85
86
87
    void setBoxPartitioning(bool b)
    {
      boxPartitioning = b;
    }

88
    void setLocalGlobalDofMap(map<DegreeOfFreedom, DegreeOfFreedom> *m)
89
90
91
92
    {
      mapLocalGlobal = m;
    }

93
94
95
96
97
    Mesh *getMesh()
    {
      return mesh;
    }

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
    map<int, bool>& getElementInRank()
    {
      return elementInRank;
    }

    map<int, vector<int> >& getRecvElements()
    {
      return recvElements;
    }

    map<int, vector<int> >& getSendElements()
    {
      return sendElements;
    }

  protected:
    MPI::Intracomm *mpiComm;

    Mesh *mesh;

Thomas Witkowski's avatar
Thomas Witkowski committed
118
119
120
121
122
123
124
125
    bool boxPartitioning;

    map<int, std::set<int> > boxSplitting;

    map<int, std::set<int> > boxNeighbours;

    map<int, int> elInBox;

126
127
    map<DegreeOfFreedom, DegreeOfFreedom> *mapLocalGlobal;

128
129
    map<int, vector<int> > elNeighbours;

130
131
132
    /// Maps to each macro element index if it is in rank's partition or not.
    map<int, bool> elementInRank;

133
134
    map<int, int> partitionMap;

135
136
137
138
139
    map<int, vector<int> > recvElements, sendElements;
  };
}

#endif