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<std::string>("device", "Run app on the chosen device.");
22  MooseEnum assembly_levels("legacy full element partial none", "legacy", true);
23  params.addParam<MooseEnum>("assembly_level", assembly_levels, "Matrix assembly level.");
24  return params;
25 }
26 
28  Executioner & ex,
29  std::vector<std::shared_ptr<Moose::MFEM::ProblemOperatorBase>> & problem_operators)
30  : SolveObject(ex),
31  _mfem_problem(dynamic_cast<MFEMProblem &>(_problem)),
32  _problem_operators(problem_operators)
33 {
34  if (const auto compute_device = _app.getComputeDevice())
36  else
37  _app.setMFEMDevice(isParamValid("device") ? getParam<std::string>("device")
38  : _app.isUltimateMaster() ? "cpu"
39  : "",
41 }
42 
43 bool
45 {
46  // FixedPointSolve::solve() is libMesh specific, so we need
47  // to include all steps therein relevant to the MFEM backend here.
48 
49  bool converged = true;
50 
51  // need to back up multi-apps even when not doing fixed point iteration for recovering from failed
52  // multiapp solve
57 
58  // Solve step begins
61 
66 
70 
71  // Update warehouse active objects
73 
75  for (const auto & problem_operator : _problem_operators)
76  problem_operator->Solve();
78 
79  // Execute user objects, transfers, and multiapps at timestep end
85  // Solve step ends
86 
87  if (converged)
88  {
89  // Fixed point iteration loop ends right above
94  }
95 
96  return converged;
97 }
98 #endif
bool shouldSolve() const
bool isUltimateMaster() const
Whether or not this app is the ultimate master app.
Definition: MooseApp.h:846
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:38
virtual void onTimestepEnd() override
const ExecFlagType EXEC_TIMESTEP_END
Definition: Moose.C:34
void displaceMesh()
Displace the mesh, if mesh displacement is enabled.
Definition: MFEMProblem.C:434
InputParameters emptyInputParameters()
std::optional< MooseEnum > getComputeDevice() const
Get the device accelerated computations are supposed to be running on.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
virtual void execute(const ExecFlagType &exec_type)
Convenience function for performing execution of MOOSE systems.
Executioner & _executioner
Executioner used to construct this.
Definition: SolveObject.h:45
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition: Moose.C:35
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:33
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:84
void backupMultiApps(ExecFlagType type)
Backup the MultiApps associated with the ExecFlagType.
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:40
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:3606
bool execMultiApps(ExecFlagType type, bool auto_advance=true)
Execute the MultiApps associated with the ExecFlagType.
virtual void outputStep(ExecFlagType type)
Output the current step.
void execTransfers(ExecFlagType type)
Execute the Transfers associated with the ExecFlagType.