https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Static 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 backup () override
 This method is overridden so that we only store the initial state and not on any other timestep when doing batch-restore.
 
virtual void initialSetup () override
 
virtual void finalize () override
 
virtual void postExecute () override
 
virtual void restore (bool force=true) override
 
virtual void preExecute ()
 
void possiblyCreateChildApplications ()
 
void init (unsigned int num_apps, const LocalRankConfig &config)
 
virtual void createLocalApp (const unsigned int i)
 
virtual void incrementTStep (Real)
 
virtual void finishStep (bool=false)
 
bool needsRestoration ()
 
virtual Executioner * getExecutioner (unsigned int app)
 
virtual libMesh::BoundingBox getBoundingBox (unsigned int app, bool displaced_mesh, const MultiAppCoordTransform *coord_transform=nullptr)
 
FEProblemBase & problemBase ()
 
FEProblemBase & appProblemBase (unsigned int app)
 
FEProblem & appProblem (unsigned int app)
 
const UserObject & appUserObjectBase (unsigned int app, const std::string &name)
 
Real appPostprocessorValue (unsigned int app, const std::string &name)
 
virtual libMesh::NumericVector< libMesh::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
 
MooseApp * localApp (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< MooseObject > getSharedPtr ()
 
std::shared_ptr< const MooseObject > getSharedPtr () const
 
bool isKokkosObject () const
 
MooseApp & getMooseApp () const
 
const std::string & type () const
 
const std::string & name () const
 
std::string typeAndName () const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
MooseObjectName uniqueName () const
 
const InputParameters & parameters () const
 
const hit::Node * getHitNode () const
 
bool hasBase () const
 
const std::string & getBase () 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 * queryParam (const std::string &name) const
 
const T & getRenamedParam (const std::string &old_name, const std::string &new_name) const
 
T getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &name) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (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
 
std::string messagePrefix (const bool hit_prefix=true) const
 
std::string errorPrefix (const std::string &) const
 
void mooseError (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecatedNoTrace (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
void callMooseError (std::string msg, const bool with_prefix, const hit::Node *node=nullptr, const bool show_trace=true) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
virtual void timestepSetup ()
 
virtual void jacobianSetup ()
 
virtual void residualSetup ()
 
virtual void subdomainSetup ()
 
virtual void customSetup (const ExecFlagType &)
 
const ExecFlagEnum & getExecuteOnEnum () const
 
PerfGraph & perfGraph ()
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 
T & getSampler (const std::string &name)
 
Sampler & getSampler (const std::string &name)
 
T & getSamplerByName (const SamplerName &name)
 
Sampler & getSamplerByName (const SamplerName &name)
 

Static Public Member Functions

static InputParameters validParams ()
 
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 void callMooseError (MooseApp *const app, const InputParameters &params, std::string msg, const bool with_prefix, const hit::Node *node, const bool show_trace=true)
 
static void transformBoundingBox (libMesh::BoundingBox &box, const MultiAppCoordTransform &transform)
 

Public Attributes

 usingCombinedWarningSolutionWarnings
 
const ConsoleStream _console
 

Static Public Attributes

static const std::string type_param
 
static const std::string name_param
 
static const std::string unique_name_param
 
static const std::string app_param
 
static const std::string moose_base_param
 
static const std::string kokkos_object_param
 

Protected Member Functions

virtual void showStatusMessage (unsigned int i) const override
 Override to avoid 'solve converged' message and print when processors are finished.
 
virtual std::vector< std::string > getCommandLineArgs (const unsigned int local_app) override
 Override to allow for batch mode to get correct cli_args.
 
void init (unsigned int num_apps, bool batch_mode=false)
 
void setAppOutputFileBase (unsigned int index)
 
bool propagateRecoverToSubApps () const override
 
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 createApps ()
 
void keepSolutionDuringRestore (bool keep_solution_during_restore)
 
void flagInvalidSolutionInternal (const InvalidSolutionID invalid_solution_id) const
 
InvalidSolutionID registerInvalidSolutionInternal (const std::string &message, const bool warning) const
 
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 ReporterContextBase & getReporterContextBaseByName (const ReporterName &reporter_name) const
 
const ReporterName & getReporterName (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.
 
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.
 
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
 
const bool _create_child_apps_on_initial_setup
 
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< libMesh::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
 
bool _keep_aux_solution_during_restore
 
const bool _no_restore
 
std::vector< std::vector< std::unique_ptr< libMesh::NumericVector< Real > > > > _end_solutions
 
std::vector< std::unique_ptr< NumericVector< Real > > > _end_aux_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
 
Factory & _factory
 
ActionFactory & _action_factory
 
const std::string & _type
 
const std::string & _name
 
const InputParameters & _pars
 
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'.
 
std::vector< std::shared_ptr< StochasticToolsTransfer > > getActiveStochasticToolsTransfers (Transfer::DIRECTION direction)
 Helper for getting StochasticToolsTransfer objects.
 
RestartableDataValue & registerRestartableDataOnApp (std::unique_ptr< RestartableDataValue > data, THREAD_ID tid) const
 
void registerRestartableNameWithFilterOnApp (const std::string &name, Moose::RESTARTABLE_FILTER filter)
 
RestartableData< T > & declareRestartableDataHelper (const std::string &data_name, void *context, Args &&... args) const
 
bool reportersAdded () const
 
void possiblyCheckHasReporter (const ReporterName &reporter_name, const std::string &param_name="") const
 

Static Private Member Functions

static const hit::Node * getHitNode (const InputParameters &params)
 
static std::string messagePrefix (const InputParameters &params, const bool hit_prefix)
 

Private Attributes

bool _solved_once
 
dof_id_type _number_of_sampler_rows
 
const std::vector< bool > * _should_run = nullptr
 Reporter value determining whether the sub-app should be run for a certain sample.
 
const bool _ignore_diverge
 
const bool _update_old_state_when_keeping_solution_during_restore
 
std::vector< Executioner * > _executioners
 
std::optional< std::string > _cli_args_param
 
const ParallelParamObject & _parent
 
const MooseBase & _si_moose_base
 
const FEProblemBase * _si_problem
 
ExecFlagEnum _empty_execute_enum
 
const RestartableDataMapName _metaname
 
std::string _restartable_name
 
const InputParameters & _si_params
 
FEProblemBase & _si_feproblem
 
THREAD_ID _si_tid
 
const InputParameters & _ri_params
 
FEProblemBase & _ri_fe_problem_base
 
const ReporterData & _ri_reporter_data
 
const MooseObject & _ri_moose_object
 

Detailed Description

Definition at line 21 of file SamplerFullSolveMultiApp.h.

Constructor & Destructor Documentation

◆ SamplerFullSolveMultiApp()

SamplerFullSolveMultiApp::SamplerFullSolveMultiApp ( const InputParameters &  parameters)

Definition at line 57 of file SamplerFullSolveMultiApp.C.

59 SamplerInterface(this),
61 _sampler(getSampler("sampler")),
62 _mode(getParam<MooseEnum>("mode").getEnum<StochasticTools::MultiAppMode>()),
64 _solved_once(false)
65{
66 if (getParam<unsigned int>("min_procs_per_app") !=
67 _sampler.getParam<unsigned int>("min_procs_per_row") ||
68 getParam<unsigned int>("max_procs_per_app") !=
69 _sampler.getParam<unsigned int>("max_procs_per_row"))
70 paramError("sampler",
71 "Sampler and multiapp communicator configuration inconsistent. Please ensure that "
72 "'MultiApps/",
73 name(),
74 "/min(max)_procs_per_app' and 'Samplers/",
75 _sampler.name(),
76 "/min(max)_procs_per_row' are the same.");
77
82
83 if (isParamValid("should_run_reporter") && _mode == StochasticTools::MultiAppMode::NORMAL)
84 paramError("should_run_reporter",
85 "Conditionally run sampler multiapp only works in batch modes.");
86}
const InputParameters & parameters() const
const std::string & name() const
void paramError(const std::string &param, Args... args) const
const T & getParam(const std::string &name) const
bool isParamValid(const std::string &name) const
void init(unsigned int num_apps, const LocalRankConfig &config)
Sampler & _sampler
Sampler to utilize for creating MultiApps.
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.
T & getSampler(const std::string &name)
dof_id_type getNumberOfRows() const
const LocalRankConfig & getRankConfig(bool batch_mode) const

Member Function Documentation

◆ backup()

void SamplerFullSolveMultiApp::backup ( )
overridevirtual

This method is overridden so that we only store the initial state and not on any other timestep when doing batch-restore.

Reimplemented from FullSolveMultiApp.

Definition at line 89 of file SamplerFullSolveMultiApp.C.

Referenced by PODFullSolveMultiApp::computeResidualBatch().

◆ 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 269 of file SamplerFullSolveMultiApp.C.

276{
277 if (verbose && transfers.size())
278 {
279 console << COLOR_CYAN << "\nBatch transfers for row " << global_row_index;
280 if (direction == MultiAppTransfer::TO_MULTIAPP)
281 console << " To ";
282 else if (direction == MultiAppTransfer::FROM_MULTIAPP)
283 console << " From ";
284 console << "MultiApps" << COLOR_DEFAULT << ":" << std::endl;
285
286 console << "Sampler row " << global_row_index << " data: [" << Moose::stringify(row_data) << "]"
287 << std::endl;
288
289 // Build Table of Transfer Info
291 {"Name", "Type", "From", "To"});
292 for (const auto & transfer : transfers)
293 table.addRow(
294 transfer->name(), transfer->type(), transfer->getFromName(), transfer->getToName());
295 table.print(console);
296 }
297
298 for (auto & transfer : transfers)
299 {
300 transfer->setGlobalRowIndex(global_row_index);
301 transfer->setCurrentRow(row_data);
302 if (direction == MultiAppTransfer::TO_MULTIAPP)
303 transfer->executeToMultiapp();
304 else if (direction == MultiAppTransfer::FROM_MULTIAPP)
305 transfer->executeFromMultiapp();
306 }
307
308 if (verbose && transfers.size())
309 console << COLOR_CYAN << "Batch transfers for row " << global_row_index << " Are Finished\n"
310 << COLOR_DEFAULT << std::endl;
311}
const std::string & type() const
void print(StreamType &stream)
std::string stringify(const T &t)

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

◆ getActiveStochasticToolsTransfers()

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

Helper for getting StochasticToolsTransfer objects.

Definition at line 349 of file SamplerFullSolveMultiApp.C.

350{
351 std::vector<std::shared_ptr<StochasticToolsTransfer>> output;
352 const ExecuteMooseObjectWarehouse<Transfer> & warehouse =
354 for (std::shared_ptr<Transfer> transfer : warehouse.getActiveObjects())
355 {
356 auto ptr = std::dynamic_pointer_cast<StochasticToolsTransfer>(transfer);
357 if (ptr && ptr->getMultiApp().get() == this)
358 output.push_back(ptr);
359 }
360 return output;
361}
const ExecuteMooseObjectWarehouse< Transfer > & getMultiAppTransferWarehouse(Transfer::DIRECTION direction) const
FEProblemBase & _fe_problem

Referenced by solveStepBatch().

◆ getCommandLineArgs()

std::vector< std::string > SamplerFullSolveMultiApp::getCommandLineArgs ( const unsigned int  local_app)
overrideprotectedvirtual

Override to allow for batch mode to get correct cli_args.

Reimplemented from FullSolveMultiApp.

Definition at line 364 of file SamplerFullSolveMultiApp.C.

365{
368
369 std::vector<std::string> args;
370
371 // With multiple processors per app, there are no local rows for non-root processors
372 if (isRootProcessor())
373 {
374 // Since we only store param_names in cli_args, we need to find the values for each param from
375 // sampler data and combine them to get full command line option strings.
376 dof_id_type row_index;
378 row_index = local_app + _first_local_app;
379 else
383 }
384
386 return args;
387}
libMesh::Parallel::Communicator _my_communicator
unsigned int _first_local_app
virtual std::vector< std::string > getCommandLineArgs(const unsigned int local_app)
LocalRankConfig _rank_config
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.
std::vector< Real > getSampleRow(dof_id_type row_index) const
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
uint8_t dof_id_type
dof_id_type first_local_sim_index

◆ preTransfer()

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

Reimplemented from FullSolveMultiApp.

Reimplemented in PODFullSolveMultiApp.

Definition at line 96 of file SamplerFullSolveMultiApp.C.

97{
98 // Logic for calling initial setup again:
99 // 1) If and only if not doing batch-reset (solveStepBatch does this at each local row)
100 // 2) If the number of rows have changed since the communicator is re-split.
101 // 3) If we have already solved and doing "normal" execution, effectively resetting the apps
102 bool initial_setup_required = false;
103
104 // Reinitialize MultiApp size
105 const auto num_rows = _sampler.getNumberOfRows();
106 if (num_rows != _number_of_sampler_rows)
107 {
108 init(num_rows,
111 _number_of_sampler_rows = num_rows;
112 initial_setup_required = _mode != StochasticTools::MultiAppMode::BATCH_RESET;
113 }
114 else if (_solved_once || _app.isRecovering())
115 initial_setup_required = _mode == StochasticTools::MultiAppMode::NORMAL;
116
117 // Call initial setup based on the logic above
118 if (initial_setup_required)
119 {
120 initialSetup();
121 _solved_once = false;
122 }
123 // Otherwise we need to restore for batch-restore
125 restore();
126
127 if (isParamValid("should_run_reporter"))
128 _should_run = &getReporterValue<std::vector<bool>>("should_run_reporter");
129}
virtual void initialSetup() override
virtual void restore(bool force=true) override
bool isRecovering() const
const std::vector< bool > * _should_run
Reporter value determining whether the sub-app should be run for a certain sample.

Referenced by PODFullSolveMultiApp::preTransfer().

◆ sampledCommandLineArgs()

std::vector< 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 390 of file SamplerFullSolveMultiApp.C.

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

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

◆ 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 314 of file SamplerFullSolveMultiApp.C.

315{
316 // Local row is the app index if in normal mode, otherwise it's _local_batch_app_index
317 const dof_id_type local_row =
319 // If the local row is less than the number of local sims, we aren't finished yet
320 if (local_row < _rank_config.num_local_sims - 1)
321 return;
322
323 // Loop through processors to communicate completeness
324 for (const auto & pid : make_range(n_processors()))
325 {
326 // This is what is being sent to trigger completeness
329 : 0;
330 // Cannot send/receive to the same processor, so avoid if root
331 if (pid > 0)
332 {
333 // Send data to root
334 if (pid == processor_id())
335 _communicator.send(0, last_row);
336 // Receive data from source
337 else if (processor_id() == 0)
338 _communicator.receive(pid, last_row);
339 }
340
341 // Output the samples that are complete if it's the main processor for the batch
342 if (last_row)
343 _console << COLOR_CYAN << type() << " [" << name() << "] " << last_row << "/"
344 << _number_of_sampler_rows << " samples complete!" << std::endl;
345 }
346}
const ConsoleStream _console
Status receive(const unsigned int dest_processor_id, T &buf, const MessageTag &tag=any_tag) const
void send(const unsigned int dest_processor_id, const T &buf, const MessageTag &tag=no_tag) const
const Parallel::Communicator & _communicator
processor_id_type processor_id() const
processor_id_type n_processors() const
IntRange< T > make_range(T beg, T end)
dof_id_type num_local_sims
bool is_first_local_rank

◆ solveStep()

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

Reimplemented from FullSolveMultiApp.

Reimplemented in PODFullSolveMultiApp.

Definition at line 132 of file SamplerFullSolveMultiApp.C.

133{
134 TIME_SECTION("solveStep", 3, "Solving SamplerFullSolveMultiApp");
135
137
138 bool last_solve_converged = true;
139
142 last_solve_converged = solveStepBatch(dt, target_time, auto_advance);
143 else
144 last_solve_converged = FullSolveMultiApp::solveStep(dt, target_time, auto_advance);
145
146 _solved_once = true;
147
148 return last_solve_converged;
149}
virtual bool solveStep(Real dt, Real target_time, bool auto_advance=true) override
unsigned int _my_num_apps
bool solveStepBatch(Real dt, Real target_time, bool auto_advance=true)
Helper method for running in mode='batch'.
dof_id_type getNumberOfLocalRows() const

Referenced by PODFullSolveMultiApp::solveStep().

◆ solveStepBatch()

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

Helper method for running in mode='batch'.

Definition at line 152 of file SamplerFullSolveMultiApp.C.

153{
154 TIME_SECTION("solveStepBatch", 3, "Solving Step Batch For SamplerFullSolveMultiApp");
155
157 paramError("should_run_reporter",
158 "Reporter deteriming multiapp run must be of size greater than or equal to the "
159 "number of local rows in the sampler, ",
160 _should_run->size(),
161 " < ",
163 ".");
164
165 // Value to return
166 bool last_solve_converged = true;
167
168 // List of active relevant Transfer objects
169 std::vector<std::shared_ptr<StochasticToolsTransfer>> to_transfers =
171 std::vector<std::shared_ptr<StochasticToolsTransfer>> from_transfers =
173
174 // Initialize to/from transfers
175 for (auto transfer : to_transfers)
176 {
177 transfer->setGlobalMultiAppIndex(_rank_config.first_local_app_index);
178 transfer->initializeToMultiapp();
179 }
180 for (auto transfer : from_transfers)
181 {
182 transfer->setGlobalMultiAppIndex(_rank_config.first_local_app_index);
183 transfer->initializeFromMultiapp();
184 }
185
188
189 // Perform batch MultiApp solves
191 for (dof_id_type i = _rank_config.first_local_sim_index;
193 ++i)
194 {
195 bool run = true;
196 if (_should_run)
197 {
198 if (isRootProcessor())
201 }
202 if (!run)
203 {
205 continue;
206 }
207
208 // Given that we don't initialize in preTransfer for batch-reset mode, we need
209 // a different logic for resetting the apps for every sample:
210 // - batch-restore: after (re-)initializing the problem, we only need to restore
211 // starting from the second sample
213 {
215 restore();
216 }
217 // - batch-reset: we don't need to initialize for the first sample in the first
218 // solve. After that, we initialize every time. This is mainly to avoid unnecessary
219 // initializations for cases when the multiapp does not need to be executed (conditional runs)
220 else
221 {
223 initialSetup();
224 }
225
226 // With multiple processors per app, there are no local rows for non-root processors
227 std::vector<Real> row_data;
228 if (isRootProcessor())
229 row_data = _sampler.getSampleRow(i);
230 execBatchTransfers(to_transfers,
231 i,
232 row_data,
235 _console);
236
237 // Set the file base based on the current row
238 for (unsigned int ai = 0; ai < _my_num_apps; ++ai)
239 {
240 const std::string mname = getMultiAppName(name(), i, _number_of_sampler_rows);
241 _apps[ai]->setOutputFileBase(_app.getOutputFileBase() + "_" + mname);
242 }
243
244 const bool curr_last_solve_converged =
245 FullSolveMultiApp::solveStep(dt, target_time, auto_advance);
246 last_solve_converged = last_solve_converged && curr_last_solve_converged;
247
248 execBatchTransfers(from_transfers,
249 i,
250 row_data,
253 _console);
254
256 }
258
259 // Finalize to/from transfers
260 for (auto transfer : to_transfers)
261 transfer->finalizeToMultiapp();
262 for (auto transfer : from_transfers)
263 transfer->finalizeFromMultiapp();
264
265 return last_solve_converged;
266}
bool verboseMultiApps() const
std::string getOutputFileBase(bool for_non_moose_build_output=false) const
static std::string getMultiAppName(const std::string &base_name, dof_id_type index, dof_id_type total)
std::vector< std::shared_ptr< MooseApp > > _apps
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.
dof_id_type first_local_app_index

Referenced by solveStep().

◆ validParams()

InputParameters SamplerFullSolveMultiApp::validParams ( )
static

Definition at line 20 of file SamplerFullSolveMultiApp.C.

21{
26 "Creates a full-solve type sub-application for each row of each Sampler matrix.");
27 params.addRequiredParam<SamplerName>(
28 "sampler",
29 "The Sampler object to utilize for creating the child applications of this MultiApp.");
30
31 // The number of applications is handled by the sampler
32 params.suppressParameter<std::vector<Point>>("positions");
33 params.suppressParameter<bool>("output_in_position");
34 params.suppressParameter<std::vector<FileName>>("positions_file");
35 params.suppressParameter<Real>("move_time");
36 params.suppressParameter<std::vector<Point>>("move_positions");
37 params.suppressParameter<std::vector<unsigned int>>("move_apps");
38 params.set<bool>("use_positions") = false;
39
40 MooseEnum modes("normal=0 batch-reset=1 batch-restore=2", "normal");
41 params.addParam<MooseEnum>(
42 "mode",
43 modes,
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.");
50 params.addParam<ReporterName>(
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.");
54 return params;
55}
static InputParameters validParams()
void suppressParameter(const std::string &name)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
static InputParameters validParams()
static InputParameters validParams()

Referenced by PODFullSolveMultiApp::validParams().

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 83 of file SamplerFullSolveMultiApp.h.

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

◆ _mode

const StochasticTools::MultiAppMode SamplerFullSolveMultiApp::_mode
protected

◆ _number_of_sampler_rows

dof_id_type SamplerFullSolveMultiApp::_number_of_sampler_rows
private

◆ _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 107 of file SamplerFullSolveMultiApp.h.

Referenced by preTransfer(), and solveStepBatch().

◆ _solved_once

bool SamplerFullSolveMultiApp::_solved_once
private

Definition at line 101 of file SamplerFullSolveMultiApp.h.

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


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