26 "Creates a full-solve type sub-application for each row of each Sampler matrix.");
29 "The Sampler object to utilize for creating the child applications of this MultiApp.");
38 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.");
51 "should_run_reporter",
52 "Vector reporter value determining whether a certain multiapp should be run with this "
53 "multiapp. This only works in batch-reset or batch-restore mode.");
61 _sampler(getSampler(
"sampler")),
63 _local_batch_app_index(0),
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.");
85 "Conditionally run sampler multiapp only works in batch modes.");
102 bool initial_setup_required =
false;
120 if (initial_setup_required)
130 _should_run = &getReporterValue<std::vector<bool>>(
"should_run_reporter");
136 TIME_SECTION(
"solveStep", 3,
"Solving SamplerFullSolveMultiApp");
140 bool last_solve_converged =
true;
144 last_solve_converged =
solveStepBatch(dt, target_time, auto_advance);
150 return last_solve_converged;
156 TIME_SECTION(
"solveStepBatch", 3,
"Solving Step Batch For SamplerFullSolveMultiApp");
160 "Reporter deteriming multiapp run must be of size greater than or equal to the "
161 "number of local rows in the sampler, ",
168 bool last_solve_converged =
true;
171 std::vector<std::shared_ptr<StochasticToolsTransfer>> to_transfers =
173 std::vector<std::shared_ptr<StochasticToolsTransfer>> from_transfers =
177 for (
auto transfer : to_transfers)
180 transfer->initializeToMultiapp();
182 for (
auto transfer : from_transfers)
185 transfer->initializeFromMultiapp();
232 std::vector<Real> row_data;
249 const bool curr_last_solve_converged =
251 last_solve_converged = last_solve_converged && curr_last_solve_converged;
265 for (
auto transfer : to_transfers)
266 transfer->finalizeToMultiapp();
267 for (
auto transfer : from_transfers)
268 transfer->finalizeFromMultiapp();
270 return last_solve_converged;
275 const std::vector<std::shared_ptr<StochasticToolsTransfer>> & transfers,
276 dof_id_type global_row_index,
277 const std::vector<Real> & row_data,
282 if (verbose && transfers.size())
284 console << COLOR_CYAN <<
"\nBatch transfers for row " << global_row_index;
289 console <<
"MultiApps" << COLOR_DEFAULT <<
":" << std::endl;
291 console <<
"Sampler row " << global_row_index <<
" data: [" <<
Moose::stringify(row_data) <<
"]"
296 {
"Name",
"Type",
"From",
"To"});
297 for (
const auto & transfer : transfers)
299 transfer->name(), transfer->type(), transfer->getFromName(), transfer->getToName());
300 table.print(console);
303 for (
auto & transfer : transfers)
305 transfer->setGlobalRowIndex(global_row_index);
306 transfer->setCurrentRow(row_data);
308 transfer->executeToMultiapp();
310 transfer->executeFromMultiapp();
313 if (verbose && transfers.size())
314 console << COLOR_CYAN <<
"Batch transfers for row " << global_row_index <<
" Are Finished\n"
315 << COLOR_DEFAULT << std::endl;
322 const dof_id_type local_row =
348 _console << COLOR_CYAN <<
type() <<
" [" <<
name() <<
"] " << last_row <<
"/"
353std::vector<std::shared_ptr<StochasticToolsTransfer>>
356 std::vector<std::shared_ptr<StochasticToolsTransfer>> output;
361 auto ptr = std::dynamic_pointer_cast<StochasticToolsTransfer>(transfer);
362 if (ptr && ptr->getMultiApp().get() ==
this)
363 output.push_back(ptr);
368std::vector<std::string>
374 std::vector<std::string> args;
381 dof_id_type row_index;
394std::vector<std::string>
396 const std::vector<std::string> & full_args_name)
398 std::vector<std::string> args;
401 std::vector<std::string> cli_args_name;
402 for (
const auto & fan : full_args_name)
405 if (fan.find(
"=") == std::string::npos)
406 cli_args_name.push_back(fan);
412 bool has_brackets =
false;
413 if (cli_args_name.size())
415 has_brackets = cli_args_name[0].find(
"[") != std::string::npos;
416 for (
unsigned int i = 1; i < cli_args_name.size(); ++i)
417 if (has_brackets != (cli_args_name[i].find(
"[") != std::string::npos))
418 ::mooseError(
"If the bracket is used, it must be provided to every parameter.");
420 if (!has_brackets && cli_args_name.size() && cli_args_name.size() != row.size())
421 ::mooseError(
"Number of command line arguments does not match number of sampler columns.");
423 for (
unsigned int i = 0; i < cli_args_name.size(); ++i)
429 const std::vector<std::string> & vector_param =
MooseUtils::split(cli_args_name[i],
"[");
431 const std::vector<std::string> & index_string =
435 std::vector<std::string>
values;
436 for (
const auto & istr : index_string)
441 if (istr.find(
"(") != std::string::npos)
442 value = std::stod(istr.substr(istr.find(
"(") + 1));
447 if (index >= row.size())
452 " is out of bound.");
461 args.push_back(vector_param[0] +
"=" +
values[0]);
std::array< Real, 2 > values
registerMooseObject("StochasticToolsApp", SamplerFullSolveMultiApp)
const ConsoleStream _console
bool verboseMultiApps() const
const ExecuteMooseObjectWarehouse< Transfer > & getMultiAppTransferWarehouse(Transfer::DIRECTION direction) const
virtual void initialSetup() override
virtual void restore(bool force=true) override
static InputParameters validParams()
virtual bool solveStep(Real dt, Real target_time, bool auto_advance=true) override
std::string getOutputFileBase(bool for_non_moose_build_output=false) const
bool isRecovering() const
const std::string & type() 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
bool isParamValid(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 InputParameters validParams()
SamplerFullSolveMultiApp(const InputParameters ¶meters)
Sampler & _sampler
Sampler to utilize for creating MultiApps.
bool solveStepBatch(Real dt, Real target_time, bool auto_advance=true)
Helper method for running in mode='batch'.
virtual void showStatusMessage(unsigned int i) const override
Override to avoid 'solve converged' message and print when processors are finished.
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.
virtual void backup() override
This method is overridden so that we only store the initial state and not on any other timestep when ...
virtual void preTransfer(Real dt, Real target_time) override
const std::vector< bool > * _should_run
Reporter value determining whether the sub-app should be run for a certain sample.
dof_id_type _number_of_sampler_rows
virtual bool solveStep(Real dt, Real target_time, bool auto_advance=true) override
std::vector< std::shared_ptr< StochasticToolsTransfer > > getActiveStochasticToolsTransfers(Transfer::DIRECTION direction)
Helper for getting StochasticToolsTransfer objects.
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.
virtual std::vector< std::string > getCommandLineArgs(const unsigned int local_app) override
Override to allow for batch mode to get correct cli_args.
static InputParameters validParams()
dof_id_type _local_batch_app_index
Counter for extracting command line arguments in batch mode.
const StochasticTools::MultiAppMode _mode
The Sup-application solve mode.
static InputParameters validParams()
dof_id_type getNumberOfLocalRows() const
std::vector< Real > getSampleRow(dof_id_type row_index) const
dof_id_type getNumberOfRows() const
const LocalRankConfig & getRankConfig(bool batch_mode) const
Status receive(const unsigned int dest_processor_id, T &buf, const MessageTag &tag=any_tag) const
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
void send(const unsigned int dest_processor_id, const T &buf, const MessageTag &tag=no_tag) const
void addRow(Ts... entries)
const Parallel::Communicator & _communicator
processor_id_type processor_id() const
processor_id_type n_processors() const
int stringToInteger(const std::string &input, bool throw_on_failure)
std::vector< std::string > split(const std::string &str, const std::string &delimiter, std::size_t max_count)
std::string stringJoin(const std::vector< std::string > &values, const std::string &separator=" ")
std::string stringify(const T &t)
std::string stringifyExact(Real)
dof_id_type num_local_sims
dof_id_type first_local_sim_index
dof_id_type first_local_app_index