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

#include "parallel/PetscSolver.h"
24
#include "parallel/ParallelTypes.h"
25
26
27
28
29
30
31
32
33

#ifndef AMDIS_PETSC_SOLVER_FETI_H
#define AMDIS_PETSC_SOLVER_FETI_H

namespace AMDiS {

  using namespace std;


Thomas Witkowski's avatar
Thomas Witkowski committed
34
35
  class PetscSolverFeti;

36
37
38
39
  /** \brief
   * This structure is used when defining the MatShell operation for solving 
   * primal schur complement. \ref petscMultMatSchurPrimal
   */
40
  struct SchurPrimalData {
41
42
43
44
45
    /// Pointers to the matrix containing the primal variables.
    Mat *mat_primal_primal;
   
    /// Coupling matrices between the primal and the B variables.
    Mat *mat_primal_b, *mat_b_primal;
46

47
    /// Temporal vector on the B variables.
48
49
    Vec tmp_vec_b;

50
    /// Temporal vecor in the primal variables.
51
52
    Vec tmp_vec_primal;

Thomas Witkowski's avatar
Thomas Witkowski committed
53
    PetscSolverFeti *fetiSolver;
54
55
56
  };


57
58
59
60
61
  /** \brief
   * This structure is used when defining the FETI-DP operator for solving 
   * the system matrix reduced to the Lagrange multipliers.
   * \ref petscMultMatFeti
   */
62
  struct FetiData {
63
64
    /// Coupling matrices between the primal and the B variables.
    Mat *mat_primal_b, *mat_b_primal;
65

66
    /// Matrix of Lagrange variables.
67
68
    Mat *mat_lagrange;

69
    /// Temporal vectors on the B variables.
Thomas Witkowski's avatar
Thomas Witkowski committed
70
    Vec tmp_vec_b;
71

72
    /// Temporal vector on the primal variables.
73
74
    Vec tmp_vec_primal;

Thomas Witkowski's avatar
Thomas Witkowski committed
75
76
77
    /// Temporal vector on the lagrange variables.
    Vec tmp_vec_lagrange;

Thomas Witkowski's avatar
Thomas Witkowski committed
78
    PetscSolverFeti *fetiSolver;
79

80
    /// Pointer to the solver of the schur complement on the primal variables.
81
82
83
84
    KSP *ksp_schur_primal;
  };


85
  struct FetiDirichletPreconData {
86
87
88
    /// Matrix of scaled Lagrange variables.
    Mat *mat_lagrange_scaled;

89
    Mat *mat_interior_interior, *mat_duals_duals, *mat_interior_duals, *mat_duals_interior;
90
91
92
93
94
95
96

    /// Pointer to the solver for \ref PetscSolverFeti::mat_bb.
    KSP *ksp_interior;

    /// Temporal vector on the B variables.
    Vec tmp_vec_b;

97
98
    /// Temporal vector on the dual variables.
    Vec tmp_vec_duals0, tmp_vec_duals1;
99
    
100
101
102
    /// Temporal vector on the interior variables.
    Vec tmp_vec_interior;    
  };
103

104

105
106
107
108
109
110
111
112
113
114
115
  struct FetiLumpedPreconData {
    /// Matrix of scaled Lagrange variables.
    Mat *mat_lagrange_scaled;

    Mat *mat_duals_duals;

    /// Temporal vector on the B variables.
    Vec tmp_vec_b;

    /// Temporal vector on the dual variables.
    Vec tmp_vec_duals0, tmp_vec_duals1;
116
117
  };

118

119
120
121
122
123
124
125
  typedef enum {
    FETI_NONE = 0,
    FETI_DIRICHLET = 1,
    FETI_LUMPED = 2
  } FetiPreconditioner;


126
/** \brief
127
128
   * FETI-DP implementation based on PETSc.
   */
129
130
131
  class PetscSolverFeti : public PetscSolver
  {
  public:
132
    PetscSolverFeti();
133

134
135
136
137
138
139
    /// 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);
140

141
    /// Solve the system using FETI-DP method.
142
    void solvePetscMatrix(SystemVector &vec, AdaptInfo *adaptInfo);
143

144
145
146
    /// Destroys all matrix data structures.
    void destroyMatrixData();

147
148
    /// Returns flags to denote which information of the boundary DOFs are 
    /// required by the FETI-DP solver.
149
150
151
152
153
154
155
    Flag getBoundaryDofRequirement()
    {
      return 
	MeshDistributor::BOUNDARY_SUBOBJ_SORTED |
	MeshDistributor::BOUNDARY_FILL_INFO_SEND_DOFS |
	MeshDistributor::BOUNDARY_FILL_INFO_RECV_DOFS;
    }
156

Thomas Witkowski's avatar
Thomas Witkowski committed
157
158
    void solveLocalProblem(Vec &rhs, Vec &sol);

159
  protected:
160
161
162
    /// After mesh changes, or if the solver is called the first time, this
    /// function creates all matrix and vector objects with the approriated
    /// sizes.
163
    void updateDofData();
164

165
166
    /// Defines which boundary nodes are primal. Creates global index of
    /// the primal variables.
167
168
    void createPrimals();

169
170
    /// Defines the set of dual variables and creates the global index of
    // dual variables.
171
172
    void createDuals();

173
174
    /// Create Lagrange multiplier variables corresponding to the dual 
    /// variables.
175
176
    void createLagrange();

177
    /// Creates a global index of the B variables.
178
179
    void createIndexB();

180
181
182
    /// Creates the Lagrange multiplier constraints and assembles them 
    /// to \ref mat_lagrange.
    void createMatLagrange();
183

184
185
186
    /// Creates PETSc KSP solver object for solving the Schur complement
    /// system on the primal variables, \ref ksp_schur_primal
    void createSchurPrimalKsp();
187

188
    /// Destroys PETSc KSP solver object \ref ksp_schur_primal
189
190
    void destroySchurPrimalKsp();

191
    /// Creates PETSc KSP solver object for the FETI-DP operator, \ref ksp_feti
192
193
    void createFetiKsp();

194
    /// Destroys FETI-DP operator, \ref ksp_feti
195
196
    void destroyFetiKsp();

197
198
199
200
201
202
203
204
205
206
207
208
209
210
    /** \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.
     */
211
212
213
214
    void recoverSolution(Vec &vec_sol_b,
			 Vec &vec_sol_primal,
			 SystemVector &vec);

Thomas Witkowski's avatar
Thomas Witkowski committed
215
216
217
218
219
220
221
222
223
    /** \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);

224
225
226
227
228
229
230
231
    /** \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
232
233
234
235
    void resetStatistics();

    void printStatistics();

236
  protected:
237
238
239
240
    /// Number of components in the PDE to be solved.
    int nComponents;

    /// Mapping from primal DOF indices to a global index of primals.
241
    DofMapping globalPrimalIndex;
242

243
244
    /// Number of rank owned primals and global primals
    int nRankPrimals, nOverallPrimals, rStartPrimals;
245

246
    /// Set of DOF indices that are considered to be dual variables.
247
248
    DofIndexSet duals;
    
249
    /// Mapping from dual DOF indices to a global index of duals.
250
251
    DofMapping globalDualIndex;

252
253
    /// Stores to each dual boundary DOF the set of ranks in which the DOF
    /// is contained in.
254
255
    DofIndexToPartitions boundaryDofRanks;

256
257
    /// Stores to each dual DOF index the index of the first Lagrange
    /// constraint that is assigned to this DOF.
258
259
    DofMapping dofFirstLagrange;

260
261
262
    /// Number of rank owned Lagrange variables, number of global
    /// Lagrange variables.
    int nRankLagrange, nOverallLagrange, rStartLagrange;
263
    
264
265
    /// Index for each non primal variables to the global index of
    /// B variables.
Thomas Witkowski's avatar
Thomas Witkowski committed
266
    DofMapping globalIndexB, localIndexB;
267

268
269
    /// Number of non primal, thus B, variables on rank and globally.
    int nRankB, nOverallB, rStartB;    
270

271
    /// Global PETSc matrix of non primal variables.
272
273
    Mat mat_b_b;

274
    /// Global PETSc matrix of primal variables.
275
276
    Mat mat_primal_primal;

277
278
    /// Global PETSc matrices that connect the primal with the non 
    /// primal variables.
279
280
    Mat mat_b_primal, mat_primal_b;

281
    /// Global PETSc matrix of Lagrange variables.
282
283
    Mat mat_lagrange;

284
    /// Right hand side PETSc vectors for primal and non primal variables.
285
286
    Vec f_b, f_primal;

287
288
    /// PETSc solver object that inverts the matrix of non primal 
    /// variables, \ref mat_b_b
289
290
    KSP ksp_b;

Thomas Witkowski's avatar
Thomas Witkowski committed
291
292
293
294
295
    /// 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;

296
297
    /// PETSc solver object to solve the Schur complement on the 
    /// primal variables.
298
299
    KSP ksp_schur_primal;

300
301
    /// Matrix object that defines a matrix-free implementation for the action
    /// of the Schur complement on the primal variables.
302
303
    Mat mat_schur_primal;

304
    /// Data for MatMult operation in matrix \ref mat_schur_primal
305
    SchurPrimalData schurPrimalData;
306

307
    /// PETSc solver object to solve a system with FETI-DP.    
308
309
    KSP ksp_feti;

310
311
    /// Matrix object that defines a matrix-free implementation for the action
    /// of the FETI-DP operator.
312
    Mat mat_feti;
313

314
    /// Data for MatMult operation in matrix \ref mat_feti
315
    FetiData fetiData;
316

317
318
319
320
321
322
    /// 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;
323
324
325

    Mat mat_lagrange_scaled;
   
326
    FetiDirichletPreconData fetiDirichletPreconData;
327

328
    FetiLumpedPreconData fetiLumpedPreconData;
329

330
    Mat mat_interior_interior, mat_duals_duals, mat_interior_duals, mat_duals_interior;
331
332
333
334
335

    KSP ksp_interior;

    int nLocalInterior;
    
336
337
    // Number of local nodes that are duals.
    int nLocalDuals;
338
339
340
341
  };
}

#endif