https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MultiAppCloneReporterTransfer.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
11#include "MultiApp.h"
12#include "UserObject.h"
13#include "Reporter.h"
14
16
19{
23 "Declare and transfer reporter data from sub-application(s) to main application.");
24 params.addRequiredParam<std::vector<ReporterName>>(
25 "from_reporters",
26 "List of the reporter names (object_name/value_name) to transfer the value from.");
27 params.addRequiredParam<std::string>(
28 "to_reporter", "Reporter object to reference when declaring reporter values.");
29
30 params.addParam<std::string>("prefix",
31 "Use the supplied string as the prefix for reporter "
32 "name rather than the transfer name.");
33
35 "reporter_type",
37 "The type of the reporter on the sub-application. This parameter is not typically required, "
38 "but if some processors do not have a sub-app, for instance if the max_procs_per_app "
39 "parameter is used in the MultiApp, then this is required.");
40
41 params.suppressParameter<MultiMooseEnum>("direction");
42 return params;
43}
44
46 : MultiAppTransfer(parameters),
48 _from_reporter_names(getParam<std::vector<ReporterName>>("from_reporters")),
49 _to_obj_name(getParam<std::string>("to_reporter")),
50 _to_reporter_names(isParamValid("prefix")
51 ? getReporterNamesHelper(getParam<std::string>("prefix"),
52 _to_obj_name,
53 _from_reporter_names)
54 : getReporterNamesHelper(_name, _to_obj_name, _from_reporter_names))
55{
56 // Deprecating direction proves fatal for this parameter for this class
57 if (isParamValid("multi_app"))
58 paramError("multi_app",
59 "The multi_app parameter is no longer valid for this class, use to_multi_app");
60
61 if (isParamValid("to_multi_app"))
62 paramError("to_multi_app",
63 "Sibling or to_multiapp transfer have not been implemented for this transfer.");
64}
65
66void
68{
70
71 if (isParamValid("to_multi_app") && !getToMultiApp()->hasApp() && !isParamValid("reporter_type"))
72 mooseError("For a direct reporter clone, all processors must be associated with a "
73 "sub-application. If you know the type of reporter being transferred, please "
74 "consider using the 'reporter_type' parameter for an indirect clone.");
75
76 if (isParamValid("from_multi_app") && !getFromMultiApp()->hasApp() &&
77 !isParamValid("reporter_type"))
78 mooseError("For a direct reporter clone, all processors must be associated with a "
79 "sub-application. If you know the type of reporter being transferred, please "
80 "consider using the 'reporter_type' parameter for an indirect clone.");
81
83 if (!dynamic_cast<const Reporter *>(&uo))
84 paramError("to_reporter", "This object must be a Reporter object.");
85
86 const auto multi_app = getMultiApp();
87 const dof_id_type n = multi_app->numGlobalApps();
88
89 for (unsigned int r = 0; r < _from_reporter_names.size(); ++r)
90 for (MooseIndex(n) i = 0; i < n; i++)
91 if (multi_app->hasLocalApp(i))
93 _from_reporter_names[r], REPORTER_MODE_ROOT, multi_app->appProblemBase(i));
94
95 if (multi_app->hasApp())
96 {
97 for (unsigned int r = 0; r < _from_reporter_names.size(); ++r)
98 for (MooseIndex(n) i = 0; i < n; i++)
99 if (multi_app->hasLocalApp(i))
100 {
101 if (n > 1)
104 multi_app->appProblemBase(i),
105 multi_app->problemBase(),
107 else
110 multi_app->appProblemBase(i),
111 multi_app->problemBase(),
113 break;
114 }
115 }
116 else
117 {
118 const auto & types = getParam<MultiMooseEnum>("reporter_type");
119 if (types.size() != _from_reporter_names.size())
120 paramError("reporter_type", "This parameter must be the same length as 'from_reporters'");
121 for (unsigned int r = 0; r < _from_reporter_names.size(); ++r)
122 {
123 if (n > 1)
125 _to_reporter_names[r], multi_app->problemBase(), types[r], REPORTER_MODE_DISTRIBUTED);
126 else
127 declareClone(_to_reporter_names[r], multi_app->problemBase(), types[r], REPORTER_MODE_ROOT);
128 }
129 }
130
131 if (n > 1 && multi_app->isRootProcessor())
132 for (const auto & rn : _to_reporter_names)
133 resizeReporter(rn, multi_app->problemBase(), multi_app->numLocalApps());
134}
135
136void
140
141void
143{
144 if (!getFromMultiApp()->isRootProcessor())
145 return;
146
147 const dof_id_type begin = getFromMultiApp()->firstLocalApp();
148 const dof_id_type end = begin + getFromMultiApp()->numLocalApps();
149
150 for (unsigned int r = 0; r < _from_reporter_names.size(); ++r)
151 for (dof_id_type i = begin; i < end; ++i)
152 {
153 if (getFromMultiApp()->numGlobalApps() > 1)
156 getFromMultiApp()->appProblemBase(i),
157 getFromMultiApp()->problemBase(),
158 i - begin);
159 else
162 getFromMultiApp()->appProblemBase(i),
163 getFromMultiApp()->problemBase());
164 }
165}
166
167void
169{
170 TIME_SECTION("MultiAppCloneReporterTransfer::execute()", 5, "Transferring reporters");
171
174 else
176}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
registerMooseObject("MooseApp", MultiAppCloneReporterTransfer)
const ReporterMode REPORTER_MODE_DISTRIBUTED
const ReporterMode REPORTER_MODE_ROOT
const UserObject & getUserObjectBase(const std::string &name, const THREAD_ID tid=0) const
Get the user object by its name.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn't required or valid in the derived class...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
Transfer for migrating reporter values between the main and sub-application(s).
MultiAppCloneReporterTransfer(const InputParameters &parameters)
virtual void execute() override
Execute the transfer.
const std::vector< ReporterName > & _from_reporter_names
virtual void initialSetup() override
Method called at the beginning of the simulation for checking integrity or doing one-time setup.
const std::vector< ReporterName > _to_reporter_names
Base class for all MultiAppTransfer objects.
void initialSetup() override
Method called at the beginning of the simulation for checking integrity or doing one-time setup.
const std::shared_ptr< MultiApp > getToMultiApp() const
Get the MultiApp to transfer data to.
const std::shared_ptr< MultiApp > getMultiApp() const
Use this getter to obtain the MultiApp for transfers with a single direction.
static InputParameters validParams()
const std::shared_ptr< MultiApp > getFromMultiApp() const
Get the MultiApp to transfer data from.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type.
The Reporter system is comprised of objects that can contain any number of data values.
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 transferReporter(const ReporterName &from_reporter, const ReporterName &to_reporter, const FEProblemBase &from_problem, FEProblemBase &to_problem, unsigned int time_index=0)
void resizeReporter(const ReporterName &name, FEProblemBase &problem, dof_id_type n)
void declareVectorClone(const ReporterName &from_reporter, const ReporterName &to_reporter, const FEProblemBase &from_problem, FEProblemBase &to_problem, const ReporterMode &mode)
void declareClone(const ReporterName &from_reporter, const ReporterName &to_reporter, const FEProblemBase &from_problem, FEProblemBase &to_problem, const ReporterMode &mode)
static MultiMooseEnum standardTransferTypes()
void addReporterTransferMode(const ReporterName &name, const ReporterMode &mode, FEProblemBase &problem)
static InputParameters validParams()
Reporter objects allow for the declaration of arbitrary data types that are aggregate values for a si...
Definition Reporter.h:48
@ FROM_MULTIAPP
Definition Transfer.h:71
FEProblemBase & _fe_problem
Definition Transfer.h:97
MooseEnum _current_direction
Definition Transfer.h:106
Base class for user-specific data.
Definition UserObject.h:20