LCOV - code coverage report
Current view: top level - src/utils - SlepcEigenSolverConfiguration.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 17 17 100.0 %
Date: 2025-07-17 01:28:37 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      14             : #include "SlepcEigenSolverConfiguration.h"
      15             : #include "SlepcSupport.h"
      16             : #include "EigenProblem.h"
      17             : #include "NonlinearEigenSystem.h"
      18             : #include "libmesh/slepc_eigen_solver.h"
      19             : #include <slepceps.h>
      20             : 
      21             : /**
      22             :  * Constructor: get a reference to the \p SlepcEigenSolver variable to be able to manipulate it
      23             :  */
      24         562 : SlepcEigenSolverConfiguration::SlepcEigenSolverConfiguration(
      25             :     EigenProblem & eigen_problem,
      26             :     libMesh::SlepcEigenSolver<libMesh::Number> & slepc_eigen_solver,
      27         562 :     const NonlinearEigenSystem & nl_eigen_sys)
      28             :   : SolverConfiguration(),
      29         562 :     _eigen_problem(eigen_problem),
      30         562 :     _slepc_solver(slepc_eigen_solver),
      31         562 :     _nl_eigen_sys(nl_eigen_sys)
      32             : {
      33         562 : }
      34             : 
      35             : void
      36        1233 : SlepcEigenSolverConfiguration::configure_solver()
      37             : {
      38        1233 :   if (_eigen_problem.isNonlinearEigenvalueSolver(_nl_eigen_sys.number()))
      39             :   {
      40             :     // Set custom monitors for SNES and KSP
      41        1178 :     _eigen_problem.initPetscOutputAndSomeSolverSettings();
      42             :     // Let us remove extra "eps_power" from SNES since users do not like it
      43        1178 :     LibmeshPetscCallA(_eigen_problem.comm().get(),
      44             :                       Moose::SlepcSupport::mooseSlepcEPSSNESSetUpOptionPrefix(_slepc_solver.eps()));
      45             :     // Let us hook up a customize PC if users ask. Users still can use PETSc options to override
      46             :     // this setting
      47        1178 :     if (_eigen_problem.solverParams(_nl_eigen_sys.number())._customized_pc_for_eigen)
      48         100 :       LibmeshPetscCallA(_eigen_problem.comm().get(),
      49             :                         Moose::SlepcSupport::mooseSlepcEPSSNESSetCustomizePC(_slepc_solver.eps()));
      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        1178 :     LibmeshPetscCallA(
      54             :         _eigen_problem.comm().get(),
      55             :         Moose::SlepcSupport::mooseSlepcEPSSNESKSPSetPCSide(_eigen_problem, _slepc_solver.eps()));
      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        1178 :     LibmeshPetscCallA(_eigen_problem.comm().get(),
      60             :                       EPSSetStoppingTestFunction(_slepc_solver.eps(),
      61             :                                                  Moose::SlepcSupport::mooseSlepcStoppingTest,
      62             :                                                  &_eigen_problem,
      63             :                                                  NULL));
      64             : 
      65             :     // Remove all SLEPc monitors.
      66        1178 :     LibmeshPetscCallA(_eigen_problem.comm().get(), EPSMonitorCancel(_slepc_solver.eps()));
      67             :     // A customized EPS monitor in moose. We need to print only eigenvalue
      68        1178 :     LibmeshPetscCallA(
      69             :         _eigen_problem.comm().get(),
      70             :         EPSMonitorSet(
      71             :             _slepc_solver.eps(), Moose::SlepcSupport::mooseSlepcEPSMonitor, &_eigen_problem, NULL));
      72             :   }
      73        1233 : }
      74             : 
      75             : #endif

Generated by: LCOV version 1.14