www.mooseframework.org
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
SamplerFullSolveMultiApp Class Reference

#include <SamplerFullSolveMultiApp.h>

Inheritance diagram for SamplerFullSolveMultiApp:
[legend]

Public Types

typedef DataFileName DataFileParameterType
 

Public Member Functions

 SamplerFullSolveMultiApp (const InputParameters &parameters)
 
virtual bool solveStep (Real dt, Real target_time, bool auto_advance=true) override
 
virtual void preTransfer (Real dt, Real target_time) override
 
virtual void initialSetup () override
 
virtual void finalize () override
 
virtual void postExecute () override
 
virtual void backup () override
 
virtual void restore (bool force=true) override
 
virtual void preExecute ()
 
void setupPositions ()
 
virtual void createLocalApp (const unsigned int i)
 
virtual void incrementTStep (Real)
 
virtual void finishStep (bool=false)
 
virtual bool needsRestoration ()
 
virtual ExecutionergetExecutioner (unsigned int app)
 
virtual BoundingBox getBoundingBox (unsigned int app, bool displaced_mesh, const MultiAppCoordTransform *coord_transform=nullptr)
 
FEProblemBaseproblemBase ()
 
FEProblemBaseappProblemBase (unsigned int app)
 
FEProblemappProblem (unsigned int app)
 
const UserObjectappUserObjectBase (unsigned int app, const std::string &name)
 
Real appPostprocessorValue (unsigned int app, const std::string &name)
 
virtual NumericVector< Number > & appTransferVector (unsigned int app, std::string var_name)
 
unsigned int numGlobalApps () const
 
unsigned int numLocalApps ()
 
unsigned int firstLocalApp ()
 
bool isFirstLocalRank () const
 
bool hasApp ()
 
bool hasLocalApp (unsigned int global_app) const
 
MooseApplocalApp (unsigned int local_app)
 
const Point & position (unsigned int app) const
 
virtual void resetApp (unsigned int global_app, Real time=0.0)
 
virtual void moveApp (unsigned int global_app, Point p)
 
virtual void parentOutputPositionChanged ()
 
MPI_Comm & comm ()
 
const Parallel::Communicator & comm () const
 
bool isRootProcessor ()
 
bool usingPositions () const
 
bool runningInPosition () const
 
void addAssociatedTransfer (MultiAppTransfer &transfer)
 
void setAppOutputFileBase ()
 
virtual bool enabled () const
 
std::shared_ptr< MooseObjectgetSharedPtr ()
 
std::shared_ptr< const MooseObjectgetSharedPtr () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
virtual const std::string & name () const
 
std::string typeAndName () const
 
std::string errorPrefix (const std::string &error_type) const
 
void callMooseError (std::string msg, const bool with_prefix) const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
const InputParametersparameters () const
 
MooseObjectName uniqueName () const
 
const T & getParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const T & getRenamedParam (const std::string &old_name, const std::string &new_name) const
 
getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &nm) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void mooseError (Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &name, const std::string *param=nullptr) const
 
virtual void timestepSetup ()
 
virtual void jacobianSetup ()
 
virtual void residualSetup ()
 
virtual void subdomainSetup ()
 
virtual void customSetup (const ExecFlagType &)
 
const ExecFlagEnumgetExecuteOnEnum () const
 
PerfGraphperfGraph ()
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 
T & getSampler (const std::string &name)
 
SamplergetSampler (const std::string &name)
 
T & getSamplerByName (const SamplerName &name)
 
SamplergetSamplerByName (const SamplerName &name)
 

Static Public Member Functions

static InputParameters validParams ()
 
static 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. More...
 
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. More...
 
static void transformBoundingBox (BoundingBox &box, const MultiAppCoordTransform &transform)
 

Public Attributes

const ConsoleStream _console
 

Protected Member Functions

virtual void showStatusMessage (unsigned int i) const override
 Override to avoid 'solve converged' message and print when processors are finished. More...
 
virtual std::string getCommandLineArgsParamHelper (unsigned int local_app) override
 Override to allow for batch mode to get correct cli_args. More...
 
void setAppOutputFileBase (unsigned int index)
 
virtual std::vector< std::string > cliArgs () const
 
virtual void fillPositions ()
 
void readCommandLineArguments ()
 
void createApp (unsigned int i, Real start_time)
 
void buildComm ()
 
unsigned int globalAppToLocal (unsigned int global_app)
 
virtual void preRunInputFile ()
 
void init (unsigned int num_apps, bool batch_mode=false)
 
void init (unsigned int num_apps, const LocalRankConfig &config)
 
void createApps ()
 
void keepSolutionDuringRestore (bool keep_solution_during_restore)
 
T & declareRestartableData (const std::string &data_name, Args &&... args)
 
ManagedValue< T > declareManagedRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 
const T & getRestartableData (const std::string &data_name) const
 
T & declareRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 
T & declareRecoverableData (const std::string &data_name, Args &&... args)
 
T & declareRestartableDataWithObjectName (const std::string &data_name, const std::string &object_name, Args &&... args)
 
T & declareRestartableDataWithObjectNameWithContext (const std::string &data_name, const std::string &object_name, void *context, Args &&... args)
 
std::string restartableName (const std::string &data_name) const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level) const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true) const
 
std::string timedSectionName (const std::string &section_name) const
 
const ReporterNamegetReporterName (const std::string &param_name) const
 
virtual void addReporterDependencyHelper (const ReporterName &)
 
const T & getReporterValue (const std::string &param_name, const std::size_t time_index=0)
 
const T & getReporterValue (const std::string &param_name, ReporterMode mode, const std::size_t time_index=0)
 
const T & getReporterValue (const std::string &param_name, const std::size_t time_index=0)
 
const T & getReporterValue (const std::string &param_name, ReporterMode mode, const std::size_t time_index=0)
 
const T & getReporterValueByName (const ReporterName &reporter_name, const std::size_t time_index=0)
 
const T & getReporterValueByName (const ReporterName &reporter_name, ReporterMode mode, const std::size_t time_index=0)
 
const T & getReporterValueByName (const ReporterName &reporter_name, const std::size_t time_index=0)
 
const T & getReporterValueByName (const ReporterName &reporter_name, ReporterMode mode, const std::size_t time_index=0)
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 

Static Protected Member Functions

static std::string getMultiAppName (const std::string &base_name, dof_id_type index, dof_id_type total)
 

Protected Attributes

Sampler_sampler
 Sampler to utilize for creating MultiApps. More...
 
const StochasticTools::MultiAppMode _mode
 The Sup-application solve mode. More...
 
dof_id_type _local_batch_app_index
 Counter for extracting command line arguments in batch mode. More...
 
FEProblemBase_fe_problem
 
std::string _app_type
 
std::vector< Point > _positions
 
std::vector< const Positions *> _positions_objs
 
std::vector< unsigned int_positions_index_offsets
 
const bool _use_positions
 
std::vector< FileName > _input_files
 
const bool & _wait_for_first_app_init
 
std::vector< unsigned int_npositions_inputfile
 
std::string _output_base
 
unsigned int _total_num_apps
 
unsigned int _my_num_apps
 
unsigned int _first_local_app
 
const MPI_Comm & _orig_comm
 
libMesh::Parallel::Communicator _my_communicator
 
MPI_Comm & _my_comm
 
int _orig_num_procs
 
int _orig_rank
 
std::string _node_name
 
int _my_rank
 
std::vector< std::shared_ptr< MooseApp > > _apps
 
std::vector< bool > _has_bounding_box
 
std::vector< BoundingBox > _bounding_box
 
Real _inflation
 
Point _bounding_box_padding
 
processor_id_type _max_procs_per_app
 
processor_id_type _min_procs_per_app
 
bool _output_in_position
 
const Real _global_time_offset
 
std::vector< Real_reset_times
 
std::vector< unsigned int_reset_apps
 
std::vector< bool > _reset_happened
 
Real _move_time
 
std::vector< unsigned int_move_apps
 
std::vector< Point > _move_positions
 
bool _move_happened
 
bool _has_an_app
 
const std::vector< CLIArgString > & _cli_args
 
std::vector< std::string > _cli_args_from_file
 
bool _keep_solution_during_restore
 
std::vector< std::unique_ptr< NumericVector< Real > > > _end_solutions
 
LocalRankConfig _rank_config
 
std::vector< MultiAppTransfer *> _associated_transfers
 
const bool _run_in_position
 
SubAppBackups_sub_app_backups
 
const PerfID _solve_step_timer
 
const PerfID _init_timer
 
const PerfID _backup_timer
 
const PerfID _restore_timer
 
const PerfID _reset_timer
 
const bool & _enabled
 
MooseApp_app
 
const std::string _type
 
const std::string _name
 
const InputParameters_pars
 
Factory_factory
 
ActionFactory_action_factory
 
const ExecFlagEnum_execute_enum
 
const ExecFlagType_current_execute_flag
 
MooseApp_restartable_app
 
const std::string _restartable_system_name
 
const THREAD_ID _restartable_tid
 
const bool _restartable_read_only
 
MooseApp_pg_moose_app
 
const std::string _prefix
 
const Parallel::Communicator & _communicator
 

Private Member Functions

bool solveStepBatch (Real dt, Real target_time, bool auto_advance=true)
 Helper method for running in mode='batch'. More...
 
void updateRowData (dof_id_type local_index)
 Helper function for updating _row_data and _local_row_index. More...
 
std::vector< std::shared_ptr< StochasticToolsTransfer > > getActiveStochasticToolsTransfers (Transfer::DIRECTION direction)
 Helper for getting StochasticToolsTransfer objects. More...
 

Private Attributes

bool _solved_once
 
dof_id_type _number_of_sampler_rows
 
std::vector< Real_row_data
 Current row of data updated by updateRowData. Used by transfers and setting command line args. More...
 
dof_id_type _local_row_index = std::numeric_limits<dof_id_type>::max()
 Current local index representing _row_data. More...
 
const std::vector< bool > * _should_run = nullptr
 Reporter value determining whether the sub-app should be run for a certain sample. More...
 

Detailed Description

Definition at line 21 of file SamplerFullSolveMultiApp.h.

Constructor & Destructor Documentation

◆ SamplerFullSolveMultiApp()

SamplerFullSolveMultiApp::SamplerFullSolveMultiApp ( const InputParameters parameters)

Definition at line 54 of file SamplerFullSolveMultiApp.C.

56  SamplerInterface(this),
57  ReporterInterface(this),
58  _sampler(getSampler("sampler")),
59  _mode(getParam<MooseEnum>("mode").getEnum<StochasticTools::MultiAppMode>()),
61  _solved_once(false)
62 {
63  if (getParam<unsigned int>("min_procs_per_app") !=
64  _sampler.getParam<unsigned int>("min_procs_per_row") ||
65  getParam<unsigned int>("max_procs_per_app") !=
66  _sampler.getParam<unsigned int>("max_procs_per_row"))
67  paramError("sampler",
68  "Sampler and multiapp communicator configuration inconsistent. Please ensure that "
69  "'MultiApps/",
70  name(),
71  "/min(max)_procs_per_app' and 'Samplers/",
72  _sampler.name(),
73  "/min(max)_procs_per_row' are the same.");
74 
79 
80  if (isParamValid("should_run_reporter") && _mode == StochasticTools::MultiAppMode::NORMAL)
81  paramError("should_run_reporter",
82  "Conditionally run sampler multiapp only works in batch modes.");
83 }
const StochasticTools::MultiAppMode _mode
The Sup-application solve mode.
dof_id_type _local_batch_app_index
Counter for extracting command line arguments in batch mode.
virtual const std::string & name() const
bool isParamValid(const std::string &name) const
FullSolveMultiApp(const InputParameters &parameters)
Sampler & _sampler
Sampler to utilize for creating MultiApps.
const T & getParam(const std::string &name) const
void paramError(const std::string &param, Args... args) const
const LocalRankConfig & getRankConfig(bool batch_mode) const
ReporterInterface(const MooseObject *moose_object)
dof_id_type getNumberOfRows() const
T & getSampler(const std::string &name)
SamplerInterface(const MooseObject *moose_object)
const InputParameters & parameters() const
void init(unsigned int num_apps, bool batch_mode=false)

Member Function Documentation

◆ execBatchTransfers()

void SamplerFullSolveMultiApp::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 
)
static

Helper for executing transfers when doing batch stochastic simulations.

Parameters
transfersA vector of transfers to execute
global_row_indexThe global row index of the run
row_dataThe current sampler row of data for the transfer to utilize
typeThe current execution flag, used for info printing
directionThe direction of the transfer, used for info printing
verboseWhether or not print information about the transfer
consoleThe console stream to output to

Definition at line 244 of file SamplerFullSolveMultiApp.C.

Referenced by SamplerTransientMultiApp::solveStepBatch(), and solveStepBatch().

251 {
252  if (verbose && transfers.size())
253  {
254  console << COLOR_CYAN << "\nBatch transfers for row " << global_row_index;
255  if (direction == MultiAppTransfer::TO_MULTIAPP)
256  console << " To ";
257  else if (direction == MultiAppTransfer::FROM_MULTIAPP)
258  console << " From ";
259  console << "MultiApps" << COLOR_DEFAULT << ":" << std::endl;
260 
261  console << "Sampler row " << global_row_index << " data: [" << Moose::stringify(row_data) << "]"
262  << std::endl;
263 
264  // Build Table of Transfer Info
266  {"Name", "Type", "From", "To"});
267  for (const auto & transfer : transfers)
268  table.addRow(
269  transfer->name(), transfer->type(), transfer->getFromName(), transfer->getToName());
270  table.print(console);
271  }
272 
273  for (auto & transfer : transfers)
274  {
275  transfer->setGlobalRowIndex(global_row_index);
276  transfer->setCurrentRow(row_data);
277  if (direction == MultiAppTransfer::TO_MULTIAPP)
278  transfer->executeToMultiapp();
279  else if (direction == MultiAppTransfer::FROM_MULTIAPP)
280  transfer->executeFromMultiapp();
281  }
282 
283  if (verbose && transfers.size())
284  console << COLOR_CYAN << "Batch transfers for row " << global_row_index << " Are Finished\n"
285  << COLOR_DEFAULT << std::endl;
286 }
std::string stringify(const T &t)
void addRow(Ts... entries)

◆ getActiveStochasticToolsTransfers()

std::vector< std::shared_ptr< StochasticToolsTransfer > > SamplerFullSolveMultiApp::getActiveStochasticToolsTransfers ( Transfer::DIRECTION  direction)
private

Helper for getting StochasticToolsTransfer objects.

Definition at line 324 of file SamplerFullSolveMultiApp.C.

Referenced by solveStepBatch().

325 {
326  std::vector<std::shared_ptr<StochasticToolsTransfer>> output;
327  const ExecuteMooseObjectWarehouse<Transfer> & warehouse =
329  for (std::shared_ptr<Transfer> transfer : warehouse.getActiveObjects())
330  {
331  auto ptr = std::dynamic_pointer_cast<StochasticToolsTransfer>(transfer);
332  if (ptr && ptr->getMultiApp().get() == this)
333  output.push_back(ptr);
334  }
335  return output;
336 }
FEProblemBase & _fe_problem
The class creates an additional API to allow Transfers to work when running the StochasticTools<FullS...
const std::vector< std::shared_ptr< Transfer > > & getActiveObjects(THREAD_ID tid=0) const
const ExecuteMooseObjectWarehouse< Transfer > & getMultiAppTransferWarehouse(Transfer::DIRECTION direction) const

◆ getCommandLineArgsParamHelper()

std::string SamplerFullSolveMultiApp::getCommandLineArgsParamHelper ( unsigned int  local_app)
overrideprotectedvirtual

Override to allow for batch mode to get correct cli_args.

Reimplemented from FullSolveMultiApp.

Definition at line 339 of file SamplerFullSolveMultiApp.C.

340 {
341  std::string args;
342 
343  // With multiple processors per app, there are no local rows for non-root processors
344  if (isRootProcessor())
345  {
346  // Since we only store param_names in cli_args, we need to find the values for each param from
347  // sampler data and combine them to get full command line option strings.
350 
351  const std::vector<std::string> & full_args_name =
353  args = sampledCommandLineArgs(_row_data, full_args_name);
354  }
355 
357  return args;
358 }
const StochasticTools::MultiAppMode _mode
The Sup-application solve mode.
virtual std::string getCommandLineArgsParamHelper(unsigned int local_app)
static 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.
dof_id_type _local_batch_app_index
Counter for extracting command line arguments in batch mode.
std::vector< Real > _row_data
Current row of data updated by updateRowData. Used by transfers and setting command line args...
std::vector< std::string > split(const std::string &str, const std::string &delimiter, std::size_t max_count=std::numeric_limits< std::size_t >::max())
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
libMesh::Parallel::Communicator _my_communicator
void updateRowData(dof_id_type local_index)
Helper function for updating _row_data and _local_row_index.

◆ preTransfer()

void SamplerFullSolveMultiApp::preTransfer ( Real  dt,
Real  target_time 
)
overridevirtual

Reimplemented from FullSolveMultiApp.

Reimplemented in PODFullSolveMultiApp.

Definition at line 85 of file SamplerFullSolveMultiApp.C.

Referenced by PODFullSolveMultiApp::preTransfer().

86 {
87  // Reinitialize MultiApp size
88  const auto num_rows = _sampler.getNumberOfRows();
89  if (num_rows != _number_of_sampler_rows)
90  {
91  init(num_rows,
94  _number_of_sampler_rows = num_rows;
95  _row_data.clear();
96  }
97 
98  // Reinitialize app to original state prior to solve, if a solve has occured.
99  // Since the app is reinitialized in the solve step either way, we skip this
100  // for batch-reset mode.
102  initialSetup();
103 
104  if (isParamValid("should_run_reporter"))
105  _should_run = &getReporterValue<std::vector<bool>>("should_run_reporter");
106 }
const StochasticTools::MultiAppMode _mode
The Sup-application solve mode.
virtual void initialSetup() override
std::vector< Real > _row_data
Current row of data updated by updateRowData. Used by transfers and setting command line args...
bool isParamValid(const std::string &name) const
Sampler & _sampler
Sampler to utilize for creating MultiApps.
const LocalRankConfig & getRankConfig(bool batch_mode) const
const std::vector< bool > * _should_run
Reporter value determining whether the sub-app should be run for a certain sample.
dof_id_type getNumberOfRows() const
void init(unsigned int num_apps, bool batch_mode=false)

◆ sampledCommandLineArgs()

std::string SamplerFullSolveMultiApp::sampledCommandLineArgs ( const std::vector< Real > &  row,
const std::vector< std::string > &  full_args_name 
)
static

Helper for inserting row data into commandline arguments Used here and in SamplerTransientMultiApp.

How it works:

  • Scalar parameters are done in order of row data: param1;param2;param3 -> param1=row[0] param2=row[1] param3=row[2]
  • Vector parameters are assigned with brackets: vec_param1[0,1];vec_param2[1,2] -> vec_param1='row[0] row[1]' vec_param2='row[1] row[2]'
  • Any parameter already with an equal sign is not modified: param1=3.14;param2[0,1,2] -> param1=3.14 param2='row[0] row[1] row[2]'

Definition at line 388 of file SamplerFullSolveMultiApp.C.

Referenced by SamplerParameterTransfer::execute(), SamplerParameterTransfer::executeToMultiapp(), SamplerTransientMultiApp::getCommandLineArgsParamHelper(), and getCommandLineArgsParamHelper().

390 {
391  std::ostringstream oss;
392 
393  // Find parameters that are meant to be assigned by sampler values
394  std::vector<std::string> cli_args_name;
395  for (const auto & fan : full_args_name)
396  {
397  // If it has an '=', then it is not meant to be modified
398  if (fan.find("=") == std::string::npos)
399  cli_args_name.push_back(fan);
400  else
401  oss << fan << ";";
402  }
403 
404  // Make sure the parameters either all have brackets, or none of them do
405  bool has_brackets = false;
406  if (cli_args_name.size())
407  {
408  has_brackets = cli_args_name[0].find("[") != std::string::npos;
409  for (unsigned int i = 1; i < cli_args_name.size(); ++i)
410  if (has_brackets != (cli_args_name[i].find("[") != std::string::npos))
411  ::mooseError("If the bracket is used, it must be provided to every parameter.");
412  }
413  if (!has_brackets && cli_args_name.size() && cli_args_name.size() != row.size())
414  ::mooseError("Number of command line arguments does not match number of sampler columns.");
415 
416  for (unsigned int i = 0; i < cli_args_name.size(); ++i)
417  {
418  // Assign bracketed parameters
419  if (has_brackets)
420  {
421  // Split param name and vector assignment: "param[0,(3.14),1]" -> {"param", "0,(3.14),1]"}
422  const std::vector<std::string> & vector_param = MooseUtils::split(cli_args_name[i], "[");
423  // Get indices of vector: "0,(3.14),1]" -> {"0", "(3.14)", "1"}
424  const std::vector<std::string> & index_string =
425  MooseUtils::split(vector_param[1].substr(0, vector_param[1].find("]")), ",");
426 
427  // Loop through indices and assign parameter: param='row[0] 3.14 row[1]'
428  oss << vector_param[0] << "='";
429  std::string sep = "";
430  for (const auto & istr : index_string)
431  {
432  oss << sep;
433  sep = " ";
434  // If the value is enclosed in parentheses, then it isn't an index, it's a value
435  if (istr.find("(") != std::string::npos)
436  oss << std::stod(istr.substr(istr.find("(") + 1));
437  // Assign the value from row if it is an index
438  else
439  {
440  unsigned int index = MooseUtils::stringToInteger(istr);
441  if (index >= row.size())
442  ::mooseError("The provided global column index (",
443  index,
444  ") for ",
445  vector_param[0],
446  " is out of bound.");
447  oss << Moose::stringifyExact(row[index]);
448  }
449  }
450  oss << "';";
451  }
452  // Assign scalar parameters
453  else
454  {
455  oss << cli_args_name[i] << "=" << Moose::stringifyExact(row[i]) << ";";
456  }
457  }
458 
459  return oss.str();
460 }
int stringToInteger(const std::string &input, bool throw_on_failure=false)
std::vector< std::string > split(const std::string &str, const std::string &delimiter, std::size_t max_count=std::numeric_limits< std::size_t >::max())
std::string stringifyExact(Real)
void mooseError(Args &&... args) const

◆ showStatusMessage()

void SamplerFullSolveMultiApp::showStatusMessage ( unsigned int  i) const
overrideprotectedvirtual

Override to avoid 'solve converged' message and print when processors are finished.

Reimplemented from FullSolveMultiApp.

Definition at line 289 of file SamplerFullSolveMultiApp.C.

290 {
291  // Local row is the app index if in normal mode, otherwise it's _local_batch_app_index
292  const dof_id_type local_row =
294  // If the local row is less than the number of local sims, we aren't finished yet
295  if (local_row < _rank_config.num_local_sims - 1)
296  return;
297 
298  // Loop through processors to communicate completeness
299  for (const auto & pid : make_range(n_processors()))
300  {
301  // This is what is being sent to trigger completeness
304  : 0;
305  // Cannot send/receive to the same processor, so avoid if root
306  if (pid > 0)
307  {
308  // Send data to root
309  if (pid == processor_id())
310  _communicator.send(0, last_row);
311  // Receive data from source
312  else if (processor_id() == 0)
313  _communicator.receive(pid, last_row);
314  }
315 
316  // Output the samples that are complete if it's the main processor for the batch
317  if (last_row)
318  _console << COLOR_CYAN << type() << " [" << name() << "] " << last_row << "/"
319  << _number_of_sampler_rows << " samples complete!" << std::endl;
320  }
321 }
const StochasticTools::MultiAppMode _mode
The Sup-application solve mode.
LocalRankConfig _rank_config
dof_id_type _local_batch_app_index
Counter for extracting command line arguments in batch mode.
const Parallel::Communicator & _communicator
virtual const std::string & name() const
processor_id_type n_processors() const
Status receive(const unsigned int dest_processor_id, T &buf, const MessageTag &tag=any_tag) const
const std::string & type() const
dof_id_type num_local_sims
void send(const unsigned int dest_processor_id, const T &buf, const MessageTag &tag=no_tag) const
bool is_first_local_rank
IntRange< T > make_range(T beg, T end)
dof_id_type first_local_sim_index
const ConsoleStream _console
processor_id_type processor_id() const
uint8_t dof_id_type

◆ solveStep()

bool SamplerFullSolveMultiApp::solveStep ( Real  dt,
Real  target_time,
bool  auto_advance = true 
)
overridevirtual

Reimplemented from FullSolveMultiApp.

Reimplemented in PODFullSolveMultiApp.

Definition at line 109 of file SamplerFullSolveMultiApp.C.

Referenced by PODFullSolveMultiApp::solveStep().

110 {
111  TIME_SECTION("solveStep", 3, "Solving SamplerFullSolveMultiApp");
112 
114 
115  bool last_solve_converged = true;
116 
119  last_solve_converged = solveStepBatch(dt, target_time, auto_advance);
120  else
121  last_solve_converged = FullSolveMultiApp::solveStep(dt, target_time, auto_advance);
122 
123  _solved_once = true;
124 
125  return last_solve_converged;
126 }
const StochasticTools::MultiAppMode _mode
The Sup-application solve mode.
bool solveStepBatch(Real dt, Real target_time, bool auto_advance=true)
Helper method for running in mode=&#39;batch&#39;.
dof_id_type getNumberOfLocalRows() const
Sampler & _sampler
Sampler to utilize for creating MultiApps.
unsigned int _my_num_apps
virtual bool solveStep(Real dt, Real target_time, bool auto_advance=true) override

◆ solveStepBatch()

bool SamplerFullSolveMultiApp::solveStepBatch ( Real  dt,
Real  target_time,
bool  auto_advance = true 
)
private

Helper method for running in mode='batch'.

Definition at line 129 of file SamplerFullSolveMultiApp.C.

Referenced by solveStep().

130 {
131  TIME_SECTION("solveStepBatch", 3, "Solving Step Batch For SamplerFullSolveMultiApp");
132 
134  paramError("should_run_reporter",
135  "Reporter deteriming multiapp run must be of size greater than or equal to the "
136  "number of local rows in the sampler, ",
137  _should_run->size(),
138  " < ",
140  ".");
141 
142  // Value to return
143  bool last_solve_converged = true;
144 
145  // List of active relevant Transfer objects
146  std::vector<std::shared_ptr<StochasticToolsTransfer>> to_transfers =
148  std::vector<std::shared_ptr<StochasticToolsTransfer>> from_transfers =
150 
151  // Initialize to/from transfers
152  for (auto transfer : to_transfers)
153  {
154  transfer->setGlobalMultiAppIndex(_rank_config.first_local_app_index);
155  transfer->initializeToMultiapp();
156  }
157  for (auto transfer : from_transfers)
158  {
159  transfer->setGlobalMultiAppIndex(_rank_config.first_local_app_index);
160  transfer->initializeFromMultiapp();
161  }
162 
164  backup();
165 
166  // Perform batch MultiApp solves
170  ++i)
171  {
173 
174  bool run = true;
175  if (_should_run)
176  {
177  if (isRootProcessor())
178  run = (*_should_run)[_local_batch_app_index];
179  _my_communicator.broadcast(run, 0);
180  }
181  if (!run)
182  {
184  continue;
185  }
186 
187  // Given that we don't initialize in preTransfer for batch-reset mode, we need
188  // a different logic for resetting the apps for every sample:
189  // - batch-restore: after (re-)initializing the problem, we only need to restore
190  // starting from the second sample
192  {
194  restore();
195  }
196  // - batch-reset: we don't need to initialize for the first sample in the first
197  // solve. After that, we initialize every time. This is mainly to avoid unnecessary
198  // initializations for cases when the multiapp does not need to be executed (conditional runs)
199  else
200  {
202  initialSetup();
203  }
204 
205  execBatchTransfers(to_transfers,
206  i,
207  _row_data,
210  _console);
211 
212  // Set the file base based on the current row
213  for (unsigned int ai = 0; ai < _my_num_apps; ++ai)
214  {
215  const std::string mname = getMultiAppName(name(), i, _number_of_sampler_rows);
216  _apps[ai]->setOutputFileBase(_app.getOutputFileBase() + "_" + mname);
217  }
218 
219  const bool curr_last_solve_converged =
220  FullSolveMultiApp::solveStep(dt, target_time, auto_advance);
221  last_solve_converged = last_solve_converged && curr_last_solve_converged;
222 
223  execBatchTransfers(from_transfers,
224  i,
225  _row_data,
228  _console);
229 
231  }
233 
234  // Finalize to/from transfers
235  for (auto transfer : to_transfers)
236  transfer->finalizeToMultiapp();
237  for (auto transfer : from_transfers)
238  transfer->finalizeFromMultiapp();
239 
240  return last_solve_converged;
241 }
const StochasticTools::MultiAppMode _mode
The Sup-application solve mode.
std::vector< std::shared_ptr< StochasticToolsTransfer > > getActiveStochasticToolsTransfers(Transfer::DIRECTION direction)
Helper for getting StochasticToolsTransfer objects.
virtual void initialSetup() override
bool verboseMultiApps() const
LocalRankConfig _rank_config
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
dof_id_type _local_batch_app_index
Counter for extracting command line arguments in batch mode.
FEProblemBase & _fe_problem
dof_id_type getNumberOfLocalRows() const
virtual const std::string & name() const
std::vector< Real > _row_data
Current row of data updated by updateRowData. Used by transfers and setting command line args...
virtual void backup() override
Sampler & _sampler
Sampler to utilize for creating MultiApps.
void paramError(const std::string &param, Args... args) const
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)
const std::vector< bool > * _should_run
Reporter value determining whether the sub-app should be run for a certain sample.
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.
void updateRowData(dof_id_type local_index)
Helper function for updating _row_data and _local_row_index.
virtual void restore(bool force=true) override
dof_id_type first_local_sim_index
const ConsoleStream _console
virtual bool solveStep(Real dt, Real target_time, bool auto_advance=true) override
uint8_t dof_id_type

◆ updateRowData()

void SamplerFullSolveMultiApp::updateRowData ( dof_id_type  local_index)
private

Helper function for updating _row_data and _local_row_index.

This allows multiple calls to the same row index

Definition at line 361 of file SamplerFullSolveMultiApp.C.

Referenced by getCommandLineArgsParamHelper(), and solveStepBatch().

362 {
363  if (!isRootProcessor())
364  return;
365 
366  mooseAssert(local_index < _sampler.getNumberOfLocalRows(),
367  "Local index must be less than number of local rows.");
368 
369  if (_row_data.empty() ||
370  (_local_row_index == _sampler.getNumberOfLocalRows() - 1 && local_index == 0))
371  {
372  mooseAssert(local_index == 0,
373  "The first time calling updateRowData must have a local index of 0.");
374  _local_row_index = 0;
376  }
377  else if (local_index - _local_row_index == 1)
378  {
381  }
382 
383  mooseAssert(local_index == _local_row_index,
384  "Local index must be equal or one greater than the index previously called.");
385 }
std::vector< Real > getNextLocalRow()
dof_id_type getNumberOfLocalRows() const
std::vector< Real > _row_data
Current row of data updated by updateRowData. Used by transfers and setting command line args...
dof_id_type _local_row_index
Current local index representing _row_data.
Sampler & _sampler
Sampler to utilize for creating MultiApps.

◆ validParams()

InputParameters SamplerFullSolveMultiApp::validParams ( )
static

Definition at line 20 of file SamplerFullSolveMultiApp.C.

Referenced by PODFullSolveMultiApp::validParams().

21 {
25  params.addClassDescription(
26  "Creates a full-solve type sub-application for each row of each Sampler matrix.");
27  params.addRequiredParam<SamplerName>("sampler",
28  "The Sampler object to utilize for creating MultiApps.");
29  params.suppressParameter<std::vector<Point>>("positions");
30  params.suppressParameter<bool>("output_in_position");
31  params.suppressParameter<std::vector<FileName>>("positions_file");
32  params.suppressParameter<Real>("move_time");
33  params.suppressParameter<std::vector<Point>>("move_positions");
34  params.suppressParameter<std::vector<unsigned int>>("move_apps");
35  params.set<bool>("use_positions") = false;
36 
37  MooseEnum modes("normal=0 batch-reset=1 batch-restore=2", "normal");
38  params.addParam<MooseEnum>(
39  "mode",
40  modes,
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.");
47  params.addParam<ReporterName>(
48  "should_run_reporter",
49  "Vector reporter value determining whether a certain multiapp should be run with this "
50  "multiapp. This only works in batch-reset or batch-restore mode.");
51  return params;
52 }
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
static InputParameters validParams()
T & set(const std::string &name, bool quiet_mode=false)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void suppressParameter(const std::string &name)
static InputParameters validParams()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void addClassDescription(const std::string &doc_string)

Member Data Documentation

◆ _local_batch_app_index

dof_id_type SamplerFullSolveMultiApp::_local_batch_app_index
protected

Counter for extracting command line arguments in batch mode.

Definition at line 76 of file SamplerFullSolveMultiApp.h.

Referenced by PODFullSolveMultiApp::computeResidualBatch(), getCommandLineArgsParamHelper(), showStatusMessage(), and solveStepBatch().

◆ _local_row_index

dof_id_type SamplerFullSolveMultiApp::_local_row_index = std::numeric_limits<dof_id_type>::max()
private

Current local index representing _row_data.

Definition at line 108 of file SamplerFullSolveMultiApp.h.

Referenced by updateRowData().

◆ _mode

const StochasticTools::MultiAppMode SamplerFullSolveMultiApp::_mode
protected

◆ _number_of_sampler_rows

dof_id_type SamplerFullSolveMultiApp::_number_of_sampler_rows
private

◆ _row_data

std::vector<Real> SamplerFullSolveMultiApp::_row_data
private

Current row of data updated by updateRowData. Used by transfers and setting command line args.

Definition at line 106 of file SamplerFullSolveMultiApp.h.

Referenced by getCommandLineArgsParamHelper(), preTransfer(), solveStepBatch(), and updateRowData().

◆ _sampler

Sampler& SamplerFullSolveMultiApp::_sampler
protected

◆ _should_run

const std::vector<bool>* SamplerFullSolveMultiApp::_should_run = nullptr
private

Reporter value determining whether the sub-app should be run for a certain sample.

Definition at line 111 of file SamplerFullSolveMultiApp.h.

Referenced by preTransfer(), and solveStepBatch().

◆ _solved_once

bool SamplerFullSolveMultiApp::_solved_once
private

Definition at line 100 of file SamplerFullSolveMultiApp.h.

Referenced by preTransfer(), solveStep(), and solveStepBatch().


The documentation for this class was generated from the following files: