forked from idaholab/moose
/
ElementVariablesDifferenceMax.C
127 lines (106 loc) · 3.76 KB
/
ElementVariablesDifferenceMax.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html
#include "ElementVariablesDifferenceMax.h"
// MOOSE includes
#include "MooseVariableFE.h"
#include "libmesh/quadrature.h"
registerMooseObject("MooseApp", ElementVariablesDifferenceMax);
defineLegacyParams(ElementVariablesDifferenceMax);
InputParameters
ElementVariablesDifferenceMax::validParams()
{
InputParameters params = ElementVectorPostprocessor::validParams();
params.addRequiredCoupledVar(
"compare_a",
"The first variable to evaluate the difference with, performed as \"compare_a - compare_b\"");
params.addRequiredCoupledVar("compare_b",
"The second variable to evaluate the difference with, "
"performed as \"compare_a - compare_b\"");
params.addParam<bool>(
"furthest_from_zero", false, "Find the difference with the highest absolute value");
// The value from this VPP is naturally already on every processor
// TODO: Make this not the case! See #11415
params.set<bool>("_auto_broadcast") = false;
return params;
}
enum CollectionOfAllValuesIntoAVector
{
MAXIMUM_DIFFERENCE,
MAXIMUM_DIFFERENCE_A_VALUE,
MAXIMUM_DIFFERENCE_B_VALUE,
MAXIMUM_DIFFERENCE_X,
MAXIMUM_DIFFERENCE_Y,
MAXIMUM_DIFFERENCE_Z,
SIZE
};
ElementVariablesDifferenceMax::ElementVariablesDifferenceMax(const InputParameters & parameters)
: ElementVectorPostprocessor(parameters),
_a(coupledValue("compare_a")),
_b(coupledValue("compare_b")),
_a_value(declareVector(getVar("compare_a", 0)->name())),
_b_value(declareVector(getVar("compare_b", 0)->name())),
_max_difference(declareVector("Difference")),
_position_x(declareVector("X")),
_position_y(declareVector("Y")),
_position_z(declareVector("Z")),
_furthest_from_zero(getParam<bool>("furthest_from_zero"))
{
// These are all single-value arrays
_a_value.resize(1);
_b_value.resize(1);
_max_difference.resize(1);
_position_x.resize(1);
_position_y.resize(1);
_position_z.resize(1);
_all.resize(CollectionOfAllValuesIntoAVector::SIZE);
}
void
ElementVariablesDifferenceMax::execute()
{
for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
{
// Get the difference
const Real difference = _furthest_from_zero ? std::abs(_a[qp] - _b[qp]) : _a[qp] - _b[qp];
// Assign the appropriate values if a new maximum is found
if (difference > _all[MAXIMUM_DIFFERENCE])
{
_all[MAXIMUM_DIFFERENCE] = difference;
_all[MAXIMUM_DIFFERENCE_A_VALUE] = _a[qp];
_all[MAXIMUM_DIFFERENCE_B_VALUE] = _b[qp];
_all[MAXIMUM_DIFFERENCE_X] = _q_point[qp](0);
_all[MAXIMUM_DIFFERENCE_Y] = _q_point[qp](1);
_all[MAXIMUM_DIFFERENCE_Z] = _q_point[qp](2);
}
}
}
void
ElementVariablesDifferenceMax::finalize()
{
// Gather all the parameters based on the maximum difference
gatherProxyValueMax(_all[MAXIMUM_DIFFERENCE], _all);
_max_difference[0] = _all[MAXIMUM_DIFFERENCE];
_a_value[0] = _all[MAXIMUM_DIFFERENCE_A_VALUE];
_b_value[0] = _all[MAXIMUM_DIFFERENCE_B_VALUE];
_position_x[0] = _all[MAXIMUM_DIFFERENCE_X];
_position_y[0] = _all[MAXIMUM_DIFFERENCE_Y];
_position_z[0] = _all[MAXIMUM_DIFFERENCE_Z];
}
void
ElementVariablesDifferenceMax::initialize()
{
_all[MAXIMUM_DIFFERENCE] = 0.0;
}
void
ElementVariablesDifferenceMax::threadJoin(const UserObject & s)
{
const ElementVariablesDifferenceMax & sibling =
static_cast<const ElementVariablesDifferenceMax &>(s);
if (_all[MAXIMUM_DIFFERENCE] < sibling._all[MAXIMUM_DIFFERENCE])
_all = sibling._all;
}