https://mooseframework.inl.gov
MFEMProblemSolve.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 "Executioner.h"
13 #include "MFEMProblemSolve.h"
14 #include "MFEMProblem.h"
15 
18 {
20  params.addClassDescription("Solve object for MFEM problems.");
21  params.addParam<unsigned int>("nl_max_its", 1, "Max Nonlinear Iterations");
22  params.addParam<Real>("nl_abs_tol", 1.0e-50, "Nonlinear Absolute Tolerance");
23  params.addParam<Real>("nl_rel_tol", 1.0e-8, "Nonlinear Relative Tolerance");
24  params.addParam<unsigned int>("print_level", 1, "Print level");
25  params.addParam<std::string>("device", "Run app on the chosen device.");
26  MooseEnum assembly_levels("legacy full element partial none", "legacy", true);
27  params.addParam<MooseEnum>("assembly_level", assembly_levels, "Matrix assembly level.");
28  return params;
29 }
30 
32  Executioner & ex,
33  std::vector<std::shared_ptr<Moose::MFEM::ProblemOperatorBase>> & problem_operators)
34  : SolveObject(ex),
35  _mfem_problem(dynamic_cast<MFEMProblem &>(_problem)),
36  _problem_operators(problem_operators),
37  _nl_max_its(getParam<unsigned int>("nl_max_its")),
38  _nl_abs_tol(getParam<mfem::real_t>("nl_abs_tol")),
39  _nl_rel_tol(getParam<mfem::real_t>("nl_rel_tol")),
40  _print_level(getParam<unsigned int>("print_level"))
41 {
42  if (const auto compute_device = _app.getComputeDevice())
44  else
45  _app.setMFEMDevice(isParamValid("device") ? getParam<std::string>("device")
46  : _app.isUltimateMaster() ? "cpu"
47  : "",
50 }
51 
52 bool
54 {
55  // FixedPointSolve::solve() is libMesh specific, so we need
56  // to include all steps therein relevant to the MFEM backend here.
57 
58  bool converged = true;
59 
60  // need to back up multi-apps even when not doing fixed point iteration for recovering from failed
61  // multiapp solve
66 
67  // Solve step begins
70 
75 
79 
80  // Update warehouse active objects
82 
84  {
85  for (const auto & problem_operator : _problem_operators)
86  problem_operator->Solve();
87 
88  // Short-circuit evaluation guarantees we only do one of p- or h-refinement between solves
90  {
91  // Reset linear solver and its preconditioner now the problem size has changed
93  solver->constructSolver();
94  if (auto * prec = solver->getPreconditioner())
95  prec->constructSolver();
96 
97  // Reset gridfunctions
98  for (const auto & problem_operator : _problem_operators)
99  problem_operator->SetGridFunctions();
100 
101  // Solve again
102  for (const auto & problem_operator : _problem_operators)
103  problem_operator->Solve();
104  }
105  }
107 
108  // Execute user objects, transfers, and multiapps at timestep end
114  // Solve step ends
115 
116  if (converged)
117  {
118  // Fixed point iteration loop ends right above
123  }
124 
125  return converged;
126 }
127 
128 #endif
bool shouldSolve() const
mfem::real_t _nl_abs_tol
bool isUltimateMaster() const
Whether or not this app is the ultimate master app.
Definition: MooseApp.h:840
MFEMProblemData & getProblemData()
Method to get the current MFEMProblemData object storing the current data specifying the FE problem...
Definition: MFEMProblem.h:263
std::vector< std::shared_ptr< Moose::MFEM::ProblemOperatorBase > > & _problem_operators
virtual bool solve() override
Solve routine provided by this object.
virtual void preSolve()
Override this for actions that should take place before execution, called by FixedPointSolve.
Definition: Executioner.h:83
virtual void updateActiveObjects()
Update the active objects in the warehouses.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const ExecFlagType EXEC_MULTIAPP_FIXED_POINT_END
Definition: Moose.C:40
virtual void onTimestepEnd() override
const ExecFlagType EXEC_TIMESTEP_END
Definition: Moose.C:36
void displaceMesh()
Displace the mesh, if mesh displacement is enabled.
Definition: MFEMProblem.C:574
bool hRefine()
If AMR is enabled, request (and perform if needed) h-refinement.
Definition: MFEMProblem.h:322
InputParameters emptyInputParameters()
std::optional< MooseEnum > getComputeDevice() const
Get the device accelerated computations are supposed to be running on.
Executioner & _executioner
Executioner used to construct this.
Definition: SolveObject.h:45
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition: Moose.C:37
MFEMProblem & _mfem_problem
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:54
Executioners are objects that do the actual work of solving your problem.
Definition: Executioner.h:30
static InputParameters validParams()
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:385
void backupMultiApps(ExecFlagType type)
Backup the MultiApps associated with the ExecFlagType.
unsigned int _print_level
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void postSolve()
Override this for actions that should take place after execution, called by FixedPointSolve.
Definition: Executioner.h:88
const ExecFlagType EXEC_MULTIAPP_FIXED_POINT_BEGIN
Definition: Moose.C:42
MFEMProblemSolve(Executioner &ex, std::vector< std::shared_ptr< Moose::MFEM::ProblemOperatorBase >> &problem_operators)
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...
void setMFEMDevice(const std::string &device_string, Moose::PassKey< MFEMProblemSolve >)
Create/configure the MFEM device with the provided device_string.
Definition: MooseApp.C:3352
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseBase.h:209
bool execMultiApps(ExecFlagType type, bool auto_advance=true)
Execute the MultiApps associated with the ExecFlagType.
unsigned int _nl_max_its
bool pRefine()
If AMR is enabled, request (and perform if needed) p-refinement.
Definition: MFEMProblem.h:327
void ErrorVector unsigned int
virtual void outputStep(ExecFlagType type)
Output the current step.
mfem::real_t _nl_rel_tol
std::shared_ptr< MFEMSolverBase > jacobian_solver
virtual void execute(const ExecFlagType &exec_type) override
Convenience function for performing execution of MOOSE systems.
Definition: MFEMProblem.C:69
void execTransfers(ExecFlagType type)
Execute the Transfers associated with the ExecFlagType.
void addMFEMNonlinearSolver(unsigned int nl_max_its, mfem::real_t nl_abs_tol, mfem::real_t nl_rel_tol, unsigned int print_level)
Add the nonlinear solver to the system.
Definition: MFEMProblem.C:125