LCOV - code coverage report
Current view: top level - src/mfem/solvers - MFEMGMRESSolver.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 35 38 92.1 %
Date: 2025-08-08 20:01:16 Functions: 4 4 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             : #ifdef MOOSE_MFEM_ENABLED
      11             : 
      12             : #include "MFEMGMRESSolver.h"
      13             : #include "MFEMProblem.h"
      14             : 
      15             : registerMooseObject("MooseApp", MFEMGMRESSolver);
      16             : 
      17             : InputParameters
      18        8652 : MFEMGMRESSolver::validParams()
      19             : {
      20        8652 :   InputParameters params = MFEMSolverBase::validParams();
      21        8652 :   params.addClassDescription("MFEM native solver for the iterative solution of MFEM equation "
      22             :                              "systems using the generalized minimal residual method.");
      23             : 
      24        8652 :   params.addParam<mfem::real_t>("l_tol", 1e-5, "Set the relative tolerance.");
      25        8652 :   params.addParam<mfem::real_t>("l_abs_tol", 1e-50, "Set the absolute tolerance.");
      26        8652 :   params.addParam<int>("l_max_its", 10000, "Set the maximum number of iterations.");
      27        8652 :   params.addParam<int>("print_level", 2, "Set the solver verbosity.");
      28        8652 :   params.addParam<UserObjectName>("preconditioner", "Optional choice of preconditioner to use.");
      29             : 
      30        8652 :   return params;
      31           0 : }
      32             : 
      33          11 : MFEMGMRESSolver::MFEMGMRESSolver(const InputParameters & parameters) : MFEMSolverBase(parameters)
      34             : {
      35          11 :   constructSolver(parameters);
      36          11 : }
      37             : 
      38             : void
      39          11 : MFEMGMRESSolver::constructSolver(const InputParameters &)
      40             : {
      41             :   auto solver =
      42          11 :       std::make_unique<mfem::GMRESSolver>(getMFEMProblem().mesh().getMFEMParMesh().GetComm());
      43          11 :   solver->SetRelTol(getParam<mfem::real_t>("l_tol"));
      44          11 :   solver->SetAbsTol(getParam<mfem::real_t>("l_abs_tol"));
      45          11 :   solver->SetMaxIter(getParam<int>("l_max_its"));
      46          11 :   solver->SetPrintLevel(getParam<int>("print_level"));
      47          11 :   setPreconditioner(*solver);
      48          11 :   _solver = std::move(solver);
      49          11 : }
      50             : 
      51             : void
      52          11 : MFEMGMRESSolver::updateSolver(mfem::ParBilinearForm & a, mfem::Array<int> & tdofs)
      53             : {
      54          11 :   if (_lor && _preconditioner)
      55           0 :     mooseError("LOR solver cannot take a preconditioner");
      56             : 
      57          11 :   if (_preconditioner)
      58             :   {
      59           9 :     _preconditioner->updateSolver(a, tdofs);
      60           9 :     setPreconditioner(static_cast<mfem::GMRESSolver &>(*_solver));
      61             :   }
      62           2 :   else if (_lor)
      63             :   {
      64           1 :     if (!checkSpectralEquivalence(a))
      65           0 :       mooseError("Low-Order-Refined solver requires the FESpace closed_basis to be GaussLobatto "
      66             :                  "and the open-basis to be IntegratedGLL for ND and RT elements.");
      67             : 
      68           1 :     auto lor_solver = new mfem::LORSolver<mfem::GMRESSolver>(a, tdofs);
      69           1 :     lor_solver->GetSolver().SetRelTol(getParam<mfem::real_t>("l_tol"));
      70           1 :     lor_solver->GetSolver().SetAbsTol(getParam<mfem::real_t>("l_abs_tol"));
      71           1 :     lor_solver->GetSolver().SetMaxIter(getParam<int>("l_max_its"));
      72           1 :     lor_solver->GetSolver().SetPrintLevel(getParam<int>("print_level"));
      73             : 
      74           1 :     _solver.reset(lor_solver);
      75             :   }
      76          11 : }
      77             : 
      78             : #endif

Generated by: LCOV version 1.14