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

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 SamplerTransfer
 Allows the SamplerTransfer 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 26 of file SamplerReceiver.h.

Constructor & Destructor Documentation

◆ SamplerReceiver()

SamplerReceiver::SamplerReceiver ( const InputParameters &  parameters)

Definition at line 26 of file SamplerReceiver.C.

26 : Control(parameters) {}

Member Function Documentation

◆ execute()

void SamplerReceiver::execute ( )
overridevirtual

Definition at line 29 of file SamplerReceiver.C.

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

◆ 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 103 of file SamplerReceiver.C.

Referenced by SamplerTransfer::execute().

104 {
105  _parameters = names;
106  _values = values;
107 }
std::vector< std::string > _parameters
Parameter names to modify.
std::vector< Real > _values
Values to use when modifying parameters.

Friends And Related Function Documentation

◆ SamplerTransfer

friend class SamplerTransfer
friend

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

Definition at line 46 of file SamplerReceiver.h.

Member Data Documentation

◆ _parameters

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

Parameter names to modify.

Definition at line 39 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 42 of file SamplerReceiver.h.

Referenced by execute(), and transfer().


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