https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
11
12#include "FEProblem.h"
13#include "MooseObject.h"
14
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
46PostprocessorInterface::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
54 const unsigned int index /* = 0 */) const
55{
56 return getPostprocessorValueInternal(param_name, index, /* t_index = */ 1);
57}
58
61 const unsigned int index /* = 0 */) const
62{
63 return getPostprocessorValueInternal(param_name, index, /* t_index = */ 2);
64}
65
67PostprocessorInterface::getPostprocessorValueByName(const PostprocessorName & name) const
68{
69 return getPostprocessorValueByNameInternal(name, /* t_index = */ 0);
70}
71
73PostprocessorInterface::getPostprocessorValueOldByName(const PostprocessorName & name) const
74{
75 return getPostprocessorValueByNameInternal(name, /* t_index = */ 1);
76}
77
80{
81 return getPostprocessorValueByNameInternal(name, /* t_index = */ 2);
82}
83
84bool
86 const unsigned int index /* = 0 */) const
87{
89}
90
91bool
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
116bool
117PostprocessorInterface::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
127bool
128PostprocessorInterface::hasPostprocessorByName(const PostprocessorName & name) const
129{
130 if (!postprocessorsAdded())
132 "Cannot call hasPostprocessorByName() until all Postprocessors have been constructed.");
133
136}
137
138std::size_t
139PostprocessorInterface::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
148void
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
194const PostprocessorName &
195PostprocessorInterface::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
201const 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
227const 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 {
240 const auto value = getDefaultPostprocessorValueByName(name);
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
248 else if (postprocessorsAdded() && !hasPostprocessorByName(name))
250 param_name, "A Postprocessor with the name \"", name, "\" was not found.");
251
252 return getPostprocessorValueByNameInternal(name, t_index);
253}
254
255const 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
273bool
InputParameters emptyInputParameters()
Real PostprocessorValue
various MOOSE typedefs
Definition MooseTypes.h:230
const ReporterMode REPORTER_MODE_ROOT
bool isTaskComplete(const std::string &task) const
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const ReporterData & getReporterData() const
Provides const access the ReporterData object.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
std::string type(const std::string &name) const
Prints the type of the requested parameter by name.
bool isType(const std::string &name) const
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another,...
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
Definition MooseApp.h:217
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
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:457
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
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition MooseBase.h:87
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
Interface class for classes which interact with Postprocessors.
virtual void addPostprocessorDependencyHelper(const PostprocessorName &) const
Helper for deriving classes to override to add dependencies when a Postprocessor is requested.
bool isDefaultPostprocessorValueByName(const PostprocessorName &name) const
const PostprocessorValue & getPostprocessorValueOlderByName(const PostprocessorName &name) const
static InputParameters validParams()
std::map< PostprocessorName, std::unique_ptr< PostprocessorValue > > _default_values
Holds the default postprocessor values that are requested (key is PostprocessorName)
const PostprocessorValue & getPostprocessorValueOlder(const std::string &param_name, const unsigned int index=0) const
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.
PostprocessorInterface(const MooseObject *moose_object)
bool isDefaultPostprocessorValue(const std::string &param_name, const unsigned int index=0) const
Determine whether or not the Postprocessor is a default value.
PostprocessorValue getDefaultPostprocessorValueByName(const PostprocessorName &name) const
std::size_t coupledPostprocessors(const std::string &param_name) const
Returns number of Postprocessors coupled under parameter name.
const PostprocessorName & getPostprocessorName(const std::string &param_name, const unsigned int index=0) const
Get the name of a postprocessor.
virtual const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name) const
Retrieve the value of the Postprocessor.
bool hasPostprocessor(const std::string &param_name, const unsigned int index=0) const
Determine if the Postprocessor data exists.
const FEProblemBase & _ppi_feproblem
Reference the the FEProblemBase class.
const PostprocessorValue & getPostprocessorValueInternal(const std::string &param_name, unsigned int index, std::size_t t_index) const
Internal methods for getting Postprocessor values.
const PostprocessorValue & getPostprocessorValueByNameInternal(const PostprocessorName &name, std::size_t t_index) const
bool hasPostprocessorByName(const PostprocessorName &name) const
Determine if the Postprocessor data exists.
const PostprocessorValue & getPostprocessorValueOld(const std::string &param_name, const unsigned int index=0) const
const MooseObject & _ppi_moose_object
The MooseObject that uses this interface.
const InputParameters & _ppi_params
PostprocessorInterface Parameters.
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's old or older values
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.
A ReporterName that represents a Postprocessor.
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
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.