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 
21 {
23  params.addClassDescription("Computes the largest difference between two variable fields.");
24  params.addRequiredCoupledVar(
25  "compare_a",
26  "The first variable to evaluate the difference with, performed as \"compare_a - compare_b\"");
27  params.addRequiredCoupledVar("compare_b",
28  "The second variable to evaluate the difference with, "
29  "performed as \"compare_a - compare_b\"");
30 
31  params.addParam<bool>(
32  "furthest_from_zero", false, "Find the difference with the highest absolute value");
33 
34  // The value from this VPP is naturally already on every processor
35  // TODO: Make this not the case! See #11415
36  params.set<bool>("_auto_broadcast") = false;
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(coupledName("compare_a"))),
57  _b_value(declareVector(coupledName("compare_b"))),
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 
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;
117  _all[MAXIMUM_DIFFERENCE_X] = 0.0;
118  _all[MAXIMUM_DIFFERENCE_Y] = 0.0;
119  _all[MAXIMUM_DIFFERENCE_Z] = 0.0;
120 }
121 
122 void
124 {
125  const auto & sibling = static_cast<const ElementVariablesDifferenceMax &>(s);
126 
127  if (_all[MAXIMUM_DIFFERENCE] < sibling._all[MAXIMUM_DIFFERENCE])
128  _all = sibling._all;
129 }
void gatherProxyValueMax(T1 &value, T2 &proxy)
Gather the parallel value of a variable according to which process has the parallel maximum of the pr...
Definition: UserObject.h:238
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.
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
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.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const QBase *const & _qrule
virtual void finalize() override
Finalize.
VectorPostprocessorValue & _b_value
The value of _b that produced the maximum difference.
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...
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...
static InputParameters validParams()
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:39