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

Copy each row from each DenseMatrix to the sub-applications SamplerReceiver object. More...

#include <SamplerTransfer.h>

Inheritance diagram for SamplerTransfer:
[legend]

Public Member Functions

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

Protected Member Functions

SamplerReceivergetReceiver (unsigned int app_index, const std::vector< DenseMatrix< Real >> &samples)
 Return the SamplerReceiver object and perform error checking. More...
 

Protected Attributes

const std::vector< std::string > & _parameter_names
 Storage for the list of parameters to control. More...
 
Sampler * _sampler_ptr
 Pointer to the Sampler object used by the SamplerMultiApp. More...
 
const std::string & _receiver_name
 The name of the SamplerReceiver Control object on the sub-application. More...
 
std::vector< std::pair< unsigned int, unsigned int > > _multi_app_matrix_row
 The matrix and row for each MultiApp. More...
 

Detailed Description

Copy each row from each DenseMatrix to the sub-applications SamplerReceiver object.

Definition at line 25 of file SamplerTransfer.h.

Constructor & Destructor Documentation

SamplerTransfer::SamplerTransfer ( const InputParameters &  parameters)

Definition at line 32 of file SamplerTransfer.C.

33  : MultiAppTransfer(parameters),
34  _parameter_names(getParam<std::vector<std::string>>("parameters")),
35  _receiver_name(getParam<std::string>("to_control"))
36 {
37 
38  // Determine the Sampler
39  std::shared_ptr<SamplerMultiApp> ptr = std::dynamic_pointer_cast<SamplerMultiApp>(_multi_app);
40  if (!ptr)
41  mooseError("The 'multi_app' parameter must provide a 'SamplerMultiApp' object.");
42  _sampler_ptr = &(ptr->getSampler());
43 
44  // Compute the matrix and row for each
45  std::vector<DenseMatrix<Real>> out = _sampler_ptr->getSamples();
46  for (auto mat = beginIndex(out); mat < out.size(); ++mat)
47  for (unsigned int row = 0; row < out[mat].m(); ++row)
48  _multi_app_matrix_row.push_back(std::make_pair(mat, row));
49 }
std::vector< std::pair< unsigned int, unsigned int > > _multi_app_matrix_row
The matrix and row for each MultiApp.
const std::vector< std::string > & _parameter_names
Storage for the list of parameters to control.
Sampler * _sampler_ptr
Pointer to the Sampler object used by the SamplerMultiApp.
const std::string & _receiver_name
The name of the SamplerReceiver Control object on the sub-application.

Member Function Documentation

void SamplerTransfer::execute ( )
overridevirtual

Definition at line 52 of file SamplerTransfer.C.

53 {
54  // Get the Sampler data
55  const std::vector<DenseMatrix<Real>> samples = _sampler_ptr->getSamples();
56 
57  // Loop over all sub-apps
58  for (unsigned int app_index = 0; app_index < _multi_app->numGlobalApps(); app_index++)
59  {
60  // Do nothing if the sub-app is not local
61  if (!_multi_app->hasLocalApp(app_index))
62  continue;
63 
64  // Get the sub-app SamplerReceiver object and perform error checking
65  SamplerReceiver * ptr = getReceiver(app_index, samples);
66 
67  // Perform the transfer
68  std::pair<unsigned int, unsigned int> loc = _multi_app_matrix_row[app_index];
69  ptr->reset(); // clears existing parameter settings
70  for (auto j = beginIndex(_parameter_names); j < _parameter_names.size(); ++j)
71  {
72  const Real & data = samples[loc.first](loc.second, j);
74  }
75  }
76 }
std::vector< std::pair< unsigned int, unsigned int > > _multi_app_matrix_row
The matrix and row for each MultiApp.
void addControlParameter(const std::string &name, const Real &value)
Appends the list of parameters to modify.
const std::vector< std::string > & _parameter_names
Storage for the list of parameters to control.
void reset()
Clears the list of parameters to modify.
SamplerReceiver * getReceiver(unsigned int app_index, const std::vector< DenseMatrix< Real >> &samples)
Return the SamplerReceiver object and perform error checking.
Sampler * _sampler_ptr
Pointer to the Sampler object used by the SamplerMultiApp.
A Control object for receiving data from a master application Sampler object.
SamplerReceiver * SamplerTransfer::getReceiver ( unsigned int  app_index,
const std::vector< DenseMatrix< Real >> &  samples 
)
protected

Return the SamplerReceiver object and perform error checking.

Parameters
app_indexThe global sup-app index

Definition at line 79 of file SamplerTransfer.C.

Referenced by execute().

80 {
81  // Test that the sub-application has the given Control object
82  FEProblemBase & to_problem = _multi_app->appProblemBase(app_index);
83  ExecuteMooseObjectWarehouse<Control> & control_wh = to_problem.getControlWarehouse();
84  if (!control_wh.hasActiveObject(_receiver_name))
85  mooseError("The sub-application (",
86  _multi_app->name(),
87  ") does not contain a Control object with the name '",
89  "'.");
90 
91  SamplerReceiver * ptr =
92  dynamic_cast<SamplerReceiver *>(control_wh.getActiveObject(_receiver_name).get());
93 
94  if (!ptr)
95  mooseError(
96  "The sub-application (",
97  _multi_app->name(),
98  ") Control object for the 'to_control' parameter must be of type 'SamplerReceiver'.");
99 
100  // Test the size of parameter list with the number of columns in Sampler matrix
101  std::pair<unsigned int, unsigned int> loc = _multi_app_matrix_row[app_index];
102  if (_parameter_names.size() != samples[loc.first].n())
103  mooseError("The number of parameters (",
104  _parameter_names.size(),
105  ") does not match the number of columns (",
106  samples[loc.first].n(),
107  ") in the Sampler data matrix with index ",
108  loc.first,
109  ".");
110 
111  return ptr;
112 }
std::vector< std::pair< unsigned int, unsigned int > > _multi_app_matrix_row
The matrix and row for each MultiApp.
const std::vector< std::string > & _parameter_names
Storage for the list of parameters to control.
A Control object for receiving data from a master application Sampler object.
const std::string & _receiver_name
The name of the SamplerReceiver Control object on the sub-application.

Member Data Documentation

std::vector<std::pair<unsigned int, unsigned int> > SamplerTransfer::_multi_app_matrix_row
protected

The matrix and row for each MultiApp.

Definition at line 49 of file SamplerTransfer.h.

Referenced by execute(), getReceiver(), and SamplerTransfer().

const std::vector<std::string>& SamplerTransfer::_parameter_names
protected

Storage for the list of parameters to control.

Definition at line 40 of file SamplerTransfer.h.

Referenced by execute(), and getReceiver().

const std::string& SamplerTransfer::_receiver_name
protected

The name of the SamplerReceiver Control object on the sub-application.

Definition at line 46 of file SamplerTransfer.h.

Referenced by getReceiver().

Sampler* SamplerTransfer::_sampler_ptr
protected

Pointer to the Sampler object used by the SamplerMultiApp.

Definition at line 43 of file SamplerTransfer.h.

Referenced by execute(), and SamplerTransfer().


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