PetscSolverFeti.h 7.61 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
24
25
#include <map>
#include "parallel/FeSpaceMapping.h"
#include "parallel/MpiHelper.h"
26
#include "parallel/PetscSolver.h"
27
#include "parallel/PetscSolverFetiStructs.h"
28
#include "parallel/ParallelTypes.h"
29
30
31
32
33
34
35
36

#ifndef AMDIS_PETSC_SOLVER_FETI_H
#define AMDIS_PETSC_SOLVER_FETI_H

namespace AMDiS {

  using namespace std;

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

45
46
47
48
49
50
    /// 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);
51

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

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

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

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

70
  protected:
71
72
73
    /// After mesh changes, or if the solver is called the first time, this
    /// function creates all matrix and vector objects with the approriated
    /// sizes.
74
    void updateDofData();
75

76
77
    /// Defines which boundary nodes are primal. Creates global index of
    /// the primal variables.
78
    void createPrimals(const FiniteElemSpace *feSpace);
79

80
81
    /// Defines the set of dual variables and creates the global index of
    // dual variables.
82
    void createDuals(const FiniteElemSpace *feSpace);
83

84
85
    /// Create Lagrange multiplier variables corresponding to the dual 
    /// variables.
86
    void createLagrange(const FiniteElemSpace *feSpace);
87

88
    /// Creates a global index of the B variables.
89
    void createIndexB(const FiniteElemSpace *feSpace);
90

91
92
    /// Creates the Lagrange multiplier constraints and assembles them 
    /// to \ref mat_lagrange.
93
    void createMatLagrange(vector<const FiniteElemSpace*> &feSpaces);
94

95
96
97
    /// Creates PETSc KSP solver object for solving the Schur complement
    /// system on the primal variables, \ref ksp_schur_primal
    void createSchurPrimalKsp();
98

99
    /// Destroys PETSc KSP solver object \ref ksp_schur_primal
100
101
    void destroySchurPrimalKsp();

102
    /// Creates PETSc KSP solver object for the FETI-DP operator, \ref ksp_feti
103
104
    void createFetiKsp();

105
    /// Destroys FETI-DP operator, \ref ksp_feti
106
107
    void destroyFetiKsp();

108
109
110
111
112
113
114
115
116
117
118
119
120
121
    /** \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.
     */
122
123
124
125
    void recoverSolution(Vec &vec_sol_b,
			 Vec &vec_sol_primal,
			 SystemVector &vec);

Thomas Witkowski's avatar
Thomas Witkowski committed
126
127
128
129
130
131
132
133
134
    /** \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);

135
136
137
138
139
140
141
142
    /** \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
143
144
145
146
    void resetStatistics();

    void printStatistics();

147
  protected:
148
149
150
151
    /// Number of components in the PDE to be solved.
    int nComponents;

    /// Mapping from primal DOF indices to a global index of primals.
152
    FeSpaceData<GlobalDofMap> primalDofMap;
153

154
    /// Mapping from dual DOF indices to a global index of duals.
155
    FeSpaceData<GlobalDofMap> dualDofMap;
156

157
158
    /// Stores to each dual DOF index the index of the first Lagrange
    /// constraint that is assigned to this DOF.
159
    FeSpaceData<GlobalDofMap> lagrangeMap;
160
    
161
    /// Index for each non primal DOF to the global index of
162
    /// B variables.
163
    FeSpaceData<GlobalDofMap> localDofMap;
164

165
166
167
168
    /// Stores to each dual boundary DOF the set of ranks in which the DOF
    /// is contained in.
    DofIndexToPartitions boundaryDofRanks;

169
    /// Global PETSc matrix of non primal variables.
170
171
    Mat mat_b_b;

172
    /// Global PETSc matrix of primal variables.
173
174
    Mat mat_primal_primal;

175
176
    /// Global PETSc matrices that connect the primal with the non 
    /// primal variables.
177
178
    Mat mat_b_primal, mat_primal_b;

179
    /// Global PETSc matrix of Lagrange variables.
180
181
    Mat mat_lagrange;

182
    /// Right hand side PETSc vectors for primal and non primal variables.
183
184
    Vec f_b, f_primal;

185
186
    /// PETSc solver object that inverts the matrix of non primal 
    /// variables, \ref mat_b_b
187
188
    KSP ksp_b;

Thomas Witkowski's avatar
Thomas Witkowski committed
189
190
191
192
193
    /// 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;

194
195
    /// PETSc solver object to solve the Schur complement on the 
    /// primal variables.
196
197
    KSP ksp_schur_primal;

198
199
    /// Matrix object that defines a matrix-free implementation for the action
    /// of the Schur complement on the primal variables.
200
201
    Mat mat_schur_primal;

202
    /// Data for MatMult operation in matrix \ref mat_schur_primal
203
    SchurPrimalData schurPrimalData;
204

205
    /// PETSc solver object to solve a system with FETI-DP.    
206
207
    KSP ksp_feti;

208
209
    /// Matrix object that defines a matrix-free implementation for the action
    /// of the FETI-DP operator.
210
    Mat mat_feti;
211

212
    /// Data for MatMult operation in matrix \ref mat_feti
213
    FetiData fetiData;
214

215
216
217
218
219
220
    /// 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;
221
222
223

    Mat mat_lagrange_scaled;
   
224
    FetiDirichletPreconData fetiDirichletPreconData;
225

226
    FetiLumpedPreconData fetiLumpedPreconData;
227

228
    Mat mat_interior_interior, mat_duals_duals, mat_interior_duals, mat_duals_interior;
229
230
231

    KSP ksp_interior;

232
    int nLocalInterior;    
233
  };
234

235
236
237
}

#endif