https://mooseframework.inl.gov
SlepcEigenSolverConfiguration.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 #include "libmesh/libmesh_config.h"
11 
12 #ifdef LIBMESH_HAVE_SLEPC
13 
15 #include "SlepcSupport.h"
16 #include "EigenProblem.h"
17 #include "NonlinearEigenSystem.h"
18 #include "libmesh/slepc_eigen_solver.h"
19 #include <slepceps.h>
20 
25  EigenProblem & eigen_problem,
26  libMesh::SlepcEigenSolver<libMesh::Number> & slepc_eigen_solver,
27  const NonlinearEigenSystem & nl_eigen_sys)
28  : SolverConfiguration(),
29  _eigen_problem(eigen_problem),
30  _slepc_solver(slepc_eigen_solver),
31  _nl_eigen_sys(nl_eigen_sys)
32 {
33 }
34 
35 void
37 {
39  {
40  // Set custom monitors for SNES and KSP
42  // Let us remove extra "eps_power" from SNES since users do not like it
43  LibmeshPetscCallA(_eigen_problem.comm().get(),
45  // Let us hook up a customize PC if users ask. Users still can use PETSc options to override
46  // this setting
47  if (_eigen_problem.solverParams(_nl_eigen_sys.number())._customized_pc_for_eigen)
48  LibmeshPetscCallA(_eigen_problem.comm().get(),
50  // Let set a default PC side. I would like to have the setting be consistent with
51  // what we do in regular nonlinear executioner. Petsc options are able to override
52  // this setting
53  LibmeshPetscCallA(
56  // A customized stopping test for nonlinear free power iterations.
57  // Nonlinear power iterations need to be marked as converged in EPS to
58  // retrieve solution from SLEPc EPS.
59  LibmeshPetscCallA(_eigen_problem.comm().get(),
60  EPSSetStoppingTestFunction(_slepc_solver.eps(),
63  NULL));
64 
65  // Remove all SLEPc monitors.
66  LibmeshPetscCallA(_eigen_problem.comm().get(), EPSMonitorCancel(_slepc_solver.eps()));
67  // A customized EPS monitor in moose. We need to print only eigenvalue
68  LibmeshPetscCallA(
70  EPSMonitorSet(
72  }
73 }
74 
75 #endif
Nonlinear eigenvalue system to be solved.
virtual void initPetscOutputAndSomeSolverSettings() override
Hook up monitors for SNES and KSP.
Definition: EigenProblem.C:687
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.
const Parallel::Communicator & comm() const
bool isNonlinearEigenvalueSolver(unsigned int eigen_sys_num) const
Definition: EigenProblem.C:676
libMesh::SlepcEigenSolver< libMesh::Number > & _slepc_solver
The slepc eigen solver object that we are configuring.
SlepcEigenSolverConfiguration(EigenProblem &eigen_problem, libMesh::SlepcEigenSolver< libMesh::Number > &slepc_eigen_solver, const NonlinearEigenSystem &nl_eigen_sys)
Constructur: get a reference to the SlepcEigenSolver variable to be able to manipulate it...
const NonlinearEigenSystem & _nl_eigen_sys
The system that owns the SLEPc solver.
unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:1159
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 mooseSlepcEPSSNESKSPSetPCSide(FEProblemBase &problem, EPS eps)
Allow users to specify PC side.
SolverParams & solverParams(unsigned int solver_sys_num=0)
Get the solver parameters.
PetscErrorCode mooseSlepcEPSSNESSetUpOptionPrefix(EPS eps)
Get rid of prefix "-eps_power" for SNES, KSP, PC, etc.
Problem for solving eigenvalue problems.
Definition: EigenProblem.h:21