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 {
47  {
48  for (const auto & problem_operator : _problem_operators)
49  problem_operator->Solve();
50 
51  // Short-circuit evaluation guarantees we only do one of p- or h-refinement between solves
53  {
54  // Reset linear solver and its preconditioner now the problem size has changed
55  if (auto & solver = _mfem_problem.getProblemData().jacobian_solver)
56  {
57  if (auto * prec = solver->GetPreconditioner())
58  prec->ConstructSolver();
59  solver->ConstructSolver();
60  }
61 
62  // Reset gridfunctions
63  for (const auto & problem_operator : _problem_operators)
64  problem_operator->SetGridFunctions();
65 
66  // Solve again
67  for (const auto & problem_operator : _problem_operators)
68  problem_operator->Solve();
69  }
70  }
71 
73 
74  return true;
75 }
76 
77 #endif
bool shouldSolve() const
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:254
std::vector< std::shared_ptr< Moose::MFEM::ProblemOperatorBase > > & _problem_operators
virtual bool solve() override
Solve routine provided by this object.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::shared_ptr< Moose::MFEM::LinearSolverBase > jacobian_solver
void displaceMesh()
Displace the mesh, if mesh displacement is enabled.
Definition: MFEMProblem.C:583
bool hRefine()
If AMR is enabled, request (and perform if needed) h-refinement.
Definition: MFEMProblem.h:313
InputParameters emptyInputParameters()
std::optional< MooseEnum > getComputeDevice() const
Get the device accelerated computations are supposed to be running on.
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
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 pRefine()
If AMR is enabled, request (and perform if needed) p-refinement.
Definition: MFEMProblem.h:318