www.mooseframework.org
SlepcSupport.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "libmesh/libmesh_config.h"
13 
14 #ifdef LIBMESH_HAVE_SLEPC
15 
16 #include "libmesh/petsc_macro.h"
17 
18 #include "Moose.h"
19 #include "SystemBase.h"
20 
21 /* We need this in order to implement moose PC */
22 #include <petsc/private/pcimpl.h>
23 #include <slepceps.h>
24 #include <slepc/private/epsimpl.h>
25 /* In order to use libMesh preconditioner */
26 #include "libmesh/linear_solver.h"
27 #include "libmesh/preconditioner.h"
28 
29 class EigenProblem;
30 class InputParameters;
31 
32 namespace Moose
33 {
34 namespace SlepcSupport
35 {
43 
48 
52 void storeSolveType(FEProblemBase & fe_problem, const InputParameters & params);
53 
57 void setEigenProblemSolverParams(EigenProblem & eigen_problem, const InputParameters & params);
58 
63 void slepcSetOptions(EigenProblem & eigen_problem, const InputParameters & params);
64 
68 void setSlepcEigenSolverTolerances(EigenProblem & eigen_problem, const InputParameters & params);
69 
73 void setFreeNonlinearPowerIterations(unsigned int free_power_iterations);
74 
75 /*
76  * Set SLEPc/PETSc options to turn the eigen-solver back to a regular Newton solver
77  */
79 
83 void moosePetscSNESFormMatrixTag(SNES snes, Vec x, Mat mat, void * ctx, TagID tag);
84 
89  SNES snes, Vec x, std::vector<Mat> & mats, void * ctx, const std::set<TagID> & tags);
90 
94 PetscErrorCode mooseSlepcEigenFormJacobianA(SNES snes, Vec x, Mat jac, Mat pc, void * ctx);
95 
99 PetscErrorCode mooseSlepcEigenFormJacobianB(SNES snes, Vec x, Mat jac, Mat pc, void * ctx);
100 
104 PetscErrorCode mooseSlepcEigenFormFunctionA(SNES snes, Vec x, Vec r, void * ctx);
105 
109 PetscErrorCode mooseSlepcEigenFormFunctionB(SNES snes, Vec x, Vec r, void * ctx);
110 
114 PetscErrorCode mooseSlepcEigenFormFunctionAB(SNES snes, Vec x, Vec Ax, Vec Bx, void * ctx);
115 
120 PetscErrorCode mooseSlepcStoppingTest(EPS eps,
121  PetscInt its,
122  PetscInt max_it,
123  PetscInt nconv,
124  PetscInt nev,
125  EPSConvergedReason * reason,
126  void * ctx);
127 
131 PetscErrorCode mooseSlepcEPSGetSNES(EPS eps, SNES * snes);
132 
136 PetscErrorCode mooseSlepcEPSMonitor(EPS eps,
137  PetscInt its,
138  PetscInt nconv,
139  PetscScalar * eigr,
140  PetscScalar * eigi,
141  PetscReal * errest,
142  PetscInt nest,
143  void * mctx);
144 
148 PetscErrorCode mooseSlepcEPSSNESSetUpOptionPrefix(EPS eps);
149 
154 PetscErrorCode mooseSlepcEPSSNESSetCustomizePC(EPS eps);
155 
160 PetscErrorCode mooseSlepcEPSSNESKSPSetPCSide(FEProblemBase & problem, EPS eps);
161 
165 void attachCallbacksToMat(EigenProblem & eigen_problem, Mat mat, bool eigen);
166 
170 PetscErrorCode mooseMatMult_Eigen(Mat mat, Vec x, Vec y);
171 
175 PetscErrorCode mooseMatMult_NonEigen(Mat mat, Vec x, Vec y);
176 
180 void setOperationsForShellMat(EigenProblem & eigen_problem, Mat mat, bool eigen);
181 
185 PETSC_EXTERN PetscErrorCode PCCreate_MoosePC(PC pc);
186 
190 PETSC_EXTERN PetscErrorCode registerPCToPETSc();
191 
195 PetscErrorCode PCDestroy_MoosePC(PC pc);
196 
200 PetscErrorCode PCView_MoosePC(PC pc, PetscViewer viewer);
201 
205 PetscErrorCode PCApply_MoosePC(PC pc, Vec x, Vec y);
206 
210 PetscErrorCode PCSetUp_MoosePC(PC pc);
211 
215 PetscErrorCode mooseSlepcEigenFormFunctionMFFD(void * ctx, Vec x, Vec r);
216 
217 } // namespace SlepcSupport
218 } // namespace moose
219 
220 #endif // LIBMESH_HAVE_SLEPC
int eps(unsigned int i, unsigned int j)
2D version
PetscErrorCode mooseSlepcEigenFormFunctionMFFD(void *ctx, Vec x, Vec r)
Function call for MFFD.
Definition: SlepcSupport.C:622
unsigned int TagID
Definition: MooseTypes.h:199
PetscErrorCode mooseSlepcEPSSNESSetCustomizePC(EPS eps)
Attach a customized PC.
PetscErrorCode mooseSlepcStoppingTest(EPS eps, PetscInt its, PetscInt max_it, PetscInt nconv, PetscInt nev, EPSConvergedReason *reason, void *ctx)
A customized convergence checker.
PetscErrorCode mooseMatMult_Eigen(Mat mat, Vec x, Vec y)
Implement MatMult via function evaluation for Bx.
PetscErrorCode mooseSlepcEigenFormJacobianB(SNES snes, Vec x, Mat jac, Mat pc, void *ctx)
Form Jacobian matrix B.
Definition: SlepcSupport.C:746
void clearFreeNonlinearPowerIterations(const InputParameters &params)
Definition: SlepcSupport.C:365
PetscErrorCode mooseSlepcEigenFormFunctionAB(SNES snes, Vec x, Vec Ax, Vec Bx, void *ctx)
Form function residual Ax-Bx.
Definition: SlepcSupport.C:899
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
PetscErrorCode PCApply_MoosePC(PC pc, Vec x, Vec y)
Preconditioner application.
PetscErrorCode PCDestroy_MoosePC(PC pc)
Destroy preconditioner.
PetscErrorCode mooseSlepcEigenFormFunctionA(SNES snes, Vec x, Vec r, void *ctx)
Form function residual Ax.
Definition: SlepcSupport.C:820
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
PetscErrorCode mooseMatMult_NonEigen(Mat mat, Vec x, Vec y)
Implement MatMult via function evaluation for Ax.
void setSlepcEigenSolverTolerances(EigenProblem &eigen_problem, const InputParameters &params)
Control eigen solver tolerances via SLEPc options.
Definition: SlepcSupport.C:127
InputParameters getSlepcValidParams(InputParameters &params)
Definition: SlepcSupport.C:37
PetscErrorCode PCSetUp_MoosePC(PC pc)
Setup preconditioner.
void attachCallbacksToMat(EigenProblem &eigen_problem, Mat mat, bool eigen)
Attach call backs to mat.
Definition: SlepcSupport.C:982
PETSC_EXTERN PetscErrorCode PCCreate_MoosePC(PC pc)
Create a preconditioner from moose side.
PetscErrorCode PCView_MoosePC(PC pc, PetscViewer viewer)
View preconditioner.
void moosePetscSNESFormMatricesTags(SNES snes, Vec x, std::vector< Mat > &mats, void *ctx, const std::set< TagID > &tags)
Form multiple matrices for multiple tags.
Definition: SlepcSupport.C:589
PetscErrorCode mooseSlepcEigenFormJacobianA(SNES snes, Vec x, Mat jac, Mat pc, void *ctx)
Form Jacobian matrix A.
Definition: SlepcSupport.C:651
PetscErrorCode mooseSlepcEigenFormFunctionB(SNES snes, Vec x, Vec r, void *ctx)
Form function residual Bx.
Definition: SlepcSupport.C:859
PetscErrorCode mooseSlepcEPSMonitor(EPS eps, PetscInt its, PetscInt nconv, PetscScalar *eigr, PetscScalar *eigi, PetscReal *errest, PetscInt nest, void *mctx)
A customized solver monitor to print out eigenvalue.
PetscErrorCode mooseSlepcEPSGetSNES(EPS eps, SNES *snes)
Retrieve SNES from EPS.
void setFreeNonlinearPowerIterations(unsigned int free_power_iterations)
Set SLEPc/PETSc options to trigger free power iteration.
Definition: SlepcSupport.C:350
PetscErrorCode mooseSlepcEPSSNESKSPSetPCSide(FEProblemBase &problem, EPS eps)
Allow users to specify PC side.
PetscErrorCode mooseSlepcEPSSNESSetUpOptionPrefix(EPS eps)
Get rid of prefix "-eps_power" for SNES, KSP, PC, etc.
void * ctx
void setOperationsForShellMat(EigenProblem &eigen_problem, Mat mat, bool eigen)
Set operations to shell mat.
void setEigenProblemSolverParams(EigenProblem &eigen_problem, const InputParameters &params)
Retrieve eigen problem params from &#39;params&#39;, and then set these params into SolverParams.
Definition: SlepcSupport.C:177
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
Problem for solving eigenvalue problems.
Definition: EigenProblem.h:21
void storeSolveType(FEProblemBase &fe_problem, const InputParameters &params)
Set solve type into eigen problem (solverParams)
Definition: SlepcSupport.C:247
PETSC_EXTERN PetscErrorCode registerPCToPETSc()
Let PETSc know there is a preconditioner.
void moosePetscSNESFormMatrixTag(SNES snes, Vec x, Mat mat, void *ctx, TagID tag)
Form matrix according to tag.
Definition: SlepcSupport.C:559
void slepcSetOptions(EigenProblem &eigen_problem, const InputParameters &params)
Push all SLEPc/PETSc options into SLEPc/PETSc side.
Definition: SlepcSupport.C:496
InputParameters getSlepcEigenProblemValidParams()
Retrieve valid params that allow users to specify eigen problem configuration.
Definition: SlepcSupport.C:66