Line data Source code
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 : #include "ReporterTransferInterface.h"
11 :
12 : #include "UserObject.h"
13 : #include "Reporter.h"
14 : #include "Transfer.h"
15 :
16 : InputParameters
17 29800 : ReporterTransferInterface::validParams()
18 : {
19 29800 : InputParameters params = emptyInputParameters();
20 29800 : return params;
21 : }
22 :
23 607 : ReporterTransferInterface::ReporterTransferInterface(const Transfer * transfer)
24 607 : : _rti_transfer(*transfer)
25 : {
26 607 : }
27 :
28 : void
29 1732 : ReporterTransferInterface::addReporterTransferMode(const ReporterName & name,
30 : const ReporterMode & mode,
31 : FEProblemBase & problem)
32 : {
33 1732 : checkHasReporterValue(name, problem);
34 1732 : problem.getReporterData(ReporterData::WriteKey())
35 1732 : .getReporterStateBase(name)
36 1732 : .addConsumer(mode, _rti_transfer);
37 1732 : }
38 :
39 : void
40 3220 : ReporterTransferInterface::transferReporter(const ReporterName & from_reporter,
41 : const ReporterName & to_reporter,
42 : const FEProblemBase & from_problem,
43 : FEProblemBase & to_problem,
44 : unsigned int time_index)
45 : {
46 3220 : checkHasReporterValue(from_reporter, from_problem);
47 3220 : checkHasReporterValue(to_reporter, to_problem);
48 3220 : from_problem.getReporterData()
49 3220 : .getReporterContextBase(from_reporter)
50 3220 : .transfer(to_problem.getReporterData(ReporterData::WriteKey()), to_reporter, time_index);
51 3220 : }
52 :
53 : void
54 684 : ReporterTransferInterface::transferToVectorReporter(const ReporterName & from_reporter,
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 684 : checkHasReporterValue(from_reporter, from_problem);
62 684 : checkHasReporterValue(to_reporter, to_problem);
63 684 : from_problem.getReporterData()
64 684 : .getReporterContextBase(from_reporter)
65 684 : .transferToVector(
66 : to_problem.getReporterData(ReporterData::WriteKey()), to_reporter, index, time_index);
67 684 : }
68 :
69 : void
70 216 : ReporterTransferInterface::transferFromVectorReporter(const ReporterName & from_reporter,
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 216 : checkHasReporterValue(from_reporter, from_problem);
78 216 : checkHasReporterValue(to_reporter, to_problem);
79 216 : from_problem.getReporterData()
80 216 : .getReporterContextBase(from_reporter)
81 216 : .transferFromVector(
82 : to_problem.getReporterData(ReporterData::WriteKey()), to_reporter, index, time_index);
83 216 : }
84 :
85 : void
86 740 : ReporterTransferInterface::hideVariableHelper(const ReporterName & reporter,
87 : FEProblemBase & problem)
88 : {
89 740 : if (problem.hasUserObject(reporter.getObjectName()))
90 : {
91 : Reporter * rep =
92 740 : dynamic_cast<Reporter *>(&problem.getUserObject<UserObject>(reporter.getObjectName()));
93 740 : if (rep)
94 1480 : rep->buildOutputHideVariableList({reporter.getCombinedName()});
95 : }
96 1480 : }
97 :
98 : void
99 210 : ReporterTransferInterface::declareClone(const ReporterName & from_reporter,
100 : const ReporterName & to_reporter,
101 : const FEProblemBase & from_problem,
102 : FEProblemBase & to_problem,
103 : const ReporterMode & mode)
104 : {
105 210 : checkHasReporterValue(from_reporter, from_problem);
106 210 : from_problem.getReporterData()
107 210 : .getReporterContextBase(from_reporter)
108 210 : .declareClone(
109 210 : 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 210 : hideVariableHelper(to_reporter, to_problem);
113 210 : }
114 :
115 : void
116 0 : ReporterTransferInterface::declareClone(const ReporterName & rname,
117 : FEProblemBase & problem,
118 : const std::string & type,
119 : const ReporterMode & mode)
120 : {
121 0 : ReporterData & rdata = problem.getReporterData(ReporterData::WriteKey());
122 0 : if (type == "bool")
123 0 : rdata.declareReporterValue<bool, ReporterGeneralContext<bool>>(rname, mode, _rti_transfer);
124 0 : else if (type == "integer")
125 0 : rdata.declareReporterValue<int, ReporterGeneralContext<int>>(rname, mode, _rti_transfer);
126 0 : else if (type == "real")
127 0 : rdata.declareReporterValue<Real, ReporterGeneralContext<Real>>(rname, mode, _rti_transfer);
128 0 : else if (type == "string")
129 0 : rdata.declareReporterValue<std::string, ReporterGeneralContext<std::string>>(
130 0 : rname, mode, _rti_transfer);
131 : else
132 0 : _rti_transfer.mooseError("Unknown reporter type, ", type, ".");
133 :
134 : // Hide variables (if requested in parameters) if name is associated with a reporter object
135 0 : hideVariableHelper(rname, problem);
136 0 : }
137 :
138 : void
139 470 : ReporterTransferInterface::declareVectorClone(const ReporterName & from_reporter,
140 : const ReporterName & to_reporter,
141 : const FEProblemBase & from_problem,
142 : FEProblemBase & to_problem,
143 : const ReporterMode & mode)
144 : {
145 470 : checkHasReporterValue(from_reporter, from_problem);
146 470 : from_problem.getReporterData()
147 470 : .getReporterContextBase(from_reporter)
148 470 : .declareVectorClone(
149 470 : 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 470 : hideVariableHelper(to_reporter, to_problem);
153 470 : }
154 :
155 : void
156 60 : ReporterTransferInterface::declareVectorClone(const ReporterName & rname,
157 : FEProblemBase & problem,
158 : const std::string & type,
159 : const ReporterMode & mode)
160 : {
161 60 : ReporterData & rdata = problem.getReporterData(ReporterData::WriteKey());
162 60 : if (type == "bool")
163 0 : rdata.declareReporterValue<std::vector<bool>, ReporterVectorContext<bool>>(
164 0 : rname, mode, _rti_transfer);
165 60 : else if (type == "integer")
166 20 : rdata.declareReporterValue<std::vector<int>, ReporterVectorContext<int>>(
167 20 : rname, mode, _rti_transfer);
168 40 : else if (type == "real")
169 20 : rdata.declareReporterValue<std::vector<Real>, ReporterVectorContext<Real>>(
170 20 : rname, mode, _rti_transfer);
171 20 : else if (type == "string")
172 20 : rdata.declareReporterValue<std::vector<std::string>, ReporterVectorContext<std::string>>(
173 20 : rname, mode, _rti_transfer);
174 : else
175 0 : _rti_transfer.mooseError("Unknown reporter type, ", type, ".");
176 :
177 : // Hide variables (if requested in parameters) if name is associated with a reporter object
178 60 : hideVariableHelper(rname, problem);
179 60 : }
180 :
181 : void
182 502 : ReporterTransferInterface::resizeReporter(const ReporterName & name,
183 : FEProblemBase & problem,
184 : dof_id_type n)
185 : {
186 502 : checkHasReporterValue(name, problem);
187 502 : problem.getReporterData(ReporterData::WriteKey()).getReporterContextBase(name).resize(n);
188 502 : }
189 : void
190 72 : ReporterTransferInterface::clearVectorReporter(const ReporterName & name, FEProblemBase & problem)
191 : {
192 72 : checkHasReporterValue(name, problem);
193 72 : problem.getReporterData(ReporterData::WriteKey()).getReporterContextBase(name).clear();
194 72 : }
195 :
196 : void
197 72 : ReporterTransferInterface::sumVectorReporter(const ReporterName & name, FEProblemBase & problem)
198 : {
199 72 : checkHasReporterValue(name, problem);
200 72 : problem.getReporterData(ReporterData::WriteKey()).getReporterContextBase(name).vectorSum();
201 72 : }
202 :
203 : std::vector<ReporterName>
204 270 : ReporterTransferInterface::getReporterNamesHelper(std::string prefix,
205 : const std::string & obj_name,
206 : const std::vector<ReporterName> & rep_names)
207 : {
208 270 : if (!prefix.empty())
209 270 : prefix += ":";
210 270 : std::vector<ReporterName> rnames;
211 270 : rnames.reserve(rep_names.size());
212 1010 : for (const auto & rn : rep_names)
213 740 : rnames.emplace_back(obj_name, prefix + rn.getObjectName() + ":" + rn.getValueName());
214 270 : return rnames;
215 0 : }
216 :
217 : void
218 11298 : ReporterTransferInterface::checkHasReporterValue(const ReporterName & reporter,
219 : const FEProblemBase & problem) const
220 : {
221 11298 : if (!problem.getReporterData().hasReporterValue(reporter))
222 0 : _rti_transfer.mooseError("Reporter with the name \"",
223 : reporter,
224 : "\" within app \"",
225 0 : problem.getMooseApp().name(),
226 : "\" was not found.");
227 11298 : }
|