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 
19 {
20  return emptyInputParameters();
21 }
22 
24  bool broadcast_by_default)
25  : _broadcast_by_default(broadcast_by_default),
26  _vpi_moose_object(*moose_object),
27  _vpi_feproblem(*_vpi_moose_object.parameters().getCheckedPointerParam<FEProblemBase *>(
28  "_fe_problem_base")),
29  _vpi_tid(_vpi_moose_object.parameters().have_parameter<THREAD_ID>("_tid")
30  ? _vpi_moose_object.parameters().get<THREAD_ID>("_tid")
31  : 0)
32 {
33 }
34 
35 #ifdef MOOSE_KOKKOS_ENABLED
38  : _broadcast_by_default(object._broadcast_by_default),
39  _vpi_moose_object(object._vpi_moose_object),
40  _vpi_feproblem(object._vpi_feproblem),
41  _vpi_tid(object._vpi_tid)
42 {
43 }
44 #endif
45 
48  const std::string & vector_name) const
49 {
50  possiblyCheckHasVectorPostprocessor(param_name, vector_name);
51  return getVectorPostprocessorValueByName(getVectorPostprocessorName(param_name), vector_name);
52 }
53 
56  const VectorPostprocessorName & name, const std::string & vector_name) const
57 {
59 }
60 
63  const std::string & vector_name) const
64 {
65  possiblyCheckHasVectorPostprocessor(param_name, vector_name);
67 }
68 
71  const VectorPostprocessorName & name, const std::string & vector_name) const
72 {
74 }
75 
78  const std::string & vector_name,
79  bool needs_broadcast) const
80 {
81  possiblyCheckHasVectorPostprocessor(param_name, vector_name);
83  getVectorPostprocessorName(param_name), vector_name, needs_broadcast);
84 }
85 
88  const VectorPostprocessorName & name,
89  const std::string & vector_name,
90  bool needs_broadcast) const
91 {
93  name, vector_name, needs_broadcast || _broadcast_by_default, 0);
94 }
95 
98  const std::string & vector_name,
99  bool needs_broadcast) const
100 {
101  possiblyCheckHasVectorPostprocessor(param_name, vector_name);
103  getVectorPostprocessorName(param_name), vector_name, needs_broadcast);
104 }
105 
108  const VectorPostprocessorName & name,
109  const std::string & vector_name,
110  bool needs_broadcast) const
111 {
113  name, vector_name, needs_broadcast || _broadcast_by_default, 1);
114 }
115 
118  const std::string & param_name, const std::string & vector_name) const
119 {
120  possiblyCheckHasVectorPostprocessor(param_name, vector_name);
122  vector_name);
123 }
124 
127  const VectorPostprocessorName & name, const std::string & vector_name) const
128 {
129  return getVectorPostprocessorContextByNameHelper(name, vector_name).getScatterValue();
130 }
131 
134  const std::string & param_name, const std::string & vector_name) const
135 {
136  possiblyCheckHasVectorPostprocessor(param_name, vector_name);
138  vector_name);
139 }
140 
143  const VectorPostprocessorName & name, const std::string & vector_name) const
144 {
145  return getVectorPostprocessorContextByNameHelper(name, vector_name).getScatterValueOld();
146 }
147 
148 bool
150  const std::string & vector_name) const
151 {
153  _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessor() until all VectorPostprocessors "
154  "have been constructed.");
155 
156  return hasVectorPostprocessorByName(getVectorPostprocessorName(param_name), vector_name);
157 }
158 
159 bool
161  const std::string & vector_name) const
162 {
164  _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessorByName() until all "
165  "VectorPostprocessors have been constructed.");
166 
168  VectorPostprocessorReporterName(name, vector_name));
169 
170  if (has_vpp)
171  mooseAssert(_vpi_feproblem.hasUserObject(name) && dynamic_cast<const VectorPostprocessor *>(
173  "Has reporter VectorPostprocessor Reporter value but not VectorPostprocessor UO");
174 
175  return has_vpp;
176 }
177 
178 bool
179 VectorPostprocessorInterface::hasVectorPostprocessor(const std::string & param_name) const
180 {
182  _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessor() until all "
183  "VectorPostprocessors have been constructed.");
184 
186 }
187 
188 bool
190  const VectorPostprocessorName & name) const
191 {
193  _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessorByName() until all "
194  "VectorPostprocessors have been constructed.");
195 
197  dynamic_cast<const VectorPostprocessor *>(&_vpi_feproblem.getUserObjectBase(name));
198 }
199 
200 bool
202 {
204 }
205 
206 bool
208  const VectorPostprocessorName & name) const
209 {
211 }
212 
213 const VectorPostprocessorName &
214 VectorPostprocessorInterface::getVectorPostprocessorName(const std::string & param_name) const
215 {
216  const auto & params = _vpi_moose_object.parameters();
217 
218  if (!params.isParamValid(param_name))
220  "When getting a VectorPostprocessor, failed to get a parameter with the name \"",
221  param_name,
222  "\".",
223  "\n\nKnown parameters:\n",
225 
226  if (!params.isType<VectorPostprocessorName>(param_name))
228  "Supplied parameter with name \"",
229  param_name,
230  "\" of type \"",
231  params.type(param_name),
232  "\" is not an expected type for getting a VectorPostprocessor.\n\n",
233  "The allowed type is \"VectorPostprocessorName\".");
234 
235  return params.get<VectorPostprocessorName>(param_name);
236 }
237 
238 void
240  const std::string & param_name, const std::string & vector_name) const
241 {
242  // Can't do checking if vpps have not been added
244  return;
245 
246  if (!hasVectorPostprocessor(param_name))
247  _vpi_moose_object.paramError(param_name,
248  "A VectorPostprocessor with the name \"",
249  getVectorPostprocessorName(param_name),
250  "\" was not found.");
251  if (!hasVectorPostprocessor(param_name, vector_name))
252  _vpi_moose_object.paramError(param_name,
253  "The VectorPostprocessor \"",
254  getVectorPostprocessorName(param_name),
255  "\" does not have a vector named \"",
256  vector_name,
257  "\".");
258 }
259 
260 void
262  const VectorPostprocessorName & name, const std::string & vector_name) const
263 {
264  // Can't do checking if vpps have not been added
266  return;
267 
270  "A VectorPostprocessor with the name \"", name, "\" was not found.");
271  if (!hasVectorPostprocessorByName(name, vector_name))
272  _vpi_moose_object.mooseError("The VectorPostprocessor \"",
273  name,
274  "\" does not have a vector named \"",
275  vector_name,
276  "\".");
277 }
278 
281  const VectorPostprocessorName & name,
282  const std::string & vector_name,
283  bool broadcast,
284  std::size_t t_index) const
285 {
288 
289  const ReporterMode mode = broadcast ? REPORTER_MODE_REPLICATED : REPORTER_MODE_ROOT;
291  VectorPostprocessorReporterName(name, vector_name), _vpi_moose_object, mode, t_index);
292 }
293 
296  const VectorPostprocessorName & name, const std::string & vector_name) const
297 {
300 
301  // The complete name of the store Reporter value
302  const VectorPostprocessorReporterName r_name(name, vector_name);
303 
304  // Indicate the scatter value is desired, so the the VectorPostprocessorContext will do scatter
307 
308  // Retrieve the VectorPostprocessorContext which contains the scattered value to be referenced
309  const auto & context = _vpi_feproblem.getReporterData().getReporterContextBase(r_name);
310  auto vpp_context_ptr =
311  dynamic_cast<const VectorPostprocessorContext<VectorPostprocessorValue> *>(&context);
312  mooseAssert(vpp_context_ptr, "Failed to get the VectorPostprocessorContext");
313  return *vpp_context_ptr;
314 }
315 
316 bool
318 {
319  return _vpi_feproblem.getMooseApp().actionWarehouse().isTaskComplete("add_vector_postprocessor");
320 }
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:439
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
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1133
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...
bool hasUserObject(const std::string &name) const
Check if there if a user object of given name.
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:388
void possiblyCheckHasVectorPostprocessorByName(const VectorPostprocessorName &name, const std::string &vector_name) 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:27
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
Definition: MooseApp.h:211
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:203
Real ScatterVectorPostprocessorValue
Definition: MooseTypes.h:204
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.
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:271
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:445
const ReporterMode REPORTER_MODE_REPLICATED
const UserObject & getUserObjectBase(const std::string &name, const THREAD_ID tid=0) const
Get the user object by its name.
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...
Base class for Postprocessors that produce a vector of values.
MooseEnumItem that automatically creates the ID and doesn&#39;t allow the ID to be assigned.
Definition: ReporterMode.h:44
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.
unsigned int THREAD_ID
Definition: MooseTypes.h:209
const ReporterContextBase & getReporterContextBase(const ReporterName &reporter_name) const
Definition: ReporterData.C:130