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 "VectorPostprocessorInterface.h"
11 : #include "FEProblemBase.h"
12 : #include "ReporterData.h"
13 : #include "VectorPostprocessor.h"
14 : #include "MooseTypes.h"
15 : #include "UserObject.h"
16 :
17 : InputParameters
18 57718 : VectorPostprocessorInterface::validParams()
19 : {
20 57718 : return emptyInputParameters();
21 : }
22 :
23 683895 : VectorPostprocessorInterface::VectorPostprocessorInterface(const MooseObject * moose_object,
24 683895 : bool broadcast_by_default)
25 683895 : : _broadcast_by_default(broadcast_by_default),
26 683895 : _vpi_moose_object(*moose_object),
27 683895 : _vpi_feproblem(*_vpi_moose_object.parameters().getCheckedPointerParam<FEProblemBase *>(
28 : "_fe_problem_base")),
29 683895 : _vpi_tid(_vpi_moose_object.parameters().have_parameter<THREAD_ID>("_tid")
30 683895 : ? _vpi_moose_object.parameters().get<THREAD_ID>("_tid")
31 683895 : : 0)
32 : {
33 683895 : }
34 :
35 : const VectorPostprocessorValue &
36 1385 : VectorPostprocessorInterface::getVectorPostprocessorValue(const std::string & param_name,
37 : const std::string & vector_name) const
38 : {
39 1385 : possiblyCheckHasVectorPostprocessor(param_name, vector_name);
40 1377 : return getVectorPostprocessorValueByName(getVectorPostprocessorName(param_name), vector_name);
41 : }
42 :
43 : const VectorPostprocessorValue &
44 1913 : VectorPostprocessorInterface::getVectorPostprocessorValueByName(
45 : const VectorPostprocessorName & name, const std::string & vector_name) const
46 : {
47 1913 : return getVectorPostprocessorByNameHelper(name, vector_name, _broadcast_by_default, 0);
48 : }
49 :
50 : const VectorPostprocessorValue &
51 36 : VectorPostprocessorInterface::getVectorPostprocessorValueOld(const std::string & param_name,
52 : const std::string & vector_name) const
53 : {
54 36 : possiblyCheckHasVectorPostprocessor(param_name, vector_name);
55 36 : return getVectorPostprocessorValueOldByName(getVectorPostprocessorName(param_name), vector_name);
56 : }
57 :
58 : const VectorPostprocessorValue &
59 36 : VectorPostprocessorInterface::getVectorPostprocessorValueOldByName(
60 : const VectorPostprocessorName & name, const std::string & vector_name) const
61 : {
62 36 : return getVectorPostprocessorByNameHelper(name, vector_name, _broadcast_by_default, 1);
63 : }
64 :
65 : const VectorPostprocessorValue &
66 271 : VectorPostprocessorInterface::getVectorPostprocessorValue(const std::string & param_name,
67 : const std::string & vector_name,
68 : bool needs_broadcast) const
69 : {
70 271 : possiblyCheckHasVectorPostprocessor(param_name, vector_name);
71 271 : return getVectorPostprocessorValueByName(
72 271 : getVectorPostprocessorName(param_name), vector_name, needs_broadcast);
73 : }
74 :
75 : const VectorPostprocessorValue &
76 271 : VectorPostprocessorInterface::getVectorPostprocessorValueByName(
77 : const VectorPostprocessorName & name,
78 : const std::string & vector_name,
79 : bool needs_broadcast) const
80 : {
81 271 : return getVectorPostprocessorByNameHelper(
82 542 : name, vector_name, needs_broadcast || _broadcast_by_default, 0);
83 : }
84 :
85 : const VectorPostprocessorValue &
86 0 : VectorPostprocessorInterface::getVectorPostprocessorValueOld(const std::string & param_name,
87 : const std::string & vector_name,
88 : bool needs_broadcast) const
89 : {
90 0 : possiblyCheckHasVectorPostprocessor(param_name, vector_name);
91 0 : return getVectorPostprocessorValueOldByName(
92 0 : getVectorPostprocessorName(param_name), vector_name, needs_broadcast);
93 : }
94 :
95 : const VectorPostprocessorValue &
96 0 : VectorPostprocessorInterface::getVectorPostprocessorValueOldByName(
97 : const VectorPostprocessorName & name,
98 : const std::string & vector_name,
99 : bool needs_broadcast) const
100 : {
101 0 : return getVectorPostprocessorByNameHelper(
102 0 : name, vector_name, needs_broadcast || _broadcast_by_default, 1);
103 : }
104 :
105 : const ScatterVectorPostprocessorValue &
106 104 : VectorPostprocessorInterface::getScatterVectorPostprocessorValue(
107 : const std::string & param_name, const std::string & vector_name) const
108 : {
109 104 : possiblyCheckHasVectorPostprocessor(param_name, vector_name);
110 104 : return getScatterVectorPostprocessorValueByName(getVectorPostprocessorName(param_name),
111 104 : vector_name);
112 : }
113 :
114 : const ScatterVectorPostprocessorValue &
115 104 : VectorPostprocessorInterface::getScatterVectorPostprocessorValueByName(
116 : const VectorPostprocessorName & name, const std::string & vector_name) const
117 : {
118 104 : return getVectorPostprocessorContextByNameHelper(name, vector_name).getScatterValue();
119 : }
120 :
121 : const ScatterVectorPostprocessorValue &
122 0 : VectorPostprocessorInterface::getScatterVectorPostprocessorValueOld(
123 : const std::string & param_name, const std::string & vector_name) const
124 : {
125 0 : possiblyCheckHasVectorPostprocessor(param_name, vector_name);
126 0 : return getScatterVectorPostprocessorValueOldByName(getVectorPostprocessorName(param_name),
127 0 : vector_name);
128 : }
129 :
130 : const ScatterVectorPostprocessorValue &
131 0 : VectorPostprocessorInterface::getScatterVectorPostprocessorValueOldByName(
132 : const VectorPostprocessorName & name, const std::string & vector_name) const
133 : {
134 0 : return getVectorPostprocessorContextByNameHelper(name, vector_name).getScatterValueOld();
135 : }
136 :
137 : bool
138 299 : VectorPostprocessorInterface::hasVectorPostprocessor(const std::string & param_name,
139 : const std::string & vector_name) const
140 : {
141 299 : if (!vectorPostprocessorsAdded())
142 4 : _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessor() until all VectorPostprocessors "
143 : "have been constructed.");
144 :
145 295 : return hasVectorPostprocessorByName(getVectorPostprocessorName(param_name), vector_name);
146 : }
147 :
148 : bool
149 594 : VectorPostprocessorInterface::hasVectorPostprocessorByName(const VectorPostprocessorName & name,
150 : const std::string & vector_name) const
151 : {
152 594 : if (!vectorPostprocessorsAdded())
153 4 : _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessorByName() until all "
154 : "VectorPostprocessors have been constructed.");
155 :
156 1180 : const bool has_vpp = _vpi_feproblem.getReporterData().hasReporterValue<VectorPostprocessorValue>(
157 1180 : VectorPostprocessorReporterName(name, vector_name));
158 :
159 : if (has_vpp)
160 : mooseAssert(_vpi_feproblem.hasUserObject(name) && dynamic_cast<const VectorPostprocessor *>(
161 : &_vpi_feproblem.getUserObjectBase(name)),
162 : "Has reporter VectorPostprocessor Reporter value but not VectorPostprocessor UO");
163 :
164 590 : return has_vpp;
165 : }
166 :
167 : bool
168 303 : VectorPostprocessorInterface::hasVectorPostprocessor(const std::string & param_name) const
169 : {
170 303 : if (!vectorPostprocessorsAdded())
171 4 : _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessor() until all "
172 : "VectorPostprocessors have been constructed.");
173 :
174 299 : return hasVectorPostprocessorByName(getVectorPostprocessorName(param_name));
175 : }
176 :
177 : bool
178 9461 : VectorPostprocessorInterface::hasVectorPostprocessorByName(
179 : const VectorPostprocessorName & name) const
180 : {
181 9461 : if (!vectorPostprocessorsAdded())
182 4 : _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessorByName() until all "
183 : "VectorPostprocessors have been constructed.");
184 :
185 18894 : return _vpi_feproblem.hasUserObject(name) &&
186 18894 : dynamic_cast<const VectorPostprocessor *>(&_vpi_feproblem.getUserObjectBase(name));
187 : }
188 :
189 : bool
190 0 : VectorPostprocessorInterface::isVectorPostprocessorDistributed(const std::string & param_name) const
191 : {
192 0 : return isVectorPostprocessorDistributedByName(getVectorPostprocessorName(param_name));
193 : }
194 :
195 : bool
196 0 : VectorPostprocessorInterface::isVectorPostprocessorDistributedByName(
197 : const VectorPostprocessorName & name) const
198 : {
199 0 : return _vpi_feproblem.getVectorPostprocessorObjectByName(name).isDistributed();
200 : }
201 :
202 : const VectorPostprocessorName &
203 2390 : VectorPostprocessorInterface::getVectorPostprocessorName(const std::string & param_name) const
204 : {
205 2390 : const auto & params = _vpi_moose_object.parameters();
206 :
207 2390 : if (!params.isParamValid(param_name))
208 4 : _vpi_moose_object.mooseError(
209 : "When getting a VectorPostprocessor, failed to get a parameter with the name \"",
210 : param_name,
211 : "\".",
212 : "\n\nKnown parameters:\n",
213 4 : _vpi_moose_object.parameters());
214 :
215 2386 : if (!params.isType<VectorPostprocessorName>(param_name))
216 4 : _vpi_moose_object.mooseError(
217 : "Supplied parameter with name \"",
218 : param_name,
219 : "\" of type \"",
220 4 : params.type(param_name),
221 : "\" is not an expected type for getting a VectorPostprocessor.\n\n",
222 : "The allowed type is \"VectorPostprocessorName\".");
223 :
224 2382 : return params.get<VectorPostprocessorName>(param_name);
225 : }
226 :
227 : void
228 1796 : VectorPostprocessorInterface::possiblyCheckHasVectorPostprocessor(
229 : const std::string & param_name, const std::string & vector_name) const
230 : {
231 : // Can't do checking if vpps have not been added
232 1796 : if (!vectorPostprocessorsAdded())
233 1497 : return;
234 :
235 299 : if (!hasVectorPostprocessor(param_name))
236 4 : _vpi_moose_object.paramError(param_name,
237 : "A VectorPostprocessor with the name \"",
238 : getVectorPostprocessorName(param_name),
239 : "\" was not found.");
240 295 : if (!hasVectorPostprocessor(param_name, vector_name))
241 4 : _vpi_moose_object.paramError(param_name,
242 : "The VectorPostprocessor \"",
243 : getVectorPostprocessorName(param_name),
244 : "\" does not have a vector named \"",
245 : vector_name,
246 : "\".");
247 : }
248 :
249 : void
250 2324 : VectorPostprocessorInterface::possiblyCheckHasVectorPostprocessorByName(
251 : const VectorPostprocessorName & name, const std::string & vector_name) const
252 : {
253 : // Can't do checking if vpps have not been added
254 2324 : if (!vectorPostprocessorsAdded())
255 2025 : return;
256 :
257 299 : if (!hasVectorPostprocessorByName(name))
258 4 : _vpi_moose_object.mooseError(
259 : "A VectorPostprocessor with the name \"", name, "\" was not found.");
260 295 : if (!hasVectorPostprocessorByName(name, vector_name))
261 4 : _vpi_moose_object.mooseError("The VectorPostprocessor \"",
262 : name,
263 : "\" does not have a vector named \"",
264 : vector_name,
265 : "\".");
266 : }
267 :
268 : const VectorPostprocessorValue &
269 2220 : VectorPostprocessorInterface::getVectorPostprocessorByNameHelper(
270 : const VectorPostprocessorName & name,
271 : const std::string & vector_name,
272 : bool broadcast,
273 : std::size_t t_index) const
274 : {
275 2220 : possiblyCheckHasVectorPostprocessorByName(name, vector_name);
276 2212 : addVectorPostprocessorDependencyHelper(name);
277 :
278 2212 : const ReporterMode mode = broadcast ? REPORTER_MODE_REPLICATED : REPORTER_MODE_ROOT;
279 4424 : return _vpi_feproblem.getReporterData().getReporterValue<VectorPostprocessorValue>(
280 6636 : VectorPostprocessorReporterName(name, vector_name), _vpi_moose_object, mode, t_index);
281 2212 : }
282 :
283 : const VectorPostprocessorContext<VectorPostprocessorValue> &
284 104 : VectorPostprocessorInterface::getVectorPostprocessorContextByNameHelper(
285 : const VectorPostprocessorName & name, const std::string & vector_name) const
286 : {
287 104 : possiblyCheckHasVectorPostprocessorByName(name, vector_name);
288 104 : addVectorPostprocessorDependencyHelper(name);
289 :
290 : // The complete name of the store Reporter value
291 104 : const VectorPostprocessorReporterName r_name(name, vector_name);
292 :
293 : // Indicate the scatter value is desired, so the the VectorPostprocessorContext will do scatter
294 104 : _vpi_feproblem.getReporterData().getReporterValue<VectorPostprocessorValue>(
295 : r_name, _vpi_moose_object, REPORTER_MODE_VPP_SCATTER, 0);
296 :
297 : // Retrieve the VectorPostprocessorContext which contains the scattered value to be referenced
298 104 : const auto & context = _vpi_feproblem.getReporterData().getReporterContextBase(r_name);
299 104 : auto vpp_context_ptr =
300 104 : dynamic_cast<const VectorPostprocessorContext<VectorPostprocessorValue> *>(&context);
301 : mooseAssert(vpp_context_ptr, "Failed to get the VectorPostprocessorContext");
302 104 : return *vpp_context_ptr;
303 104 : }
304 :
305 : bool
306 14777 : VectorPostprocessorInterface::vectorPostprocessorsAdded() const
307 : {
308 14777 : return _vpi_feproblem.getMooseApp().actionWarehouse().isTaskComplete("add_vector_postprocessor");
309 : }
|