23 params.
addClassDescription(
"Creates a sub-application for each row of each Sampler matrix.");
25 "The Sampler object to utilize for creating MultiApps.");
32 params.
set<
bool>(
"use_positions") =
false;
37 MooseEnum modes(
"normal=0 batch-reset=1 batch-restore=2",
"normal");
41 "The operation mode, 'normal' creates one sub-application for each row in the Sampler and " 42 "'batch-reset' and 'batch-restore' creates N sub-applications, where N is the minimum of " 43 "'num_rows' in the Sampler and floor(number of processes / min_procs_per_app). To run " 44 "the rows in the Sampler, 'batch-reset' will destroy and re-create sub-apps as needed, " 45 "whereas the 'batch-restore' will backup and restore sub-apps to the initial state prior " 46 "to execution, without destruction.");
54 _sampler(getSampler(
"sampler")),
56 _local_batch_app_index(0),
57 _number_of_sampler_rows(_sampler.getNumberOfRows())
61 "The supplied mode, '",
62 getParam<MooseEnum>(
"mode"),
63 "', currently is not implemented for the SamplerTransientMultiApp, the available " 64 "options are 'normal' or 'batch-restore'.");
66 if (getParam<unsigned int>(
"min_procs_per_app") !=
68 getParam<unsigned int>(
"max_procs_per_app") !=
71 "Sampler and multiapp communicator configuration inconsistent. Please ensure that " 74 "/min(max)_procs_per_app' and 'Samplers/",
76 "/min(max)_procs_per_row' are the same.");
86 TIME_SECTION(
"initialSetup", 2,
"Setting Up SamplerTransientMultiApp");
95 for (MooseIndex(n) i = 0; i < n; ++i)
104 TIME_SECTION(
"solveStep", 3,
"Solving SamplerTransientMultiApp");
107 mooseError(
"The size of the sampler has changed; SamplerTransientMultiApp object do not " 108 "support dynamic Sampler output.");
110 bool last_solve_converged =
true;
112 last_solve_converged =
solveStepBatch(dt, target_time, auto_advance);
115 return last_solve_converged;
122 bool last_solve_converged =
true;
125 std::vector<std::shared_ptr<StochasticToolsTransfer>> to_transfers =
127 std::vector<std::shared_ptr<StochasticToolsTransfer>> from_transfers =
131 for (
auto transfer : to_transfers)
134 transfer->initializeToMultiapp();
136 for (
auto transfer : from_transfers)
139 transfer->initializeFromMultiapp();
154 _apps[
j]->finalizeRestore();
171 const bool curr_last_solve_converged =
173 last_solve_converged = last_solve_converged && curr_last_solve_converged;
193 for (
auto transfer : to_transfers)
194 transfer->finalizeToMultiapp();
195 for (
auto transfer : from_transfers)
196 transfer->finalizeFromMultiapp();
198 return last_solve_converged;
201 std::vector<std::shared_ptr<StochasticToolsTransfer>>
204 std::vector<std::shared_ptr<StochasticToolsTransfer>> output;
209 std::shared_ptr<StochasticToolsTransfer> ptr =
211 if (ptr && ptr->getMultiApp().get() ==
this)
212 output.push_back(ptr);
217 std::vector<std::string>
220 std::vector<std::string> args;
244 "Local index must be less than number of local rows.");
249 mooseAssert(local_index == 0,
250 "The first time calling updateRowData must have a local index of 0.");
261 "Local index must be equal or one greater than the index previously called.");
bool verboseMultiApps() const
static InputParameters validParams()
static InputParameters validParams()
registerMooseObject("StochasticToolsApp", SamplerTransientMultiApp)
LocalRankConfig _rank_config
std::vector< Real > _row_data
Current row of data updated by updateRowData. Used by transfers and setting command line args...
virtual void initialSetup() override
std::string getOutputFileBase(bool for_non_moose_build_output=false) const
std::vector< std::shared_ptr< MooseApp > > _apps
dof_id_type first_local_app_index
std::vector< Real > getNextLocalRow()
std::vector< std::shared_ptr< StochasticToolsTransfer > > getActiveStochasticToolsTransfers(Transfer::DIRECTION direction)
Helper for getting StochasticToolsTransfer objects.
const StochasticTools::MultiAppMode _mode
The Sup-application solve mode.
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...
static InputParameters validParams()
FEProblemBase & _fe_problem
dof_id_type getNumberOfLocalRows() const
virtual std::vector< std::string > getCommandLineArgs(const unsigned int local_app)
virtual const std::string & name() const
virtual std::vector< std::string > getCommandLineArgs(const unsigned int local_app) override
Override to allow to get correct cli_args.
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.
const std::vector< std::shared_ptr< Transfer > > & getActiveObjects(THREAD_ID tid=0) const
void updateRowData(dof_id_type local_index)
Helper function for updating _row_data and _local_row_index.
const T & getParam(const std::string &name) const
void paramError(const std::string ¶m, Args... args) const
const LocalRankConfig & getRankConfig(bool batch_mode) const
virtual bool solveStep(Real dt, Real target_time, bool auto_advance=true) override
Override solveStep to allow for batch execution.
dof_id_type _local_row_index
Current local index representing _row_data.
dof_id_type num_local_sims
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
unsigned int _my_num_apps
static std::string getMultiAppName(const std::string &base_name, dof_id_type index, dof_id_type total)
libMesh::Parallel::Communicator _my_communicator
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.
dof_id_type getNumberOfRows() const
const ExecuteMooseObjectWarehouse< Transfer > & getMultiAppTransferWarehouse(Transfer::DIRECTION direction) const
SamplerTransientMultiApp(const InputParameters ¶meters)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const
bool solveStepBatch(Real dt, Real target_time, bool auto_advance=true)
Helper method for running in mode='batch'.
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
Sampler & _sampler
Sampler to utilize for creating MultiApps.
dof_id_type first_local_sim_index
dof_id_type _local_batch_app_index
Counter for extracting command line arguments in batch mode.
const ConsoleStream _console
void init(unsigned int num_apps, bool batch_mode=false)
virtual void initialSetup() override
Override to initialize batch backups.
virtual void incrementTStep(Real target_time) override
virtual bool solveStep(Real dt, Real target_time, bool auto_advance=true) override
const dof_id_type _number_of_sampler_rows
Store the number of rows initialized, if this changes error because it doesn't make sense...