www.mooseframework.org
VectorPostprocessorComparison.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 
12 
14 
17 {
19 
20  params.addRequiredParam<VectorPostprocessorName>(
21  "vectorpostprocessor_a", "The first vector post-processor in the comparison");
22  params.addRequiredParam<VectorPostprocessorName>(
23  "vectorpostprocessor_b", "The second vector post-processor in the comparison");
24  params.addRequiredParam<std::string>(
25  "vector_name_a", "The name of the vector in the first vector post-processor to compare");
26  params.addRequiredParam<std::string>(
27  "vector_name_b", "The name of the vector in the second vector post-processor to compare");
28 
29  params.addClassDescription(
30  "Compares two vector post-processors of equal size and produces a boolean value");
31 
32  return params;
33 }
34 
36  : ComparisonPostprocessor(parameters),
37 
38  _values_a(getVectorPostprocessorValue("vectorpostprocessor_a",
39  getParam<std::string>("vector_name_a"))),
40  _values_b(getVectorPostprocessorValue("vectorpostprocessor_b",
41  getParam<std::string>("vector_name_b"))),
42 
43  _comparison_value(0.0)
44 {
45 }
46 
47 void
49 {
50  _comparison_value = 0.0;
51 }
52 
53 void
55 {
56  if (_values_a.size() != _values_b.size())
57  mooseError("The compared vector post-processors must have the same size");
58 
59  // Set comparison value to "false" if comparison is false for any pair of elements
60  bool comparison_bool = true;
61  for (unsigned int i = 0; i < _values_a.size(); ++i)
62  comparison_bool = comparison_bool && comparisonIsTrue(_values_a[i], _values_b[i]);
63 
64  _comparison_value = comparison_bool;
65 }
66 
69 {
70  return _comparison_value;
71 }
PostprocessorValue _comparison_value
The comparison value; 1 for all true and 0 for at least one false.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
const VectorPostprocessorValue & _values_b
Values of the second vector post-processor to compare.
static InputParameters validParams()
virtual void execute() override
Execute method.
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...
VectorPostprocessorComparison(const InputParameters &parameters)
bool comparisonIsTrue(const Real &a, const Real &b) const
Performs the selected comparison on the two values.
Real PostprocessorValue
various MOOSE typedefs
Definition: MooseTypes.h:191
Base class for comparing quantities and producing a boolean value.
Compares two vector post-processors of equal size and produces a boolean value.
virtual PostprocessorValue getValue() const override
This will get called to actually grab the final value the postprocessor has calculated.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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...
const VectorPostprocessorValue & _values_a
Values of the first vector post-processor to compare.
registerMooseObject("MooseApp", VectorPostprocessorComparison)