www.mooseframework.org
PostprocessorInterface.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 
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 const PostprocessorValue &
36 PostprocessorInterface::getPostprocessorValue(const std::string & param_name,
37  const unsigned int index /* = 0 */) const
38 {
39  return getPostprocessorValueInternal(param_name, index, /* t_index = */ 0);
40 }
41 
42 const PostprocessorValue &
43 PostprocessorInterface::getPostprocessorValueOld(const std::string & param_name,
44  const unsigned int index /* = 0 */) const
45 {
46  return getPostprocessorValueInternal(param_name, index, /* t_index = */ 1);
47 }
48 
49 const PostprocessorValue &
51  const unsigned int index /* = 0 */) const
52 {
53  return getPostprocessorValueInternal(param_name, index, /* t_index = */ 2);
54 }
55 
56 const PostprocessorValue &
57 PostprocessorInterface::getPostprocessorValueByName(const PostprocessorName & name) const
58 {
59  return getPostprocessorValueByNameInternal(name, /* t_index = */ 0);
60 }
61 
62 const PostprocessorValue &
63 PostprocessorInterface::getPostprocessorValueOldByName(const PostprocessorName & name) const
64 {
65  return getPostprocessorValueByNameInternal(name, /* t_index = */ 1);
66 }
67 
68 const PostprocessorValue &
69 PostprocessorInterface::getPostprocessorValueOlderByName(const PostprocessorName & name) const
70 {
71  return getPostprocessorValueByNameInternal(name, /* t_index = */ 2);
72 }
73 
74 bool
76  const unsigned int index /* = 0 */) const
77 {
79 }
80 
81 bool
82 PostprocessorInterface::isDefaultPostprocessorValueByName(const PostprocessorName & name) const
83 {
84  // We do allow actual Postprocessor objects to have names that will succeed in being
85  // represented as a double... so if the name does actually exist as a PP, it's not a default
88  return false;
89 
90  std::istringstream ss(name);
91  Real real_value = -std::numeric_limits<Real>::max();
92  return (ss >> real_value && ss.eof());
93 }
94 
97 {
98  mooseAssert(isDefaultPostprocessorValueByName(name), "Not a default value");
99 
100  Real real_value = -std::numeric_limits<Real>::max();
101  std::istringstream ss(name);
102  ss >> real_value;
103  return real_value;
104 }
105 
106 bool
107 PostprocessorInterface::hasPostprocessor(const std::string & param_name,
108  const unsigned int index /* = 0 */) const
109 {
110  if (!postprocessorsAdded())
112  "Cannot call hasPostprocessor() until all Postprocessors have been constructed.");
113 
114  return hasPostprocessorByName(getPostprocessorNameInternal(param_name, index));
115 }
116 
117 bool
118 PostprocessorInterface::hasPostprocessorByName(const PostprocessorName & name) const
119 {
120  if (!postprocessorsAdded())
122  "Cannot call hasPostprocessorByName() until all Postprocessors have been constructed.");
123 
126 }
127 
128 std::size_t
129 PostprocessorInterface::coupledPostprocessors(const std::string & param_name) const
130 {
131  checkParam(param_name);
132 
133  if (_ppi_params.isType<PostprocessorName>(param_name))
134  return 1;
135  return _ppi_params.get<std::vector<PostprocessorName>>(param_name).size();
136 }
137 
138 void
140  const std::string & param_name,
141  const unsigned int index /* = std::numeric_limits<unsigned int>::max() */) const
142 {
143  const bool check_index = index != std::numeric_limits<unsigned int>::max();
144 
145  if (!_ppi_params.isParamValid(param_name))
147  "When getting a Postprocessor, failed to get a parameter with the name \"",
148  param_name,
149  "\".",
150  "\n\nKnown parameters:\n",
152 
153  if (_ppi_params.isType<PostprocessorName>(param_name))
154  {
155  if (check_index && index > 0)
156  _ppi_moose_object.paramError(param_name,
157  "A Postprocessor was requested with index ",
158  index,
159  " but a single Postprocessor is coupled.");
160  }
161  else if (_ppi_params.isType<std::vector<PostprocessorName>>(param_name))
162  {
163  const auto & names = _ppi_params.get<std::vector<PostprocessorName>>(param_name);
164  if (check_index && names.size() <= index)
165  _ppi_moose_object.paramError(param_name,
166  "A Postprocessor was requested with index ",
167  index,
168  " but only ",
169  names.size(),
170  " Postprocessors are coupled.");
171  }
172  else
173  {
175  "Supplied parameter with name \"",
176  param_name,
177  "\" of type \"",
178  _ppi_params.type(param_name),
179  "\" is not an expected type for getting a Postprocessor.\n\n",
180  "Allowed types are \"PostprocessorName\" and \"std::vector<PostprocessorName>\".");
181  }
182 }
183 
184 const PostprocessorName &
185 PostprocessorInterface::getPostprocessorName(const std::string & param_name,
186  const unsigned int index /* = 0 */) const
187 {
188  return getPostprocessorNameInternal(param_name, index, /* allow_default_value = */ false);
189 }
190 
191 const PostprocessorName &
193  const std::string & param_name,
194  const unsigned int index,
195  const bool allow_default_value /* = true */) const
196 {
197  checkParam(param_name, index);
198 
199  const auto & name = _ppi_params.isType<PostprocessorName>(param_name)
200  ? _ppi_params.get<PostprocessorName>(param_name)
201  : _ppi_params.get<std::vector<PostprocessorName>>(param_name)[index];
202 
203  if (!allow_default_value && isDefaultPostprocessorValueByName(name))
204  {
205  std::stringstream oss;
206  oss << "Cannot get the name associated with PostprocessorName parameter \"" << param_name
207  << "\"";
208  if (index)
209  oss << " at index " << index;
210  oss << ",\nbecause said parameter is a default Postprocessor value.";
211  _ppi_moose_object.paramError(param_name, oss.str());
212  }
213 
214  return name;
215 }
216 
217 const PostprocessorValue &
219  unsigned int index,
220  std::size_t t_index) const
221 {
222  const auto & name = getPostprocessorNameInternal(param_name, index);
223 
224  // If the Postprocessor is a default value (either set by addParam or set to a constant
225  // value by the user in input/an action), we covert the name to a value, store said
226  // value locally, and return it so that it fits in with the rest of the interface
227  // (needing a reference to a value)
229  {
231  const auto & value_ref =
232  *_default_values.emplace(name, std::make_unique<PostprocessorValue>(value))
233  .first->second; // first is inserted pair, second is value in pair
234  mooseAssert(value == value_ref, "Inconsistent default value");
235  return value_ref;
236  }
237  // If not a default and all pps have been added, we check check for existance
240  param_name, "A Postprocessor with the name \"", name, "\" was not found.");
241 
242  return getPostprocessorValueByNameInternal(name, t_index);
243 }
244 
245 const PostprocessorValue &
247  std::size_t t_index) const
248 {
249  mooseAssert(t_index < 3, "Invalid time index");
250  mooseAssert(!isDefaultPostprocessorValueByName(name), "Should not be default");
251 
252  // If all pps have been added, we can check for existance
254  _ppi_moose_object.mooseError("A Postprocessor with the name \"", name, "\" was not found.");
255 
256  if (t_index == 0)
258 
261 }
262 
263 bool
265 {
266  return _ppi_feproblem.getMooseApp().actionWarehouse().isTaskComplete("add_postprocessor");
267 }
std::string name(const ElemQuality q)
static InputParameters validParams()
const PostprocessorValue & getPostprocessorValueOlderByName(const PostprocessorName &name) const
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 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:44
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:379
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:33
bool hasPostprocessorByName(const PostprocessorName &name) const
Determine if the Postprocessor data exists.
Real PostprocessorValue
various MOOSE typedefs
Definition: MooseTypes.h:191
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:206
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 ...
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:134
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.
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
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.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.