www.mooseframework.org
SamplerPostprocessorTransfer.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
8 // StochasticTools includes
10 #include "SamplerMultiApp.h"
11 #include "SamplerReceiver.h"
12 #include "StochasticResults.h"
13 
14 template <>
15 InputParameters
17 {
18  InputParameters params = validParams<MultiAppTransfer>();
19  params.addClassDescription("Transfers data to and from Postprocessors on the sub-application.");
20  params.addParam<VectorPostprocessorName>(
21  "results",
22  "Name of the StochasticResults object that the results are to be stored or extracted.");
23  params.addParam<std::string>(
24  "postprocessor", "Name of the Postprocessor on the sub-application to transfer to or from.");
25  params.set<MooseEnum>("direction") = "from_multiapp";
26  params.suppressParameter<MooseEnum>("direction");
27  return params;
28 }
29 
31  : MultiAppTransfer(parameters),
32  _results_name(getParam<VectorPostprocessorName>("results")),
33  _sampler_multi_app(std::dynamic_pointer_cast<SamplerMultiApp>(_multi_app).get()),
34  _sampler(_sampler_multi_app->getSampler()),
35  _sub_pp_name(getParam<std::string>("postprocessor"))
36 {
37  if (!_sampler_multi_app)
38  mooseError("The 'multi_app' must be a 'SamplerMultiApp.'");
39 }
40 
41 void
43 {
44  const ExecuteMooseObjectWarehouse<UserObject> & user_objects = _fe_problem.getUserObjects();
45  UserObject * uo = user_objects.getActiveObject(_results_name).get();
46  _results = dynamic_cast<StochasticResults *>(uo);
47 
48  if (!_results)
49  mooseError("The 'results' object must be a 'StochasticResults' object.");
50 
52 }
53 
54 void
56 {
57  // Number of PP is equal to the number of MultiApps
58  const unsigned int n = _multi_app->numGlobalApps();
59 
60  // Collect the PP values for this processor
61  std::vector<PostprocessorValue> values;
62  values.reserve(_multi_app->numLocalApps());
63  for (unsigned int i = 0; i < n; i++)
64  {
65  if (_multi_app->hasLocalApp(i))
66  {
67  FEProblemBase & app_problem = _multi_app->appProblemBase(i);
68 
69  // use reserve and push_back b/c access to FEProblemBase is based on global id
70  values.push_back(app_problem.getPostprocessorValue(_sub_pp_name));
71  }
72  }
73 
74  // Gather the PP values from all ranks
75  _communicator.allgather<PostprocessorValue>(values);
76 
77  // Update VPP
78  for (unsigned int i = 0; i < n; i++)
79  {
80  Sampler::Location loc = _sampler.getLocation(i);
81  VectorPostprocessorValue & vpp = _results->getVectorPostprocessorValueByGroup(loc.sample());
82  vpp[loc.row()] = values[i];
83  }
84 }
SamplerPostprocessorTransfer(const InputParameters &parameters)
void init(Sampler &_sampler)
Initialize storage based on the Sampler returned by the SamplerMultiApp.
StochasticResults * _results
Storage for StochasticResults object that data will be transferred to/from.
VectorPostprocessorValue & getVectorPostprocessorValueByGroup(unsigned int group)
Return the VectorPostprocessorValue for a given Sampler group index.
Sampler & _sampler
Sampler object that is retrieved from the SamplerMultiApp.
SamplerMultiApp * _sampler_multi_app
SamplerMultiApp that this transfer is working with.
const VectorPostprocessorName & _results_name
Name of VPP that will store the data.
A tool for output Sampler data.
InputParameters validParams< SamplerPostprocessorTransfer >()
const std::string & _sub_pp_name
Name of Postprocessor transferring from.