https://mooseframework.inl.gov
SamplerReporterTransfer.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 #include "StochasticReporter.h"
18 #include "Executioner.h"
19 
20 registerMooseObject("StochasticToolsApp", SamplerReporterTransfer);
21 
24 {
26  params.addClassDescription("Transfers data from Reporters on the sub-application to a "
27  "StochasticReporter on the main application.");
28 
29  params.addRequiredParam<std::vector<ReporterName>>(
30  "from_reporter", "The name(s) of the Reporter(s) on the sub-app to transfer from.");
31  params.addRequiredParam<std::string>(
32  "stochastic_reporter", "The name of the StochasticReporter object to transfer values to.");
33 
34  params.addParam<std::string>("prefix",
35  "Use the supplied string as the prefix for reporter "
36  "name rather than the transfer name.");
37 
38  params.suppressParameter<MultiMooseEnum>("direction");
39  params.suppressParameter<MultiAppName>("multi_app");
40  return params;
41 }
42 
44  : StochasticToolsTransfer(parameters),
46  _sub_reporter_names(getParam<std::vector<ReporterName>>("from_reporter"))
47 {
48  if (hasToMultiApp())
49  paramError("to_multi_app", "To and between multiapp directions are not implemented");
50 }
51 
52 void
54 {
55  // Get the StochasticResults VPP object to populate
56  auto & uo = _fe_problem.getUserObject<UserObject>(getParam<std::string>("stochastic_reporter"));
57  _results = dynamic_cast<StochasticReporter *>(&uo);
58  if (!_results)
59  paramError("stochastic_reporter", "This object must be a 'StochasticReporter' object.");
60 
62 }
63 
64 void
66 {
67  // Initialize vectors so they are the proper size before transfer
70 }
71 
72 void
74 {
75  if (getFromMultiApp()->isRootProcessor())
76  {
77  const dof_id_type n = getFromMultiApp()->numGlobalApps();
78  for (MooseIndex(n) i = 0; i < n; i++)
80  }
81 }
82 
83 void
85 {
86  // Execute reporter so that things are gathered after transfer properly
89 }
90 
91 void
93 {
95 
98 
100 }
101 
102 void
104 {
105  const dof_id_type n = getFromMultiApp()->numGlobalApps();
106 
107  for (const auto & sub_rname : _sub_reporter_names)
108  for (MooseIndex(n) i = 0; i < n; i++)
109  if (getFromMultiApp()->hasLocalApp(i))
111  sub_rname, REPORTER_MODE_ROOT, getFromMultiApp()->appProblemBase(i));
112 
113  const std::string prefix = isParamValid("prefix") ? getParam<std::string>("prefix") : name();
114  for (const auto & sub_rname : _sub_reporter_names)
115  for (MooseIndex(n) i = 0; i < n; i++)
116  if (getFromMultiApp()->hasLocalApp(i))
117  {
118  const ReporterData & rdata = getFromMultiApp()->appProblemBase(i).getReporterData();
119  ReporterName rname =
120  _results->declareStochasticReporterClone(*_sampler_ptr, rdata, sub_rname, prefix);
121  if (rname.empty())
122  paramError("from_reporter",
123  "Reporter value ",
124  sub_rname,
125  " is of unsupported type ",
126  rdata.getReporterContextBase(sub_rname).type(),
127  ". Contact MOOSE developers on how to transfer this type of reporter value.");
128  _reporter_names.push_back(rname);
129  break;
130  }
131 
133  prefix + (prefix.empty() ? "" : ":") + "converged", *_sampler_ptr);
134 }
135 
136 void
138  dof_id_type app_index)
139 {
140  if (getFromMultiApp()->hasLocalApp(app_index))
141  {
142  const dof_id_type local_index = global_index - _sampler_ptr->getLocalRowBegin();
143  for (unsigned int r = 0; r < _sub_reporter_names.size(); ++r)
145  _reporter_names[r],
146  getFromMultiApp()->appProblemBase(app_index),
147  getFromMultiApp()->problemBase(),
148  local_index);
149 
150  (*_converged)[local_index] = getFromMultiApp()->getExecutioner(app_index)->lastSolveConverged();
151  }
152 }
StochasticReporter * _results
StochasticReporter object where values are being transferred.
dof_id_type _global_index
Index for tracking the row index when using batch mode operation.
static InputParameters validParams()
const ExecFlagType EXEC_TRANSFER
Sampler * _sampler_ptr
Pointer to the Sampler object used by the SamplerTransientMultiApp or SamplerFullSolveMultiApp.
T & getUserObject(const std::string &name, unsigned int tid=0) const
const std::shared_ptr< MultiApp > getFromMultiApp() const
void paramError(const std::string &param, Args... args) const
void addReporterTransferMode(const ReporterName &name, const ReporterMode &mode, FEProblemBase &problem)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const ReporterMode REPORTER_MODE_ROOT
virtual std::string type() const=0
virtual ReporterName declareStochasticReporterClone(const Sampler &sampler, const ReporterData &from_data, const ReporterName &from_reporter, std::string prefix="")
const std::vector< ReporterName > & _sub_reporter_names
Name of reporters on the sub-applications.
void intitializeStochasticReporters()
Used to declare reporter values on main app and add consumer modes on subapps.
dof_id_type getLocalRowBegin() const
FEProblemBase & _fe_problem
void addRequiredParam(const std::string &name, const std::string &doc_string)
The class creates an additional API to allow Transfers to work when running the StochasticTools<FullS...
void suppressParameter(const std::string &name)
registerMooseObject("StochasticToolsApp", SamplerReporterTransfer)
virtual void initialSetup() override
std::vector< ReporterName > _reporter_names
Storage vector names.
bool contains(const std::string &value) const
const std::string & name() const
virtual void executeFromMultiapp() override
const ExecFlagEnum & getExecuteOnEnum() const
virtual void finalizeFromMultiapp() override
static InputParameters validParams()
void transferStochasticReporters(dof_id_type global_index, dof_id_type app_index)
Transfer reporter values.
dof_id_type getLocalRowEnd() const
virtual void initializeFromMultiapp() override
Methods used when running in batch mode (see SamplerFullSolveMultiApp)
virtual void execute() override
Traditional Transfer callback.
virtual void initialize() override final
bool hasToMultiApp() const
std::vector< bool > * _converged
Reporter value for whether or not sub app converged.
void addClassDescription(const std::string &doc_string)
bool isParamValid(const std::string &name) const
void transferToVectorReporter(const ReporterName &from_reporter, const ReporterName &to_reporter, const FEProblemBase &from_problem, FEProblemBase &to_problem, dof_id_type index, unsigned int time_index=0)
std::vector< T > & declareStochasticReporter(std::string value_name, const Sampler &sampler)
virtual void computeUserObjectByName(const ExecFlagType &type, const Moose::AuxGroup &group, const std::string &name)
bool empty() const
Transfer Reporters from sub-applications to a StochasticReporter on the main application.
uint8_t dof_id_type
const ReporterContextBase & getReporterContextBase(const ReporterName &reporter_name) const
SamplerReporterTransfer(const InputParameters &parameters)