https://mooseframework.inl.gov
Loading...
Searching...
No Matches
VectorPostprocessorInterface.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 "FEProblemBase.h"
12#include "ReporterData.h"
13#include "VectorPostprocessor.h"
14#include "MooseTypes.h"
15#include "UserObject.h"
16
17#include <algorithm>
18
24
26 bool broadcast_by_default)
27 : _broadcast_by_default(broadcast_by_default),
28 _vpi_moose_object(*moose_object),
29 _vpi_feproblem(*_vpi_moose_object.parameters().getCheckedPointerParam<FEProblemBase *>(
30 "_fe_problem_base")),
31 _vpi_tid(_vpi_moose_object.parameters().have_parameter<THREAD_ID>("_tid")
32 ? _vpi_moose_object.parameters().get<THREAD_ID>("_tid")
33 : 0)
34{
35}
36
37#ifdef MOOSE_KOKKOS_ENABLED
40 : _broadcast_by_default(object._broadcast_by_default),
41 _vpi_moose_object(object._vpi_moose_object),
42 _vpi_feproblem(object._vpi_feproblem),
43 _vpi_tid(object._vpi_tid)
44{
45}
46#endif
47
50 const std::string & vector_name) const
51{
52 possiblyCheckHasVectorPostprocessor(param_name, vector_name);
54}
55
58 const VectorPostprocessorName & name, const std::string & vector_name) const
59{
61}
62
65 const std::string & vector_name) const
66{
67 possiblyCheckHasVectorPostprocessor(param_name, vector_name);
69}
70
73 const VectorPostprocessorName & name, const std::string & vector_name) const
74{
76}
77
80 const std::string & vector_name,
81 bool needs_broadcast) const
82{
83 possiblyCheckHasVectorPostprocessor(param_name, vector_name);
85 getVectorPostprocessorName(param_name), vector_name, needs_broadcast);
86}
87
90 const VectorPostprocessorName & name,
91 const std::string & vector_name,
92 bool needs_broadcast) const
93{
95 name, vector_name, needs_broadcast || _broadcast_by_default, 0);
96}
97
100 const std::string & vector_name,
101 bool needs_broadcast) const
102{
103 possiblyCheckHasVectorPostprocessor(param_name, vector_name);
105 getVectorPostprocessorName(param_name), vector_name, needs_broadcast);
106}
107
110 const VectorPostprocessorName & name,
111 const std::string & vector_name,
112 bool needs_broadcast) const
113{
115 name, vector_name, needs_broadcast || _broadcast_by_default, 1);
116}
117
120 const std::string & param_name, const std::string & vector_name) const
121{
122 possiblyCheckHasVectorPostprocessor(param_name, vector_name);
124 vector_name);
125}
126
129 const VectorPostprocessorName & name, const std::string & vector_name) const
130{
131 return getVectorPostprocessorContextByNameHelper(name, vector_name).getScatterValue();
132}
133
136 const std::string & param_name, const std::string & vector_name) const
137{
138 possiblyCheckHasVectorPostprocessor(param_name, vector_name);
140 vector_name);
141}
142
145 const VectorPostprocessorName & name, const std::string & vector_name) const
146{
147 return getVectorPostprocessorContextByNameHelper(name, vector_name).getScatterValueOld();
148}
149
150bool
152 const std::string & vector_name) const
153{
155 _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessor() until all VectorPostprocessors "
156 "have been constructed.");
157
158 return hasVectorPostprocessorByName(getVectorPostprocessorName(param_name), vector_name);
159}
160
161bool
163 const std::string & vector_name) const
164{
166 _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessorByName() until all "
167 "VectorPostprocessors have been constructed.");
168
170 VectorPostprocessorReporterName(name, vector_name)) &&
172}
173
174bool
175VectorPostprocessorInterface::hasVectorPostprocessor(const std::string & param_name) const
176{
178 _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessor() until all "
179 "VectorPostprocessors have been constructed.");
180
182}
183
184bool
186 const VectorPostprocessorName & name) const
187{
189 _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessorByName() until all "
190 "VectorPostprocessors have been constructed.");
191
192 std::vector<VectorPostprocessor *> objs;
194 .query()
196 .condition<AttribThread>(0)
197 .condition<AttribName>(name)
198 .queryInto(objs);
199 return !objs.empty();
200}
201
202bool
207
208bool
214
215const VectorPostprocessorName &
217{
218 const auto & params = _vpi_moose_object.parameters();
219
220 if (!params.isParamValid(param_name))
222 "When getting a VectorPostprocessor, failed to get a parameter with the name \"",
223 param_name,
224 "\".",
225 "\n\nKnown parameters:\n",
227
228 if (!params.isType<VectorPostprocessorName>(param_name))
230 "Supplied parameter with name \"",
231 param_name,
232 "\" of type \"",
233 params.type(param_name),
234 "\" is not an expected type for getting a VectorPostprocessor.\n\n",
235 "The allowed type is \"VectorPostprocessorName\".");
236
237 return params.get<VectorPostprocessorName>(param_name);
238}
239
240void
242 const std::string & param_name, const std::string & vector_name) const
243{
244 // Can't do checking if vpps have not been added
246 return;
247
248 if (!hasVectorPostprocessor(param_name))
249 _vpi_moose_object.paramError(param_name,
250 "A VectorPostprocessor with the name \"",
251 getVectorPostprocessorName(param_name),
252 "\" was not found.");
253 if (!hasVectorPostprocessor(param_name, vector_name))
254 _vpi_moose_object.paramError(param_name,
255 "The VectorPostprocessor \"",
256 getVectorPostprocessorName(param_name),
257 "\" does not have a vector named \"",
258 vector_name,
259 "\".");
260}
261
262void
264 const VectorPostprocessorName & name, const std::string & vector_name) const
265{
266 // Can't do checking if vpps have not been added
268 return;
269
272 "A VectorPostprocessor with the name \"", name, "\" was not found.");
273 if (!hasVectorPostprocessorByName(name, vector_name))
274 _vpi_moose_object.mooseError("The VectorPostprocessor \"",
275 name,
276 "\" does not have a vector named \"",
277 vector_name,
278 "\".");
279}
280
283 const VectorPostprocessorName & name,
284 const std::string & vector_name,
285 bool broadcast,
286 std::size_t t_index) const
287{
290
293 VectorPostprocessorReporterName(name, vector_name), _vpi_moose_object, mode, t_index);
294}
295
298 const VectorPostprocessorName & name, const std::string & vector_name) const
299{
302
303 // The complete name of the store Reporter value
304 const VectorPostprocessorReporterName r_name(name, vector_name);
305
306 // Indicate the scatter value is desired, so the the VectorPostprocessorContext will do scatter
309
310 // Retrieve the VectorPostprocessorContext which contains the scattered value to be referenced
311 const auto & context = _vpi_feproblem.getReporterData().getReporterContextBase(r_name);
312 auto vpp_context_ptr =
313 dynamic_cast<const VectorPostprocessorContext<VectorPostprocessorValue> *>(&context);
314 mooseAssert(vpp_context_ptr, "Failed to get the VectorPostprocessorContext");
315 return *vpp_context_ptr;
316}
317
318bool
@ VectorPostprocessor
InputParameters emptyInputParameters()
Real ScatterVectorPostprocessorValue
Definition MooseTypes.h:232
unsigned int THREAD_ID
Definition MooseTypes.h:237
std::vector< Real > VectorPostprocessorValue
Definition MooseTypes.h:231
const ReporterMode REPORTER_MODE_REPLICATED
const ReporterMode REPORTER_MODE_ROOT
const ReporterMode REPORTER_MODE_VPP_SCATTER
bool isTaskComplete(const std::string &task) const
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const VectorPostprocessor & getVectorPostprocessorObjectByName(const std::string &object_name, const THREAD_ID tid=0) const
Return the VPP object given the name.
const ReporterData & getReporterData() const
Provides const access the ReporterData object.
TheWarehouse & theWarehouse() const
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
Definition MooseApp.h:217
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
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
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
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
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.
const T & getReporterValue(const ReporterName &reporter_name, const MooseObject &consumer, const ReporterMode &mode, const std::size_t time_index=0) const
Method for returning read only references to Reporter values.
MooseEnumItem that automatically creates the ID and doesn't allow the ID to be assigned.
QueryCache & condition(Args &&... args)
Adds a new condition to the query.
Query query()
query creates and returns an initialized a query object for querying objects from the warehouse.
const ScatterVectorPostprocessorValue & getScatterVectorPostprocessorValueByName(const VectorPostprocessorName &name, const std::string &vector_name) const
Return the scatter value for the post processor.
bool hasVectorPostprocessor(const std::string &param_name, const std::string &vector_name) const
Determine if the VectorPostprocessor data exists by parameter.
const VectorPostprocessorValue & getVectorPostprocessorValue(const std::string &param_name, const std::string &vector_name) const
DEPRECATED: Use the new version where you need to specify whether or not the vector must be broadcast...
bool isVectorPostprocessorDistributed(const std::string &param_name) const
Return true if the VectorPostprocessor is marked with parallel_type as DISTRIBUTED.
bool hasVectorPostprocessorByName(const VectorPostprocessorName &name, const std::string &vector_name) const
Determine if the VectorPostprocessor data exists by name.
const FEProblemBase & _vpi_feproblem
Reference the FEProblemBase class.
const VectorPostprocessorValue & getVectorPostprocessorByNameHelper(const VectorPostprocessorName &name, const std::string &vector_name, bool broadcast, std::size_t t_index) const
Helper function for extracting VPP data from ReporterData object.
void possiblyCheckHasVectorPostprocessorByName(const VectorPostprocessorName &name, const std::string &vector_name) const
virtual void addVectorPostprocessorDependencyHelper(const VectorPostprocessorName &) const
Helper for deriving classes to override to add dependencies when a VectorPostprocessor is requested.
void possiblyCheckHasVectorPostprocessor(const std::string &param_name, const std::string &vector_name) const
Helpers for "possibly" checking if a vpp exists.
const ScatterVectorPostprocessorValue & getScatterVectorPostprocessorValueOldByName(const VectorPostprocessorName &name, const std::string &vector_name) const
Return the old scatter value for the post processor.
const VectorPostprocessorName & getVectorPostprocessorName(const std::string &param_name) const
Get the name of a VectorPostprocessor associated with a parameter.
const VectorPostprocessorValue & getVectorPostprocessorValueByName(const VectorPostprocessorName &name, const std::string &vector_name) const
DEPRECATED: Use the new version where you need to specify whether or not the vector must be broadcast...
const VectorPostprocessorValue & getVectorPostprocessorValueOld(const std::string &param_name, const std::string &vector_name) const
DEPRECATED: Use the new version where you need to specify whether or not the vector must be broadcast...
const ScatterVectorPostprocessorValue & getScatterVectorPostprocessorValueOld(const std::string &param_name, const std::string &vector_name) const
Return the old scatter value for the post processor.
const ScatterVectorPostprocessorValue & getScatterVectorPostprocessorValue(const std::string &param_name, const std::string &vector_name) const
Return the scatter value for the post processor.
const VectorPostprocessorContext< VectorPostprocessorValue > & getVectorPostprocessorContextByNameHelper(const VectorPostprocessorName &name, const std::string &vector_name) const
Helper for getting the VPP context that handles scatter values.
const VectorPostprocessorValue & getVectorPostprocessorValueOldByName(const VectorPostprocessorName &name, const std::string &vector_name) const
DEPRECATED: Use the new version where you need to specify whether or not the vector must be broadcast...
bool isVectorPostprocessorDistributedByName(const VectorPostprocessorName &name) const
VectorPostprocessorInterface(const MooseObject *moose_object, bool broadcast_by_default=false)
Constructor.
const bool _broadcast_by_default
Whether or not to force broadcasting by default.
const MooseObject & _vpi_moose_object
The MooseObject that uses this interface.
A ReporterName that represents a VectorPostprocessor.
bool isDistributed() const
Return true if the VPP is operating in distributed mode.