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 }
68 
69 void
71 {
72  if (getFromMultiApp()->isRootProcessor())
73  {
74  const dof_id_type n = getFromMultiApp()->numGlobalApps();
75  for (MooseIndex(n) i = 0; i < n; i++)
77  }
78 }
79 
80 void
82 {
83 }
84 
85 void
87 {
90 }
91 
92 void
94 {
95  const dof_id_type n = getFromMultiApp()->numGlobalApps();
96 
97  for (const auto & sub_rname : _sub_reporter_names)
98  for (MooseIndex(n) i = 0; i < n; i++)
99  if (getFromMultiApp()->hasLocalApp(i))
101  sub_rname, REPORTER_MODE_ROOT, getFromMultiApp()->appProblemBase(i));
102 
103  const std::string prefix = isParamValid("prefix") ? getParam<std::string>("prefix") : name();
104  for (const auto & sub_rname : _sub_reporter_names)
105  for (MooseIndex(n) i = 0; i < n; i++)
106  if (getFromMultiApp()->hasLocalApp(i))
107  {
108  const ReporterData & rdata = getFromMultiApp()->appProblemBase(i).getReporterData();
109  ReporterName rname =
110  _results->declareStochasticReporterClone(*_sampler_ptr, rdata, sub_rname, prefix);
111  if (rname.empty())
112  paramError("from_reporter",
113  "Reporter value ",
114  sub_rname,
115  " is of unsupported type ",
116  rdata.getReporterContextBase(sub_rname).type(),
117  ". Contact MOOSE developers on how to transfer this type of reporter value.");
118  _reporter_names.push_back(rname);
119  break;
120  }
121 
123  prefix + (prefix.empty() ? "" : ":") + "converged", *_sampler_ptr);
124 }
125 
126 void
128  dof_id_type app_index)
129 {
130  if (getFromMultiApp()->hasLocalApp(app_index))
131  {
132  const dof_id_type local_index = global_index - _sampler_ptr->getLocalRowBegin();
133  for (unsigned int r = 0; r < _sub_reporter_names.size(); ++r)
135  _reporter_names[r],
136  getFromMultiApp()->appProblemBase(app_index),
137  getFromMultiApp()->problemBase(),
138  local_index);
139 
140  (*_converged)[local_index] = getFromMultiApp()->getExecutioner(app_index)->lastSolveConverged();
141  }
142 }
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()
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 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
virtual const std::string & name() const
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)
bool isParamValid(const std::string &name) const
registerMooseObject("StochasticToolsApp", SamplerReporterTransfer)
virtual void initialSetup() override
std::vector< ReporterName > _reporter_names
Storage vector names.
virtual void executeFromMultiapp() override
virtual void finalizeFromMultiapp() override
static InputParameters validParams()
void transferStochasticReporters(dof_id_type global_index, dof_id_type app_index)
Transfer reporter values.
void paramError(const std::string &param, Args... args) const
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.
bool hasToMultiApp() const
std::vector< bool > * _converged
Reporter value for whether or not sub app converged.
void addClassDescription(const std::string &doc_string)
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)
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)