www.mooseframework.org
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
 

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 30 of file MultiAppCommandLineControl.h.

Constructor & Destructor Documentation

◆ MultiAppCommandLineControl()

MultiAppCommandLineControl::MultiAppCommandLineControl ( const InputParameters &  parameters)

Definition at line 40 of file MultiAppCommandLineControl.C.

41  : Control(parameters),
42  SamplerInterface(this),
43  _multi_app(_fe_problem.getMultiApp(getParam<MultiAppName>("multi_app"))),
44  _sampler(SamplerInterface::getSampler("sampler")),
45  _param_names(getParam<std::vector<std::string>>("param_names"))
46 {
47  if (_multi_app->numGlobalApps() != _sampler.getTotalNumberOfRows())
48  mooseError("The number of sub apps (",
49  _multi_app->numGlobalApps(),
50  ") created by MultiApp object '",
51  _multi_app->name(),
52  "' must be equal to the number for rows (",
53  _sampler.getTotalNumberOfRows(),
54  ") for the '",
55  _sampler.name(),
56  "' Sampler object.");
57 }
std::shared_ptr< MultiApp > _multi_app
The MultiApp this Transfer is transferring data to or from.
Sampler & _sampler
Sampler to utilize for creating MultiApps.
const std::vector< std::string > & _param_names
Storage for the parameter names to be applied.

Member Function Documentation

◆ execute()

void MultiAppCommandLineControl::execute ( )
overridevirtual

Definition at line 67 of file MultiAppCommandLineControl.C.

68 {
69  std::vector<std::string> cli_args;
70  std::vector<DenseMatrix<Real>> samples = _sampler.getSamples();
71 
72  for (const DenseMatrix<Real> & matrix : samples)
73  {
74  if (matrix.n() != _param_names.size())
75  paramError("param_names",
76  "The number of columns (",
77  matrix.n(),
78  ") must match the number of parameters (",
79  _param_names.size(),
80  ").");
81 
82  for (unsigned int row = 0; row < matrix.m(); ++row)
83  {
84  std::ostringstream oss;
85  for (unsigned int col = 0; col < matrix.n(); ++col)
86  {
87  if (col > 0)
88  oss << ";";
89  oss << _param_names[col] << "=" << Moose::stringify(matrix(row, col));
90  }
91 
92  cli_args.push_back(oss.str());
93  }
94  }
95 
96  setControllableValueByName<std::vector<std::string>>(
97  "MultiApp", _multi_app->name(), "cli_args", cli_args);
98 }
std::shared_ptr< MultiApp > _multi_app
The MultiApp this Transfer is transferring data to or from.
Sampler & _sampler
Sampler to utilize for creating MultiApps.
const std::vector< std::string > & _param_names
Storage for the parameter names to be applied.

◆ 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 60 of file MultiAppCommandLineControl.C.

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

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 46 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 52 of file MultiAppCommandLineControl.h.

Referenced by execute().

◆ _sampler

Sampler& MultiAppCommandLineControl::_sampler
protected

Sampler to utilize for creating MultiApps.

Definition at line 49 of file MultiAppCommandLineControl.h.

Referenced by execute(), and MultiAppCommandLineControl().


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