www.mooseframework.org
ElementVariablesDifferenceMax.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
16 
17 // MOOSE includes
18 #include "MooseVariable.h"
19 
20 #include "libmesh/quadrature.h"
21 
22 template <>
25 {
27 
28  params.addRequiredCoupledVar(
29  "compare_a",
30  "The first variable to evaluate the difference with, performed as \"compare_a - compare_b\"");
31  params.addRequiredCoupledVar("compare_b",
32  "The second variable to evaluate the difference with, "
33  "performed as \"compare_a - compare_b\"");
34 
35  params.addParam<bool>(
36  "furthest_from_zero", false, "Find the difference with the highest absolute value");
37 
38  return params;
39 }
40 
42 {
50 };
51 
53  : ElementVectorPostprocessor(parameters),
54  _a(coupledValue("compare_a")),
55  _b(coupledValue("compare_b")),
56  _a_value(declareVector(getVar("compare_a", 0)->name())),
57  _b_value(declareVector(getVar("compare_b", 0)->name())),
58  _max_difference(declareVector("Difference")),
59  _position_x(declareVector("X")),
60  _position_y(declareVector("Y")),
61  _position_z(declareVector("Z")),
62  _furthest_from_zero(getParam<bool>("furthest_from_zero"))
63 {
64  // These are all single-value arrays
65  _a_value.resize(1);
66  _b_value.resize(1);
67  _max_difference.resize(1);
68  _position_x.resize(1);
69  _position_y.resize(1);
70  _position_z.resize(1);
71 
73 }
74 
75 void
77 {
78  for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
79  {
80  // Get the difference
81  const Real difference = _furthest_from_zero ? std::abs(_a[qp] - _b[qp]) : _a[qp] - _b[qp];
82 
83  // Assign the appropriate values if a new maximum is found
84  if (difference > _all[MAXIMUM_DIFFERENCE])
85  {
86  _all[MAXIMUM_DIFFERENCE] = difference;
89 
92  _all[MAXIMUM_DIFFERENCE_Z] = _q_point[qp](2);
93  }
94  }
95 }
96 
97 void
99 {
100  // Gather all the parameters based on the maximum difference
102 
109 }
110 
111 void
113 {
114  _all[MAXIMUM_DIFFERENCE] = 0.0;
115 }
116 
117 void
119 {
120  const ElementVariablesDifferenceMax & sibling =
121  static_cast<const ElementVariablesDifferenceMax &>(s);
122 
124  _all = sibling._all;
125 }
void gatherProxyValueMax(T1 &value, T2 &proxy)
Definition: UserObject.h:137
std::vector< Real > _all
Collection of all the items so only one MPI call is required, these will be spread to the actual Vect...
CollectionOfAllValuesIntoAVector
const MooseArray< Point > & _q_point
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
VectorPostprocessorValue & _max_difference
The actual maximum difference.
ElementVariablesDifferenceMax(const InputParameters &parameters)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
VectorPostprocessorValue & _a_value
The value of _a that produced the maximum difference.
virtual void threadJoin(const UserObject &s) override
Must override.
const bool _furthest_from_zero
Internal flag to indicate we are seeking the largest absolute value.
VectorPostprocessorValue & _position_z
The z position of the associated quadrature point.
const VariableValue & _a
The first variable, operated to produce a difference as: _a - _b.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
virtual void finalize() override
Finalize.
VectorPostprocessorValue & _b_value
The value of _b that produced the maximum difference.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
Finds the largest difference between two variable fields.
const VariableValue & _b
The second variable, operated to produce a difference as: _a - _b.
VectorPostprocessorValue & _position_x
The x position of the associated quadrature point.
virtual void execute() override
Execute method.
VectorPostprocessorValue & _position_y
The y position of the associated quadrature point.
Base class for user-specific data.
Definition: UserObject.h:42
InputParameters validParams< ElementVariablesDifferenceMax >()
InputParameters validParams< ElementVectorPostprocessor >()