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 
15 template <>
18 {
20 
21  params.addRequiredParam<VectorPostprocessorName>(
22  "vectorpostprocessor_a", "The first vector post-processor in the comparison");
23  params.addRequiredParam<VectorPostprocessorName>(
24  "vectorpostprocessor_b", "The second vector post-processor in the comparison");
25  params.addRequiredParam<std::string>(
26  "vector_name_a", "The name of the vector in the first vector post-processor to compare");
27  params.addRequiredParam<std::string>(
28  "vector_name_b", "The name of the vector in the second vector post-processor to compare");
29 
30  params.addClassDescription(
31  "Compares two vector post-processors of equal size and produces a boolean value");
32 
33  return params;
34 }
35 
37  : ComparisonPostprocessor(parameters),
38 
39  _values_a(getVectorPostprocessorValue("vectorpostprocessor_a",
40  getParam<std::string>("vector_name_a"))),
41  _values_b(getVectorPostprocessorValue("vectorpostprocessor_b",
42  getParam<std::string>("vector_name_b"))),
43 
44  _comparison_value(0.0)
45 {
46 }
47 
48 void
50 {
51  _comparison_value = 0.0;
52 }
53 
54 void
56 {
57  if (_values_a.size() != _values_b.size())
58  mooseError("The compared vector post-processors must have the same size");
59 
60  // Set comparison value to "false" if comparison is false for any pair of elements
61  bool comparison_bool = true;
62  for (unsigned int i = 0; i < _values_a.size(); ++i)
63  comparison_bool = comparison_bool && comparisonIsTrue(_values_a[i], _values_b[i]);
64 
65  _comparison_value = comparison_bool;
66 }
67 
70 {
71  return _comparison_value;
72 }
PostprocessorValue _comparison_value
The comparison value; 1 for all true and 0 for at least one false.
InputParameters validParams< ComparisonPostprocessor >()
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.
virtual void execute() override
Execute method.
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
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.
virtual PostprocessorValue getValue() override
This will get called to actually grab the final value the postprocessor has calculated.
InputParameters validParams< VectorPostprocessorComparison >()
Real PostprocessorValue
MOOSE typedefs.
Definition: MooseTypes.h:154
Base class for comparing quantities and producing a boolean value.
Compares two vector post-processors of equal size and produces a boolean value.
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)