PetscSolverFeti.h 10.6 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
// ============================================================================
// ==                                                                        ==
// == 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 PetscSolverFeti.h */

23
#include <map>
24
#include "AMDiS_fwd.h"
25
#include "parallel/MpiHelper.h"
26
#include "parallel/PetscSolver.h"
27
#include "parallel/PetscSolverFetiStructs.h"
28
#include "parallel/ParallelDofMapping.h"
29
#include "parallel/ParallelTypes.h"
30
31
32
33
34
35
36
37

#ifndef AMDIS_PETSC_SOLVER_FETI_H
#define AMDIS_PETSC_SOLVER_FETI_H

namespace AMDiS {

  using namespace std;

38
39
40
  /** \brief
   * FETI-DP implementation based on PETSc.
   */
41
42
43
  class PetscSolverFeti : public PetscSolver
  {
  public:
44
    PetscSolverFeti();
45

46
47
48
49
50
51
    /// Assemble the sequentially created matrices to the global matrices
    /// required by the FETI-DP method.
    void fillPetscMatrix(Matrix<DOFMatrix*> *mat);

    /// Assembles the global rhs vectors from the sequentially created ones.
    void fillPetscRhs(SystemVector *vec);
52

53
    /// Solve the system using FETI-DP method.
54
    void solvePetscMatrix(SystemVector &vec, AdaptInfo *adaptInfo);
55

56
57
58
    /// Destroys all matrix data structures.
    void destroyMatrixData();

59
60
61
    /// Detroys all vector data structures.
    void destroyVectorData();

62
63
    /// Returns flags to denote which information of the boundary DOFs are 
    /// required by the FETI-DP solver.
64
65
66
67
68
69
70
    Flag getBoundaryDofRequirement()
    {
      return 
	MeshDistributor::BOUNDARY_SUBOBJ_SORTED |
	MeshDistributor::BOUNDARY_FILL_INFO_SEND_DOFS |
	MeshDistributor::BOUNDARY_FILL_INFO_RECV_DOFS;
    }
71

72
73
74
75
76
77
    /// Initialization of the data structures with a given list of the FE 
    /// spaces of all components.
    void initialize(vector<const FiniteElemSpace*> feSpaces);

    int getNumberOfPrimals()
    {
78
      return primalDofMap.getOverallDofs();
79
    }
80

81
82
    int getNumberOfRankPrimals()
    {
83
      return primalDofMap.getRankDofs();
84
85
    }

86
87
    int getNumberOfDuals()
    {
88
      return dualDofMap.getOverallDofs();
89
90
    }

91
92
    int getNumberOfRankDuals()
    {
93
      return dualDofMap.getRankDofs();
94
95
    }

Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
96
97
98
99
100
    int getNumberOfLagrange()
    {
      return lagrangeMap.getOverallDofs();
    }

101
  protected:
Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
102
103
104
105
106
107
108
109
    ///
    void createDirichletData(Matrix<DOFMatrix*> &mat);

    /// After mesh changes, or if the solver is called the first time, this
    /// function creates all information about primal nodes, dual nodes and
    /// lagrange constraints.    
    void createFetiData();

110
111
    /// Defines which boundary nodes are primal. Creates global index of
    /// the primal variables.
112
    void createPrimals(const FiniteElemSpace *feSpace);
113

114
    /// Defines the set of dual variables and creates the global index of
115
    /// dual variables.
116
    void createDuals(const FiniteElemSpace *feSpace);
117

118
119
120
    /// 
    void createInterfaceNodes(const FiniteElemSpace *feSpace);

121
122
    /// Create Lagrange multiplier variables corresponding to the dual 
    /// variables.
123
    void createLagrange(const FiniteElemSpace *feSpace);
124

125
126
    void createAugmentedLagrange(const FiniteElemSpace *feSpace);

127
    /// Creates a global index of the B variables.
128
    void createIndexB(const FiniteElemSpace *feSpace);
129

130
131
    /// Creates the Lagrange multiplier constraints and assembles them 
    /// to \ref mat_lagrange.
132
    void createMatLagrange(vector<const FiniteElemSpace*> &feSpaces);
133

134
135
    void createMatAugmentedLagrange(vector<const FiniteElemSpace*> &feSpaces);

136
137
138
    ///
    void createPreconditionerMatrix(Matrix<DOFMatrix*> *mat);

139
140
    /// Creates PETSc KSP solver object for solving the Schur complement
    /// system on the primal variables, \ref ksp_schur_primal
141
    void createSchurPrimalKsp(vector<const FiniteElemSpace*> &feSpaces);
142

143
144
145
146
147
148
    ///
    void createMatExplicitSchurPrimal();
    
    ///
    void createMatExplicitAugmentedSchurPrimal();

149
    /// Destroys PETSc KSP solver object \ref ksp_schur_primal
150
151
    void destroySchurPrimalKsp();

152
    /// Creates PETSc KSP solver object for the FETI-DP operator, \ref ksp_feti
153
    void createFetiKsp(vector<const FiniteElemSpace*> &feSpaces);
154

155
    /// Destroys FETI-DP operator, \ref ksp_feti
156
157
    void destroyFetiKsp();

Thomas Witkowski's avatar
Thomas Witkowski committed
158
159
160
161
    /// Create the null space of the FETI-DP operator (if there is one) and
    /// attachets it to the corresponding matrices and KSP objects.
    void createNullSpace();

162
163
164
165
    /// In debug modes, this function runs some debug tests on the FETI
    /// matrices. In optimized mode, nothing is done here.
    void dbgMatrix();

166
167
168
169
170
171
172
173
174
175
176
177
178
179
    /** \brief
     * Recovers AMDiS solution vector from PETSc's solution vectors of the
     * FETI-DP system. First, the B variables can locally be copied to the
     * corresponding entries in the DOF vectors. The primal variable must
     * be communicated such that all ranks sharing a primal get a copy of
     * the corresponding value.
     *
     * \param[in]   vec_sol_b        Global PETSc vector of the solution of
     *                               the B variables.
     * \param[in]   vec_sol_primal   Global PETSc vector of the solution of
     *                               the primal variables.
     * \param[out]  vec              SystemVector containing all solution 
     *                               DOF vectors.
     */
180
181
182
183
    void recoverSolution(Vec &vec_sol_b,
			 Vec &vec_sol_primal,
			 SystemVector &vec);

Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
184
    ///
185
186
187
    void recoverInterfaceSolution(Vec& vecInterface, 
				  SystemVector &vec);

Thomas Witkowski's avatar
Thomas Witkowski committed
188
189
190
191
192
193
194
195
196
    /** \brief
     * Solves the FETI-DP system globally, thus without reducing it to the 
     * Lagrange multipliers. This should be used for debugging only to test
     * if the FETI-DP system is setup correctly.
     *
     * \param[out]  vec    Solution DOF vectors.
     */
    void solveFetiMatrix(SystemVector &vec);

197
198
199
200
201
202
203
204
    /** \brief
     * Solves the FETI-DP system with reducing it first to the Lagrange
     * multipliers. This is what one expects when using the FETI-DP methid :)
     *
     * \param[out]  vec    Solution DOF vectors.
     */
    void solveReducedFetiMatrix(SystemVector &vec);

Thomas Witkowski's avatar
Thomas Witkowski committed
205
206
207
208
    void resetStatistics();

    void printStatistics();

209
    /// Checks whether a given DOF in a given FE space is a primal DOF.
210
211
    inline bool isPrimal(const FiniteElemSpace *feSpace, 
			 DegreeOfFreedom dof)
212
    {
213
      return primalDofMap[feSpace].isSet(dof);
214
215
    }

216
    /// Checks whether a given DOF in a give FE space is a dual DOF.
217
218
    inline bool isDual(const FiniteElemSpace *feSpace, 
		       DegreeOfFreedom dof)
219
    {
220
      return dualDofMap[feSpace].isSet(dof);
221
222
    }

223
224
225
226
    /// Checks whether a given DOF in a give FE space is an interface DOF.
    inline bool isInterface(const FiniteElemSpace *feSpace, 
			    DegreeOfFreedom dof)
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
227
      if (feSpace == pressureFeSpace)
Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
228
229
230
	return interfaceDofMap[feSpace].isSet(dof);
      
      return false;
231
232
    }

233
234
235
236
    /// Traverse the mesh and create a DOF vector where each DOF is in the
    /// order of: 1/h^2
    void createH2vec(DOFVector<double> &vec);

237
  protected:
238
    /// Mapping from primal DOF indices to a global index of primals.
Thomas Witkowski's avatar
Thomas Witkowski committed
239
    ParallelDofMapping primalDofMap;
240

241
    /// Mapping from dual DOF indices to a global index of duals.
Thomas Witkowski's avatar
Thomas Witkowski committed
242
    ParallelDofMapping dualDofMap;
243

244
245
246
247
248
    /// Mapping from interface DOF indices to a global index of interface 
    /// nodes. This is mainly used for Stokes-like solvers, where the pressure
    /// interface nodes are neither primal nor dual.
    ParallelDofMapping interfaceDofMap;

Thomas Witkowski's avatar
Thomas Witkowski committed
249
250
251
252
    /// Index for each non primal DOF to the global index of B variables (thus,
    /// all pure local variables).
    ParallelDofMapping localDofMap;

253
254
    /// Stores to each dual DOF index the index of the first Lagrange
    /// constraint that is assigned to this DOF.
Thomas Witkowski's avatar
Thomas Witkowski committed
255
    ParallelDofMapping lagrangeMap;
256
    
257
258
    /// Mapping of pure local DOF indices, thus no primal and no dual DOFs are
    /// in this map. Is used for the Dirichlet preconditioner only.
Thomas Witkowski's avatar
Thomas Witkowski committed
259
    ParallelDofMapping interiorDofMap;
260

Thomas Witkowski's avatar
Thomas Witkowski committed
261
262
    /// Stores to all dual boundary DOFs in each FE space the set of
    /// ranks which contain this global DOF.
263
    map<const FiniteElemSpace*, DofIndexToPartitions> boundaryDofRanks;
264

265
    /// Global PETSc matrix of Lagrange variables.
266
267
    Mat mat_lagrange;

268
269
270
    ///
    Mat mat_augmented_lagrange; 

Thomas Witkowski's avatar
Thomas Witkowski committed
271
272
273
274
275
    /// 0: Solve the Schur complement on primal variables with iterative solver.
    /// 1: Create the Schur complement matrix explicitly and solve it with a
    ///    direct solver.
    int schurPrimalSolver;

276
277
    /// PETSc solver object to solve the Schur complement on the 
    /// primal variables.
278
279
    KSP ksp_schur_primal;

280
281
    /// Matrix object that defines a matrix-free implementation for the action
    /// of the Schur complement on the primal variables.
282
283
    Mat mat_schur_primal;

284
    /// Data for MatMult operation in matrix \ref mat_schur_primal
285
    SchurPrimalData schurPrimalData;
286

287
288
289
    ///
    SchurPrimalAugmentedData schurPrimalAugmentedData;

290
    /// PETSc solver object to solve a system with FETI-DP.    
291
292
    KSP ksp_feti;

293
294
    /// Matrix object that defines a matrix-free implementation for the action
    /// of the FETI-DP operator.
295
    Mat mat_feti;
296

297
    /// Data for MatMult operation in matrix \ref mat_feti
298
    FetiData fetiData;
299

300
301
302
303
304
305
    /// Defines which preconditioner should be used to solve the reduced
    /// FETI-DP system.
    FetiPreconditioner fetiPreconditioner;

    /// Preconditioner object for the reduced FETI-DP system.
    PC precon_feti;
306
307
308

    Mat mat_lagrange_scaled;
   
309
    FetiDirichletPreconData fetiDirichletPreconData;
310

311
    FetiLumpedPreconData fetiLumpedPreconData;
312

Thomas Witkowski's avatar
Thomas Witkowski committed
313
314
    FetiInterfaceLumpedPreconData fetiInterfaceLumpedPreconData;

315
316
    FetiKspData fetiKspData;

Thomas Witkowski's avatar
Thomas Witkowski committed
317
    /// Matrices for Dirichlet preconditioner.
318
    Mat mat_interior_interior, mat_duals_duals, mat_interior_duals, mat_duals_interior;
319
320

    KSP ksp_interior;
321
322
323

    bool multiLevelTest;

Thomas Witkowski's avatar
Thomas Witkowski committed
324
    PetscSolver *subdomain;
325

326
327
    PetscSolver *massMatrixSolver;

328
    int meshLevel;
329
330
331
332

    int rStartInterior;

    int nGlobalOverallInterior;
Thomas Witkowski's avatar
Thomas Witkowski committed
333
334

    bool printTimings;
Thomas Witkowski's avatar
Thomas Witkowski committed
335

336
337
338
339
340
341
    bool augmentedLagrange;

    int nRankEdges;

    int nOverallEdges;

Thomas Witkowski's avatar
Thomas Witkowski committed
342
343
344
345
346
    bool stokesMode;

    const FiniteElemSpace* pressureFeSpace;

    int pressureComponent;
Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
347
348

    map<const FiniteElemSpace*, std::set<DegreeOfFreedom> > dirichletRows;
349
350

    friend class PetscSolverFetiDebug;
351
  };
352

353
354
355
}

#endif