LCOV - code coverage report
Current view: top level - src/mfem/solvers - MFEMHypreFGMRES.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #33187 (5aa0b2) with base d7c4bd Lines: 39 43 90.7 %
Date: 2026-06-30 12:18:20 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> & ess_bdr_markers)
      53             : {
      54           4 :   if (_lor && _preconditioner)
      55           0 :     mooseError("LOR solver cannot take a preconditioner");
      56             : 
      57           4 :   mfem::Array<int> ess_tdofs;
      58           4 :   a.ParFESpace()->GetEssentialTrueDofs(ess_bdr_markers, ess_tdofs);
      59           4 :   if (_preconditioner)
      60             :   {
      61           0 :     _preconditioner->SetupLOR(a, ess_tdofs);
      62           0 :     SetPreconditioner(static_cast<mfem::HypreFGMRES &>(*_solver));
      63             :   }
      64           4 :   else if (_lor)
      65             :   {
      66           2 :     CheckSpectralEquivalence(a);
      67           2 :     mfem::ParLORDiscretization lor_disc(a, ess_tdofs);
      68           2 :     auto lor_solver = new mfem::LORSolver<mfem::HypreFGMRES>(lor_disc, getMFEMProblem().getComm());
      69           4 :     lor_solver->GetSolver().SetTol(getParam<mfem::real_t>("l_tol"));
      70           4 :     lor_solver->GetSolver().SetMaxIter(getParam<int>("l_max_its"));
      71           4 :     lor_solver->GetSolver().SetKDim(getParam<int>("kdim"));
      72           4 :     lor_solver->GetSolver().SetPrintLevel(getParam<int>("print_level"));
      73             : 
      74           2 :     _solver.reset(lor_solver);
      75           2 :   }
      76           4 : }
      77             : 
      78             : #endif

Generated by: LCOV version 1.14