https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LinearCombinationPostprocessor.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
13
16{
18
19 params.addRequiredParam<std::vector<PostprocessorName>>("pp_names", "List of post-processors");
20 params.addRequiredParam<std::vector<Real>>(
21 "pp_coefs", "List of linear combination coefficients for each post-processor");
22 params.addParam<Real>("b", 0, "Additional value to add to sum");
24 "Computes a linear combination between an arbitrary number of post-processors");
25 return params;
26}
27
29 : GeneralPostprocessor(parameters),
30 _n_pp(coupledPostprocessors("pp_names")),
31 _pp_coefs(getParam<std::vector<Real>>("pp_coefs")),
32 _b_value(getParam<Real>("b"))
33{
34 if (_pp_coefs.size() != _n_pp)
35 mooseError("The list parameters 'pp_names' and 'pp_coefs' must have the same length");
36
37 _pp_values.resize(_n_pp);
38 for (unsigned int i = 0; i < _n_pp; i++)
39 _pp_values[i] = &getPostprocessorValue("pp_names", i);
40}
41
42void
46
47void
51
54{
55 Real linear_combination = _b_value;
56 for (unsigned int i = 0; i < _n_pp; i++)
57 linear_combination += _pp_coefs[i] * *(_pp_values[i]);
58
59 return linear_combination;
60}
registerMooseObject("MooseApp", LinearCombinationPostprocessor)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Real PostprocessorValue
various MOOSE typedefs
Definition MooseTypes.h:230
This class is here to combine the Postprocessor interface and the base class Postprocessor object alo...
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
Computes a linear combination between an arbitrary number of post-processors.
LinearCombinationPostprocessor(const InputParameters &parameters)
std::vector< const PostprocessorValue * > _pp_values
List of post-processor values.
virtual void execute() override
Execute method.
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
const unsigned int _n_pp
Number of post-processors in linear combination.
const Real _b_value
Additional value to add to sum.
virtual PostprocessorValue getValue() const override
This will get called to actually grab the final value the postprocessor has calculated.
const std::vector< Real > & _pp_coefs
List of linear combination coefficients for each post-processor value.
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