LCOV - code coverage report
Current view: top level - src/mfem/solvers - MFEMHypreBoomerAMG.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 40 42 95.2 %
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 "MFEMHypreBoomerAMG.h"
      13             : #include "MFEMFESpace.h"
      14             : 
      15             : registerMooseObject("MooseApp", MFEMHypreBoomerAMG);
      16             : 
      17             : InputParameters
      18        8934 : MFEMHypreBoomerAMG::validParams()
      19             : {
      20        8934 :   InputParameters params = MFEMSolverBase::validParams();
      21        8934 :   params.addClassDescription("Hypre BoomerAMG solver and preconditioner for the iterative solution "
      22             :                              "of MFEM equation systems.");
      23        8934 :   params.addParam<mfem::real_t>("l_tol", 1e-5, "Set the relative tolerance.");
      24        8934 :   params.addParam<int>("l_max_its", 10000, "Set the maximum number of iterations.");
      25        8934 :   params.addParam<int>("print_level", 2, "Set the solver verbosity.");
      26        8934 :   params.addParam<UserObjectName>(
      27             :       "fespace", "H1 FESpace to use in HypreBoomerAMG setup for elasticity problems.");
      28       26802 :   params.addParam<mfem::real_t>(
      29       17868 :       "strength_threshold", 0.25, "HypreBoomerAMG strong threshold. Defaults to 0.25.");
      30        8934 :   MooseEnum errmode("ignore=0 warn=1 abort=2", "abort", false);
      31        8934 :   params.addParam<MooseEnum>("error_mode", errmode, "Set the behavior for treating hypre errors.");
      32       17868 :   return params;
      33        8934 : }
      34             : 
      35         152 : MFEMHypreBoomerAMG::MFEMHypreBoomerAMG(const InputParameters & parameters)
      36             :   : MFEMSolverBase(parameters),
      37         152 :     _mfem_fespace(isParamSetByUser("fespace") ? getUserObject<MFEMFESpace>("fespace").getFESpace()
      38         152 :                                               : nullptr)
      39             : {
      40         152 :   constructSolver(parameters);
      41         152 : }
      42             : 
      43             : void
      44         152 : MFEMHypreBoomerAMG::constructSolver(const InputParameters &)
      45             : {
      46         152 :   auto solver = std::make_unique<mfem::HypreBoomerAMG>();
      47             : 
      48         152 :   solver->SetTol(getParam<mfem::real_t>("l_tol"));
      49         152 :   solver->SetMaxIter(getParam<int>("l_max_its"));
      50         152 :   solver->SetPrintLevel(getParam<int>("print_level"));
      51         152 :   solver->SetStrengthThresh(getParam<mfem::real_t>("strength_threshold"));
      52         152 :   solver->SetErrorMode(mfem::HypreSolver::ErrorMode(int(getParam<MooseEnum>("error_mode"))));
      53             : 
      54         152 :   if (_mfem_fespace && !mfem::HypreUsingGPU())
      55           5 :     solver->SetElasticityOptions(_mfem_fespace.get());
      56             : 
      57         152 :   _solver = std::move(solver);
      58         152 : }
      59             : 
      60             : void
      61         150 : MFEMHypreBoomerAMG::updateSolver(mfem::ParBilinearForm & a, mfem::Array<int> & tdofs)
      62             : {
      63         150 :   if (_lor)
      64             :   {
      65           1 :     if (!checkSpectralEquivalence(a))
      66           0 :       mooseError("Low-Order-Refined solver requires the FESpace closed_basis to be GaussLobatto "
      67             :                  "and the open-basis to be IntegratedGLL for ND and RT elements.");
      68             : 
      69           1 :     auto lor_solver = new mfem::LORSolver<mfem::HypreBoomerAMG>(a, tdofs);
      70           1 :     lor_solver->GetSolver().SetTol(getParam<mfem::real_t>("l_tol"));
      71           1 :     lor_solver->GetSolver().SetMaxIter(getParam<int>("l_max_its"));
      72           1 :     lor_solver->GetSolver().SetPrintLevel(getParam<int>("print_level"));
      73           1 :     lor_solver->GetSolver().SetStrengthThresh(getParam<mfem::real_t>("strength_threshold"));
      74             : 
      75           1 :     if (_mfem_fespace && !mfem::HypreUsingGPU())
      76           0 :       lor_solver->GetSolver().SetElasticityOptions(_mfem_fespace.get());
      77             : 
      78           1 :     _solver.reset(lor_solver);
      79             :   }
      80         150 : }
      81             : 
      82             : #endif

Generated by: LCOV version 1.14