23 #include "libmesh/mesh_tools.h" 24 #include "libmesh/numeric_vector.h" 33 params.
addClassDescription(
"MultiApp for performing coupled simulations with the parent and " 34 "sub-application both progressing in time.");
38 "Set to true to allow this MultiApp to take smaller " 39 "timesteps than the rest of the simulation. More " 40 "than one timestep will be performed for each " 41 "parent application timestep");
43 params.
addParam<
bool>(
"interpolate_transfers",
45 "Only valid when sub_cycling. This allows " 46 "transferred values to be interpolated " 47 "over the time frame the MultiApp is " 48 "executing over when sub_cycling");
50 params.
addParam<
bool>(
"detect_steady_state",
52 "If true, then if/while sub-cycling ('sub_cycling = true'), a steady-state " 53 "check will be performed for each child app, allowing them to skip to the " 54 "end of the parent time step if steady conditions are detected.");
56 params.
addParam<
bool>(
"output_sub_cycles",
false,
"If true then every sub-cycle will be output.");
58 "print_sub_cycles",
true,
"Toggle the display of sub-cycles on the screen.");
61 "max_failures", 0,
"Maximum number of solve failures tolerated while sub_cycling.");
64 "output_sub_cycles print_sub_cycles max_failures",
67 params.
addParam<
bool>(
"tolerate_failure",
69 "If true this MultiApp won't participate in dt " 70 "decisions and will always be fast-forwarded to " 76 "If true this will allow failed solves to attempt to 'catch up' using smaller timesteps.");
80 "Maximum number of steps to allow an app to take " 81 "when trying to catch back up after a failed " 92 _sub_cycling(getParam<bool>(
"sub_cycling")),
93 _interpolate_transfers(getParam<bool>(
"interpolate_transfers")),
94 _detect_steady_state(getParam<bool>(
"detect_steady_state")),
95 _output_sub_cycles(getParam<bool>(
"output_sub_cycles")),
96 _max_failures(getParam<unsigned
int>(
"max_failures")),
97 _tolerate_failure(getParam<bool>(
"tolerate_failure")),
99 _catch_up(getParam<bool>(
"catch_up")),
100 _max_catch_up_steps(getParam<
Real>(
"max_catch_up_steps")),
101 _first(declareRecoverableData<bool>(
"first", true)),
102 _auto_advance(false),
103 _print_sub_cycles(getParam<bool>(
"print_sub_cycles"))
110 " is set to interpolate_transfers but is not sub_cycling! That is not valid!");
117 " \"sub_cycling\" and \"catch_up\" cannot both be set to true simultaneously.");
123 " it doesn't make any sense to keep a solution during restore when doing " 124 "sub_cycling. Consider trying \"catch_up\" steps instead");
130 " \"keep_solution_during_restore\" requires \"catch_up = true\". Either disable " 131 "\"keep_solution_during_restart\" or set \"catch_up = true\"");
137 " both \"sub_cycling\" and \"tolerate_failure\" are set to true. \"tolerate_failure\"" 138 " will be ignored.");
184 _console << COLOR_CYAN <<
"Solving MultiApp '" <<
name() <<
"' with target time " << target_time
185 <<
" and dt " << dt <<
" with auto-advance " << (auto_advance ?
"on" :
"off")
186 << COLOR_DEFAULT << std::endl;
192 bool return_value =
true;
200 mooseCheckMPIErr(ierr);
209 Real app_time_offset =
_apps[i]->getGlobalTimeOffset();
223 "The target time (time a multiapp must reach at the end of the time step) " 224 "is desynchronized between this app and subapp ",
226 ".\n If this is desired: use the 'global_time_offset' multiapp parameter to " 227 "declare a constant offset\n" 228 "If the apps should (eventually) be synchronized in time, please either: \n" 229 " - match the 'start_time' in the main app and the multiapp, in the Executioner " 231 " - set 'sub_cycling' to true in the multiapp parameters\n" 232 "This message will only print once for all apps and all time steps."));
242 System & libmesh_aux_system = aux_system.
system();
250 transfer_old = solution;
252 transfer_old.
close();
257 Threads::parallel_reduce(elem_range, aldit);
270 bool at_steady =
false;
282 bool local_first =
_first;
285 while ((!at_steady && ex->
getTime() + app_time_offset + ex->
timestepTol() < target_time) ||
288 if (local_first !=
true)
302 Real step_percent = (future_time - time_old) / (target_time - time_old);
304 Real one_minus_step_percent = 1.0 - step_percent;
309 System & libmesh_aux_system = aux_system.
system();
317 transfer_old.
close();
322 (transfer_old(dof) * one_minus_step_percent) +
323 (transfer(dof) * step_percent));
345 std::stringstream oss;
356 _console <<
"Detected Steady State! Fast-forwarding to " << target_time << std::endl;
363 ex->
endStep(target_time - app_time_offset);
384 ex->
endStep(target_time - app_time_offset);
416 _console <<
"Starting time step catch up!" << std::endl;
418 bool caught_up =
false;
420 unsigned int catch_up_step = 0;
423 Real catch_up_dt = dt / 2;
424 Real catch_up_time = 0;
429 _console <<
"Solving " <<
name() <<
" catch up step " << catch_up_step
434 if (catch_up_time + catch_up_dt > dt)
435 catch_up_dt = dt - catch_up_time;
443 catch_up_time += catch_up_dt;
474 _console <<
"Starting Catch Up!" << std::endl;
476 bool caught_up =
false;
478 unsigned int catch_up_step = 0;
480 Real catch_up_dt = dt / 2;
486 _console <<
"Solving " <<
name() <<
" catch up step " << catch_up_step
499 if (current_time + app_time_offset +
533 _console <<
"Successfully Solved MultiApp " <<
name() <<
"." << std::endl;
538 _console <<
"Failed to Solve MultiApp " <<
name() <<
", attempting to recover." << std::endl;
539 return_value =
false;
557 Real app_time_offset =
_apps[i]->getGlobalTimeOffset();
561 if (
_apps[i]->getStartTime() + app_time_offset < target_time)
577 if (recurse_through_multiapp_levels)
606 smallest_dt =
std::min(dt, smallest_dt);
621 unsigned int global_app,
649 auto & app =
_apps[i];
652 mooseError(
"MultiApp ",
name(),
" is not using a Transient Executioner!");
665 System & libmesh_aux_system = aux_system.
system();
668 libmesh_aux_system.
add_vector(
"transfer_old",
false);
671 libmesh_aux_system.
add_vector(
"transfer",
false);
virtual void preExecute() override
Override this for actions that should take place before execution.
virtual NumericVector< Number > & appTransferVector(unsigned int app, std::string var_name) override
Get the vector to transfer to for this MultiApp.
bool hasLocalApp(unsigned int global_app) const
Whether or not the given global app number is on this processor.
Utility class for catching solve failure errors so that MOOSE can recover state before continuing...
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
libMesh::ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems...
bool _print_sub_cycles
Flag for toggling console output on sub cycles.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
bool verboseMultiApps() const
Whether or not to use verbose printing for MultiApps.
const ExecFlagType EXEC_FORCED
NumericVector< Number > & solution()
const std::map< std::string, unsigned int > & getOutputFileNumbers() const
Store a map of outputter names and file numbers The MultiApp system requires this to get the file num...
static InputParameters validParams()
virtual void endStep(Real input_time=-1.0)
virtual void setTargetTime(Real target_time)
Can be used to set the next "target time" which is a time to nail perfectly.
An output object for writing to the console (screen)
unsigned int _max_failures
const PerfID _solve_step_timer
Timers.
virtual void initialSetup() override
Method to be called in main-app initial setup for create sub-apps if using positions is false...
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices)
std::vector< std::shared_ptr< MooseApp > > _apps
Pointers to each of the Apps.
FEProblemBase & feProblem()
Return a reference to this Executioner's FEProblemBase instance.
void setupApp(unsigned int i, Real time=0.0)
Setup the executioner for the local app.
virtual void resetApp(unsigned int global_app, Real time) override
"Reset" the App corresponding to the global App number passed in.
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
MultiApp Implementation for Transient Apps.
void finishMultiAppStep(ExecFlagType type, bool recurse_through_multiapp_levels=false)
Finish the MultiApp time step (endStep, postStep) associated with the ExecFlagType.
const Parallel::Communicator & _communicator
const ExecFlagType EXEC_TIMESTEP_END
static InputParameters validParams()
FEProblemBase & _fe_problem
The FEProblemBase this MultiApp is part of.
bool isRestarting() const
Whether or not this is a "restart" calculation.
bool convergedToSteadyState() const
Determines whether the problem has converged to steady state.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const std::set< dof_id_type > & getDofIndices() const
auto max(const L &left, const R &right)
Grab all the (possibly semi)local dof indices for the variables passed in, in the system passed in...
virtual void advanceState()
Advance all of the state holding vectors / datastructures so that we can move to the next timestep...
bool _detect_steady_state
const std::string & name() const
Get the name of the class.
bool _keep_solution_during_restore
Flag indicates if or not restart from the latest solution.
void min(const T &r, T &o, Request &req) const
const ExecFlagType EXEC_TIMESTEP_BEGIN
TransientMultiApp(const InputParameters ¶meters)
std::set< dof_id_type > _transferred_dofs
The DoFs associated with all of the currently transferred variables.
virtual void takeStep(Real input_dt=-1.0)
Do whatever is necessary to advance one step.
FEProblemBase & appProblemBase(unsigned int app)
Get the FEProblemBase for the global app desired.
virtual Real getTime() const
Get the current time.
std::vector< TransientBase * > _transient_executioners
void forceOutput()
Indicates that the next call to outputStep should be forced.
Base class for transient executioners that use a FixedPointSolve solve object for multiapp-main app i...
bool & _first
Is it our first time through the execution loop?
MooseApp & _app
The MOOSE application this is associated with.
virtual void resetApp(unsigned int global_app, Real time=0.0)
"Reset" the App corresponding to the global App number passed in.
std::vector< std::string > _transferred_vars
The variables that have been transferred to. Used when doing transfer interpolation. This will be cleared after each solve.
AuxiliarySystem & getAuxiliarySystem()
virtual int & timeStep() const
unsigned int _my_num_apps
The number of apps this object is involved in simulating.
bool _has_an_app
Whether or not this processor as an App at all
Real computeDT()
Finds the smallest dt from among any of the apps.
unsigned int _first_local_app
The number of the first app on this processor.
virtual void init() override
Initialize the executioner.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real & endTime()
Get a modifiable reference to the end time.
virtual void initialSetup() override
Method to be called in main-app initial setup for create sub-apps if using positions is false...
Real & timestepTol()
Get the timestep tolerance.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
virtual void incrementStepOrReject()
This is where the solve step is actually incremented.
virtual MooseMesh & mesh() override
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...
virtual void set(const numeric_index_type i, const Number value)=0
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.
virtual libMesh::System & system() override
Get the reference to the libMesh system.
static InputParameters validParams()
bool _interpolate_transfers
A MultiApp represents one or more MOOSE applications that are running simultaneously.
registerMooseObject("MooseApp", TransientMultiApp)
bool isRecovering() const
Whether or not this is a "recover" calculation.
auto min(const L &left, const R &right)
Real getGlobalTimeOffset() const
Each App has it's own local time.
MPI_Comm & _my_comm
The MPI communicator this object is going to use.
A system that holds auxiliary variables.
void ErrorVector unsigned int
virtual void incrementTStep(Real target_time) override
Advances the multi-apps time step which is important for dt selection.
void allowOutput(bool state)
Ability to enable/disable all output calls.
virtual void outputStep(ExecFlagType type)
Output the current step.
const NumericVector< Number > & get_vector(std::string_view vec_name) const
virtual bool solveStep(Real dt, Real target_time, bool auto_advance=true) override
Re-solve all of the Apps.
unsigned int globalAppToLocal(unsigned int global_app)
Map a global App number to the local number.
void paramInfo(const std::string ¶m, Args... args) const
Emits an informational message prefixed with the file and line number of the given param (from the in...
std::vector< bool > _reset_happened
Whether or not apps have been reset at each time.
virtual void finishStep(bool recurse_through_multiapp_levels=false) override
Calls multi-apps executioners' endStep and postStep methods which creates output and advances time (n...