LCOV - code coverage report
Current view: top level - src/mfem/solvers - MFEMHypreBoomerAMG.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 44 45 97.8 %
Date: 2026-05-29 20:35:17 Functions: 5 6 83.3 %
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 "MFEMHypreBoomerAMG.h"
      13             : #include "MFEMFESpace.h"
      14             : #include "MFEMProblem.h"
      15             : 
      16             : registerMooseObject("MooseApp", MFEMHypreBoomerAMG);
      17             : 
      18             : InputParameters
      19        3498 : MFEMHypreBoomerAMG::validParams()
      20             : {
      21        3498 :   InputParameters params = MFEMSolverBase::validParams();
      22        6996 :   params.addClassDescription("Hypre BoomerAMG solver and preconditioner for the iterative solution "
      23             :                              "of MFEM equation systems.");
      24       13992 :   params.addParam<mfem::real_t>("l_tol", 1e-5, "Set the relative tolerance.");
      25       13992 :   params.addParam<int>("l_max_its", 10000, "Set the maximum number of iterations.");
      26       13992 :   params.addParam<int>("print_level", 2, "Set the solver verbosity.");
      27       13992 :   params.addParam<MFEMFESpaceName>(
      28             :       "fespace", "H1 FESpace to use in HypreBoomerAMG setup for elasticity problems.");
      29       10494 :   params.addParam<mfem::real_t>(
      30        6996 :       "strength_threshold", 0.25, "HypreBoomerAMG strong threshold. Defaults to 0.25.");
      31       13992 :   MooseEnum errmode("ignore=0 warn=1 abort=2", "abort", false);
      32       10494 :   params.addParam<MooseEnum>("error_mode", errmode, "Set the behavior for treating hypre errors.");
      33        6996 :   return params;
      34        3498 : }
      35             : 
      36         700 : MFEMHypreBoomerAMG::MFEMHypreBoomerAMG(const InputParameters & parameters)
      37             :   : MFEMSolverBase(parameters),
      38         697 :     _mfem_fespace(
      39         700 :         isParamSetByUser("fespace")
      40         700 :             ? getMFEMProblem()
      41         712 :                   .getMFEMObject<MFEMFESpace>("MFEMFESpace", getParam<MFEMFESpaceName>("fespace"))
      42             :                   .getFESpace()
      43         700 :             : nullptr)
      44             : {
      45         700 :   constructSolver();
      46         700 : }
      47             : 
      48         700 : MFEMHypreBoomerAMG::~MFEMHypreBoomerAMG() { _solver.reset(); }
      49             : 
      50             : void
      51         700 : MFEMHypreBoomerAMG::constructSolver()
      52             : {
      53         700 :   auto solver = std::make_unique<mfem::HypreBoomerAMG>();
      54             : 
      55        1400 :   solver->SetTol(getParam<mfem::real_t>("l_tol"));
      56        1400 :   solver->SetMaxIter(getParam<int>("l_max_its"));
      57        1400 :   solver->SetPrintLevel(getParam<int>("print_level"));
      58        1400 :   solver->SetStrengthThresh(getParam<mfem::real_t>("strength_threshold"));
      59        1400 :   solver->SetErrorMode(mfem::HypreSolver::ErrorMode(int(getParam<MooseEnum>("error_mode"))));
      60             : 
      61         700 :   if (_mfem_fespace && !mfem::HypreUsingGPU())
      62           3 :     solver->SetElasticityOptions(_mfem_fespace.get());
      63             : 
      64         700 :   _solver = std::move(solver);
      65         700 : }
      66             : 
      67             : void
      68        1182 : MFEMHypreBoomerAMG::updateSolver(mfem::ParBilinearForm & a, mfem::Array<int> & tdofs)
      69             : {
      70        1182 :   if (_lor)
      71             :   {
      72           2 :     checkSpectralEquivalence(a);
      73           2 :     auto lor_solver = new mfem::LORSolver<mfem::HypreBoomerAMG>(a, tdofs);
      74           4 :     lor_solver->GetSolver().SetTol(getParam<mfem::real_t>("l_tol"));
      75           4 :     lor_solver->GetSolver().SetMaxIter(getParam<int>("l_max_its"));
      76           4 :     lor_solver->GetSolver().SetPrintLevel(getParam<int>("print_level"));
      77           4 :     lor_solver->GetSolver().SetStrengthThresh(getParam<mfem::real_t>("strength_threshold"));
      78             : 
      79             :     /// HypreBoomerAMG options for elasticity problems are not compatible with GPU execution
      80           2 :     if (_mfem_fespace && !mfem::HypreUsingGPU())
      81           0 :       lor_solver->GetSolver().SetElasticityOptions(_mfem_fespace.get());
      82             : 
      83           2 :     _solver.reset(lor_solver);
      84             :   }
      85        1182 : }
      86             : 
      87             : #endif

Generated by: LCOV version 1.14