www.mooseframework.org
VectorPostprocessorInterface.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
37  const std::string & vector_name) const
38 {
39  possiblyCheckHasVectorPostprocessor(param_name, vector_name);
40  return getVectorPostprocessorValueByName(getVectorPostprocessorName(param_name), vector_name);
41 }
42 
45  const VectorPostprocessorName & name, const std::string & vector_name) const
46 {
48 }
49 
52  const std::string & vector_name) const
53 {
54  possiblyCheckHasVectorPostprocessor(param_name, vector_name);
56 }
57 
60  const VectorPostprocessorName & name, const std::string & vector_name) const
61 {
63 }
64 
67  const std::string & vector_name,
68  bool needs_broadcast) const
69 {
70  possiblyCheckHasVectorPostprocessor(param_name, vector_name);
72  getVectorPostprocessorName(param_name), vector_name, needs_broadcast);
73 }
74 
77  const VectorPostprocessorName & name,
78  const std::string & vector_name,
79  bool needs_broadcast) const
80 {
82  name, vector_name, needs_broadcast || _broadcast_by_default, 0);
83 }
84 
87  const std::string & vector_name,
88  bool needs_broadcast) const
89 {
90  possiblyCheckHasVectorPostprocessor(param_name, vector_name);
92  getVectorPostprocessorName(param_name), vector_name, needs_broadcast);
93 }
94 
97  const VectorPostprocessorName & name,
98  const std::string & vector_name,
99  bool needs_broadcast) const
100 {
102  name, vector_name, needs_broadcast || _broadcast_by_default, 1);
103 }
104 
107  const std::string & param_name, const std::string & vector_name) const
108 {
109  possiblyCheckHasVectorPostprocessor(param_name, vector_name);
111  vector_name);
112 }
113 
116  const VectorPostprocessorName & name, const std::string & vector_name) const
117 {
118  return getVectorPostprocessorContextByNameHelper(name, vector_name).getScatterValue();
119 }
120 
123  const std::string & param_name, const std::string & vector_name) const
124 {
125  possiblyCheckHasVectorPostprocessor(param_name, vector_name);
127  vector_name);
128 }
129 
132  const VectorPostprocessorName & name, const std::string & vector_name) const
133 {
134  return getVectorPostprocessorContextByNameHelper(name, vector_name).getScatterValueOld();
135 }
136 
137 bool
139  const std::string & vector_name) const
140 {
142  _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessor() until all VectorPostprocessors "
143  "have been constructed.");
144 
145  return hasVectorPostprocessorByName(getVectorPostprocessorName(param_name), vector_name);
146 }
147 
148 bool
150  const std::string & vector_name) const
151 {
153  _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessorByName() until all "
154  "VectorPostprocessors have been constructed.");
155 
157  VectorPostprocessorReporterName(name, vector_name));
158 
159  if (has_vpp)
160  mooseAssert(_vpi_feproblem.hasUserObject(name) && dynamic_cast<const VectorPostprocessor *>(
162  "Has reporter VectorPostprocessor Reporter value but not VectorPostprocessor UO");
163 
164  return has_vpp;
165 }
166 
167 bool
168 VectorPostprocessorInterface::hasVectorPostprocessor(const std::string & param_name) const
169 {
171  _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessor() until all "
172  "VectorPostprocessors have been constructed.");
173 
175 }
176 
177 bool
179  const VectorPostprocessorName & name) const
180 {
182  _vpi_feproblem.mooseError("Cannot call hasVectorPostprocessorByName() until all "
183  "VectorPostprocessors have been constructed.");
184 
186  dynamic_cast<const VectorPostprocessor *>(&_vpi_feproblem.getUserObjectBase(name));
187 }
188 
189 bool
191 {
193 }
194 
195 bool
197  const VectorPostprocessorName & name) const
198 {
200 }
201 
202 const VectorPostprocessorName &
203 VectorPostprocessorInterface::getVectorPostprocessorName(const std::string & param_name) const
204 {
205  const auto & params = _vpi_moose_object.parameters();
206 
207  if (!params.isParamValid(param_name))
209  "When getting a VectorPostprocessor, failed to get a parameter with the name \"",
210  param_name,
211  "\".",
212  "\n\nKnown parameters:\n",
214 
215  if (!params.isType<VectorPostprocessorName>(param_name))
217  "Supplied parameter with name \"",
218  param_name,
219  "\" of type \"",
220  params.type(param_name),
221  "\" is not an expected type for getting a VectorPostprocessor.\n\n",
222  "The allowed type is \"VectorPostprocessorName\".");
223 
224  return params.get<VectorPostprocessorName>(param_name);
225 }
226 
227 void
229  const std::string & param_name, const std::string & vector_name) const
230 {
231  // Can't do checking if vpps have not been added
233  return;
234 
235  if (!hasVectorPostprocessor(param_name))
236  _vpi_moose_object.paramError(param_name,
237  "A VectorPostprocessor with the name \"",
238  getVectorPostprocessorName(param_name),
239  "\" was not found.");
240  if (!hasVectorPostprocessor(param_name, vector_name))
241  _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
251  const VectorPostprocessorName & name, const std::string & vector_name) const
252 {
253  // Can't do checking if vpps have not been added
255  return;
256 
259  "A VectorPostprocessor with the name \"", name, "\" was not found.");
260  if (!hasVectorPostprocessorByName(name, vector_name))
261  _vpi_moose_object.mooseError("The VectorPostprocessor \"",
262  name,
263  "\" does not have a vector named \"",
264  vector_name,
265  "\".");
266 }
267 
270  const VectorPostprocessorName & name,
271  const std::string & vector_name,
272  bool broadcast,
273  std::size_t t_index) const
274 {
277 
278  const ReporterMode mode = broadcast ? REPORTER_MODE_REPLICATED : REPORTER_MODE_ROOT;
280  VectorPostprocessorReporterName(name, vector_name), _vpi_moose_object, mode, t_index);
281 }
282 
285  const VectorPostprocessorName & name, const std::string & vector_name) const
286 {
289 
290  // The complete name of the store Reporter value
291  const VectorPostprocessorReporterName r_name(name, vector_name);
292 
293  // Indicate the scatter value is desired, so the the VectorPostprocessorContext will do scatter
296 
297  // Retrieve the VectorPostprocessorContext which contains the scattered value to be referenced
298  const auto & context = _vpi_feproblem.getReporterData().getReporterContextBase(r_name);
299  auto vpp_context_ptr =
300  dynamic_cast<const VectorPostprocessorContext<VectorPostprocessorValue> *>(&context);
301  mooseAssert(vpp_context_ptr, "Failed to get the VectorPostprocessorContext");
302  return *vpp_context_ptr;
303 }
304 
305 bool
307 {
308  return _vpi_feproblem.getMooseApp().actionWarehouse().isTaskComplete("add_vector_postprocessor");
309 }
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.
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.
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:1147
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:45
InputParameters emptyInputParameters()
bool isVectorPostprocessorDistributedByName(const VectorPostprocessorName &name) const
A ReporterName that represents a VectorPostprocessor.
Definition: ReporterName.h:143
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:379
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:33
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
Definition: MooseApp.h:195
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.
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 ...
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:192
Real ScatterVectorPostprocessorValue
Definition: MooseTypes.h:193
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.
bool isDistributed() const
Return true if the VPP is operating in distributed mode.
const InputParameters & parameters() const
Get the parameters of the object.
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:436
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:198
const ReporterContextBase & getReporterContextBase(const ReporterName &reporter_name) const
Definition: ReporterData.C:105