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

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

#include <SamplerReceiver.h>

Inheritance diagram for SamplerReceiver:
[legend]

Public Member Functions

 SamplerReceiver (const InputParameters &parameters)
 
virtual void execute () override
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Member Functions

void transfer (const std::vector< std::string > &names, const std::vector< Real > &values)
 Update the parameter names and associated values. More...
 

Protected Attributes

std::vector< std::string > _parameters
 Parameter names to modify. More...
 
std::vector< Real > _values
 Values to use when modifying parameters. More...
 

Friends

class SamplerParameterTransfer
 Allows the SamplerParameterTransfer to call the transfer method, which should only be called by that object so making it public is dangerous. More...
 

Detailed Description

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

Definition at line 25 of file SamplerReceiver.h.

Constructor & Destructor Documentation

◆ SamplerReceiver()

SamplerReceiver::SamplerReceiver ( const InputParameters &  parameters)

Definition at line 28 of file SamplerReceiver.C.

28 : Control(parameters) {}

Member Function Documentation

◆ execute()

void SamplerReceiver::execute ( )
overridevirtual

Definition at line 31 of file SamplerReceiver.C.

32 {
33  std::size_t value_position = 0;
34 
35  // Loop through all the parameters and set the controllable values for each parameter.
36  for (const std::string & param_name : _parameters)
37  {
38  ControllableParameter control_param = getControllableParameterByName(param_name);
39 
40  // Real
41  if (control_param.check<Real>())
42  {
43  // There must be enough data to populate the controlled parameter
44  if (value_position >= _values.size())
45  mooseError("The supplied vector of Real values is not sized correctly, the "
46  "Real parameter '",
47  param_name,
48  " requires a value but no more values are available in "
49  "the supplied values which have a size of ",
50  _values.size(),
51  ".");
52  control_param.set<Real>(_values[value_position++]);
53  }
54 
55  else if (control_param.check<std::vector<Real>>())
56  {
57  std::vector<std::vector<Real>> values = control_param.get<std::vector<Real>>();
58  mooseAssert(values.size() != 0,
59  "ControllableParameter must not be empty."); // should not be possible
60  std::size_t n = values[0].size(); // size of vector to changed
61 
62  // All vectors being controlled must be the same size
63  for (const std::vector<Real> & value : values)
64  if (value.size() != n)
65  mooseError(
66  "The std::vector<Real> parameters being controlled must all be the same size:\n",
67  control_param.dump());
68 
69  // There must be enough data to populate the controlled parameter
70  if (value_position + n > _values.size())
71  mooseError("The supplied vector of Real values is not sized correctly, the "
72  "std::vector<Real> parameter '",
73  param_name,
74  " requires ",
75  n,
76  " values but only ",
77  _values.size() - value_position,
78  " are available in the supplied vector.");
79 
80  // Set the value
81  std::vector<Real> value(_values.begin() + value_position,
82  _values.begin() + value_position + n);
83  value_position += n;
84  control_param.set<std::vector<Real>>(value);
85  }
86 
87  else
88 
89  // If the loop gets here it failed to find what it was looking for
90  mooseError("Unable to locate a Real or std::vector<Real> parameter with the name '",
91  param_name,
92  ".'");
93  }
94 
95  // Error if there is un-used values
96  if (value_position != _values.size())
97  mooseError("The number of values supplied (",
98  _values.size(),
99  ") does not match the number of values consumed by setting parameter values (",
100  value_position,
101  ").");
102 }

◆ transfer()

void SamplerReceiver::transfer ( const std::vector< std::string > &  names,
const std::vector< Real > &  values 
)
protected

Update the parameter names and associated values.

Definition at line 105 of file SamplerReceiver.C.

106 {
107  _parameters = names;
108  _values = values;
109 }

Referenced by SamplerParameterTransfer::executeToMultiapp().

◆ validParams()

InputParameters SamplerReceiver::validParams ( )
static

Definition at line 19 of file SamplerReceiver.C.

20 {
21  InputParameters params = Control::validParams();
22  params.addClassDescription(
23  "Control for receiving data from a Sampler via SamplerParameterTransfer.");
24  params.set<ExecFlagEnum>("execute_on") = EXEC_TIMESTEP_BEGIN;
25  return params;
26 }

Friends And Related Function Documentation

◆ SamplerParameterTransfer

friend class SamplerParameterTransfer
friend

Allows the SamplerParameterTransfer to call the transfer method, which should only be called by that object so making it public is dangerous.

Definition at line 47 of file SamplerReceiver.h.

Member Data Documentation

◆ _parameters

std::vector<std::string> SamplerReceiver::_parameters
protected

Parameter names to modify.

Definition at line 40 of file SamplerReceiver.h.

Referenced by execute(), and transfer().

◆ _values

std::vector<Real> SamplerReceiver::_values
protected

Values to use when modifying parameters.

Definition at line 43 of file SamplerReceiver.h.

Referenced by execute(), and transfer().


The documentation for this class was generated from the following files:
SamplerReceiver::_values
std::vector< Real > _values
Values to use when modifying parameters.
Definition: SamplerReceiver.h:43
SamplerReceiver::_parameters
std::vector< std::string > _parameters
Parameter names to modify.
Definition: SamplerReceiver.h:40
validParams
InputParameters validParams()