https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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",
29 "Vector H1 FESpace of the unknown, required when vector_treatment is 'by_component' or "
30 "'rigid_body_modes'.");
31 MooseEnum vector_treatment("auto scalar by_component rigid_body_modes", "auto");
32 params.addParam<MooseEnum>("vector_treatment",
33 vector_treatment,
34 "Specifies how BoomerAMG treats the components of a vector unknown.");
35 vector_treatment.addDocumentation("scalar",
36 "Coarsens all degrees of "
37 "freedom together as one unknown.");
38 vector_treatment.addDocumentation(
39 "by_component",
40 "Coarsens each component separately and "
41 "does not interpolate between them (hypre's 'unknown' approach, SetSystemsOptions).");
42 vector_treatment.addDocumentation(
43 "rigid_body_modes",
44 "Adds the rigid body modes of the fespace to the interpolation "
45 "(hypre's GM/LN approach, SetElasticityOptions). Only applied on the CPU.");
46 vector_treatment.addDocumentation("auto",
47 "Applies 'rigid_body_modes' vector_treatment option if fespace "
48 "is set and 'scalar' otherwise.");
49 params.addParam<mfem::real_t>(
50 "strength_threshold",
51 0.25,
52 "HypreBoomerAMG strong threshold. Defaults to 0.25, or to 0.5 when vector_treatment is "
53 "'by_component' or 'rigid_body_modes'.");
54 MooseEnum errmode("ignore=0 warn=1 abort=2", "abort");
55 params.addParam<MooseEnum>("error_mode", errmode, "Set the behavior for treating hypre errors.");
56 return params;
57}
58
60 : Moose::MFEM::LORLinearSolverBase<mfem::HypreBoomerAMG>(parameters),
61 _mfem_fespace(
62 isParamSetByUser("fespace")
63 ? getMFEMProblem()
64 .getMFEMObject<MFEMFESpace>("MFEMFESpace", getParam<MFEMFESpaceName>("fespace"))
65 .getFESpace()
66 : nullptr)
67{
68 _vector_treatment = getParam<MooseEnum>("vector_treatment").getEnum<VectorTreatment>();
71
73 paramError("fespace",
74 "is only used when vector_treatment is 'by_component' or 'rigid_body_modes'.");
76 {
77 if (!_mfem_fespace)
78 paramError("vector_treatment",
79 "'by_component' and 'rigid_body_modes' require fespace to be set.");
80 if (_mfem_fespace->GetVDim() < 2)
81 paramError("fespace",
82 "must be a vector space when vector_treatment is 'by_component' or "
83 "'rigid_body_modes'.");
84 // mfem::HypreBoomerAMG builds the component map of a byNODES space from the size of its
85 // operator, which a preconditioner does not have when these options are applied.
86 if (_mfem_fespace->GetOrdering() != mfem::Ordering::byVDIM)
87 paramError("fespace",
88 "must have ordering = VDIM when vector_treatment is 'by_component' or "
89 "'rigid_body_modes'.");
90 }
91
93}
94
96
97void
99{
100 auto solver = std::make_unique<mfem::HypreBoomerAMG>();
101 SetSolverParameters(*solver);
102 _solver = std::move(solver);
103}
104
105void
106MFEMHypreBoomerAMG::SetSolverParameters(mfem::HypreBoomerAMG & solver)
107{
108 solver.iterative_mode = getParam<bool>("use_initial_guess");
109 solver.SetTol(getParam<mfem::real_t>("l_tol"));
110 solver.SetMaxIter(getParam<int>("l_max_its"));
111 solver.SetPrintLevel(getParam<int>("print_level"));
112 solver.SetErrorMode(mfem::HypreSolver::ErrorMode(int(getParam<MooseEnum>("error_mode"))));
113
114 switch (_vector_treatment)
115 {
117 solver.SetSystemsOptions(_mfem_fespace->GetVDim(), /*order_bynodes=*/false);
118 break;
120 if (!mfem::HypreUsingGPU())
121 solver.SetElasticityOptions(_mfem_fespace.get());
122 break;
123 default:
124 break;
125 }
126
127 // Both option sets above reset the strength threshold to 0.5, so it is applied after them,
128 // and only when given, to leave each set's own default in place otherwise.
129 if (isParamSetByUser("strength_threshold"))
130 solver.SetStrengthThresh(getParam<mfem::real_t>("strength_threshold"));
131}
132
133#endif
registerMooseObject("MooseApp", MFEMHypreBoomerAMG)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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.
Constructs and stores an mfem::ParFiniteElementSpace object.
Definition MFEMFESpace.h:21
Wrapper for mfem::HypreBoomerAMG solver.
MFEMHypreBoomerAMG(const InputParameters &)
std::shared_ptr< mfem::ParFiniteElementSpace > _mfem_fespace
VectorTreatment
How BoomerAMG treats the components of a vector unknown.
VectorTreatment _vector_treatment
The vector treatment in use, with AUTO resolved.
virtual void SetSolverParameters(mfem::HypreBoomerAMG &solver) override
Update the wrapped MFEM solver parameters.
static InputParameters validParams()
void ConstructSolver() override
Override in derived classes to construct and set the solver options.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
bool isParamSetByUser(const std::string &name) const
Test if the supplied parameter is set by a user, as opposed to not set or set to default.
Definition MooseBase.h:205
void addDocumentation(const std::string &name, const std::string &doc)
Add an item documentation string.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
std::unique_ptr< mfem::Solver > _solver
Solver to be used for the problem.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...