https://mooseframework.inl.gov
MFEMHypreBoomerAMG.C
Go to the documentation of this file.
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 
17 
20 {
22  params.addClassDescription("Hypre BoomerAMG solver and preconditioner for the iterative solution "
23  "of MFEM equation systems.");
24  params.addParam<mfem::real_t>("l_tol", 1e-5, "Set the relative tolerance.");
25  params.addParam<int>("l_max_its", 10000, "Set the maximum number of iterations.");
26  params.addParam<int>("print_level", 2, "Set the solver verbosity.");
27  params.addParam<MFEMFESpaceName>(
28  "fespace", "H1 FESpace to use in HypreBoomerAMG setup for elasticity problems.");
29  params.addParam<mfem::real_t>(
30  "strength_threshold", 0.25, "HypreBoomerAMG strong threshold. Defaults to 0.25.");
31  MooseEnum errmode("ignore=0 warn=1 abort=2", "abort", false);
32  params.addParam<MooseEnum>("error_mode", errmode, "Set the behavior for treating hypre errors.");
33  return params;
34 }
35 
37  : Moose::MFEM::LinearSolverBase(parameters),
38  _mfem_fespace(
39  isParamSetByUser("fespace")
40  ? getMFEMProblem()
41  .getMFEMObject<MFEMFESpace>("MFEMFESpace", getParam<MFEMFESpaceName>("fespace"))
42  .getFESpace()
43  : nullptr)
44 {
46 }
47 
49 
50 void
52 {
53  auto solver = std::make_unique<mfem::HypreBoomerAMG>();
54 
55  solver->iterative_mode = getParam<bool>("use_initial_guess");
56  solver->SetTol(getParam<mfem::real_t>("l_tol"));
57  solver->SetMaxIter(getParam<int>("l_max_its"));
58  solver->SetPrintLevel(getParam<int>("print_level"));
59  solver->SetStrengthThresh(getParam<mfem::real_t>("strength_threshold"));
60  solver->SetErrorMode(mfem::HypreSolver::ErrorMode(int(getParam<MooseEnum>("error_mode"))));
61 
62  if (_mfem_fespace && !mfem::HypreUsingGPU())
63  solver->SetElasticityOptions(_mfem_fespace.get());
64 
65  _solver = std::move(solver);
66 }
67 
68 void
69 MFEMHypreBoomerAMG::SetupLOR(mfem::ParBilinearForm & a, mfem::Array<int> & tdofs)
70 {
71  if (_lor)
72  {
74  auto lor_solver = new mfem::LORSolver<mfem::HypreBoomerAMG>(a, tdofs);
75  lor_solver->GetSolver().SetTol(getParam<mfem::real_t>("l_tol"));
76  lor_solver->GetSolver().SetMaxIter(getParam<int>("l_max_its"));
77  lor_solver->GetSolver().SetPrintLevel(getParam<int>("print_level"));
78  lor_solver->GetSolver().SetStrengthThresh(getParam<mfem::real_t>("strength_threshold"));
79 
81  if (_mfem_fespace && !mfem::HypreUsingGPU())
82  lor_solver->GetSolver().SetElasticityOptions(_mfem_fespace.get());
83 
84  _solver.reset(lor_solver);
85  }
86 }
87 
88 #endif
MFEMHypreBoomerAMG(const InputParameters &)
void SetupLOR(mfem::ParBilinearForm &a, mfem::Array< int > &tdofs) override
Updates the solver with the bilinear form in case LOR solve is required.
Wrapper for mfem::HypreBoomerAMG solver.
std::unique_ptr< mfem::Solver > _solver
Solver to be used for the problem.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
registerMooseObject("MooseApp", MFEMHypreBoomerAMG)
bool _lor
Variable defining whether to use LOR solver.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:54
Constructs and stores an mfem::ParFiniteElementSpace object.
Definition: MFEMFESpace.h:20
std::shared_ptr< mfem::ParFiniteElementSpace > _mfem_fespace
void ConstructSolver() override
Override in derived classes to construct and set the solver options.
static InputParameters validParams()
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
virtual void CheckSpectralEquivalence(mfem::ParBilinearForm &blf) const
Checks for the correct configuration of quadrature bases for LOR spectral equivalence.