https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
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
52void
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
64void
66{
67 // Initialize vectors so they are the proper size before transfer
70}
71
72void
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
83void
90
91void
101
102void
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
136void
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)
146 getFromMultiApp()->appProblemBase(app_index),
147 getFromMultiApp()->problemBase(),
148 local_index);
149
150 (*_converged)[local_index] = getFromMultiApp()->getExecutioner(app_index)->lastSolveConverged();
151 }
152}
const ExecFlagType EXEC_TRANSFER
const ReporterMode REPORTER_MODE_ROOT
registerMooseObject("StochasticToolsApp", SamplerReporterTransfer)
T & getUserObject(const std::string &name, unsigned int tid=0) const
virtual void computeUserObjectByName(const ExecFlagType &type, const Moose::AuxGroup &group, const std::string &name)
void suppressParameter(const std::string &name)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
const std::string & name() const
void paramError(const std::string &param, Args... args) const
bool isParamValid(const std::string &name) const
bool hasToMultiApp() const
const std::shared_ptr< MultiApp > getFromMultiApp() const
bool contains(const std::string &value) const
virtual std::string type() const=0
const ReporterContextBase & getReporterContextBase(const ReporterName &reporter_name) const
bool empty() 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)
void addReporterTransferMode(const ReporterName &name, const ReporterMode &mode, FEProblemBase &problem)
Transfer Reporters from sub-applications to a StochasticReporter on the main application.
virtual void initializeFromMultiapp() override
Methods used when running in batch mode (see SamplerFullSolveMultiApp)
StochasticReporter * _results
StochasticReporter object where values are being transferred.
std::vector< bool > * _converged
Reporter value for whether or not sub app converged.
virtual void initialSetup() override
void intitializeStochasticReporters()
Used to declare reporter values on main app and add consumer modes on subapps.
virtual void executeFromMultiapp() override
virtual void execute() override
Traditional Transfer callback.
void transferStochasticReporters(dof_id_type global_index, dof_id_type app_index)
Transfer reporter values.
virtual void finalizeFromMultiapp() override
std::vector< ReporterName > _reporter_names
Storage vector names.
static InputParameters validParams()
const std::vector< ReporterName > & _sub_reporter_names
Name of reporters on the sub-applications.
SamplerReporterTransfer(const InputParameters &parameters)
dof_id_type getLocalRowEnd() const
dof_id_type getLocalRowBegin() const
const ExecFlagEnum & getExecuteOnEnum() const
virtual ReporterName declareStochasticReporterClone(const Sampler &sampler, const ReporterData &from_data, const ReporterName &from_reporter, std::string prefix="")
std::vector< T > & declareStochasticReporter(std::string value_name, const Sampler &sampler)
virtual void initialize() override final
The class creates an additional API to allow Transfers to work when running the StochasticTools<FullS...
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.
FEProblemBase & _fe_problem