PetscSolverFeti.h 8.44 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
#include <map>
#include "parallel/MpiHelper.h"
25
#include "parallel/PetscSolver.h"
26
#include "parallel/PetscSolverFetiStructs.h"
27
#include "parallel/ParallelDofMapping.h"
28
#include "parallel/ParallelTypes.h"
29
#include "parallel/SubDomainSolver.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
    /// Initialization of the data structures with a given list of the FE 
    /// spaces of all components.
    void initialize(vector<const FiniteElemSpace*> feSpaces);

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

    int getNumberOfPrimals()
    {
83
      return primalDofMap.getOverallDofs();
84
    }
85

86
87
    int getNumberOfRankPrimals()
    {
88
      return primalDofMap.getRankDofs();
89
90
    }

91
92
    int getNumberOfDuals()
    {
93
      return dualDofMap.getOverallDofs();
94
95
    }

96
97
    int getNumberOfRankDuals()
    {
98
      return dualDofMap.getRankDofs();
99
100
    }

101
  protected:
102
103
    /// Defines which boundary nodes are primal. Creates global index of
    /// the primal variables.
104
    void createPrimals(const FiniteElemSpace *feSpace);
105

106
107
    /// Defines the set of dual variables and creates the global index of
    // dual variables.
108
    void createDuals(const FiniteElemSpace *feSpace);
109

110
111
    /// Create Lagrange multiplier variables corresponding to the dual 
    /// variables.
112
    void createLagrange(const FiniteElemSpace *feSpace);
113

114
    /// Creates a global index of the B variables.
115
    void createIndexB(const FiniteElemSpace *feSpace);
116

117
118
    /// Creates the Lagrange multiplier constraints and assembles them 
    /// to \ref mat_lagrange.
119
    void createMatLagrange(vector<const FiniteElemSpace*> &feSpaces);
120

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

125
    /// Destroys PETSc KSP solver object \ref ksp_schur_primal
126
127
    void destroySchurPrimalKsp();

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

131
    /// Destroys FETI-DP operator, \ref ksp_feti
132
133
    void destroyFetiKsp();

134
135
136
137
138
139
140
141
142
143
144
145
146
147
    /** \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.
     */
148
149
150
151
    void recoverSolution(Vec &vec_sol_b,
			 Vec &vec_sol_primal,
			 SystemVector &vec);

Thomas Witkowski's avatar
Thomas Witkowski committed
152
153
154
155
156
157
158
159
160
    /** \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);

161
162
163
164
165
166
167
168
    /** \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
169
170
171
172
    void resetStatistics();

    void printStatistics();

173
    /// Checks whether a given DOF in a given FE space is a primal DOF.
174
175
    inline bool isPrimal(const FiniteElemSpace *feSpace, 
			 DegreeOfFreedom dof)
176
    {
177
      return primalDofMap[feSpace].isSet(dof);
178
179
    }

180
    /// Checks whether a given DOF in a give FE space is a dual DOF.
181
182
    inline bool isDual(const FiniteElemSpace *feSpace, 
		       DegreeOfFreedom dof)
183
    {
184
      return dualDofMap[feSpace].isSet(dof);
185
186
    }

187
  protected:
188
    /// Mapping from primal DOF indices to a global index of primals.
Thomas Witkowski's avatar
Thomas Witkowski committed
189
    ParallelDofMapping primalDofMap;
190

191
    /// Mapping from dual DOF indices to a global index of duals.
Thomas Witkowski's avatar
Thomas Witkowski committed
192
    ParallelDofMapping dualDofMap;
193

194
195
    /// 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
196
    ParallelDofMapping lagrangeMap;
197
    
198
    /// Index for each non primal DOF to the global index of B variables.
Thomas Witkowski's avatar
Thomas Witkowski committed
199
    ParallelDofMapping localDofMap;
200

201
202
    /// 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
203
    ParallelDofMapping interiorDofMap;
204

205
    /// Stores to each dual boundary DOF in each FE space the set of
206
207
    /// ranks in which the DOF is contained in.
    map<const FiniteElemSpace*, DofIndexToPartitions> boundaryDofRanks;
208

209
    /// Global PETSc matrix of Lagrange variables.
210
211
    Mat mat_lagrange;

Thomas Witkowski's avatar
Thomas Witkowski committed
212
213
214
215
216
    /// 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;

217
218
    /// PETSc solver object to solve the Schur complement on the 
    /// primal variables.
219
220
    KSP ksp_schur_primal;

221
222
    /// Matrix object that defines a matrix-free implementation for the action
    /// of the Schur complement on the primal variables.
223
224
    Mat mat_schur_primal;

225
    /// Data for MatMult operation in matrix \ref mat_schur_primal
226
    SchurPrimalData schurPrimalData;
227

228
    /// PETSc solver object to solve a system with FETI-DP.    
229
230
    KSP ksp_feti;

231
232
    /// Matrix object that defines a matrix-free implementation for the action
    /// of the FETI-DP operator.
233
    Mat mat_feti;
234

235
    /// Data for MatMult operation in matrix \ref mat_feti
236
    FetiData fetiData;
237

238
239
240
241
242
243
    /// 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;
244
245
246

    Mat mat_lagrange_scaled;
   
247
    FetiDirichletPreconData fetiDirichletPreconData;
248

249
    FetiLumpedPreconData fetiLumpedPreconData;
250

251
    Mat mat_interior_interior, mat_duals_duals, mat_interior_duals, mat_duals_interior;
252
253

    KSP ksp_interior;
254
255
256
257

    bool multiLevelTest;

    SubDomainSolver *subDomainSolver;
258
259

    int meshLevel;
260
261
262
263
264

    int rStartInterior;

    int nGlobalOverallInterior;

265
  };
266

267
268
269
}

#endif