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 #include "FEProblem.h"
12 #include "Postprocessor.h"
13 #include "MooseTypes.h"
14 #include "MooseObject.h"
15 
17  : _ppi_params(moose_object->parameters()),
18  _pi_feproblem(*_ppi_params.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"))
19 {
20 }
21 
22 const PostprocessorValue &
23 PostprocessorInterface::getPostprocessorValue(const std::string & name, unsigned int index)
24 {
25  if (singlePostprocessor(name) && index > 0)
26  mooseError("Postprocessor requested with index ",
27  index,
28  " when only a single postprocessor is coupled.");
29 
30  // Return the default if the Postprocessor does not exist and a default does, otherwise
31  // continue as usual
32  if (!hasPostprocessor(name, index) && _ppi_params.hasDefaultPostprocessorValue(name, index))
33  return _ppi_params.getDefaultPostprocessorValue(name, false, index);
34  else
35  {
36  if (singlePostprocessor(name))
37  return _pi_feproblem.getPostprocessorValue(_ppi_params.get<PostprocessorName>(name));
38 
39  // check size of parameter array here
40  if (index >= _ppi_params.get<std::vector<PostprocessorName>>(name).size())
41  mooseError("Postprocessor requested with index ",
42  index,
43  " but parameter ",
44  name,
45  " has only ",
46  _ppi_params.get<std::vector<PostprocessorName>>(name).size(),
47  " entries.");
48 
50  _ppi_params.get<std::vector<PostprocessorName>>(name)[index]);
51  }
52 }
53 
54 const PostprocessorValue &
55 PostprocessorInterface::getPostprocessorValueOld(const std::string & name, unsigned int index)
56 {
57  if (singlePostprocessor(name) && index > 0)
58  mooseError("Postprocessor requested with index ",
59  index,
60  " when only a single postprocessor is coupled.");
61 
62  // Return the default if the Postprocessor does not exist and a default does, otherwise
63  // continue as usual
64  if (!hasPostprocessor(name, index) && _ppi_params.hasDefaultPostprocessorValue(name, index))
65  return _ppi_params.getDefaultPostprocessorValue(name, false, index);
66  else
67  {
68  if (singlePostprocessor(name))
69  return _pi_feproblem.getPostprocessorValueOld(_ppi_params.get<PostprocessorName>(name));
70 
71  // check size of parameter array here
72  if (index >= _ppi_params.get<std::vector<PostprocessorName>>(name).size())
73  mooseError("Postprocessor requested with index ",
74  index,
75  " but parameter ",
76  name,
77  " has only ",
78  _ppi_params.get<std::vector<PostprocessorName>>(name).size(),
79  " entries.");
80 
82  _ppi_params.get<std::vector<PostprocessorName>>(name)[index]);
83  }
84 }
85 
86 const PostprocessorValue &
87 PostprocessorInterface::getPostprocessorValueOlder(const std::string & name, unsigned int index)
88 {
89  if (singlePostprocessor(name) && index > 0)
90  mooseError("Postprocessor requested with index ",
91  index,
92  " when only a single postprocessor is coupled.");
93 
94  // Return the default if the Postprocessor does not exist and a default does, otherwise
95  // continue as usual
96  if (!hasPostprocessor(name, index) && _ppi_params.hasDefaultPostprocessorValue(name, index))
97  return _ppi_params.getDefaultPostprocessorValue(name, false, index);
98  else
99  {
100  if (singlePostprocessor(name))
101  return _pi_feproblem.getPostprocessorValueOlder(_ppi_params.get<PostprocessorName>(name));
102 
103  // check size of parameter array here
104  if (index >= _ppi_params.get<std::vector<PostprocessorName>>(name).size())
105  mooseError("Postprocessor requested with index ",
106  index,
107  " but parameter ",
108  name,
109  " has only ",
110  _ppi_params.get<std::vector<PostprocessorName>>(name).size(),
111  " entries.");
112 
114  _ppi_params.get<std::vector<PostprocessorName>>(name)[index]);
115  }
116 }
117 
118 const PostprocessorValue &
120 {
122 }
123 
124 const PostprocessorValue &
126 {
128 }
129 
130 const PostprocessorValue &
132 {
134 }
135 
136 bool
137 PostprocessorInterface::hasPostprocessor(const std::string & name, unsigned int index) const
138 {
139  if (singlePostprocessor(name))
140  return _pi_feproblem.hasPostprocessor(_ppi_params.get<PostprocessorName>(name));
142  _ppi_params.get<std::vector<PostprocessorName>>(name)[index]);
143 }
144 
145 unsigned int
146 PostprocessorInterface::coupledPostprocessors(const std::string & name) const
147 {
148  if (singlePostprocessor(name))
149  return 1;
150  return _ppi_params.get<std::vector<PostprocessorName>>(name).size();
151 }
152 
153 bool
154 PostprocessorInterface::singlePostprocessor(const std::string & name) const
155 {
156  return _ppi_params.isSinglePostprocessor(name);
157 }
158 
159 bool
160 PostprocessorInterface::hasPostprocessorByName(const PostprocessorName & name)
161 {
162  return _pi_feproblem.hasPostprocessor(name);
163 }
164 
165 const PostprocessorValue &
167 {
169 }
FEProblemBase::getPostprocessorValue
PostprocessorValue & getPostprocessorValue(const PostprocessorName &name)
Get a reference to the value associated with the postprocessor.
Definition: FEProblemBase.C:3222
FEProblem.h
InputParameters::hasDefaultPostprocessorValue
bool hasDefaultPostprocessorValue(const std::string &name, unsigned int index=0) const
Returns true if a default PostprocessorValue is defined.
Definition: InputParameters.C:683
PostprocessorInterface::hasPostprocessor
bool hasPostprocessor(const std::string &name, unsigned int index=0) const
Determine if the Postprocessor exists.
Definition: PostprocessorInterface.C:137
PostprocessorInterface::singlePostprocessor
bool singlePostprocessor(const std::string &name) const
Checks if there is a single postprocessor coupled by parameter name.
Definition: PostprocessorInterface.C:154
InputParameters::isSinglePostprocessor
bool isSinglePostprocessor(const std::string &pp_name) const
Getter for the _vector_of_postprocessors flag in parameters.
Definition: InputParameters.h:816
PostprocessorInterface::hasPostprocessorByName
bool hasPostprocessorByName(const PostprocessorName &name)
Determine if the Postprocessor exists.
Definition: PostprocessorInterface.C:160
PostprocessorInterface::PostprocessorInterface
PostprocessorInterface(const MooseObject *moose_object)
Definition: PostprocessorInterface.C:16
PostprocessorInterface::_pi_feproblem
FEProblemBase & _pi_feproblem
Reference the the FEProblemBase class.
Definition: PostprocessorInterface.h:131
mooseError
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition: MooseError.h:210
MooseObject
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:50
PostprocessorValue
Real PostprocessorValue
MOOSE typedefs.
Definition: MooseTypes.h:189
FEProblemBase::getPostprocessorValueOld
PostprocessorValue & getPostprocessorValueOld(const std::string &name)
Get the reference to the old value of a post-processor.
Definition: FEProblemBase.C:3228
PostprocessorInterface::getDefaultPostprocessorValue
const PostprocessorValue & getDefaultPostprocessorValue(const std::string &name)
Return the default postprocessor value.
Definition: PostprocessorInterface.C:166
MooseObject.h
PostprocessorInterface::getPostprocessorValueOld
const PostprocessorValue & getPostprocessorValueOld(const std::string &name, unsigned int index=0)
Definition: PostprocessorInterface.C:55
FEProblemBase::getPostprocessorValueOlder
PostprocessorValue & getPostprocessorValueOlder(const std::string &name)
Get the reference to the older value of a post-processor.
Definition: FEProblemBase.C:3234
PostprocessorInterface::_ppi_params
const InputParameters & _ppi_params
PostprocessorInterface Parameters.
Definition: PostprocessorInterface.h:128
PostprocessorInterface::getPostprocessorValue
const PostprocessorValue & getPostprocessorValue(const std::string &name, unsigned int index=0)
doco-normal-methods-begin Retrieve the value of a Postprocessor or one of it's old or older values
Definition: PostprocessorInterface.C:23
PostprocessorInterface::getPostprocessorValueByName
const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name)
Retrieve the value of the Postprocessor.
Definition: PostprocessorInterface.C:119
PostprocessorInterface::getPostprocessorValueOlder
const PostprocessorValue & getPostprocessorValueOlder(const std::string &name, unsigned int index=0)
Definition: PostprocessorInterface.C:87
PostprocessorInterface::coupledPostprocessors
unsigned int coupledPostprocessors(const std::string &name) const
Returns number of Postprocessors coupled under parameter name.
Definition: PostprocessorInterface.C:146
PostprocessorInterface::getPostprocessorValueOlderByName
const PostprocessorValue & getPostprocessorValueOlderByName(const PostprocessorName &name)
Definition: PostprocessorInterface.C:131
PostprocessorInterface.h
InputParameters::getDefaultPostprocessorValue
const PostprocessorValue & getDefaultPostprocessorValue(const std::string &name, bool suppress_error=false, unsigned int index=0) const
Get the default value for a postprocessor added with addPostprocessor.
Definition: InputParameters.C:629
MooseTypes.h
FEProblemBase
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition: FEProblemBase.h:139
PostprocessorInterface::getPostprocessorValueOldByName
const PostprocessorValue & getPostprocessorValueOldByName(const PostprocessorName &name)
Definition: PostprocessorInterface.C:125
FEProblemBase::hasPostprocessor
bool hasPostprocessor(const std::string &name)
Check existence of the postprocessor.
Definition: FEProblemBase.C:3216
Postprocessor.h