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 "ArrayVariableValueVolumeHistogram.h" 11 : 12 : // MOOSE includes 13 : #include "MooseVariableFE.h" 14 : 15 : #include "libmesh/quadrature.h" 16 : 17 : registerMooseObject("MooseApp", ArrayVariableValueVolumeHistogram); 18 : 19 : InputParameters 20 3086 : ArrayVariableValueVolumeHistogram::validParams() 21 : { 22 3086 : InputParameters params = ElementVectorPostprocessor::validParams(); 23 6172 : params.addClassDescription("Compute histograms of volume fractions binned according to component " 24 : "values of an array variable."); 25 12344 : params.addParam<unsigned int>("bin_number", 50, "Number of histogram bins"); 26 12344 : params.addCoupledVar("variable", "Variable to bin the volume of"); 27 12344 : params.addRequiredParam<Real>("min_value", "Minimum variable value"); 28 9258 : params.addRequiredParam<Real>("max_value", "Maximum variable value"); 29 3086 : return params; 30 0 : } 31 : 32 13 : ArrayVariableValueVolumeHistogram::ArrayVariableValueVolumeHistogram( 33 13 : const InputParameters & parameters) 34 : : ElementVectorPostprocessor(parameters), 35 13 : _nbins(getParam<unsigned int>("bin_number")), 36 26 : _min_value(getParam<Real>("min_value")), 37 26 : _max_value(getParam<Real>("max_value")), 38 13 : _deltaV((_max_value - _min_value) / _nbins), 39 26 : _value(coupledArrayValue("variable")), 40 26 : _var(*getArrayVar("variable", 0)), 41 52 : _bin_center(declareVector("value")) 42 : { 43 39 : if (coupledComponents("variable") != 1) 44 0 : mooseError("ArrayVariableValueVolumeHistogram works on exactly one coupled variable"); 45 : 46 39 : for (const unsigned int i : make_range(_var.count())) 47 26 : _volumes.push_back(&declareVector(_var.arrayVariableComponent(i))); 48 : 49 : // initialize the bin center value vector 50 13 : _bin_center.resize(_nbins); 51 663 : for (const unsigned int i : make_range(_nbins)) 52 650 : _bin_center[i] = (i + 0.5) * _deltaV + _min_value; 53 13 : } 54 : 55 : void 56 25 : ArrayVariableValueVolumeHistogram::initialize() 57 : { 58 : // reset the histogram 59 75 : for (auto & volume : _volumes) 60 50 : volume->assign(_nbins, 0.0); 61 25 : } 62 : 63 : void 64 6800 : ArrayVariableValueVolumeHistogram::execute() 65 : { 66 : // loop over quadrature points 67 34000 : for (auto _qp : make_range(_qrule->n_points())) 68 : { 69 81600 : for (const unsigned int i : make_range(_var.count())) 70 : { 71 : // compute target bin 72 54400 : int bin = (_value[_qp](i) - _min_value) / _deltaV; 73 : 74 : // add the volume contributed by the current quadrature point 75 54400 : if (bin >= 0 && static_cast<unsigned int>(bin) < _nbins) 76 54400 : (*_volumes[i])[bin] += _JxW[_qp] * _coord[_qp]; 77 : } 78 : } 79 6800 : } 80 : 81 : void 82 23 : ArrayVariableValueVolumeHistogram::finalize() 83 : { 84 69 : for (const unsigned int i : make_range(_var.count())) 85 46 : gatherSum(*_volumes[i]); 86 23 : } 87 : 88 : void 89 2 : ArrayVariableValueVolumeHistogram::threadJoin(const UserObject & y) 90 : { 91 2 : const auto & uo = static_cast<const ArrayVariableValueVolumeHistogram &>(y); 92 : mooseAssert(uo._volumes.size() == _volumes.size(), 93 : "Inconsistent number of array variable components across threads."); 94 : 95 6 : for (const unsigned int i : make_range(_var.count())) 96 : { 97 : mooseAssert(uo._volumes[i]->size() == _volumes[i]->size(), 98 : "Inconsistent volume vector lengths across threads."); 99 204 : for (const unsigned int j : index_range(*_volumes[i])) 100 200 : (*_volumes[i])[j] += (*uo._volumes[i])[j]; 101 : } 102 2 : }