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

Generated by: LCOV version 1.14