Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 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 : 10 : #include "ElementVariablesDifferenceMax.h" 11 : 12 : // MOOSE includes 13 : #include "MooseVariableFE.h" 14 : 15 : #include "libmesh/quadrature.h" 16 : 17 : registerMooseObject("MooseApp", ElementVariablesDifferenceMax); 18 : 19 : InputParameters 20 14315 : ElementVariablesDifferenceMax::validParams() 21 : { 22 14315 : InputParameters params = ElementVectorPostprocessor::validParams(); 23 14315 : params.addClassDescription("Computes the largest difference between two variable fields."); 24 14315 : params.addRequiredCoupledVar( 25 : "compare_a", 26 : "The first variable to evaluate the difference with, performed as \"compare_a - compare_b\""); 27 14315 : params.addRequiredCoupledVar("compare_b", 28 : "The second variable to evaluate the difference with, " 29 : "performed as \"compare_a - compare_b\""); 30 : 31 42945 : params.addParam<bool>( 32 28630 : "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 14315 : params.set<bool>("_auto_broadcast") = false; 37 : 38 14315 : return params; 39 0 : } 40 : 41 : enum CollectionOfAllValuesIntoAVector 42 : { 43 : MAXIMUM_DIFFERENCE, 44 : MAXIMUM_DIFFERENCE_A_VALUE, 45 : MAXIMUM_DIFFERENCE_B_VALUE, 46 : MAXIMUM_DIFFERENCE_X, 47 : MAXIMUM_DIFFERENCE_Y, 48 : MAXIMUM_DIFFERENCE_Z, 49 : SIZE 50 : }; 51 : 52 26 : ElementVariablesDifferenceMax::ElementVariablesDifferenceMax(const InputParameters & parameters) 53 : : ElementVectorPostprocessor(parameters), 54 26 : _a(coupledValue("compare_a")), 55 26 : _b(coupledValue("compare_b")), 56 26 : _a_value(declareVector(coupledName("compare_a"))), 57 26 : _b_value(declareVector(coupledName("compare_b"))), 58 26 : _max_difference(declareVector("Difference")), 59 26 : _position_x(declareVector("X")), 60 26 : _position_y(declareVector("Y")), 61 26 : _position_z(declareVector("Z")), 62 52 : _furthest_from_zero(getParam<bool>("furthest_from_zero")) 63 : { 64 : // These are all single-value arrays 65 26 : _a_value.resize(1); 66 26 : _b_value.resize(1); 67 26 : _max_difference.resize(1); 68 26 : _position_x.resize(1); 69 26 : _position_y.resize(1); 70 26 : _position_z.resize(1); 71 : 72 26 : _all.resize(CollectionOfAllValuesIntoAVector::SIZE); 73 26 : } 74 : 75 : void 76 32000 : ElementVariablesDifferenceMax::execute() 77 : { 78 288000 : for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp) 79 : { 80 : // Get the difference 81 256000 : 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 256000 : if (difference > _all[MAXIMUM_DIFFERENCE]) 85 : { 86 126 : _all[MAXIMUM_DIFFERENCE] = difference; 87 126 : _all[MAXIMUM_DIFFERENCE_A_VALUE] = _a[qp]; 88 126 : _all[MAXIMUM_DIFFERENCE_B_VALUE] = _b[qp]; 89 : 90 126 : _all[MAXIMUM_DIFFERENCE_X] = _q_point[qp](0); 91 126 : _all[MAXIMUM_DIFFERENCE_Y] = _q_point[qp](1); 92 126 : _all[MAXIMUM_DIFFERENCE_Z] = _q_point[qp](2); 93 : } 94 : } 95 32000 : } 96 : 97 : void 98 44 : ElementVariablesDifferenceMax::finalize() 99 : { 100 : // Gather all the parameters based on the maximum difference 101 44 : gatherProxyValueMax(_all[MAXIMUM_DIFFERENCE], _all); 102 : 103 44 : _max_difference[0] = _all[MAXIMUM_DIFFERENCE]; 104 44 : _a_value[0] = _all[MAXIMUM_DIFFERENCE_A_VALUE]; 105 44 : _b_value[0] = _all[MAXIMUM_DIFFERENCE_B_VALUE]; 106 44 : _position_x[0] = _all[MAXIMUM_DIFFERENCE_X]; 107 44 : _position_y[0] = _all[MAXIMUM_DIFFERENCE_Y]; 108 44 : _position_z[0] = _all[MAXIMUM_DIFFERENCE_Z]; 109 44 : } 110 : 111 : void 112 48 : ElementVariablesDifferenceMax::initialize() 113 : { 114 48 : _all[MAXIMUM_DIFFERENCE] = 0.0; 115 48 : _all[MAXIMUM_DIFFERENCE_A_VALUE] = 0.0; 116 48 : _all[MAXIMUM_DIFFERENCE_B_VALUE] = 0.0; 117 48 : _all[MAXIMUM_DIFFERENCE_X] = 0.0; 118 48 : _all[MAXIMUM_DIFFERENCE_Y] = 0.0; 119 48 : _all[MAXIMUM_DIFFERENCE_Z] = 0.0; 120 48 : } 121 : 122 : void 123 4 : ElementVariablesDifferenceMax::threadJoin(const UserObject & s) 124 : { 125 4 : const auto & sibling = static_cast<const ElementVariablesDifferenceMax &>(s); 126 : 127 4 : if (_all[MAXIMUM_DIFFERENCE] < sibling._all[MAXIMUM_DIFFERENCE]) 128 0 : _all = sibling._all; 129 4 : }