www.mooseframework.org
SamplerPostprocessorTransfer.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 // StochasticTools includes
14 #include "SamplerReceiver.h"
15 #include "StochasticResults.h"
16 #include "Sampler.h"
17 
19 
21 
22 InputParameters
24 {
25  InputParameters params = StochasticToolsTransfer::validParams();
26  params.addClassDescription("Transfers data from Postprocessors on the sub-application to a "
27  "VectorPostprocessor on the master application.");
28  params.addParam<PostprocessorName>(
29  "from_postprocessor", "The name of the Postprocessors on the sub-app to transfer from.");
30  params.addParam<VectorPostprocessorName>("to_vector_postprocessor",
31  "The name of the VectorPostprocessor in "
32  "the MultiApp to transfer values "
33  "to.");
34 
35  params.addDeprecatedParam<PostprocessorName>(
36  "postprocessor",
37  "The name of the Postprocessors on the sub-app to transfer from.",
38  "Replaced by from_postprocessor");
39  params.addDeprecatedParam<VectorPostprocessorName>("vector_postprocessor",
40  "The name of the VectorPostprocessor in "
41  "the MultiApp to transfer values "
42  "to.",
43  "Replaced by to_vector_postprocessor");
44 
45  params.set<MultiMooseEnum>("direction") = "from_multiapp";
46  params.suppressParameter<MultiMooseEnum>("direction");
47  return params;
48 }
49 
51  : StochasticToolsTransfer(parameters),
52  _sub_pp_name(isParamValid("postprocessor") ? getParam<PostprocessorName>("postprocessor")
53  : getParam<PostprocessorName>("from_postprocessor")),
54  _master_vpp_name(isParamValid("vector_postprocessor")
55  ? getParam<VectorPostprocessorName>("vector_postprocessor")
56  : getParam<VectorPostprocessorName>("to_vector_postprocessor"))
57 {
58 }
59 
60 void
62 {
63  auto & uo = _fe_problem.getUserObjectTempl<UserObject>(_master_vpp_name);
64  _results = dynamic_cast<StochasticResults *>(&uo);
65 
66  if (!_results)
67  mooseError("The 'results' object must be a 'StochasticResults' object.");
68 
70 }
71 
72 void
74 {
75  _current_data.clear();
76  _current_data.reserve(_sampler_ptr->getNumberOfLocalRows());
77 }
78 
79 void
81 {
82  const dof_id_type n = _multi_app->numGlobalApps();
83  for (MooseIndex(n) i = 0; i < n; i++)
84  {
85  if (_multi_app->hasLocalApp(i))
86  {
87  FEProblemBase & app_problem = _multi_app->appProblemBase(i);
88  _current_data.emplace_back(app_problem.getPostprocessorValue(_sub_pp_name));
89  }
90  }
91 }
92 
93 void
95 {
97  _current_data.clear();
98 }
99 
100 void
102 {
103  VectorPostprocessorValue current;
104  current.reserve(_sampler_ptr->getNumberOfLocalRows());
105  for (dof_id_type i = _sampler_ptr->getLocalRowBegin(); i < _sampler_ptr->getLocalRowEnd(); ++i)
106  {
107  FEProblemBase & app_problem = _multi_app->appProblemBase(i);
108  current.emplace_back(app_problem.getPostprocessorValue(_sub_pp_name));
109  }
110  _results->setCurrentLocalVectorPostprocessorValue(_sampler_ptr->name(), std::move(current));
111 }
StochasticToolsTransfer
The class creates an additional API to allow Transfers to work when running the StochasticTools<FullS...
Definition: StochasticToolsTransfer.h:24
SamplerPostprocessorTransfer::executeFromMultiapp
virtual void executeFromMultiapp() override
Definition: SamplerPostprocessorTransfer.C:80
SamplerPostprocessorTransfer::execute
virtual void execute() override
Traditional Transfer callback.
Definition: SamplerPostprocessorTransfer.C:101
SamplerPostprocessorTransfer::_results
StochasticResults * _results
Storage for StochasticResults object that data will be transferred to/from.
Definition: SamplerPostprocessorTransfer.h:53
SamplerFullSolveMultiApp.h
SamplerReceiver.h
SamplerPostprocessorTransfer::initializeFromMultiapp
virtual void initializeFromMultiapp() override
Methods used when running in batch mode (see SamplerFullSolveMultiApp)
Definition: SamplerPostprocessorTransfer.C:73
StochasticToolsTransfer::_sampler_ptr
Sampler * _sampler_ptr
Pointer to the Sampler object used by the SamplerTransientMultiApp or SamplerFullSolveMultiApp.
Definition: StochasticToolsTransfer.h:61
SamplerPostprocessorTransfer::_current_data
VectorPostprocessorValue _current_data
Temporary storage for batch mode execution.
Definition: SamplerPostprocessorTransfer.h:62
SamplerTransientMultiApp.h
SamplerPostprocessorTransfer::finalizeFromMultiapp
virtual void finalizeFromMultiapp() override
Definition: SamplerPostprocessorTransfer.C:94
StochasticResults.h
SamplerPostprocessorTransfer::validParams
static InputParameters validParams()
Definition: SamplerPostprocessorTransfer.C:23
SamplerPostprocessorTransfer::_master_vpp_name
const VectorPostprocessorName & _master_vpp_name
Name of vector-postprocessor on the master.
Definition: SamplerPostprocessorTransfer.h:59
SamplerPostprocessorTransfer::_sub_pp_name
const PostprocessorName & _sub_pp_name
Name of postprocessor on the sub-applications.
Definition: SamplerPostprocessorTransfer.h:56
StochasticToolsTransfer::validParams
static InputParameters validParams()
Definition: StochasticToolsTransfer.C:18
SamplerPostprocessorTransfer::initialSetup
virtual void initialSetup() override
Definition: SamplerPostprocessorTransfer.C:61
registerMooseObject
registerMooseObject("StochasticToolsApp", SamplerPostprocessorTransfer)
SamplerPostprocessorTransfer
Transfer Postprocessor from sub-applications to a VectorPostprocessor on the master application.
Definition: SamplerPostprocessorTransfer.h:29
StochasticResults::setCurrentLocalVectorPostprocessorValue
void setCurrentLocalVectorPostprocessorValue(const std::string &vector_name, const VectorPostprocessorValue &&current)
Definition: StochasticResults.C:127
SamplerPostprocessorTransfer::SamplerPostprocessorTransfer
SamplerPostprocessorTransfer(const InputParameters &parameters)
Definition: SamplerPostprocessorTransfer.C:50
defineLegacyParams
defineLegacyParams(SamplerPostprocessorTransfer)
StochasticResults::init
void init(Sampler &_sampler)
DEPRECATED Initialize storage based on the Sampler returned by the SamplerTransientMultiApp or Sample...
Definition: StochasticResults.C:141
SamplerPostprocessorTransfer.h