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 while sub_cycling a steady state check will be " 53 "done. In this mode output will only be done once the " 54 "MultiApp reaches the target time or steady state is reached");
58 "The relative difference between the new " 59 "solution and the old solution that will be " 60 "considered to be at steady state");
62 params.
addParam<
bool>(
"output_sub_cycles",
false,
"If true then every sub-cycle will be output.");
64 "print_sub_cycles",
true,
"Toggle the display of sub-cycles on the screen.");
67 "max_failures", 0,
"Maximum number of solve failures tolerated while sub_cycling.");
70 "steady_state_tol output_sub_cycles print_sub_cycles max_failures",
73 params.
addParam<
bool>(
"tolerate_failure",
75 "If true this MultiApp won't participate in dt " 76 "decisions and will always be fast-forwarded to " 82 "If true this will allow failed solves to attempt to 'catch up' using smaller timesteps.");
86 "Maximum number of steps to allow an app to take " 87 "when trying to catch back up after a failed " 98 _sub_cycling(getParam<bool>(
"sub_cycling")),
99 _interpolate_transfers(getParam<bool>(
"interpolate_transfers")),
100 _detect_steady_state(getParam<bool>(
"detect_steady_state")),
101 _steady_state_tol(getParam<
Real>(
"steady_state_tol")),
102 _output_sub_cycles(getParam<bool>(
"output_sub_cycles")),
103 _max_failures(getParam<unsigned
int>(
"max_failures")),
104 _tolerate_failure(getParam<bool>(
"tolerate_failure")),
106 _catch_up(getParam<bool>(
"catch_up")),
107 _max_catch_up_steps(getParam<
Real>(
"max_catch_up_steps")),
108 _first(declareRecoverableData<bool>(
"first", true)),
109 _auto_advance(false),
110 _print_sub_cycles(getParam<bool>(
"print_sub_cycles"))
117 " is set to interpolate_transfers but is not sub_cycling! That is not valid!");
124 " \"sub_cycling\" and \"catch_up\" cannot both be set to true simultaneously.");
130 " it doesn't make any sense to keep a solution during restore when doing " 131 "sub_cycling. Consider trying \"catch_up\" steps instead");
137 " \"keep_solution_during_restore\" requires \"catch_up = true\". Either disable " 138 "\"keep_solution_during_restart\" or set \"catch_up = true\"");
144 " both \"sub_cycling\" and \"tolerate_failure\" are set to true. \"tolerate_failure\"" 145 " will be ignored.");
191 _console << COLOR_CYAN <<
"Solving MultiApp '" <<
name() <<
"' with target time " << target_time
192 <<
" and dt " << dt <<
" with auto-advance " << (auto_advance ?
"on" :
"off")
193 << COLOR_DEFAULT << std::endl;
199 bool return_value =
true;
207 mooseCheckMPIErr(
ierr);
216 Real app_time_offset =
_apps[i]->getGlobalTimeOffset();
230 "The target time (time a multiapp must reach at the end of the time step) " 231 "is desynchronized between this app and subapp ",
233 ".\n If this is desired: use the 'global_time_offset' multiapp parameter to " 234 "declare a constant offset\n" 235 "If the apps should (eventually) be synchronized in time, please either: \n" 236 " - match the 'start_time' in the main app and the multiapp, in the Executioner " 238 " - set 'sub_cycling' to true in the multiapp parameters\n" 239 "This message will only print once for all apps and all time steps."));
249 System & libmesh_aux_system = aux_system.
system();
257 transfer_old = solution;
259 transfer_old.
close();
264 Threads::parallel_reduce(elem_range, aldit);
277 bool at_steady =
false;
289 bool local_first =
_first;
292 while ((!at_steady && ex->
getTime() + app_time_offset + ex->
timestepTol() < target_time) ||
295 if (local_first !=
true)
309 Real step_percent = (future_time - time_old) / (target_time - time_old);
311 Real one_minus_step_percent = 1.0 - step_percent;
316 System & libmesh_aux_system = aux_system.
system();
324 transfer_old.
close();
329 (transfer_old(dof) * one_minus_step_percent) +
330 (transfer(dof) * step_percent));
352 std::stringstream oss;
361 _console <<
"Solution change norm: " << solution_change_norm << std::endl;
366 _console <<
"Detected Steady State! Fast-forwarding to " << target_time << std::endl;
375 ex->
endStep(target_time - app_time_offset);
396 ex->
endStep(target_time - app_time_offset);
428 _console <<
"Starting time step catch up!" << std::endl;
430 bool caught_up =
false;
432 unsigned int catch_up_step = 0;
435 Real catch_up_dt = dt / 2;
436 Real catch_up_time = 0;
441 _console <<
"Solving " <<
name() <<
" catch up step " << catch_up_step
446 if (catch_up_time + catch_up_dt > dt)
447 catch_up_dt = dt - catch_up_time;
455 catch_up_time += catch_up_dt;
486 _console <<
"Starting Catch Up!" << std::endl;
488 bool caught_up =
false;
490 unsigned int catch_up_step = 0;
492 Real catch_up_dt = dt / 2;
498 _console <<
"Solving " <<
name() <<
" catch up step " << catch_up_step
511 if (current_time + app_time_offset +
545 _console <<
"Successfully Solved MultiApp " <<
name() <<
"." << std::endl;
550 _console <<
"Failed to Solve MultiApp " <<
name() <<
", attempting to recover." << std::endl;
551 return_value =
false;
569 Real app_time_offset =
_apps[i]->getGlobalTimeOffset();
573 if (
_apps[i]->getStartTime() + app_time_offset < target_time)
589 if (recurse_through_multiapp_levels)
624 smallest_dt =
std::min(dt, smallest_dt);
639 unsigned int global_app,
667 auto & app =
_apps[i];
670 mooseError(
"MultiApp ",
name(),
" is not using a Transient Executioner!");
683 System & libmesh_aux_system = aux_system.
system();
686 libmesh_aux_system.add_vector(
"transfer_old",
false);
689 libmesh_aux_system.add_vector(
"transfer",
false);
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...
ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems...
Transient executioners usually loop through a number of timesteps...
bool _print_sub_cycles
Flag for toggling console output on sub cycles.
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...
virtual void setTargetTime(Real target_time)
Can be used to set the next "target time" which is a time to nail perfectly.
static InputParameters validParams()
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...
std::vector< std::shared_ptr< MooseApp > > _apps
Pointers to each of the Apps.
virtual void init() override
Initialize the executioner.
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 endStep(Real input_time=-1.0)
virtual void resetApp(unsigned int global_app, Real time) override
"Reset" the App corresponding to the global App number passed in.
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.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual const std::string & name() const
Get the name of the class.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
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...
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
virtual void advanceState()
Advance all of the state holding vectors / datastructures so that we can move to the next timestep...
bool _detect_steady_state
virtual void takeStep(Real input_dt=-1.0)
Do whatever is necessary to advance one step.
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
virtual bool lastSolveConverged() const override
Whether or not the last solve converged.
const ExecFlagType EXEC_TIMESTEP_BEGIN
TransientMultiApp(const InputParameters ¶meters)
virtual bool needsRestoration() override
Whether or not this MultiApp should be restored at the beginning of each Picard iteration.
std::set< dof_id_type > _transferred_dofs
The DoFs associated with all of the currently transferred variables.
FEProblemBase & appProblemBase(unsigned int app)
Get the FEProblemBase for the global app desired.
void forceOutput()
Indicates that the next call to outputStep should be forced.
bool & _first
Is it our first time through the execution loop?
MooseApp & _app
The MOOSE application this is associated with.
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 ...
virtual void incrementStepOrReject()
This is where the solve step is actually incremented.
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()
std::vector< Transient * > _transient_executioners
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.
virtual void preExecute() override
Override this for actions that should take place before execution.
unsigned int _first_local_app
The number of the first app on this processor.
Real & endTime()
Get a modifiable reference to the end time.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void initialSetup() override
Method to be called in main-app initial setup for create sub-apps if using positions is false...
virtual Real getTime() const
Get the current time.
Real & timestepTol()
Get the timestep tolerance.
virtual System & system() override
Get the reference to the libMesh system.
virtual MooseMesh & mesh() override
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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.
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.
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...
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.
Real getSolutionChangeNorm()
Get the Relative L2 norm of the change in the solution.
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.
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...