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", 0, "Set the relative tolerance.");
25 params.addParam<int>("l_max_its", 1, "Set the maximum number of iterations.");
26 params.suppressParameter<mfem::real_t>("l_tol"); // mfem/mfem#5627
27 params.suppressParameter<int>("l_max_its"); // mfem/mfem#5627
28 params.addParam<int>("print_level", 2, "Set the solver verbosity.");
29 params.addParam<MFEMFESpaceName>(
30 "fespace",
31 "Vector H1 FESpace of the unknown, required when vector_treatment is 'by_component' or "
32 "'rigid_body_modes'.");
33 MooseEnum vector_treatment("auto scalar by_component rigid_body_modes", "auto");
34 params.addParam<MooseEnum>("vector_treatment",
35 vector_treatment,
36 "Specifies how BoomerAMG treats the components of a vector unknown.");
37 vector_treatment.addDocumentation("scalar",
38 "Coarsens all degrees of "
39 "freedom together as one unknown.");
40 vector_treatment.addDocumentation(
41 "by_component",
42 "Coarsens each component separately and "
43 "does not interpolate between them (hypre's 'unknown' approach, SetSystemsOptions).");
44 vector_treatment.addDocumentation(
45 "rigid_body_modes",
46 "Adds the rigid body modes of the fespace to the interpolation "
47 "(hypre's GM/LN approach, SetElasticityOptions). Only applied on the CPU.");
48 vector_treatment.addDocumentation("auto",
49 "Applies 'rigid_body_modes' vector_treatment option if fespace "
50 "is set and 'scalar' otherwise.");
51 params.addParam<mfem::real_t>(
52 "strength_threshold",
53 0.25,
54 "HypreBoomerAMG strong threshold. Defaults to 0.25, or to 0.5 when vector_treatment is "
55 "'by_component' or 'rigid_body_modes'.");
56 MooseEnum errmode("ignore=0 warn=1 abort=2", "abort");
57 params.addParam<MooseEnum>("error_mode", errmode, "Set the behavior for treating hypre errors.");
58 return params;
59}
60
62 : Moose::MFEM::LORLinearSolverBase<mfem::HypreBoomerAMG>(parameters),
63 _mfem_fespace(
64 isParamSetByUser("fespace")
65 ? getMFEMProblem()
66 .getMFEMObject<MFEMFESpace>("MFEMFESpace", getParam<MFEMFESpaceName>("fespace"))
67 .getFESpace()
68 : nullptr)
69{
70 _vector_treatment = getParam<MooseEnum>("vector_treatment").getEnum<VectorTreatment>();
73
75 paramError("fespace",
76 "is only used when vector_treatment is 'by_component' or 'rigid_body_modes'.");
78 {
79 if (!_mfem_fespace)
80 paramError("vector_treatment",
81 "'by_component' and 'rigid_body_modes' require fespace to be set.");
82 if (_mfem_fespace->GetVDim() < 2)
83 paramError("fespace",
84 "must be a vector space when vector_treatment is 'by_component' or "
85 "'rigid_body_modes'.");
86 // mfem::HypreBoomerAMG builds the component map of a byNODES space from the size of its
87 // operator, which a preconditioner does not have when these options are applied.
88 if (_mfem_fespace->GetOrdering() != mfem::Ordering::byVDIM)
89 paramError("fespace",
90 "must have ordering = VDIM when vector_treatment is 'by_component' or "
91 "'rigid_body_modes'.");
92 }
93
95}
96
98
99void
101{
102 auto solver = std::make_unique<mfem::HypreBoomerAMG>();
103 SetSolverParameters(*solver);
104 _solver = std::move(solver);
105}
106
107void
108MFEMHypreBoomerAMG::SetSolverParameters(mfem::HypreBoomerAMG & solver)
109{
110 solver.iterative_mode = getParam<bool>("use_initial_guess");
111 solver.SetTol(getParam<mfem::real_t>("l_tol"));
112 solver.SetMaxIter(getParam<int>("l_max_its"));
113 solver.SetPrintLevel(getParam<int>("print_level"));
114 solver.SetErrorMode(mfem::HypreSolver::ErrorMode(int(getParam<MooseEnum>("error_mode"))));
115
116 switch (_vector_treatment)
117 {
119 solver.SetSystemsOptions(_mfem_fespace->GetVDim(), /*order_bynodes=*/false);
120 break;
122 if (!mfem::HypreUsingGPU())
123 solver.SetElasticityOptions(_mfem_fespace.get());
124 break;
125 default:
126 break;
127 }
128
129 // Both option sets above reset the strength threshold to 0.5, so it is applied after them,
130 // and only when given, to leave each set's own default in place otherwise.
131 if (isParamSetByUser("strength_threshold"))
132 solver.SetStrengthThresh(getParam<mfem::real_t>("strength_threshold"));
133}
134
135#endif
registerMooseObject("MooseApp", MFEMHypreBoomerAMG)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn't required or valid in the derived class...
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...