www.mooseframework.org
ElementVariablesDifferenceMax.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 
11 
12 // MOOSE includes
13 #include "MooseVariableFE.h"
14 
15 #include "libmesh/quadrature.h"
16 
18 
19 template <>
22 {
24 
25  params.addRequiredCoupledVar(
26  "compare_a",
27  "The first variable to evaluate the difference with, performed as \"compare_a - compare_b\"");
28  params.addRequiredCoupledVar("compare_b",
29  "The second variable to evaluate the difference with, "
30  "performed as \"compare_a - compare_b\"");
31 
32  params.addParam<bool>(
33  "furthest_from_zero", false, "Find the difference with the highest absolute value");
34 
35  // The value from this VPP is naturally already on every processor
36  // TODO: Make this not the case! See #11415
37  params.set<bool>("_is_broadcast") = true;
38 
39  return params;
40 }
41 
43 {
51 };
52 
54  : ElementVectorPostprocessor(parameters),
55  _a(coupledValue("compare_a")),
56  _b(coupledValue("compare_b")),
57  _a_value(declareVector(getVar("compare_a", 0)->name())),
58  _b_value(declareVector(getVar("compare_b", 0)->name())),
59  _max_difference(declareVector("Difference")),
60  _position_x(declareVector("X")),
61  _position_y(declareVector("Y")),
62  _position_z(declareVector("Z")),
63  _furthest_from_zero(getParam<bool>("furthest_from_zero"))
64 {
65  // These are all single-value arrays
66  _a_value.resize(1);
67  _b_value.resize(1);
68  _max_difference.resize(1);
69  _position_x.resize(1);
70  _position_y.resize(1);
71  _position_z.resize(1);
72 
74 }
75 
76 void
78 {
79  for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
80  {
81  // Get the difference
82  const Real difference = _furthest_from_zero ? std::abs(_a[qp] - _b[qp]) : _a[qp] - _b[qp];
83 
84  // Assign the appropriate values if a new maximum is found
85  if (difference > _all[MAXIMUM_DIFFERENCE])
86  {
87  _all[MAXIMUM_DIFFERENCE] = difference;
90 
94  }
95  }
96 }
97 
98 void
100 {
101  // Gather all the parameters based on the maximum difference
103 
110 }
111 
112 void
114 {
115  _all[MAXIMUM_DIFFERENCE] = 0.0;
116 }
117 
118 void
120 {
121  const ElementVariablesDifferenceMax & sibling =
122  static_cast<const ElementVariablesDifferenceMax &>(s);
123 
125  _all = sibling._all;
126 }
void gatherProxyValueMax(T1 &value, T2 &proxy)
Definition: UserObject.h:121
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
ElementVariablesDifferenceMax(const InputParameters &parameters)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
registerMooseObject("MooseApp", ElementVariablesDifferenceMax)
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.
const QBase *const & _qrule
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:37
InputParameters validParams< ElementVariablesDifferenceMax >()
InputParameters validParams< ElementVectorPostprocessor >()