https://mooseframework.inl.gov
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
PODFullSolveMultiApp Class Reference

#include <PODFullSolveMultiApp.h>

Inheritance diagram for PODFullSolveMultiApp:
[legend]

Public Types

typedef DataFileName DataFileParameterType
 

Public Member Functions

 PODFullSolveMultiApp (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
 Overriding preTransfer to reinit the subappliations if the object needs to be executed twice. More...
 
bool snapshotGeneration ()
 Returning the value of the snapshot generation flag. More...
 
virtual void initialSetup () override
 
virtual void finalize () override
 
virtual void postExecute () 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 void backup ()
 
bool needsRestoration ()
 
virtual ExecutionergetExecutioner (unsigned int app)
 
virtual libMesh::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 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
 
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 * queryParam (const std::string &name) 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 &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 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::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. 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 (libMesh::BoundingBox &box, const MultiAppCoordTransform &transform)
 

Public Attributes

const ConsoleStream _console
 

Protected Member Functions

std::vector< std::shared_ptr< PODSamplerSolutionTransfer > > getActiveSolutionTransfers (Transfer::DIRECTION direction)
 Returning pointers to the solution transfers. Used in batch mode. More...
 
std::vector< std::shared_ptr< PODResidualTransfer > > getActiveResidualTransfers (Transfer::DIRECTION direction)
 Returning pointers to the solution transfers. Used in batch mode. More...
 
void computeResidual ()
 Evaluating the residuals for every tag in the trainer. More...
 
void computeResidualBatch (Real target_time)
 Evaluating the residuals for every tag in the trainer in batch mode. More...
 
virtual void showStatusMessage (unsigned int i) const override
 Override to avoid 'solve converged' message and print when processors are finished. More...
 
virtual std::vector< std::string > getCommandLineArgs (const 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

PODReducedBasisTrainer_trainer
 Pointer to the trainer object itself. More...
 
bool _snapshot_generation
 Switch used to differentiate between snapshot generation and residual computation. More...
 
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< 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::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
 
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

template<>
SurrogateModelgetSurrogateModel (const std::string &name) const
 
template<>
SurrogateTrainerBasegetSurrogateTrainer (const std::string &name) const
 
template<>
SurrogateModelgetSurrogateModelByName (const UserObjectName &name) const
 
template<>
SurrogateTrainerBasegetSurrogateTrainerByName (const UserObjectName &name) const
 
template<typename T = SurrogateModel>
T & getSurrogateModel (const std::string &name) const
 Get a SurrogateModel/Trainer with a given name. More...
 
template<typename T = SurrogateTrainerBase>
T & getSurrogateTrainer (const std::string &name) const
 
template<typename T = SurrogateModel>
T & getSurrogateModelByName (const UserObjectName &name) const
 Get a sampler with a given name. More...
 
template<typename T = SurrogateTrainerBase>
T & getSurrogateTrainerByName (const UserObjectName &name) const
 

Detailed Description

Definition at line 23 of file PODFullSolveMultiApp.h.

Constructor & Destructor Documentation

◆ PODFullSolveMultiApp()

PODFullSolveMultiApp::PODFullSolveMultiApp ( const InputParameters parameters)

Definition at line 34 of file PODFullSolveMultiApp.C.

37  _trainer(getSurrogateTrainer<PODReducedBasisTrainer>("trainer_name")),
39 {
40  if (getParam<unsigned int>("max_procs_per_app") != 1)
41  paramError("max_procs_per_app", " does not support more than one processors per subapp!");
42 
44  mooseError(type(),
45  " needs to be run with fewer processors (detected ",
46  n_processors(),
47  ") than samples (detected ",
49  ")!");
50 }
SamplerFullSolveMultiApp(const InputParameters &parameters)
processor_id_type n_processors() const
Sampler & _sampler
Sampler to utilize for creating MultiApps.
bool _snapshot_generation
Switch used to differentiate between snapshot generation and residual computation.
const std::string & type() const
void paramError(const std::string &param, Args... args) const
dof_id_type getNumberOfRows() const
PODReducedBasisTrainer & _trainer
Pointer to the trainer object itself.
void mooseError(Args &&... args) const
const InputParameters & parameters() const
SurrogateModelInterface(const MooseObject *moose_object)

Member Function Documentation

◆ computeResidual()

void PODFullSolveMultiApp::computeResidual ( )
protected

Evaluating the residuals for every tag in the trainer.

Definition at line 101 of file PODFullSolveMultiApp.C.

Referenced by computeResidualBatch(), and solveStep().

102 {
103  // Doing the regular computation but instead of solving the subapplication,
104  // the residuals for different tags are evaluated.
105  if (!_has_an_app)
106  return;
107 
109 
110  int rank;
111  int ierr;
112  ierr = MPI_Comm_rank(_communicator.get(), &rank);
113  mooseCheckMPIErr(ierr);
114 
115  // Getting the necessary tag names.
116  const std::vector<std::string> & trainer_tags = _trainer.getTagNames();
117 
118  // Looping over the subapplications and computing residuals.
119  for (unsigned int i = 0; i < _my_num_apps; i++)
120  {
121  // Getting the local problem
122  FEProblemBase & problem = _apps[i]->getExecutioner()->feProblem();
123 
124  // Extracting the TagIDs based on tag names from the current subapp.
125  std::set<TagID> tags_to_compute;
126  for (auto & tag_name : trainer_tags)
127  tags_to_compute.insert(problem.getVectorTagID(tag_name));
128 
129  problem.setCurrentNonlinearSystem(0);
130  problem.computeResidualTags(tags_to_compute);
131  }
132 }
virtual TagID getVectorTagID(const TagName &tag_name) const
std::vector< std::shared_ptr< MooseApp > > _apps
const Parallel::Communicator & _communicator
virtual void computeResidualTags(const std::set< TagID > &tags)
void setCurrentNonlinearSystem(const unsigned int nl_sys_num)
const std::vector< std::string > & getTagNames() const
unsigned int _my_num_apps
PODReducedBasisTrainer & _trainer
Pointer to the trainer object itself.
MPI_Comm & _my_comm

◆ computeResidualBatch()

void PODFullSolveMultiApp::computeResidualBatch ( Real  target_time)
protected

Evaluating the residuals for every tag in the trainer in batch mode.

Definition at line 135 of file PODFullSolveMultiApp.C.

Referenced by solveStep().

136 {
137  // Getting the overall base size from the trainer.
138  dof_id_type base_size = _trainer.getSumBaseSize();
139 
140  // Distributing the residual evaluation among processes.
141  dof_id_type local_base_begin;
142  dof_id_type local_base_end;
143  dof_id_type n_local_bases;
145  base_size, n_processors(), processor_id(), n_local_bases, local_base_begin, local_base_end);
146 
147  // List of active relevant Transfer objects
148  std::vector<std::shared_ptr<PODSamplerSolutionTransfer>> to_transfers =
150  std::vector<std::shared_ptr<PODResidualTransfer>> from_transfers =
152 
153  // Initialize to/from transfers
154  for (auto transfer : to_transfers)
155  transfer->initializeToMultiapp();
156 
157  for (auto transfer : from_transfers)
158  transfer->initializeFromMultiapp();
159 
161  backup();
162 
163  // Perform batch MultiApp solves
165  for (dof_id_type i = local_base_begin; i < local_base_end; ++i)
166  {
167  for (auto & transfer : to_transfers)
168  {
169  transfer->setGlobalMultiAppIndex(i);
170  transfer->executeToMultiapp();
171  }
172 
173  computeResidual();
174 
175  for (auto & transfer : from_transfers)
176  {
177  transfer->setGlobalMultiAppIndex(i);
178  transfer->executeFromMultiapp();
179  }
180 
181  if (i < _sampler.getLocalRowEnd() - 1)
182  {
184  restore();
185  else
186  {
187  // The app is being reset for the next loop, thus the batch index must be indexed as such
189  resetApp(_local_batch_app_index + i, target_time);
190  initialSetup();
191  }
192  }
193  }
194 
195  // Finalize to/from transfers
196  for (auto transfer : to_transfers)
197  transfer->finalizeToMultiapp();
198  for (auto transfer : from_transfers)
199  transfer->finalizeFromMultiapp();
200 }
const StochasticTools::MultiAppMode _mode
The Sup-application solve mode.
virtual void initialSetup() override
virtual void backup()
std::vector< std::shared_ptr< PODResidualTransfer > > getActiveResidualTransfers(Transfer::DIRECTION direction)
Returning pointers to the solution transfers. Used in batch mode.
std::vector< std::shared_ptr< PODSamplerSolutionTransfer > > getActiveSolutionTransfers(Transfer::DIRECTION direction)
Returning pointers to the solution transfers. Used in batch mode.
dof_id_type _local_batch_app_index
Counter for extracting command line arguments in batch mode.
void linearPartitionItems(dof_id_type num_items, dof_id_type num_chunks, dof_id_type chunk_id, dof_id_type &num_local_items, dof_id_type &local_items_begin, dof_id_type &local_items_end)
processor_id_type n_processors() const
Sampler & _sampler
Sampler to utilize for creating MultiApps.
virtual void resetApp(unsigned int global_app, Real time=0.0)
dof_id_type getLocalRowEnd() const
virtual void restore(bool force=true) override
PODReducedBasisTrainer & _trainer
Pointer to the trainer object itself.
processor_id_type processor_id() const
unsigned int getSumBaseSize() const
Getting the overall base size, which is the sum of the individual bases.
uint8_t dof_id_type
void computeResidual()
Evaluating the residuals for every tag in the trainer.

◆ 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 
)
staticinherited

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

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

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

◆ getActiveResidualTransfers()

std::vector< std::shared_ptr< PODResidualTransfer > > PODFullSolveMultiApp::getActiveResidualTransfers ( Transfer::DIRECTION  direction)
protected

Returning pointers to the solution transfers. Used in batch mode.

Definition at line 218 of file PODFullSolveMultiApp.C.

Referenced by computeResidualBatch().

219 {
220  std::vector<std::shared_ptr<PODResidualTransfer>> output;
221  const ExecuteMooseObjectWarehouse<Transfer> & warehouse =
223  for (std::shared_ptr<Transfer> transfer : warehouse.getActiveObjects())
224  {
225  auto ptr = std::dynamic_pointer_cast<PODResidualTransfer>(transfer);
226  if (ptr)
227  output.push_back(ptr);
228  }
229  return output;
230 }
FEProblemBase & _fe_problem
const std::vector< std::shared_ptr< Transfer > > & getActiveObjects(THREAD_ID tid=0) const
Transfers residuals for given variables and vector tags from a sub-subapplication to a PODReducedBasi...
const ExecuteMooseObjectWarehouse< Transfer > & getMultiAppTransferWarehouse(Transfer::DIRECTION direction) const

◆ getActiveSolutionTransfers()

std::vector< std::shared_ptr< PODSamplerSolutionTransfer > > PODFullSolveMultiApp::getActiveSolutionTransfers ( Transfer::DIRECTION  direction)
protected

Returning pointers to the solution transfers. Used in batch mode.

Definition at line 203 of file PODFullSolveMultiApp.C.

Referenced by computeResidualBatch().

204 {
205  std::vector<std::shared_ptr<PODSamplerSolutionTransfer>> output;
206  const ExecuteMooseObjectWarehouse<Transfer> & warehouse =
208  for (std::shared_ptr<Transfer> transfer : warehouse.getActiveObjects())
209  {
210  auto ptr = std::dynamic_pointer_cast<PODSamplerSolutionTransfer>(transfer);
211  if (ptr)
212  output.push_back(ptr);
213  }
214  return output;
215 }
Transfer solutions from sub-applications to a container in a Trainer.
FEProblemBase & _fe_problem
const std::vector< std::shared_ptr< Transfer > > & getActiveObjects(THREAD_ID tid=0) const
const ExecuteMooseObjectWarehouse< Transfer > & getMultiAppTransferWarehouse(Transfer::DIRECTION direction) const

◆ getCommandLineArgs()

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

Override to allow for batch mode to get correct cli_args.

Reimplemented from FullSolveMultiApp.

Definition at line 340 of file SamplerFullSolveMultiApp.C.

341 {
342  std::vector<std::string> args;
343 
344  // With multiple processors per app, there are no local rows for non-root processors
345  if (isRootProcessor())
346  {
347  // Since we only store param_names in cli_args, we need to find the values for each param from
348  // sampler data and combine them to get full command line option strings.
351 
353  }
354 
356  return args;
357 }
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 std::vector< std::string > getCommandLineArgs(const unsigned int local_app)
std::vector< Real > _row_data
Current row of data updated by updateRowData. Used by transfers and setting command line 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.
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.

◆ getSurrogateModel() [1/2]

template<>
SurrogateModel& SurrogateModelInterface::getSurrogateModel ( const std::string &  name) const
inherited

Definition at line 46 of file SurrogateModelInterface.C.

47 {
48  return getSurrogateModelByName<SurrogateModel>(_smi_params.get<UserObjectName>(name));
49 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateModel() [2/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateModel ( const std::string &  name) const
inherited

Get a SurrogateModel/Trainer with a given name.

Parameters
nameThe name of the parameter key of the sampler to retrieve
Returns
The sampler with name associated with the parameter 'name'

Definition at line 81 of file SurrogateModelInterface.h.

Referenced by SurrogateTrainer::initialize().

82 {
83  return getSurrogateModelByName<T>(_smi_params.get<UserObjectName>(name));
84 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateModelByName() [1/2]

template<>
SurrogateModel& SurrogateModelInterface::getSurrogateModelByName ( const UserObjectName &  name) const
inherited

Definition at line 31 of file SurrogateModelInterface.C.

32 {
33  std::vector<SurrogateModel *> models;
35  .query()
36  .condition<AttribName>(name)
37  .condition<AttribSystem>("SurrogateModel")
38  .queryInto(models);
39  if (models.empty())
40  mooseError("Unable to find a SurrogateModel object with the name '" + name + "'");
41  return *(models[0]);
42 }
void mooseError(Args &&... args)
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
TheWarehouse & theWarehouse() const
const std::string name
Definition: Setup.h:20
Query query()

◆ getSurrogateModelByName() [2/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateModelByName ( const UserObjectName &  name) const
inherited

Get a sampler with a given name.

Parameters
nameThe name of the sampler to retrieve
Returns
The sampler with name 'name'

Definition at line 88 of file SurrogateModelInterface.h.

Referenced by CrossValidationScores::CrossValidationScores(), EvaluateSurrogate::EvaluateSurrogate(), and InverseMapping::initialSetup().

89 {
90  std::vector<T *> models;
92  .query()
93  .condition<AttribName>(name)
94  .condition<AttribSystem>("SurrogateModel")
95  .queryInto(models);
96  if (models.empty())
97  mooseError("Unable to find a SurrogateModel object of type " + std::string(typeid(T).name()) +
98  " with the name '" + name + "'");
99  return *(models[0]);
100 }
void mooseError(Args &&... args)
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
TheWarehouse & theWarehouse() const
const std::string name
Definition: Setup.h:20
Query query()

◆ getSurrogateTrainer() [1/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateTrainer ( const std::string &  name) const
inherited

Definition at line 104 of file SurrogateModelInterface.h.

105 {
106  return getSurrogateTrainerByName<T>(_smi_params.get<UserObjectName>(name));
107 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateTrainer() [2/2]

template<>
SurrogateTrainerBase& SurrogateModelInterface::getSurrogateTrainer ( const std::string &  name) const
inherited

Definition at line 60 of file SurrogateModelInterface.C.

61 {
62  return getSurrogateTrainerByName<SurrogateTrainerBase>(_smi_params.get<UserObjectName>(name));
63 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateTrainerByName() [1/2]

template<>
SurrogateTrainerBase& SurrogateModelInterface::getSurrogateTrainerByName ( const UserObjectName &  name) const
inherited

Definition at line 53 of file SurrogateModelInterface.C.

54 {
56 }
T & getUserObject(const std::string &name, unsigned int tid=0) const
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
const std::string name
Definition: Setup.h:20
This is the base trainer class whose main functionality is the API for declaring model data...

◆ getSurrogateTrainerByName() [2/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateTrainerByName ( const UserObjectName &  name) const
inherited

Definition at line 111 of file SurrogateModelInterface.h.

Referenced by SurrogateTrainerOutput::output().

112 {
113  SurrogateTrainerBase * base_ptr =
115  T * obj_ptr = dynamic_cast<T *>(base_ptr);
116  if (!obj_ptr)
117  mooseError("Failed to find a SurrogateTrainer object of type " + std::string(typeid(T).name()) +
118  " with the name '",
119  name,
120  "' for the desired type.");
121  return *obj_ptr;
122 }
T & getUserObject(const std::string &name, unsigned int tid=0) const
void mooseError(Args &&... args)
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
const std::string name
Definition: Setup.h:20
const THREAD_ID _smi_tid
Thread ID.
This is the base trainer class whose main functionality is the API for declaring model data...

◆ preTransfer()

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

Overriding preTransfer to reinit the subappliations if the object needs to be executed twice.

Reimplemented from SamplerFullSolveMultiApp.

Definition at line 53 of file PODFullSolveMultiApp.C.

54 {
55  // Reinitialize the problem only if the snapshot generation part is done.
57  {
58  dof_id_type base_size = _trainer.getSumBaseSize();
59  if (base_size < 1)
60  mooseError(
61  "There are no basis vectors available for residual generation."
62  " This indicates that the bases have not been created yet."
63  " The most common cause of this error is the wrong setting"
64  " of the 'execute_on' flags in the PODFullSolveMultiApp and/or PODReducedBasisTrainer.");
65 
66  init(base_size,
69 
70  initialSetup();
71  }
73 }
const StochasticTools::MultiAppMode _mode
The Sup-application solve mode.
virtual void initialSetup() override
Sampler & _sampler
Sampler to utilize for creating MultiApps.
bool _snapshot_generation
Switch used to differentiate between snapshot generation and residual computation.
const LocalRankConfig & getRankConfig(bool batch_mode) const
virtual void preTransfer(Real dt, Real target_time) override
PODReducedBasisTrainer & _trainer
Pointer to the trainer object itself.
void mooseError(Args &&... args) const
void init(unsigned int num_apps, bool batch_mode=false)
unsigned int getSumBaseSize() const
Getting the overall base size, which is the sum of the individual bases.
uint8_t dof_id_type

◆ sampledCommandLineArgs()

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

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

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

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

◆ showStatusMessage()

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

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

Reimplemented from FullSolveMultiApp.

Definition at line 290 of file SamplerFullSolveMultiApp.C.

291 {
292  // Local row is the app index if in normal mode, otherwise it's _local_batch_app_index
293  const dof_id_type local_row =
295  // If the local row is less than the number of local sims, we aren't finished yet
296  if (local_row < _rank_config.num_local_sims - 1)
297  return;
298 
299  // Loop through processors to communicate completeness
300  for (const auto & pid : make_range(n_processors()))
301  {
302  // This is what is being sent to trigger completeness
305  : 0;
306  // Cannot send/receive to the same processor, so avoid if root
307  if (pid > 0)
308  {
309  // Send data to root
310  if (pid == processor_id())
311  _communicator.send(0, last_row);
312  // Receive data from source
313  else if (processor_id() == 0)
314  _communicator.receive(pid, last_row);
315  }
316 
317  // Output the samples that are complete if it's the main processor for the batch
318  if (last_row)
319  _console << COLOR_CYAN << type() << " [" << name() << "] " << last_row << "/"
320  << _number_of_sampler_rows << " samples complete!" << std::endl;
321  }
322 }
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

◆ snapshotGeneration()

bool PODFullSolveMultiApp::snapshotGeneration ( )
inline

Returning the value of the snapshot generation flag.

Definition at line 37 of file PODFullSolveMultiApp.h.

37 { return _snapshot_generation; }
bool _snapshot_generation
Switch used to differentiate between snapshot generation and residual computation.

◆ solveStep()

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

Reimplemented from SamplerFullSolveMultiApp.

Definition at line 76 of file PODFullSolveMultiApp.C.

77 {
78 
79  bool last_solve_converged = true;
80 
81  // If snapshot generation phase, solve the subapplications in a regular manner.
82  // Otherwise, compute the residuals only.
84  {
85  last_solve_converged = SamplerFullSolveMultiApp::solveStep(dt, target_time, auto_advance);
86  _snapshot_generation = false;
87  }
88  else
89  {
92  computeResidualBatch(target_time);
93  else
95  }
96 
97  return last_solve_converged;
98 }
const StochasticTools::MultiAppMode _mode
The Sup-application solve mode.
virtual bool solveStep(Real dt, Real target_time, bool auto_advance=true) override
bool _snapshot_generation
Switch used to differentiate between snapshot generation and residual computation.
void computeResidualBatch(Real target_time)
Evaluating the residuals for every tag in the trainer in batch mode.
void computeResidual()
Evaluating the residuals for every tag in the trainer.

◆ validParams()

InputParameters PODFullSolveMultiApp::validParams ( )
static

Definition at line 21 of file PODFullSolveMultiApp.C.

22 {
24  params.addClassDescription(
25  "Creates a full-solve type sub-application for each row of a Sampler matrix. "
26  "On second call, this object creates residuals for a PODReducedBasisTrainer with given basis "
27  "functions.");
28  params.addRequiredParam<UserObjectName>(
29  "trainer_name", "Trainer object that contains the solutions for different samples.");
30 
31  return params;
32 }
void addRequiredParam(const std::string &name, const std::string &doc_string)
static InputParameters validParams()
void addClassDescription(const std::string &doc_string)

Member Data Documentation

◆ _local_batch_app_index

dof_id_type SamplerFullSolveMultiApp::_local_batch_app_index
protectedinherited

◆ _mode

const StochasticTools::MultiAppMode SamplerFullSolveMultiApp::_mode
protectedinherited

◆ _sampler

Sampler& SamplerFullSolveMultiApp::_sampler
protectedinherited

◆ _snapshot_generation

bool PODFullSolveMultiApp::_snapshot_generation
protected

Switch used to differentiate between snapshot generation and residual computation.

Residual generation is only possible after the snapshot generation part is complete.

Definition at line 60 of file PODFullSolveMultiApp.h.

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

◆ _trainer

PODReducedBasisTrainer& PODFullSolveMultiApp::_trainer
protected

Pointer to the trainer object itself.

Definition at line 55 of file PODFullSolveMultiApp.h.

Referenced by computeResidual(), computeResidualBatch(), and preTransfer().


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