https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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");
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
46bool
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
InputParameters emptyInputParameters()
Executioners are objects that do the actual work of solving your problem.
Definition Executioner.h:37
bool shouldSolve() const
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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 addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
virtual bool solve() override
Solve routine provided by this object.
MFEMProblem & _mfem_problem
static InputParameters validParams()
MFEMProblemSolve(Executioner &ex, std::vector< std::shared_ptr< Moose::MFEM::ProblemOperatorBase > > &problem_operators)
std::vector< std::shared_ptr< Moose::MFEM::ProblemOperatorBase > > & _problem_operators
bool hRefine()
If AMR is enabled, request (and perform if needed) h-refinement.
MFEMProblemData & getProblemData()
Method to get the current MFEMProblemData object storing the current data specifying the FE problem.
bool pRefine()
If AMR is enabled, request (and perform if needed) p-refinement.
void displaceMesh()
Displace the mesh, if mesh displacement is enabled.
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:3625
bool isUltimateMaster() const
Whether or not this app is the ultimate master app.
Definition MooseApp.h:866
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.
Definition MooseBase.h:199
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
std::shared_ptr< Moose::MFEM::LinearSolverBase > jacobian_solver