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::LORLinearSolverBase<mfem::HypreBoomerAMG>(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  SetSolverParameters(*solver);
55  _solver = std::move(solver);
56 }
57 
58 void
59 MFEMHypreBoomerAMG::SetSolverParameters(mfem::HypreBoomerAMG & solver)
60 {
61  solver.iterative_mode = getParam<bool>("use_initial_guess");
62  solver.SetTol(getParam<mfem::real_t>("l_tol"));
63  solver.SetMaxIter(getParam<int>("l_max_its"));
64  solver.SetPrintLevel(getParam<int>("print_level"));
65  solver.SetStrengthThresh(getParam<mfem::real_t>("strength_threshold"));
66  solver.SetErrorMode(mfem::HypreSolver::ErrorMode(int(getParam<MooseEnum>("error_mode"))));
67 
68  if (_mfem_fespace && !mfem::HypreUsingGPU())
69  solver.SetElasticityOptions(_mfem_fespace.get());
70 }
71 
72 #endif
MFEMHypreBoomerAMG(const InputParameters &)
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...
virtual void SetSolverParameters(mfem::HypreBoomerAMG &solver) override
Update the wrapped MFEM solver parameters.
registerMooseObject("MooseApp", MFEMHypreBoomerAMG)
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...