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)
 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 27 of file SamplerTransfer.h.

Constructor & Destructor Documentation

◆ SamplerTransfer()

SamplerTransfer::SamplerTransfer ( const InputParameters &  parameters)

Definition at line 36 of file SamplerTransfer.C.

37  : MultiAppTransfer(parameters),
38  _parameter_names(getParam<std::vector<std::string>>("parameters")),
39  _receiver_name(getParam<std::string>("to_control"))
40 {
41 
42  // Determine the Sampler
43  std::shared_ptr<SamplerMultiApp> ptr = std::dynamic_pointer_cast<SamplerMultiApp>(_multi_app);
44  if (!ptr)
45  mooseError("The 'multi_app' parameter must provide a 'SamplerMultiApp' object.");
46  _sampler_ptr = &(ptr->getSampler());
47 
48  // Compute the matrix and row for each
49  std::vector<DenseMatrix<Real>> out = _sampler_ptr->getSamples();
50  for (auto mat = beginIndex(out); mat < out.size(); ++mat)
51  for (unsigned int row = 0; row < out[mat].m(); ++row)
52  _multi_app_matrix_row.push_back(std::make_pair(mat, row));
53 }
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

◆ execute()

void SamplerTransfer::execute ( )
overridevirtual

Definition at line 56 of file SamplerTransfer.C.

57 {
58  // Get the Sampler data
59  const std::vector<DenseMatrix<Real>> samples = _sampler_ptr->getSamples();
60 
61  // Loop over all sub-apps
62  for (unsigned int app_index = 0; app_index < _multi_app->numGlobalApps(); app_index++)
63  {
64  // Do nothing if the sub-app is not local
65  if (!_multi_app->hasLocalApp(app_index))
66  continue;
67 
68  // Get the sub-app SamplerReceiver object and perform error checking
69  SamplerReceiver * ptr = getReceiver(app_index);
70 
71  // Populate the row of data to transfer
72  std::pair<unsigned int, unsigned int> loc = _multi_app_matrix_row[app_index];
73  std::vector<Real> row;
74  row.reserve(samples[loc.first].n());
75  for (unsigned int j = 0; j < samples[loc.first].n(); ++j)
76  row.emplace_back(samples[loc.first](loc.second, j));
77 
78  // Perform the transfer
79  ptr->transfer(_parameter_names, row);
80  }
81 }
std::vector< std::pair< unsigned int, unsigned int > > _multi_app_matrix_row
The matrix and row for each MultiApp.
SamplerReceiver * getReceiver(unsigned int app_index)
Return the SamplerReceiver object and perform error checking.
const std::vector< std::string > & _parameter_names
Storage for the list of parameters to control.
void transfer(const std::vector< std::string > &names, const std::vector< Real > &values)
Update the parameter names and associated values.
Sampler * _sampler_ptr
Pointer to the Sampler object used by the SamplerMultiApp.
A Control object for receiving data from a master application Sampler object.

◆ getReceiver()

SamplerReceiver * SamplerTransfer::getReceiver ( unsigned int  app_index)
protected

Return the SamplerReceiver object and perform error checking.

Parameters
app_indexThe global sup-app index

Definition at line 84 of file SamplerTransfer.C.

Referenced by execute().

85 {
86  // Test that the sub-application has the given Control object
87  FEProblemBase & to_problem = _multi_app->appProblemBase(app_index);
88  ExecuteMooseObjectWarehouse<Control> & control_wh = to_problem.getControlWarehouse();
89  if (!control_wh.hasActiveObject(_receiver_name))
90  mooseError("The sub-application (",
91  _multi_app->name(),
92  ") does not contain a Control object with the name '",
94  "'.");
95 
96  SamplerReceiver * ptr =
97  dynamic_cast<SamplerReceiver *>(control_wh.getActiveObject(_receiver_name).get());
98 
99  if (!ptr)
100  mooseError(
101  "The sub-application (",
102  _multi_app->name(),
103  ") Control object for the 'to_control' parameter must be of type 'SamplerReceiver'.");
104 
105  return ptr;
106 }
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

◆ _multi_app_matrix_row

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

The matrix and row for each MultiApp.

Definition at line 50 of file SamplerTransfer.h.

Referenced by execute(), and SamplerTransfer().

◆ _parameter_names

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

Storage for the list of parameters to control.

Definition at line 41 of file SamplerTransfer.h.

Referenced by execute().

◆ _receiver_name

const std::string& SamplerTransfer::_receiver_name
protected

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

Definition at line 47 of file SamplerTransfer.h.

Referenced by getReceiver().

◆ _sampler_ptr

Sampler* SamplerTransfer::_sampler_ptr
protected

Pointer to the Sampler object used by the SamplerMultiApp.

Definition at line 44 of file SamplerTransfer.h.

Referenced by execute(), and SamplerTransfer().


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