https://mooseframework.inl.gov
MFEMCGSolver.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 "MFEMCGSolver.h"
13 #include "MFEMProblem.h"
14 
16 
19 {
21  params.addClassDescription("MFEM native solver for the iterative solution of MFEM equation "
22  "systems using the conjugate gradient method.");
23  params.set<bool>("use_initial_guess", /*quiet_mode=*/true) = true;
24  params.addParam<mfem::real_t>("l_tol", 1e-5, "Set the relative tolerance.");
25  params.addParam<mfem::real_t>("l_abs_tol", 1e-50, "Set the absolute tolerance.");
26  params.addParam<int>("l_max_its", 10000, "Set the maximum number of iterations.");
27  params.addParam<int>("print_level", 2, "Set the solver verbosity.");
28  params.addParam<MFEMSolverName>("preconditioner", "Optional choice of preconditioner to use.");
29 
30  return params;
31 }
32 
34  : Moose::MFEM::LinearSolverBase(parameters)
35 {
37 }
38 
39 void
41 {
42  auto solver = std::make_unique<mfem::CGSolver>(getMFEMProblem().getComm());
43  solver->iterative_mode = getParam<bool>("use_initial_guess");
44  solver->SetRelTol(getParam<mfem::real_t>("l_tol"));
45  solver->SetAbsTol(getParam<mfem::real_t>("l_abs_tol"));
46  solver->SetMaxIter(getParam<int>("l_max_its"));
47  solver->SetPrintLevel(getParam<int>("print_level"));
48  SetPreconditioner(*solver);
49  _solver = std::move(solver);
50 }
51 
52 void
53 MFEMCGSolver::SetupLOR(mfem::ParBilinearForm & a, mfem::Array<int> & tdofs)
54 {
55  if (_lor && _preconditioner)
56  mooseError("LOR solver cannot take a preconditioner");
57 
58  if (_preconditioner)
59  {
60  _preconditioner->SetupLOR(a, tdofs);
61  SetPreconditioner(static_cast<mfem::CGSolver &>(*_solver));
62  }
63  else if (_lor)
64  {
66  auto lor_solver = new mfem::LORSolver<mfem::CGSolver>(a, tdofs);
67  lor_solver->GetSolver().SetRelTol(getParam<mfem::real_t>("l_tol"));
68  lor_solver->GetSolver().SetAbsTol(getParam<mfem::real_t>("l_abs_tol"));
69  lor_solver->GetSolver().SetMaxIter(getParam<int>("l_max_its"));
70  lor_solver->GetSolver().SetPrintLevel(getParam<int>("print_level"));
71 
72  _solver.reset(lor_solver);
73  }
74 }
75 
76 #endif
Wrapper for mfem::CGSolver.
Definition: MFEMCGSolver.h:19
MFEMProblem & getMFEMProblem()
Return the owning MFEM problem.
Definition: MFEMObject.h:45
void ConstructSolver() override
Override in derived classes to construct and set the solver options.
Definition: MFEMCGSolver.C:40
registerMooseObject("MooseApp", MFEMCGSolver)
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
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()
std::shared_ptr< LinearSolverBase > _preconditioner
Preconditioner to be used for the problem.
static InputParameters validParams()
Definition: MFEMCGSolver.C:18
void SetupLOR(mfem::ParBilinearForm &a, mfem::Array< int > &tdofs) override
Updates the solver with the bilinear form in case LOR solve is required.
Definition: MFEMCGSolver.C:53
bool _lor
Variable defining whether to use LOR solver.
MPI_Comm getComm()
Return the MPI communicator associated with this FE problem&#39;s mesh.
Definition: MFEMProblem.h:260
MFEMCGSolver(const InputParameters &parameters)
Definition: MFEMCGSolver.C:33
void SetPreconditioner(T &solver)
Retrieves the preconditioner userobject if present, sets the member pointer to said object if still u...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:281
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.