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 18 : FunctionElementLoopIntegralUserObject::validParams() 18 : { 19 18 : InputParameters params = ElementLoopUserObject::validParams(); 20 : 21 18 : params.addClassDescription("Computes the integral of a function using an element loop."); 22 : 23 36 : params.addRequiredParam<FunctionName>("function", "Function to integrate."); 24 : 25 18 : return params; 26 0 : } 27 : 28 9 : FunctionElementLoopIntegralUserObject::FunctionElementLoopIntegralUserObject( 29 9 : const InputParameters & parameters) 30 : : ElementLoopUserObject(parameters), 31 : 32 9 : _function(getFunction("function")), 33 9 : _qp(0), 34 9 : _integral_value(0) 35 : { 36 9 : } 37 : 38 : void 39 8 : FunctionElementLoopIntegralUserObject::initialize() 40 : { 41 8 : _integral_value = 0; 42 8 : } 43 : 44 : void 45 60 : FunctionElementLoopIntegralUserObject::computeElement() 46 : { 47 60 : _assembly.reinit(_current_elem); 48 60 : _integral_value += computeIntegral(); 49 60 : } 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 8 : FunctionElementLoopIntegralUserObject::finalize() 60 : { 61 8 : gatherSum(_integral_value); 62 8 : } 63 : 64 : Real 65 60 : FunctionElementLoopIntegralUserObject::computeIntegral() 66 : { 67 : Real sum = 0; 68 120 : for (_qp = 0; _qp < _qrule->n_points(); _qp++) 69 60 : sum += _JxW[_qp] * _coord[_qp] * computeQpIntegral(); 70 60 : return sum; 71 : } 72 : 73 : Real 74 60 : FunctionElementLoopIntegralUserObject::computeQpIntegral() 75 : { 76 60 : return _function.value(_t, _q_point[_qp]); 77 : } 78 : 79 : Real 80 8 : FunctionElementLoopIntegralUserObject::getValue() const 81 : { 82 8 : return _integral_value; 83 : }