ParallelDomainProblem.h 7.99 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
27
28
29
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file ParallelDomainProblem.h */

#ifndef AMDIS_PARALLELDOMAINPROBLEM_H
#define AMDIS_PARALLELDOMAINPROBLEM_H

#include <map>
#include <vector>

#include "ProblemTimeInterface.h"
#include "ProblemIterationInterface.h"
30
#include "FiniteElemSpace.h"
31
#include "AdaptInfo.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
32
#include "InteriorBoundary.h"
33
34
#include "petsc.h"
#include "petscsys.h"
35
#include "petscao.h"
36
37
38
39
40
41
42
43
#include "mpi.h"

namespace AMDiS {

  class ProblemScal;
  class ProblemInstatScal;
  class ParMetisPartitioner;
  class Mesh;
44
45
  class DOFMatrix;
  template<typename T> class DOFVector;
46
47
48
49
50
51
52
53

  class ParallelDomainProblemBase : public ProblemIterationInterface,
                                    public ProblemTimeInterface
  {
  public:
    ParallelDomainProblemBase(const std::string& name,
			      ProblemIterationInterface *iterationIF,
			      ProblemTimeInterface *timeIF,
54
			      FiniteElemSpace *feSpace);
55
56
57

    virtual ~ParallelDomainProblemBase() {}

58
    virtual void initParallelization(AdaptInfo *adaptInfo);
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

    void exitParallelization(AdaptInfo *adaptInfo);    

    /// Set for each element on the partitioning level the number of leaf elements.
    double setElemWeights(AdaptInfo *adaptInfo);

    void partitionMesh(AdaptInfo *adaptInfo);

    virtual void setTime(AdaptInfo *adaptInfo) {}

    virtual void initTimestep(AdaptInfo *adaptInfo) {}

    virtual void closeTimestep(AdaptInfo *adaptInfo) {}

    virtual void solveInitialProblem(AdaptInfo *adaptInfo) {}
  
    virtual void transferInitialSolution(AdaptInfo *adaptInfo) {}

77
78
    virtual void beginIteration(AdaptInfo *adaptInfo) 
    {
79
80
81
      iterationIF->beginIteration(adaptInfo);
    }

82
83
    virtual Flag oneIteration(AdaptInfo *adaptInfo, Flag toDo = FULL_ITERATION) 
    {
84
85
86
      ERROR_EXIT("Not implemented!\n");
      return 0;
    }
87

88
89
    virtual void endIteration(AdaptInfo *adaptInfo) 
    {
90
91
      iterationIF->endIteration(adaptInfo);
    }
92
93
94

    virtual int getNumProblems() {}

95
96
    inline virtual const std::string& getName() 
    { 
97
98
99
      return name; 
    }

100
    /// Returns pointer to \ref applicationOrdering.
101
102
    AO* getApplicationOrdering() 
    {
103
104
105
106
      return &applicationOrdering;
    }

    /// Returns \ref nRankDOFs, the number of DOFs in the rank mesh.
107
108
    int getNumberRankDOFs() 
    {
109
110
111
      return nRankDOFs;
    }

112
113
    void fillPetscMatrix(DOFMatrix *mat, DOFVector<double> *vec);

114
115
    void solvePetscMatrix(DOFVector<double> *vec);

116
117
118
119
120
    virtual ProblemStatBase *getProblem(int number = 0) {}

    virtual void serialize(std::ostream&) {}

    virtual void deserialize(std::istream&) {}
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147


  protected:
    /** \brief
     * This function traverses the whole mesh, i.e. before it is really partitioned,
     * and collects information about which DOF corresponds to which rank.
     *
     * @param[out] partionDOFs   Stores to each DOF pointer the set of ranks the DOF is
     *                           part of.
     * @param[out] rankDOFs      Stores all rank DOFs.
     * @param[out] boundaryDOFs  Stores all DOFs in ranks partition that are on an 
     *                           interior boundary but correspond to another rank.
     */
    void createDOFMemberInfo(std::map<const DegreeOfFreedom*, std::set<int>& partitionDOFs,
			     std::vector<const DegreeOfFreedom*>& rankDOFs,
			     std::map<const DegreeOfFreedom*, int>& boundaryDOFs);
    
    /** \brief
     * Determine the interior boundaries, i.e. boundaries between ranks, and store
     * all information about them in \ref interiorBoundary.
     */
    void createInteriorBoundaryInfo();

    /// Removes all macro elements from the mesh that are not part of ranks partition.
    void removeMacroElements();

    void createLocalGlobalOrder();
148
    
149

150
  protected:
151
152
153
154
155
156
    ///
    ProblemIterationInterface *iterationIF;

    ///
    ProblemTimeInterface *timeIF;

157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
    /// The rank of the current process.
    int mpiRank;

    /// Overall number of processes.
    int mpiSize;

    /** \brief
     * MPI communicator collected all processes, which should
     * be used for calculation. The Debug procces is not included
     * in this communicator.
     */
    MPI::Intracomm mpiComm;

    /// Name of the problem (as used in the init files)
    std::string name;

173
174
175
    /// Finite element space of the problem.
    FiniteElemSpace *feSpace;

176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
    /// Mesh of the problem.
    Mesh *mesh;

    /// Pointer to the paritioner which is used to devide a mesh into partitions.
    ParMetisPartitioner *partitioner;

    /// Weights for the elements, i.e., the number of leaf elements within this element.
    std::map<int, double> elemWeights;

    /// Is true, if the mesh was not partitioned before, otherwise it's false.
    bool initialPartitionMesh;

    /** \brief
     * Stores to every coarse element index the number of the partition it 
     * corresponds to.
     */
    std::map<int, int> partitionVec;

    /** \brief
     * Stores an old partitioning of elements. To every element index the number
     * of the parition it corresponds to is stored.
     */
    std::map<int, int> oldPartitionVec;    
199

200
201
202
203
    Mat petscMatrix;

    Vec petscRhsVec;
    
204
    Vec petscSolVec;
205

206
207
    /// Number of DOFs in the rank mesh.
    int nRankDOFs;
Thomas Witkowski's avatar
Thomas Witkowski committed
208
209
210
211
212
213
214

    /** \brief 
     * Defines the interioir boundaries of the domain that result from partitioning
     * the whole mesh.
     */
    InteriorBoundary interiorBoundary;

215
216
217
218
219
220
221
222
223
224
225
    /** \brief
     * This map contains for each rank the list of dofs the current rank must send
     * to exchange solution dofs at the interior boundaries.
     */
    std::map<int, std::vector<DegreeOfFreedom> > sendDofs;

    /** \brief
     * This map contains for each rank the list of dofs from which the current rank 
     * must receive solution values of dofs at the interior boundaries.
     */
    std::map<int, std::vector<DegreeOfFreedom> > recvDofs;
226
227
228
229
230
231
232
233
234
235
236
237
238

    /// Maps local to global dof indices.
    std::map<DegreeOfFreedom, DegreeOfFreedom> mapLocalGlobalDOFs;

    /// Maps global to local dof indices.
    std::map<DegreeOfFreedom, DegreeOfFreedom> mapGlobalLocalDOFs;

    /** \brief
     * Maps all DOFs in ranks partition to a bool value. If it is true, the DOF is
     * owned by the rank. Otherwise, its an interior boundary DOF that is owned by
     * another rank.
     */
    std::map<DegreeOfFreedom, bool> isRankDOF;
239
240
241
242
243
244
245
246
247
  };

  class ParallelDomainProblemScal : public ParallelDomainProblemBase
  {
  public:
    ParallelDomainProblemScal(const std::string& name,
			      ProblemScal *problem,
			      ProblemInstatScal *problemInstat);

248
249
    void initParallelization(AdaptInfo *adaptInfo);

250
251
252
253
254
    virtual Flag oneIteration(AdaptInfo *adaptInfo, Flag toDo = FULL_ITERATION);

  protected:
    ProblemScal *probScal;

255
256
257
258
  };
}

#endif // AMDIS_PARALLELDOMAINPROBLEM_H