https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SetupTimeStepperAction.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
11#include "TransientBase.h"
12#include "MooseApp.h"
13#include "Factory.h"
14#include "TimeStepper.h"
16#include "FEProblemBase.h"
17#include "CompositionDT.h"
18
19registerMooseAction("MooseApp", SetupTimeStepperAction, "setup_time_steppers");
20
23{
25 params.addClassDescription("Set up the final time stepper.");
26 return params;
27}
28
30 : Action(parameters)
31{
32}
33
34void
36{
37 if (TransientBase * transient = dynamic_cast<TransientBase *>(_app.getExecutioner()))
38 {
39 std::vector<TimeStepper *> timesteppers;
40 _problem->theWarehouse().query().condition<AttribSystem>("TimeStepper").queryInto(timesteppers);
41
42 // No timestepper(s) were added by the user, so add a default one
43 if (timesteppers.empty())
44 {
45 const auto ts_name = "ConstantDT";
46 auto params = _factory.getValidParams(ts_name);
47 params.set<TransientBase *>("_executioner") = transient;
48
49 if (!transient->parameters().isParamSetByAddParam("end_time") &&
50 !transient->parameters().isParamSetByAddParam("num_steps") &&
51 transient->parameters().isParamSetByAddParam("dt"))
52 params.set<Real>("dt") =
53 (transient->getParam<Real>("end_time") - transient->getParam<Real>("start_time")) /
54 static_cast<Real>(transient->getParam<unsigned int>("num_steps"));
55 else
56 params.set<Real>("dt") = transient->getParam<Real>("dt");
57
58 params.set<bool>("reset_dt") = transient->getParam<bool>("reset_dt");
59
60 auto ts =
61 _problem->addObject<TimeStepper>(ts_name, ts_name, params, /* threaded = */ false)[0];
62 transient->setTimeStepper(*ts);
63 }
64 // TimeStepper(s) were added by the user
65 else
66 {
67 // The user add a time stepper with [TimeStepper] or [TimeSteppers], create one for them
68 auto no_time_stepper = _awh.getActionListByName("add_time_stepper").empty();
69 auto no_time_steppers = _awh.getActionListByName("add_time_steppers").empty();
70 if (!no_time_stepper || !no_time_steppers)
71 {
72 std::vector<TimeStepper *> timesteppers;
73 _problem->theWarehouse()
74 .query()
75 .condition<AttribSystem>("TimeStepper")
76 .queryInto(timesteppers);
77
78 mooseAssert(timesteppers.size(), "Timesteppers not found");
79
80 if (timesteppers.size() == 1)
81 transient->setTimeStepper(*timesteppers[0]);
82 else
83 for (auto ts : timesteppers)
84 if (dynamic_cast<CompositionDT *>(ts))
85 transient->setTimeStepper(*ts);
86
87 mooseAssert(transient->getTimeStepper(), "Not set");
88 }
89 // The user used both [TimeStepper] and [TimeSteppers] for time stepper setup, use input in
90 // [TimeSteppers] block and give an error message
91 if (!no_time_stepper && !no_time_steppers)
92 mooseError("Both [TimeStepper] and [TimeSteppers] are used to setup the time stepper. The "
93 "[TimeStepper] block will be ignored. Note [TimeStepper] will be deprecated "
94 "soon. Please consider [TimeSteppers] for future use.");
95 }
96 }
97}
registerMooseAction("MooseApp", SetupTimeStepperAction, "setup_time_steppers")
const std::list< Action * > & getActionListByName(const std::string &task) const
Retrieve a constant list of Action pointers associated with the passed in task.
Base class for actions.
Definition Action.h:38
static InputParameters validParams()
Definition Action.C:26
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition Action.h:178
ActionWarehouse & _awh
Reference to ActionWarehouse where we store object build by actions.
Definition Action.h:169
A TimeStepper that takes time steppers as inputs and computes the minimum time step size among all ti...
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Executioner * getExecutioner() const
Retrieve the Executioner for this App.
Definition MooseApp.C:2015
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271
Factory & _factory
The Factory associated with the MooseApp.
Set up the final time stepper for the simulation.
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
SetupTimeStepperAction(const InputParameters &parameters)
static InputParameters validParams()
Base class for time stepping.
Definition TimeStepper.h:23
Base class for transient executioners that use a FixedPointSolve solve object for multiapp-main app i...