https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ReporterTransferInterface.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
12#include "UserObject.h"
13#include "Reporter.h"
14#include "Transfer.h"
15
22
24 : _rti_transfer(*transfer)
25{
26}
27
28void
38
39void
41 const ReporterName & to_reporter,
42 const FEProblemBase & from_problem,
43 FEProblemBase & to_problem,
44 unsigned int time_index)
45{
46 checkHasReporterValue(from_reporter, from_problem);
47 checkHasReporterValue(to_reporter, to_problem);
48 from_problem.getReporterData()
49 .getReporterContextBase(from_reporter)
50 .transfer(to_problem.getReporterData(ReporterData::WriteKey()), to_reporter, time_index);
51}
52
53void
55 const ReporterName & to_reporter,
56 const FEProblemBase & from_problem,
57 FEProblemBase & to_problem,
58 dof_id_type index,
59 unsigned int time_index)
60{
61 checkHasReporterValue(from_reporter, from_problem);
62 checkHasReporterValue(to_reporter, to_problem);
63 from_problem.getReporterData()
64 .getReporterContextBase(from_reporter)
66 to_problem.getReporterData(ReporterData::WriteKey()), to_reporter, index, time_index);
67}
68
69void
71 const ReporterName & to_reporter,
72 const FEProblemBase & from_problem,
73 FEProblemBase & to_problem,
74 dof_id_type index,
75 unsigned int time_index)
76{
77 checkHasReporterValue(from_reporter, from_problem);
78 checkHasReporterValue(to_reporter, to_problem);
79 from_problem.getReporterData()
80 .getReporterContextBase(from_reporter)
82 to_problem.getReporterData(ReporterData::WriteKey()), to_reporter, index, time_index);
83}
84
85void
87 FEProblemBase & problem)
88{
89 if (problem.hasUserObject(reporter.getObjectName()))
90 {
91 Reporter * rep =
92 dynamic_cast<Reporter *>(&problem.getUserObject<UserObject>(reporter.getObjectName()));
93 if (rep)
95 }
96}
97
98void
100 const ReporterName & to_reporter,
101 const FEProblemBase & from_problem,
102 FEProblemBase & to_problem,
103 const ReporterMode & mode)
104{
105 checkHasReporterValue(from_reporter, from_problem);
106 from_problem.getReporterData()
107 .getReporterContextBase(from_reporter)
109 to_problem.getReporterData(ReporterData::WriteKey()), to_reporter, mode, _rti_transfer);
110
111 // Hide variables (if requested in parameters) if name is associated with a reporter object
112 hideVariableHelper(to_reporter, to_problem);
113}
114
115void
117 FEProblemBase & problem,
118 const std::string & type,
119 const ReporterMode & mode)
120{
122 if (type == "bool")
124 else if (type == "integer")
126 else if (type == "real")
128 else if (type == "string")
130 rname, mode, _rti_transfer);
131 else
132 _rti_transfer.mooseError("Unknown reporter type, ", type, ".");
133
134 // Hide variables (if requested in parameters) if name is associated with a reporter object
135 hideVariableHelper(rname, problem);
136}
137
138void
140 const ReporterName & to_reporter,
141 const FEProblemBase & from_problem,
142 FEProblemBase & to_problem,
143 const ReporterMode & mode)
144{
145 checkHasReporterValue(from_reporter, from_problem);
146 from_problem.getReporterData()
147 .getReporterContextBase(from_reporter)
149 to_problem.getReporterData(ReporterData::WriteKey()), to_reporter, mode, _rti_transfer);
150
151 // Hide variables (if requested in parameters) if name is associated with a reporter object
152 hideVariableHelper(to_reporter, to_problem);
153}
154
155void
157 FEProblemBase & problem,
158 const std::string & type,
159 const ReporterMode & mode)
160{
162 if (type == "bool")
163 rdata.declareReporterValue<std::vector<bool>, ReporterVectorContext<bool>>(
164 rname, mode, _rti_transfer);
165 else if (type == "integer")
166 rdata.declareReporterValue<std::vector<int>, ReporterVectorContext<int>>(
167 rname, mode, _rti_transfer);
168 else if (type == "real")
169 rdata.declareReporterValue<std::vector<Real>, ReporterVectorContext<Real>>(
170 rname, mode, _rti_transfer);
171 else if (type == "string")
172 rdata.declareReporterValue<std::vector<std::string>, ReporterVectorContext<std::string>>(
173 rname, mode, _rti_transfer);
174 else
175 _rti_transfer.mooseError("Unknown reporter type, ", type, ".");
176
177 // Hide variables (if requested in parameters) if name is associated with a reporter object
178 hideVariableHelper(rname, problem);
179}
180
181void
183 FEProblemBase & problem,
184 dof_id_type n)
185{
186 checkHasReporterValue(name, problem);
188}
189void
195
196void
202
203std::vector<ReporterName>
205 const std::string & obj_name,
206 const std::vector<ReporterName> & rep_names)
207{
208 if (!prefix.empty())
209 prefix += ":";
210 std::vector<ReporterName> rnames;
211 rnames.reserve(rep_names.size());
212 for (const auto & rn : rep_names)
213 rnames.emplace_back(obj_name, prefix + rn.getObjectName() + ":" + rn.getValueName());
214 return rnames;
215}
216
217void
219 const FEProblemBase & problem) const
220{
221 if (!problem.getReporterData().hasReporterValue(reporter))
222 _rti_transfer.mooseError("Reporter with the name \"",
223 reporter,
224 "\" within app \"",
225 problem.getMooseApp().name(),
226 "\" was not found.");
227}
InputParameters emptyInputParameters()
void ErrorVector unsigned int
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
T & getUserObject(const std::string &name, unsigned int tid=0) const
Get the user object by its name.
const ReporterData & getReporterData() const
Provides const access the ReporterData object.
bool hasUserObject(const std::string &name) const
Check if there if a user object of given name.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition MooseBase.h:87
void buildOutputHideVariableList(std::set< std::string > variable_names)
Builds hide lists for output objects NOT listed in the 'outputs' parameter.
virtual void transferToVector(ReporterData &r_data, const ReporterName &r_name, dof_id_type index, unsigned int time_index=0) const =0
Helper for enabling generic transfer of Reporter values to a vector.
virtual void resize(dof_id_type local_size)=0
Helper for resizing vector data.
virtual void declareVectorClone(ReporterData &r_data, const ReporterName &r_name, const ReporterMode &mode, const MooseObject &producer) const =0
Helper for declaring new vector reporter values based on this context.
virtual void clear()=0
Helper for clearing vector data.
virtual void transferFromVector(ReporterData &r_data, const ReporterName &r_name, dof_id_type index, unsigned int time_index=0) const =0
Helper for enabling generic transfer of a vector Reporter of values to a single value.
virtual void vectorSum()=0
Helper for summing reporter value.
virtual void transfer(ReporterData &r_data, const ReporterName &r_name, unsigned int time_index=0) const =0
Helper for enabling generic transfer of Reporter values.
virtual void declareClone(ReporterData &r_data, const ReporterName &r_name, const ReporterMode &mode, const MooseObject &producer) const =0
Helper for declaring new reporter values based on this context.
This is a helper class for managing the storage of declared Reporter object values.
const ReporterStateBase & getReporterStateBase(const ReporterName &reporter_name) const
@Returns The ReporterStateBase associated with the Reporter with name reporter_name.
T & declareReporterValue(const ReporterName &reporter_name, const ReporterMode &mode, const MooseObject &producer, Args &&... args)
Method for returning a writable reference to the current Reporter value.
const ReporterContextBase & getReporterContextBase(const ReporterName &reporter_name) const
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
MooseEnumItem that automatically creates the ID and doesn't allow the ID to be assigned.
The Reporter system is comprised of objects that can contain any number of data values.
const std::string & getObjectName() const
Return the object name that produces the Reporter value.
const std::string getCombinedName() const
Return the name of the object and data as object_name/data_name.
void addConsumer(ReporterMode mode, const MooseObject &moose_object)
Add a consumer for this ReporterState.
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 checkHasReporterValue(const ReporterName &reporter, const FEProblemBase &problem) const
Checks if the problem problem has a Reporter value with the name reporter.
ReporterTransferInterface(const Transfer *transfer)
void transferReporter(const ReporterName &from_reporter, const ReporterName &to_reporter, const FEProblemBase &from_problem, FEProblemBase &to_problem, unsigned int time_index=0)
std::vector< ReporterName > getReporterNamesHelper(std::string prefix, const std::string &obj_name, const std::vector< ReporterName > &rep_names)
void resizeReporter(const ReporterName &name, FEProblemBase &problem, dof_id_type n)
void clearVectorReporter(const ReporterName &name, FEProblemBase &problem)
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)
const Transfer & _rti_transfer
The Transfer that this interface is associated with.
void addReporterTransferMode(const ReporterName &name, const ReporterMode &mode, FEProblemBase &problem)
void transferFromVectorReporter(const ReporterName &from_reporter, const ReporterName &to_reporter, const FEProblemBase &from_problem, FEProblemBase &to_problem, dof_id_type index, unsigned int time_index=0)
static InputParameters validParams()
void sumVectorReporter(const ReporterName &name, FEProblemBase &problem)
void hideVariableHelper(const ReporterName &reporter, FEProblemBase &problem)
Helper for hiding the variables in the problem problem if the Reporter with name reporter is associat...
This context is specific for vector types of reporters, mainly for declaring a vector of the type fro...
Reporter objects allow for the declaration of arbitrary data types that are aggregate values for a si...
Definition Reporter.h:48
Base class for all Transfer objects.
Definition Transfer.h:40
Base class for user-specific data.
Definition UserObject.h:20