https://mooseframework.inl.gov
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 
21 {
22  return emptyInputParameters();
23 }
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);
53  return getVectorPostprocessorValueByName(getVectorPostprocessorName(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 
150 bool
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 
161 bool
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 
174 bool
175 VectorPostprocessorInterface::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 
184 bool
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 
202 bool
204 {
206 }
207 
208 bool
210  const VectorPostprocessorName & name) const
211 {
213 }
214 
215 const VectorPostprocessorName &
216 VectorPostprocessorInterface::getVectorPostprocessorName(const std::string & param_name) const
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 
240 void
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 
262 void
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 
291  const ReporterMode mode = broadcast ? REPORTER_MODE_REPLICATED : REPORTER_MODE_ROOT;
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 
318 bool
320 {
321  return _vpi_feproblem.getMooseApp().actionWarehouse().isTaskComplete("add_vector_postprocessor");
322 }
std::string name(const ElemQuality q)
const VectorPostprocessorContext< VectorPostprocessorValue > & getVectorPostprocessorContextByNameHelper(const VectorPostprocessorName &name, const std::string &vector_name) const
Helper for getting the VPP context that handles scatter values.
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:467
const ReporterMode REPORTER_MODE_ROOT
bool hasVectorPostprocessor(const std::string &param_name, const std::string &vector_name) const
Determine if the VectorPostprocessor data exists by parameter.
bool isTaskComplete(const std::string &task) const
void possiblyCheckHasVectorPostprocessor(const std::string &param_name, const std::string &vector_name) const
Helpers for "possibly" checking if a vpp exists.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
const ScatterVectorPostprocessorValue & getScatterVectorPostprocessorValueOldByName(const VectorPostprocessorName &name, const std::string &vector_name) const
Return the old scatter value for the post processor.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
VectorPostprocessorInterface(const MooseObject *moose_object, bool broadcast_by_default=false)
Constructor.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const VectorPostprocessorName & getVectorPostprocessorName(const std::string &param_name) const
Get the name of a VectorPostprocessor associated with a parameter.
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition: MooseBase.h:87
InputParameters emptyInputParameters()
bool isVectorPostprocessorDistributedByName(const VectorPostprocessorName &name) const
A ReporterName that represents a VectorPostprocessor.
Definition: ReporterName.h:152
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...
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...
const ReporterData & getReporterData() const
Provides const access the ReporterData object.
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.
Definition: ReporterData.h:394
void possiblyCheckHasVectorPostprocessorByName(const VectorPostprocessorName &name, const std::string &vector_name) const
TheWarehouse & theWarehouse() const
const ReporterMode REPORTER_MODE_VPP_SCATTER
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
Definition: MooseApp.h:216
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.
const VectorPostprocessor & getVectorPostprocessorObjectByName(const std::string &object_name, const THREAD_ID tid=0) const
Return the VPP object given the name.
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.
virtual void addVectorPostprocessorDependencyHelper(const VectorPostprocessorName &) const
Helper for deriving classes to override to add dependencies when a VectorPostprocessor is requested...
bool isVectorPostprocessorDistributed(const std::string &param_name) const
Return true if the VectorPostprocessor is marked with parallel_type as DISTRIBUTED.
std::vector< Real > VectorPostprocessorValue
Definition: MooseTypes.h:231
Real ScatterVectorPostprocessorValue
Definition: MooseTypes.h:232
bool hasVectorPostprocessorByName(const VectorPostprocessorName &name, const std::string &vector_name) const
Determine if the VectorPostprocessor data exists by name.
const MooseObject & _vpi_moose_object
The MooseObject that uses this interface.
Query query()
query creates and returns an initialized a query object for querying objects from the warehouse...
Definition: TheWarehouse.h:467
const ScatterVectorPostprocessorValue & getScatterVectorPostprocessorValueByName(const VectorPostprocessorName &name, const std::string &vector_name) const
Return the scatter value for the post processor.
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:281
bool isDistributed() const
Return true if the VPP is operating in distributed mode.
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
Definition: ReporterData.h:458
QueryCache & condition(Args &&... args)
Adds a new condition to the query.
Definition: TheWarehouse.h:285
const ReporterMode REPORTER_MODE_REPLICATED
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...
MooseEnumItem that automatically creates the ID and doesn&#39;t allow the ID to be assigned.
Definition: ReporterMode.h:45
const bool _broadcast_by_default
Whether or not to force broadcasting by default.
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 FEProblemBase & _vpi_feproblem
Reference the FEProblemBase class.
const Elem & get(const ElemType type_in)
unsigned int THREAD_ID
Definition: MooseTypes.h:237
const ReporterContextBase & getReporterContextBase(const ReporterName &reporter_name) const
Definition: ReporterData.C:130