23 params.
addClassDescription(
"Creates a sub-application for each row of each Sampler matrix.");
26 "The Sampler object to utilize for creating the child applications of this MultiApp.");
35 params.
set<
bool>(
"use_positions") =
false;
40 MooseEnum modes(
"normal=0 batch-reset=1 batch-restore=2",
"normal");
44 "The operation mode, 'normal' creates one sub-application for each row in the Sampler and "
45 "'batch-reset' and 'batch-restore' creates N sub-applications, where N is the minimum of "
46 "'num_rows' in the Sampler and floor(number of processes / min_procs_per_app). To run "
47 "the rows in the Sampler, 'batch-reset' will destroy and re-create sub-apps as needed, "
48 "whereas the 'batch-restore' will backup and restore sub-apps to the initial state prior "
49 "to execution, without destruction.");
57 _sampler(getSampler(
"sampler")),
59 _local_batch_app_index(0),
60 _number_of_sampler_rows(_sampler.getNumberOfRows()),
62 declareRestartableData<
std::vector<
std::vector<
std::unique_ptr<
Backup>>>>(
"batch_backup"))
66 "The supplied mode, '",
67 getParam<MooseEnum>(
"mode"),
68 "', currently is not implemented for the SamplerTransientMultiApp, the available "
69 "options are 'normal' or 'batch-restore'.");
71 if (getParam<unsigned int>(
"min_procs_per_app") !=
73 getParam<unsigned int>(
"max_procs_per_app") !=
76 "Sampler and multiapp communicator configuration inconsistent. Please ensure that "
79 "/min(max)_procs_per_app' and 'Samplers/",
81 "/min(max)_procs_per_row' are the same.");
91 TIME_SECTION(
"initialSetup", 2,
"Setting Up SamplerTransientMultiApp");
100 for (MooseIndex(n) i = 0; i < n; ++i)
109 TIME_SECTION(
"solveStep", 3,
"Solving SamplerTransientMultiApp");
112 mooseError(
"The size of the sampler has changed; SamplerTransientMultiApp object do not "
113 "support dynamic Sampler output.");
115 bool last_solve_converged =
true;
117 last_solve_converged =
solveStepBatch(dt, target_time, auto_advance);
120 return last_solve_converged;
127 bool last_solve_converged =
true;
130 std::vector<std::shared_ptr<StochasticToolsTransfer>> to_transfers =
132 std::vector<std::shared_ptr<StochasticToolsTransfer>> from_transfers =
136 for (
auto transfer : to_transfers)
139 transfer->initializeToMultiapp();
141 for (
auto transfer : from_transfers)
144 transfer->initializeFromMultiapp();
157 _apps[j]->finalizeRestore();
161 std::vector<Real> row_data;
178 const bool curr_last_solve_converged =
180 last_solve_converged = last_solve_converged && curr_last_solve_converged;
200 for (
auto transfer : to_transfers)
201 transfer->finalizeToMultiapp();
202 for (
auto transfer : from_transfers)
203 transfer->finalizeFromMultiapp();
205 return last_solve_converged;
208std::vector<std::shared_ptr<StochasticToolsTransfer>>
211 std::vector<std::shared_ptr<StochasticToolsTransfer>> output;
216 std::shared_ptr<StochasticToolsTransfer> ptr =
217 std::dynamic_pointer_cast<StochasticToolsTransfer>(transfer);
218 if (ptr && ptr->getMultiApp().get() ==
this)
219 output.push_back(ptr);
224std::vector<std::string>
227 std::vector<std::string> args;
234 dof_id_type row_index;
registerMooseObject("StochasticToolsApp", SamplerTransientMultiApp)
const ConsoleStream _console
bool verboseMultiApps() const
const ExecuteMooseObjectWarehouse< Transfer > & getMultiAppTransferWarehouse(Transfer::DIRECTION direction) const
std::string getOutputFileBase(bool for_non_moose_build_output=false) const
bool isRecovering() const
const std::string & name() const
void paramError(const std::string ¶m, Args... args) const
void mooseError(Args &&... args) const
const T & getParam(const std::string &name) const
const std::vector< std::shared_ptr< T > > & getActiveObjects(THREAD_ID tid=0) const
libMesh::Parallel::Communicator _my_communicator
void init(unsigned int num_apps, const LocalRankConfig &config)
static std::string getMultiAppName(const std::string &base_name, dof_id_type index, dof_id_type total)
unsigned int _first_local_app
FEProblemBase & _fe_problem
std::vector< std::shared_ptr< MooseApp > > _apps
virtual std::vector< std::string > getCommandLineArgs(const unsigned int local_app)
LocalRankConfig _rank_config
unsigned int _my_num_apps
static std::vector< std::string > sampledCommandLineArgs(const std::vector< Real > &row, const std::vector< std::string > &full_args_name)
Helper for inserting row data into commandline arguments Used here and in SamplerTransientMultiApp.
static void execBatchTransfers(const std::vector< std::shared_ptr< StochasticToolsTransfer > > &transfers, dof_id_type global_row_index, const std::vector< Real > &row_data, Transfer::DIRECTION direction, bool verbose, const ConsoleStream &console)
Helper for executing transfers when doing batch stochastic simulations.
static InputParameters validParams()
virtual bool solveStep(Real dt, Real target_time, bool auto_advance=true) override
Override solveStep to allow for batch execution.
const dof_id_type _number_of_sampler_rows
Store the number of rows initialized, if this changes error because it doesn't make sense.
virtual void initialSetup() override
Override to initialize batch backups.
bool solveStepBatch(Real dt, Real target_time, bool auto_advance=true)
Helper method for running in mode='batch'.
Sampler & _sampler
Sampler to utilize for creating MultiApps.
std::vector< std::vector< std::unique_ptr< Backup > > > & _batch_backup
Storage for batch-restore mode; the outer vector if for the local stochastic data and the inner vecto...
const StochasticTools::MultiAppMode _mode
The Sup-application solve mode.
virtual std::vector< std::string > getCommandLineArgs(const unsigned int local_app) override
Override to allow to get correct cli_args.
std::vector< std::shared_ptr< StochasticToolsTransfer > > getActiveStochasticToolsTransfers(Transfer::DIRECTION direction)
Helper for getting StochasticToolsTransfer objects.
static InputParameters validParams()
dof_id_type _local_batch_app_index
Counter for extracting command line arguments in batch mode.
SamplerTransientMultiApp(const InputParameters ¶meters)
std::vector< Real > getSampleRow(dof_id_type row_index) const
dof_id_type getNumberOfRows() const
const LocalRankConfig & getRankConfig(bool batch_mode) const
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
virtual void initialSetup() override
virtual void incrementTStep(Real target_time) override
virtual bool solveStep(Real dt, Real target_time, bool auto_advance=true) override
static InputParameters validParams()
dof_id_type num_local_sims
dof_id_type first_local_sim_index
dof_id_type first_local_app_index