https://mooseframework.inl.gov
MFEMTransient.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 "MFEMTransient.h"
13 #include "MFEMProblem.h"
15 #include "TimeStepper.h"
16 
18 
21 {
23  params += TransientBase::validParams();
24  params.addClassDescription("Executioner for transient MFEM problems.");
25  return params;
26 }
27 
29  : TransientBase(params),
30  _mfem_problem(dynamic_cast<MFEMProblem &>(feProblem())),
31  _mfem_problem_data(_mfem_problem.getProblemData()),
32  _mfem_problem_solve(*this, getProblemOperators())
33 {
34  // If no ProblemOperators have been added by the user, add a default
35  if (getProblemOperators().empty())
36  {
37  _mfem_problem_data.eqn_system = std::make_shared<Moose::MFEM::TimeDependentEquationSystem>(
39  auto problem_operator =
40  std::make_shared<Moose::MFEM::TimeDependentEquationSystemProblemOperator>(_mfem_problem);
41  addProblemOperator(std::move(problem_operator));
42  }
43 }
44 
45 void
47 {
49 
50  // verify that the requested time integration scheme is actually supported by MFEM transient
52  paramError("scheme",
53  "Time Integration scheme \"" + stringify(getTimeScheme()) +
54  "\" is not supported by MFEMTransient Executioner.");
55 
57  _mfem_problem_data.eqn_system->SetSolverRequiresGradient(
58  _mfem_problem_data.nonlinear_solver->RequiresGradient());
59 
60  // Set up initial conditions
64  getParam<MooseEnum>("assembly_level").getEnum<mfem::AssemblyLevel>());
65 
66  for (const auto & problem_operator : getProblemOperators())
67  {
68  problem_operator->SetGridFunctions();
69  problem_operator->Init(_mfem_problem_data.f);
70  }
71 }
72 
73 void
75 {
76  _dt_old = _dt;
77 
78  if (input_dt == -1.0)
80  else
81  _dt = input_dt;
82 
84 
85  // Unfortunately, time needs to be temporarily incremented so we get
86  // meaningful console output in timestepSetup(). We decrement it back
87  // immediately after so step() below behaves as expected.
88  _time += _dt;
90  _time -= _dt;
91 
95  {
96  _last_solve_converged = false;
97  return;
98  }
100 
101  // Advance time step of the MFEM problem. Time is also updated here, and
102  // _problem_operator->SetTime is called inside the ode_solver->Step method to
103  // update the time used by time dependent (function) coefficients.
104  _time_stepper->step();
105 
106  // Continue with usual TransientBase::takeStep() finalisation
108 
109  if (!lastSolveConverged())
110  {
111  _console << "Aborting as solve did not converge" << std::endl;
112  return;
113  }
114 
118 
119  if (lastSolveConverged())
121  else
123 
124  // Set time to time old, since final time is updated in TransientBase::endStep()
125  _time = _time_old;
126 
128 }
129 
130 #endif
void timestepSetup() override
Moose::MFEM::ComplexGridFunctions cmplx_gridfunctions
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:467
static InputParameters validParams()
Definition: TransientBase.C:69
bool & _last_solve_converged
Whether or not the last solve converged.
virtual std::vector< std::shared_ptr< ProblemOperatorBase > > & getProblemOperators()
Returns a pointer to the operator&#39;s equation system.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void preSolve()
Definition: TimeStepper.h:36
Real & _time
Current time.
virtual void takeStep(Real input_dt=-1.0) override
Do whatever is necessary to advance one step.
Definition: MFEMTransient.C:74
const ExecFlagType EXEC_TIMESTEP_END
Definition: Moose.C:36
virtual bool converged() const
If the time step converged.
Definition: TimeStepper.C:201
TimeStepper * _time_stepper
std::string stringify(MOOSEIOType type)
Definition: NEML2Utils.C:18
virtual void init() override
Initialize the executioner.
Definition: MFEMTransient.C:46
virtual Real computeConstrainedDT()
FEProblemBase & _problem
Here for backward compatibility.
virtual void execute(const ExecFlagType &exec_type)
Convenience function for performing execution of MOOSE systems.
mfem::BlockVector f
virtual void acceptStep()
This gets called when time step is accepted.
Definition: TimeStepper.C:176
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition: Moose.C:37
Real & _time_old
Previous time.
MFEMTransient(const InputParameters &params)
Definition: MFEMTransient.C:28
Real & _dt
Current delta t... or timestep size.
Base class for transient executioners that use a FixedPointSolve solve object for multiapp-main app i...
Definition: TransientBase.h:27
static InputParameters validParams()
std::shared_ptr< Moose::MFEM::EquationSystem > eqn_system
std::shared_ptr< Moose::MFEM::NonlinearSolverBase > nonlinear_solver
virtual void init() override
Initialize the executioner.
virtual void onTimestepBegin() override
virtual void rejectStep()
This gets called when time step is rejected.
Definition: TimeStepper.C:188
virtual void postSolve()
Definition: TimeStepper.h:37
virtual void step()
Take a time step.
Definition: TimeStepper.C:167
virtual void addProblemOperator(std::shared_ptr< ProblemOperatorBase > problem_operator)
Add an MFEM problem operator. Takes ownership.
MFEMProblem & _mfem_problem
Definition: MFEMTransient.h:49
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...
Moose::TimeIntegratorType getTimeScheme() const
Get the time scheme used.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
virtual bool lastSolveConverged() const override
Whether or not the last solve converged.
bool execMultiApps(ExecFlagType type, bool auto_advance=true)
Execute the MultiApps associated with the ExecFlagType.
registerMooseObject("MooseApp", MFEMTransient)
static InputParameters validParams()
Definition: MFEMTransient.C:20
Moose::MFEM::GridFunctions gridfunctions
MFEMProblemData & _mfem_problem_data
Definition: MFEMTransient.h:50
Moose::MFEM::TimeDerivativeMap time_derivative_map
void execTransfers(ExecFlagType type)
Execute the Transfers associated with the ExecFlagType.