PetscSolverFeti.h 8.45 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
34

#ifndef AMDIS_PETSC_SOLVER_FETI_H
#define AMDIS_PETSC_SOLVER_FETI_H

namespace AMDiS {

  using namespace std;


#ifdef HAVE_PETSC_DEV
35

36
37
38
39
  /** \brief
   * This structure is used when defining the MatShell operation for solving 
   * primal schur complement. \ref petscMultMatSchurPrimal
   */
40
  struct PetscSchurPrimalData {
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;

53
    /// Pointer to the solver for \ref PetscSolverFeti::mat_bb.
54
55
56
57
    KSP *ksp_b;
  };


58
59
60
61
62
  /** \brief
   * This structure is used when defining the FETI-DP operator for solving 
   * the system matrix reduced to the Lagrange multipliers.
   * \ref petscMultMatFeti
   */
63
  struct PetscFetiData {
64
65
66
67
68
    /// 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;
69

70
    /// Matrix of Lagrange variables.
71
72
    Mat *mat_lagrange;

73
    /// Temporal vector on the B variables.
74
75
    Vec tmp_vec_b;

76
    /// Temporal vector on the primal variables.
77
78
    Vec tmp_vec_primal;

79
    /// Temporal vector on the Lagrange variables.
80
81
    Vec tmp_vec_lagrange;

82
    /// Pointer to the solver for \ref PetscSolverFeti::mat_bb.
83
84
    KSP *ksp_b;

85
    /// Pointer to the solver of the schur complement on the primal variables.
86
87
88
89
90
    KSP *ksp_schur_primal;
  };



91
92
93
  /** \brief
   * FETI-DP implementation based on PETSc.
   */
94
95
96
97
  class PetscSolverFeti : public PetscSolver
  {
  public:
    PetscSolverFeti() 
98
99
      : PetscSolver(),
	nComponents(-1)
100
101
    {}

102
103
    /// Assemble the sequentially created matrices and vectors to the
    /// global matrices and vectors required by the FETI-DP method.
104
105
    void fillPetscMatrix(Matrix<DOFMatrix*> *mat, SystemVector *vec);

106
    /// Solve the system using FETI-DP method.
107
    void solvePetscMatrix(SystemVector &vec, AdaptInfo *adaptInfo);
108

109
110
    /// Returns flags to denote which information of the boundary DOFs are 
    /// required by the FETI-DP solver.
111
112
113
114
115
116
117
    Flag getBoundaryDofRequirement()
    {
      return 
	MeshDistributor::BOUNDARY_SUBOBJ_SORTED |
	MeshDistributor::BOUNDARY_FILL_INFO_SEND_DOFS |
	MeshDistributor::BOUNDARY_FILL_INFO_RECV_DOFS;
    }
118

119
  protected:
120
121
122
    /// After mesh changes, or if the solver is called the first time, this
    /// function creates all matrix and vector objects with the approriated
    /// sizes.
123
    void updateDofData();
124

125
126
    /// Defines which boundary nodes are primal. Creates global index of
    /// the primal variables.
127
128
    void createPrimals();

129
130
    /// Defines the set of dual variables and creates the global index of
    // dual variables.
131
132
    void createDuals();

133
134
    /// Create Lagrange multiplier variables corresponding to the dual 
    /// variables.
135
136
    void createLagrange();

137
    /// Creates a global index of the B variables.
138
139
    void createIndexB();

140
141
142
    /// Creates the Lagrange multiplier constraints and assembles them 
    /// to \ref mat_lagrange.
    void createMatLagrange();
143

144
145
146
    /// Creates PETSc KSP solver object for solving the Schur complement
    /// system on the primal variables, \ref ksp_schur_primal
    void createSchurPrimalKsp();
147

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

151
    /// Creates PETSc KSP solver object for the FETI-DP operator, \ref ksp_feti
152
153
    void createFetiKsp();

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

157
158
159
160
161
162
163
164
165
166
167
168
169
170
    /** \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.
     */
171
172
173
174
    void recoverSolution(Vec &vec_sol_b,
			 Vec &vec_sol_primal,
			 SystemVector &vec);

175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
    /** \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);

    /** \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);

192
  protected:
193
194
195
196
    /// Number of components in the PDE to be solved.
    int nComponents;

    /// Set of DOF indices that are considered to be primal variables.
197
    DofIndexSet primals;
198

199
    /// Mapping from primal DOF indices to a global index of primals.
200
    DofMapping globalPrimalIndex;
201

202
203
    /// Number of rank owned primals and global primals
    int nRankPrimals, nOverallPrimals, rStartPrimals;
204

205
    /// Set of DOF indices that are considered to be dual variables.
206
207
    DofIndexSet duals;
    
208
    /// Mapping from dual DOF indices to a global index of duals.
209
210
    DofMapping globalDualIndex;

211
212
    /// Stores to each dual boundary DOF the set of ranks in which the DOF
    /// is contained in.
213
214
    DofIndexToPartitions boundaryDofRanks;

215
216
    /// Stores to each dual DOF index the index of the first Lagrange
    /// constraint that is assigned to this DOF.
217
218
    DofMapping dofFirstLagrange;

219
220
221
    /// Number of rank owned Lagrange variables, number of global
    /// Lagrange variables.
    int nRankLagrange, nOverallLagrange, rStartLagrange;
222
    
223
224
    /// Index for each non primal variables to the global index of
    /// B variables.
225
226
    DofMapping globalIndexB;

227
228
    /// Number of non primal, thus B, variables on rank and globally.
    int nRankB, nOverallB, rStartB;    
229

230
    /// Global PETSc matrix of non primal variables.
231
232
    Mat mat_b_b;

233
    /// Global PETSc matrix of primal variables.
234
235
    Mat mat_primal_primal;

236
237
    /// Global PETSc matrices that connect the primal with the non 
    /// primal variables.
238
239
    Mat mat_b_primal, mat_primal_b;

240
    /// Global PETSc matrix of Lagrange variables.
241
242
    Mat mat_lagrange;

243
    /// Right hand side PETSc vectors for primal and non primal variables.
244
245
    Vec f_b, f_primal;

246
247
    /// PETSc solver object that inverts the matrix of non primal 
    /// variables, \ref mat_b_b
248
249
    KSP ksp_b;

250
251
    /// PETSc solver object to solve the Schur complement on the 
    /// primal variables.
252
253
    KSP ksp_schur_primal;

254
255
    /// Matrix object that defines a matrix-free implementation for the action
    /// of the Schur complement on the primal variables.
256
257
    Mat mat_schur_primal;

258
    /// Data for MatMult operation in matrix \ref mat_schur_primal
259
260
    PetscSchurPrimalData petscSchurPrimalData;

261
    /// PETSc solver object to solve a system with FETI-DP.    
262
263
    KSP ksp_feti;

264
265
    /// Matrix object that defines a matrix-free implementation for the action
    /// of the FETI-DP operator.
266
    Mat mat_feti;
267

268
    /// Data for MatMult operation in matrix \ref mat_feti
269
    PetscFetiData petscFetiData;
270
271
272
273
274
275
  };
#endif

}

#endif