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  params.addParam<bool>("gpu_aware_mpi", false, "Use GPU-aware MPI.");
23  MooseEnum assembly_levels("legacy full element partial none", "legacy", true);
24  params.addParam<MooseEnum>("assembly_level", assembly_levels, "Matrix assembly level.");
25  return params;
26 }
27 
29  Executioner & ex,
30  std::vector<std::shared_ptr<Moose::MFEM::ProblemOperatorBase>> & problem_operators)
31  : SolveObject(ex),
32  _mfem_problem(dynamic_cast<MFEMProblem &>(_problem)),
33  _problem_operators(problem_operators)
34 {
35  if (const auto compute_device = _app.getComputeDevice())
37  *compute_device, getParam<bool>("gpu_aware_mpi"), Moose::PassKey<MFEMProblemSolve>());
38  else
39  _app.setMFEMDevice(isParamValid("device") ? getParam<std::string>("device")
40  : _app.isUltimateMaster() ? "cpu"
41  : "",
42  getParam<bool>("gpu_aware_mpi"),
44 }
45 
46 bool
48 {
50  {
51  for (const auto & problem_operator : _problem_operators)
52  problem_operator->Solve();
53 
54  // Short-circuit evaluation guarantees we only do one of p- or h-refinement between solves
56  {
57  // Reset linear solver and its preconditioner now the problem size has changed
58  if (auto & solver = _mfem_problem.getProblemData().jacobian_solver)
59  {
60  if (auto * prec = solver->GetPreconditioner())
61  prec->ConstructSolver();
62  solver->ConstructSolver();
63  }
64 
65  // Reset gridfunctions
66  for (const auto & problem_operator : _problem_operators)
67  problem_operator->SetGridFunctions();
68 
69  // Solve again
70  for (const auto & problem_operator : _problem_operators)
71  problem_operator->Solve();
72  }
73  }
74 
76 
77  return true;
78 }
79 
80 #endif
bool shouldSolve() const
bool isUltimateMaster() const
Whether or not this app is the ultimate master app.
Definition: MooseApp.h:866
MFEMProblemData & getProblemData()
Method to get the current MFEMProblemData object storing the current data specifying the FE problem...
Definition: MFEMProblem.h:250
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:309
InputParameters emptyInputParameters()
std::optional< MooseEnum > getComputeDevice() const
Get the device accelerated computations are supposed to be running on.
MFEMProblem & _mfem_problem
void setMFEMDevice(const std::string &device_string, bool gpu_aware_mpi, Moose::PassKey< MFEMProblemSolve >)
Create/configure the MFEM device with the provided device_string.
Definition: MooseApp.C:3624
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...
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:314