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 MFEM_ENABLED
11 
12 #include "MFEMTransient.h"
13 #include "MFEMProblem.h"
15 
17 
20 {
22  params.addClassDescription("Executioner for transient MFEM problems.");
23  params.addParam<Real>("start_time", 0.0, "The start time of the simulation");
24  params.addParam<Real>("end_time", 1.0e30, "The end time of the simulation");
25  params.addParam<Real>("dt", 1., "The timestep size between solves");
26  params.addParam<unsigned int>(
27  "visualisation_steps", 1, "The number of timesteps in a transient run");
28  return params;
29 }
30 
32  : MFEMExecutioner(params),
33  _t_step(getParam<Real>("dt")),
34  _t_initial(getParam<Real>("start_time")),
35  _t_final(getParam<Real>("end_time")),
36  _t(_mfem_problem.time()),
37  _it(0),
38  _vis_steps(params.get<unsigned int>("visualisation_steps")),
39  _last_step(false)
40 {
42  _t = _t_initial;
44 }
45 
46 void
48 {
49  _problem_data.eqn_system = std::make_shared<Moose::MFEM::TimeDependentEquationSystem>();
50  auto problem_operator =
51  std::make_unique<Moose::MFEM::TimeDomainEquationSystemProblemOperator>(_problem_data);
52  _problem_operator.reset();
53  _problem_operator = std::move(problem_operator);
54 }
55 
56 void
57 MFEMTransient::step(double dt, int) const
58 {
59  // Check if current time step is final
60  if (_t + dt >= _t_final - dt / 2)
61  {
62  _last_step = true;
63  }
64 
65  // Advance time step.
67 
68  // Synchonise time dependent GridFunctions with updated DoF data.
69  _problem_operator->SetTestVariablesFromTrueVectors();
70 
71  // Sync Host/Device
72  _problem_data.f.HostRead();
73 
74  // Execute user objects at timestep end
76  // Perform the output of the current time step
78 }
79 
80 void
82 {
85 
86  // Set up initial conditions
90  getParam<MooseEnum>("assembly_level").getEnum<mfem::AssemblyLevel>());
91 
92  _problem_operator->SetGridFunctions();
94 
95  // Set timestepper
96  _problem_data.ode_solver = std::make_unique<mfem::BackwardEulerSolver>();
98  _problem_operator->SetTime(0.0);
99 }
100 
101 void
103 {
105  preExecute();
106 
107  while (_last_step != true)
108  {
109  _it++;
110  step(_t_step, _it);
111  }
112 
114  /*recurse_through_multiapp_levels=*/true);
115  _mfem_problem.finishMultiAppStep(EXEC_TIMESTEP_BEGIN, /*recurse_through_multiapp_levels=*/true);
116  _mfem_problem.finishMultiAppStep(EXEC_TIMESTEP_END, /*recurse_through_multiapp_levels=*/true);
118  /*recurse_through_multiapp_levels=*/true);
119 
120  TIME_SECTION("final", 1, "Executing Final Objects");
126 
127  postExecute();
128 }
129 
130 #endif
static InputParameters validParams()
void finalizeMultiApps()
virtual void preExecute()
Override this for actions that should take place before execution.
Definition: Executioner.h:73
virtual void postExecute()
Method called at the end of the simulation.
std::unique_ptr< Moose::MFEM::TimeDomainProblemOperator > _problem_operator
Definition: MFEMTransient.h:37
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1155
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:36
void finishMultiAppStep(ExecFlagType type, bool recurse_through_multiapp_levels=false)
Finish the MultiApp time step (endStep, postStep) associated with the ExecFlagType.
const ExecFlagType EXEC_TIMESTEP_END
Definition: Moose.C:34
std::unique_ptr< mfem::ODESolver > ode_solver
Moose::MFEM::FESpaces fespaces
double _t_initial
Definition: MFEMTransient.h:31
virtual void init() override
Initialize the executioner.
Definition: MFEMTransient.C:81
virtual void execute(const ExecFlagType &exec_type)
Convenience function for performing execution of MOOSE systems.
mfem::BlockVector f
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition: Moose.C:35
const ExecFlagType EXEC_PRE_MULTIAPP_SETUP
Definition: Moose.C:50
void constructProblemOperator() override
Virtual method to construct the ProblemOperator. Call for default problems.
Definition: MFEMTransient.C:47
virtual void postExecute()
Override this for actions that should take place after execution.
Definition: Executioner.h:78
virtual void initialSetup() override
Definition: MFEMProblem.C:40
MFEMTransient(const InputParameters &params)
Definition: MFEMTransient.C:31
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
void step(double dt, int it) const
Definition: MFEMTransient.C:57
MFEMProblemData & _problem_data
std::shared_ptr< Moose::MFEM::EquationSystem > eqn_system
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const ExecFlagType EXEC_MULTIAPP_FIXED_POINT_BEGIN
Definition: Moose.C:38
virtual void transient(bool trans)
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...
virtual void execute() override
Pure virtual execute function MUST be overridden by children classes.
bool execMultiApps(ExecFlagType type, bool auto_advance=true)
Execute the MultiApps associated with the ExecFlagType.
registerMooseObject("MooseApp", MFEMTransient)
static InputParameters validParams()
Definition: MFEMTransient.C:19
Moose::MFEM::GridFunctions gridfunctions
MFEMProblem & _mfem_problem
const ExecFlagType EXEC_FINAL
Definition: Moose.C:42
void ErrorVector unsigned int
virtual void outputStep(ExecFlagType type)
Output the current step.
void setStartTime(Real time)
Set the starting time for the simulation.
Definition: MooseApp.C:2368
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:28