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

A Control object for receiving data from a master application Sampler object. More...

#include <MultiAppCommandLineControl.h>

Inheritance diagram for MultiAppCommandLineControl:
[legend]

Public Member Functions

 MultiAppCommandLineControl (const InputParameters &parameters)
 
virtual void initialSetup () override final
 Do not allow the use of initialSetup, because this class is designed to operate on PRE_MULTIAPP_SETUP, which occurs before this callback. More...
 
virtual void execute () override
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Attributes

std::shared_ptr< MultiApp > _multi_app
 The MultiApp this Transfer is transferring data to or from. More...
 
Sampler & _sampler
 Sampler to utilize for creating MultiApps. More...
 
const std::vector< std::string > & _param_names
 Storage for the parameter names to be applied. More...
 

Detailed Description

A Control object for receiving data from a master application Sampler object.

Definition at line 29 of file MultiAppCommandLineControl.h.

Constructor & Destructor Documentation

◆ MultiAppCommandLineControl()

MultiAppCommandLineControl::MultiAppCommandLineControl ( const InputParameters &  parameters)

Definition at line 42 of file MultiAppCommandLineControl.C.

43  : Control(parameters),
44  SamplerInterface(this),
45  _multi_app(_fe_problem.getMultiApp(getParam<MultiAppName>("multi_app"))),
46  _sampler(SamplerInterface::getSampler("sampler")),
47  _param_names(getParam<std::vector<std::string>>("param_names"))
48 {
49  if (!_sampler.getParamTempl<ExecFlagEnum>("execute_on").contains(EXEC_PRE_MULTIAPP_SETUP))
50  _sampler.paramError(
51  "execute_on",
52  "The sampler object, '",
53  _sampler.name(),
54  "', is being used by the '",
55  name(),
56  "' object, thus the 'execute_on' of the sampler must include 'PRE_MULTIAPP_SETUP'.");
57 
58  bool batch_reset = _multi_app->isParamValid("mode") &&
59  (_multi_app->getParamTempl<MooseEnum>("mode") == "batch-reset");
60  bool batch_restore = _multi_app->isParamValid("mode") &&
61  (_multi_app->getParamTempl<MooseEnum>("mode") == "batch-restore");
62  if (batch_reset)
63  ; // Do not perform the App count test, because in batch mode there is only one
64 
65  else if (batch_restore)
66  _multi_app->paramError(
67  "mode",
68  "The MultiApp object, '",
69  _multi_app->name(),
70  "', supplied to the '",
71  name(),
72  "' object is setup to run in 'batch-restore' mode, when using this mode command line "
73  "arguments cannot be modified; batch-reset mode should be used instead.");
74 
75  else if (_multi_app->numGlobalApps() != _sampler.getNumberOfRows())
76  mooseError("The number of sub apps (",
77  _multi_app->numGlobalApps(),
78  ") created by MultiApp object '",
79  _multi_app->name(),
80  "' must be equal to the number for rows (",
81  _sampler.getNumberOfRows(),
82  ") for the '",
83  _sampler.name(),
84  "' Sampler object.");
85 }

Member Function Documentation

◆ execute()

void MultiAppCommandLineControl::execute ( )
overridevirtual

Definition at line 95 of file MultiAppCommandLineControl.C.

96 {
97  std::vector<std::string> cli_args;
98 
99  if (_sampler.getNumberOfCols() != _param_names.size())
100  paramError("param_names",
101  "The number of columns (",
102  _sampler.getNumberOfCols(),
103  ") must match the number of parameters (",
104  _param_names.size(),
105  ").");
106 
107  // For SamplerFullSolveMultiApp, to avoid storing duplicated param_names for each sampler, we
108  // store only param_names once in "cli_args". For other MultApp, we store the full information
109  // of params_names and values for each sampler.
110 
111  if (std::dynamic_pointer_cast<SamplerFullSolveMultiApp>(_multi_app) == nullptr)
112  {
113  for (dof_id_type row = _sampler.getLocalRowBegin(); row < _sampler.getLocalRowEnd(); ++row)
114  {
115  std::vector<Real> data = _sampler.getNextLocalRow();
116  std::ostringstream oss;
117  for (std::size_t col = 0; col < data.size(); ++col)
118  {
119  if (col > 0)
120  oss << ";";
121  oss << _param_names[col] << "=" << Moose::stringify(data[col]);
122  }
123 
124  cli_args.push_back(oss.str());
125  }
126  }
127  else
128  {
129  std::ostringstream oss;
130  for (dof_id_type col = 0; col < _sampler.getNumberOfCols(); ++col)
131  {
132  if (col > 0)
133  oss << ";";
134  oss << _param_names[col];
135  }
136 
137  cli_args.push_back(oss.str());
138  }
139 
140  setControllableValueByName<std::vector<std::string>>(
141  "MultiApp", _multi_app->name(), "cli_args", cli_args);
142 }

◆ initialSetup()

void MultiAppCommandLineControl::initialSetup ( )
finaloverridevirtual

Do not allow the use of initialSetup, because this class is designed to operate on PRE_MULTIAPP_SETUP, which occurs before this callback.

This will prevent a child class adding something to this function without it doing anything.

Definition at line 88 of file MultiAppCommandLineControl.C.

89 {
90  // Do not put anything here, this method is being called after execute because the execute_on
91  // is set to PRE_MULTIAPP_SETUP for this class. It won't work any other way.
92 }

◆ validParams()

InputParameters MultiAppCommandLineControl::validParams ( )
static

Definition at line 22 of file MultiAppCommandLineControl.C.

23 {
24  InputParameters params = Control::validParams();
26  params.addClassDescription("Control for modifying the command line arguments of MultiApps.");
27 
28  // Set and suppress the 'execute_on' flag, it doesn't work with any other flag
29  params.set<ExecFlagEnum>("execute_on") = {EXEC_PRE_MULTIAPP_SETUP};
30  params.suppressParameter<ExecFlagEnum>("execute_on");
31 
32  params.addRequiredParam<MultiAppName>("multi_app", "The name of the MultiApp to control.");
33  params.addParam<SamplerName>(
34  "sampler",
35  "The Sampler object to utilize for altering the command line options of the MultiApp.");
36  params.addParam<std::vector<std::string>>(
37  "param_names", "The names of the command line parameters to set via the sampled data.");
38 
39  return params;
40 }

Member Data Documentation

◆ _multi_app

std::shared_ptr<MultiApp> MultiAppCommandLineControl::_multi_app
protected

The MultiApp this Transfer is transferring data to or from.

Definition at line 47 of file MultiAppCommandLineControl.h.

Referenced by execute(), and MultiAppCommandLineControl().

◆ _param_names

const std::vector<std::string>& MultiAppCommandLineControl::_param_names
protected

Storage for the parameter names to be applied.

Definition at line 53 of file MultiAppCommandLineControl.h.

Referenced by execute().

◆ _sampler

Sampler& MultiAppCommandLineControl::_sampler
protected

Sampler to utilize for creating MultiApps.

Definition at line 50 of file MultiAppCommandLineControl.h.

Referenced by execute(), and MultiAppCommandLineControl().


The documentation for this class was generated from the following files:
MultiAppCommandLineControl::_param_names
const std::vector< std::string > & _param_names
Storage for the parameter names to be applied.
Definition: MultiAppCommandLineControl.h:53
MultiAppCommandLineControl::_multi_app
std::shared_ptr< MultiApp > _multi_app
The MultiApp this Transfer is transferring data to or from.
Definition: MultiAppCommandLineControl.h:47
validParams
InputParameters validParams()
name
const std::string name
Definition: Setup.h:21
MultiAppCommandLineControl::_sampler
Sampler & _sampler
Sampler to utilize for creating MultiApps.
Definition: MultiAppCommandLineControl.h:50