LCOV - code coverage report
Current view: top level - src/mfem/solvers - MFEMHypreFGMRES.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: fa5e60 Lines: 37 41 90.2 %
Date: 2026-06-24 08:03:36 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 "MFEMHypreFGMRES.h"
      13             : #include "MFEMProblem.h"
      14             : 
      15             : registerMooseObject("MooseApp", MFEMHypreFGMRES);
      16             : 
      17             : InputParameters
      18        2106 : MFEMHypreFGMRES::validParams()
      19             : {
      20        2106 :   InputParameters params = Moose::MFEM::LinearSolverBase::validParams();
      21        4212 :   params.addClassDescription("Hypre solver for the iterative solution of MFEM equation systems "
      22             :                              "using the flexible generalized minimal residual method.");
      23        8424 :   params.addParam<mfem::real_t>("l_tol", 1e-5, "Set the relative tolerance.");
      24        8424 :   params.addParam<int>("l_max_its", 10000, "Set the maximum number of iterations.");
      25        8424 :   params.addParam<int>("kdim", 10, "Set the k-dimension.");
      26        8424 :   params.addParam<int>("print_level", 2, "Set the solver verbosity.");
      27        6318 :   params.addParam<MFEMSolverName>("preconditioner", "Optional choice of preconditioner to use.");
      28             : 
      29        2106 :   return params;
      30           0 : }
      31             : 
      32           4 : MFEMHypreFGMRES::MFEMHypreFGMRES(const InputParameters & parameters)
      33           4 :   : Moose::MFEM::LinearSolverBase(parameters)
      34             : {
      35           4 :   ConstructSolver();
      36           4 : }
      37             : 
      38             : void
      39           4 : MFEMHypreFGMRES::ConstructSolver()
      40             : {
      41           4 :   auto solver = std::make_unique<mfem::HypreFGMRES>(getMFEMProblem().getComm());
      42           8 :   solver->iterative_mode = getParam<bool>("use_initial_guess");
      43           8 :   solver->SetTol(getParam<mfem::real_t>("l_tol"));
      44           8 :   solver->SetMaxIter(getParam<int>("l_max_its"));
      45           8 :   solver->SetKDim(getParam<int>("kdim"));
      46           8 :   solver->SetPrintLevel(getParam<int>("print_level"));
      47           4 :   SetPreconditioner(*solver);
      48           4 :   _solver = std::move(solver);
      49           4 : }
      50             : 
      51             : void
      52           4 : MFEMHypreFGMRES::SetupLOR(mfem::ParBilinearForm & a, mfem::Array<int> & tdofs)
      53             : {
      54           4 :   if (_lor && _preconditioner)
      55           0 :     mooseError("LOR solver cannot take a preconditioner");
      56             : 
      57           4 :   if (_preconditioner)
      58             :   {
      59           0 :     _preconditioner->SetupLOR(a, tdofs);
      60           0 :     SetPreconditioner(static_cast<mfem::HypreFGMRES &>(*_solver));
      61             :   }
      62           4 :   else if (_lor)
      63             :   {
      64           2 :     CheckSpectralEquivalence(a);
      65           2 :     mfem::ParLORDiscretization lor_disc(a, tdofs);
      66           2 :     auto lor_solver = new mfem::LORSolver<mfem::HypreFGMRES>(lor_disc, getMFEMProblem().getComm());
      67           4 :     lor_solver->GetSolver().SetTol(getParam<mfem::real_t>("l_tol"));
      68           4 :     lor_solver->GetSolver().SetMaxIter(getParam<int>("l_max_its"));
      69           4 :     lor_solver->GetSolver().SetKDim(getParam<int>("kdim"));
      70           4 :     lor_solver->GetSolver().SetPrintLevel(getParam<int>("print_level"));
      71             : 
      72           2 :     _solver.reset(lor_solver);
      73           2 :   }
      74           4 : }
      75             : 
      76             : #endif

Generated by: LCOV version 1.14