https://mooseframework.inl.gov
PostprocessorInterface.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 
10 #include "PostprocessorInterface.h"
11 
12 #include "FEProblem.h"
13 #include "MooseObject.h"
14 
17 {
18  return emptyInputParameters();
19 }
20 
22  : _ppi_moose_object(*moose_object),
23  _ppi_params(_ppi_moose_object.parameters()),
24  _ppi_feproblem(*_ppi_params.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"))
25 {
26 }
27 
29  : _ppi_moose_object(*problem),
30  _ppi_params(_ppi_moose_object.parameters()),
31  _ppi_feproblem(*problem)
32 {
33 }
34 
35 #ifdef MOOSE_KOKKOS_ENABLED
38  : _ppi_moose_object(object._ppi_moose_object),
39  _ppi_params(object._ppi_params),
40  _ppi_feproblem(object._ppi_feproblem)
41 {
42 }
43 #endif
44 
45 const PostprocessorValue &
46 PostprocessorInterface::getPostprocessorValue(const std::string & param_name,
47  const unsigned int index /* = 0 */) const
48 {
49  return getPostprocessorValueInternal(param_name, index, /* t_index = */ 0);
50 }
51 
52 const PostprocessorValue &
53 PostprocessorInterface::getPostprocessorValueOld(const std::string & param_name,
54  const unsigned int index /* = 0 */) const
55 {
56  return getPostprocessorValueInternal(param_name, index, /* t_index = */ 1);
57 }
58 
59 const PostprocessorValue &
61  const unsigned int index /* = 0 */) const
62 {
63  return getPostprocessorValueInternal(param_name, index, /* t_index = */ 2);
64 }
65 
66 const PostprocessorValue &
67 PostprocessorInterface::getPostprocessorValueByName(const PostprocessorName & name) const
68 {
69  return getPostprocessorValueByNameInternal(name, /* t_index = */ 0);
70 }
71 
72 const PostprocessorValue &
73 PostprocessorInterface::getPostprocessorValueOldByName(const PostprocessorName & name) const
74 {
75  return getPostprocessorValueByNameInternal(name, /* t_index = */ 1);
76 }
77 
78 const PostprocessorValue &
79 PostprocessorInterface::getPostprocessorValueOlderByName(const PostprocessorName & name) const
80 {
81  return getPostprocessorValueByNameInternal(name, /* t_index = */ 2);
82 }
83 
84 bool
86  const unsigned int index /* = 0 */) const
87 {
89 }
90 
91 bool
92 PostprocessorInterface::isDefaultPostprocessorValueByName(const PostprocessorName & name) const
93 {
94  // We do allow actual Postprocessor objects to have names that will succeed in being
95  // represented as a double... so if the name does actually exist as a PP, it's not a default
98  return false;
99 
100  std::istringstream ss(name);
101  Real real_value = -std::numeric_limits<Real>::max();
102  return (ss >> real_value && ss.eof());
103 }
104 
107 {
108  mooseAssert(isDefaultPostprocessorValueByName(name), "Not a default value");
109 
110  Real real_value = -std::numeric_limits<Real>::max();
111  std::istringstream ss(name);
112  ss >> real_value;
113  return real_value;
114 }
115 
116 bool
117 PostprocessorInterface::hasPostprocessor(const std::string & param_name,
118  const unsigned int index /* = 0 */) const
119 {
120  if (!postprocessorsAdded())
122  "Cannot call hasPostprocessor() until all Postprocessors have been constructed.");
123 
124  return hasPostprocessorByName(getPostprocessorNameInternal(param_name, index));
125 }
126 
127 bool
128 PostprocessorInterface::hasPostprocessorByName(const PostprocessorName & name) const
129 {
130  if (!postprocessorsAdded())
132  "Cannot call hasPostprocessorByName() until all Postprocessors have been constructed.");
133 
136 }
137 
138 std::size_t
139 PostprocessorInterface::coupledPostprocessors(const std::string & param_name) const
140 {
141  checkParam(param_name);
142 
143  if (_ppi_params.isType<PostprocessorName>(param_name))
144  return 1;
145  return _ppi_params.get<std::vector<PostprocessorName>>(param_name).size();
146 }
147 
148 void
150  const std::string & param_name,
151  const unsigned int index /* = std::numeric_limits<unsigned int>::max() */) const
152 {
153  const bool check_index = index != std::numeric_limits<unsigned int>::max();
154 
155  if (!_ppi_params.isParamValid(param_name))
157  "When getting a Postprocessor, failed to get a parameter with the name \"",
158  param_name,
159  "\".",
160  "\n\nKnown parameters:\n",
162 
163  if (_ppi_params.isType<PostprocessorName>(param_name))
164  {
165  if (check_index && index > 0)
166  _ppi_moose_object.paramError(param_name,
167  "A Postprocessor was requested with index ",
168  index,
169  " but a single Postprocessor is coupled.");
170  }
171  else if (_ppi_params.isType<std::vector<PostprocessorName>>(param_name))
172  {
173  const auto & names = _ppi_params.get<std::vector<PostprocessorName>>(param_name);
174  if (check_index && names.size() <= index)
175  _ppi_moose_object.paramError(param_name,
176  "A Postprocessor was requested with index ",
177  index,
178  " but only ",
179  names.size(),
180  " Postprocessors are coupled.");
181  }
182  else
183  {
185  "Supplied parameter with name \"",
186  param_name,
187  "\" of type \"",
188  _ppi_params.type(param_name),
189  "\" is not an expected type for getting a Postprocessor.\n\n",
190  "Allowed types are \"PostprocessorName\" and \"std::vector<PostprocessorName>\".");
191  }
192 }
193 
194 const PostprocessorName &
195 PostprocessorInterface::getPostprocessorName(const std::string & param_name,
196  const unsigned int index /* = 0 */) const
197 {
198  return getPostprocessorNameInternal(param_name, index, /* allow_default_value = */ false);
199 }
200 
201 const PostprocessorName &
203  const std::string & param_name,
204  const unsigned int index,
205  const bool allow_default_value /* = true */) const
206 {
207  checkParam(param_name, index);
208 
209  const auto & name = _ppi_params.isType<PostprocessorName>(param_name)
210  ? _ppi_params.get<PostprocessorName>(param_name)
211  : _ppi_params.get<std::vector<PostprocessorName>>(param_name)[index];
212 
213  if (!allow_default_value && isDefaultPostprocessorValueByName(name))
214  {
215  std::stringstream oss;
216  oss << "Cannot get the name associated with PostprocessorName parameter \"" << param_name
217  << "\"";
218  if (index)
219  oss << " at index " << index;
220  oss << ",\nbecause said parameter is a default Postprocessor value.";
221  _ppi_moose_object.paramError(param_name, oss.str());
222  }
223 
224  return name;
225 }
226 
227 const PostprocessorValue &
229  unsigned int index,
230  std::size_t t_index) const
231 {
232  const auto & name = getPostprocessorNameInternal(param_name, index);
233 
234  // If the Postprocessor is a default value (either set by addParam or set to a constant
235  // value by the user in input/an action), we covert the name to a value, store said
236  // value locally, and return it so that it fits in with the rest of the interface
237  // (needing a reference to a value)
239  {
241  const auto & value_ref =
242  *_default_values.emplace(name, std::make_unique<PostprocessorValue>(value))
243  .first->second; // first is inserted pair, second is value in pair
244  mooseAssert(value == value_ref, "Inconsistent default value");
245  return value_ref;
246  }
247  // If not a default and all pps have been added, we check check for existance
250  param_name, "A Postprocessor with the name \"", name, "\" was not found.");
251 
252  return getPostprocessorValueByNameInternal(name, t_index);
253 }
254 
255 const PostprocessorValue &
257  std::size_t t_index) const
258 {
259  mooseAssert(t_index < 3, "Invalid time index");
260  mooseAssert(!isDefaultPostprocessorValueByName(name), "Should not be default");
261 
262  // If all pps have been added, we can check for existance
264  _ppi_moose_object.mooseError("A Postprocessor with the name \"", name, "\" was not found.");
265 
266  if (t_index == 0)
268 
271 }
272 
273 bool
275 {
276  return _ppi_feproblem.getMooseApp().actionWarehouse().isTaskComplete("add_postprocessor");
277 }
std::string name(const ElemQuality q)
static InputParameters validParams()
const PostprocessorValue & getPostprocessorValueOlderByName(const PostprocessorName &name) const
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 FEProblemBase & _ppi_feproblem
Reference the the FEProblemBase class.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
const ReporterMode REPORTER_MODE_ROOT
bool isTaskComplete(const std::string &task) const
bool hasPostprocessor(const std::string &param_name, const unsigned int index=0) const
Determine if the Postprocessor data exists.
bool isDefaultPostprocessorValueByName(const PostprocessorName &name) const
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
const PostprocessorValue & getPostprocessorValueOlder(const std::string &param_name, const unsigned int index=0) const
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const PostprocessorValue & getPostprocessorValueOldByName(const PostprocessorName &name) const
const PostprocessorValue & getPostprocessorValue(const std::string &param_name, const unsigned int index=0) const
doco-normal-methods-begin Retrieve the value of a Postprocessor or one of it&#39;s old or older values ...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition: MooseBase.h:87
InputParameters emptyInputParameters()
auto max(const L &left, const R &right)
PostprocessorValue getDefaultPostprocessorValueByName(const PostprocessorName &name) const
const ReporterData & getReporterData() const
Provides const access the ReporterData object.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
const PostprocessorName & getPostprocessorNameInternal(const std::string &param_name, const unsigned int index, const bool allow_default_value=true) const
Internal method for getting the PostprocessorName associated with a paremeter.
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
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:27
bool hasPostprocessorByName(const PostprocessorName &name) const
Determine if the Postprocessor data exists.
Real PostprocessorValue
various MOOSE typedefs
Definition: MooseTypes.h:202
const MooseObject & _ppi_moose_object
The MooseObject that uses this interface.
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
Definition: MooseApp.h:211
void checkParam(const std::string &param_name, const unsigned int index=std::numeric_limits< unsigned int >::max()) const
Checks the parameters relating to a Postprocessor.
const PostprocessorValue & getPostprocessorValueInternal(const std::string &param_name, unsigned int index, std::size_t t_index) const
Internal methods for getting Postprocessor values.
bool isDefaultPostprocessorValue(const std::string &param_name, const unsigned int index=0) const
Determine whether or not the Postprocessor is a default value.
A ReporterName that represents a Postprocessor.
Definition: ReporterName.h:143
virtual const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name) const
Retrieve the value of the Postprocessor.
const PostprocessorValue & getPostprocessorValueByNameInternal(const PostprocessorName &name, std::size_t t_index) const
bool isType(const std::string &name) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void addPostprocessorDependencyHelper(const PostprocessorName &) const
Helper for deriving classes to override to add dependencies when a Postprocessor is requested...
std::string type(const std::string &name) const
Prints the type of the requested parameter by name.
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 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
PostprocessorInterface(const MooseObject *moose_object)
std::size_t coupledPostprocessors(const std::string &param_name) const
Returns number of Postprocessors coupled under parameter name.
const PostprocessorValue & getPostprocessorValueOld(const std::string &param_name, const unsigned int index=0) const
const InputParameters & _ppi_params
PostprocessorInterface Parameters.
std::map< PostprocessorName, std::unique_ptr< PostprocessorValue > > _default_values
Holds the default postprocessor values that are requested (key is PostprocessorName) ...
const PostprocessorName & getPostprocessorName(const std::string &param_name, const unsigned int index=0) const
Get the name of a postprocessor.
Interface class for classes which interact with Postprocessors.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.