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 "FunctionElementLoopIntegralUserObject.h" 11 : #include "Assembly.h" 12 : #include "Function.h" 13 : 14 : registerMooseObject("ThermalHydraulicsApp", FunctionElementLoopIntegralUserObject); 15 : 16 : InputParameters 17 38 : FunctionElementLoopIntegralUserObject::validParams() 18 : { 19 38 : InputParameters params = ElementLoopUserObject::validParams(); 20 : 21 38 : params.addClassDescription("Computes the integral of a function using an element loop."); 22 : 23 76 : params.addRequiredParam<FunctionName>("function", "Function to integrate."); 24 : 25 38 : return params; 26 0 : } 27 : 28 19 : FunctionElementLoopIntegralUserObject::FunctionElementLoopIntegralUserObject( 29 19 : const InputParameters & parameters) 30 : : ElementLoopUserObject(parameters), 31 : 32 19 : _function(getFunction("function")), 33 19 : _qp(0), 34 19 : _integral_value(0) 35 : { 36 19 : } 37 : 38 : void 39 14 : FunctionElementLoopIntegralUserObject::initialize() 40 : { 41 14 : _integral_value = 0; 42 14 : } 43 : 44 : void 45 90 : FunctionElementLoopIntegralUserObject::computeElement() 46 : { 47 90 : _assembly.reinit(_current_elem); 48 90 : _integral_value += computeIntegral(); 49 90 : } 50 : 51 : void 52 0 : FunctionElementLoopIntegralUserObject::threadJoin(const UserObject & y) 53 : { 54 : const auto & uo = static_cast<const FunctionElementLoopIntegralUserObject &>(y); 55 0 : _integral_value += uo._integral_value; 56 0 : } 57 : 58 : void 59 14 : FunctionElementLoopIntegralUserObject::finalize() 60 : { 61 14 : gatherSum(_integral_value); 62 14 : } 63 : 64 : Real 65 90 : FunctionElementLoopIntegralUserObject::computeIntegral() 66 : { 67 : Real sum = 0; 68 180 : for (_qp = 0; _qp < _qrule->n_points(); _qp++) 69 90 : sum += _JxW[_qp] * _coord[_qp] * computeQpIntegral(); 70 90 : return sum; 71 : } 72 : 73 : Real 74 90 : FunctionElementLoopIntegralUserObject::computeQpIntegral() 75 : { 76 90 : return _function.value(_t, _q_point[_qp]); 77 : } 78 : 79 : Real 80 14 : FunctionElementLoopIntegralUserObject::getValue() const 81 : { 82 14 : return _integral_value; 83 : }