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 "ShaftTimeDerivativeScalarKernel.h" 11 : #include "ShaftConnectableUserObjectInterface.h" 12 : #include "UserObject.h" 13 : #include "MooseVariableScalar.h" 14 : #include "Assembly.h" 15 : 16 : registerMooseObject("ThermalHydraulicsApp", ShaftTimeDerivativeScalarKernel); 17 : 18 : InputParameters 19 10 : ShaftTimeDerivativeScalarKernel::validParams() 20 : { 21 10 : InputParameters params = ScalarKernel::validParams(); 22 20 : params.addRequiredParam<std::vector<UserObjectName>>("uo_names", 23 : "Names of shaft-connectable user objects"); 24 10 : params.addClassDescription("Adds a time derivative term to the shaft ODE"); 25 20 : params.set<MultiMooseEnum>("vector_tags") = "time"; 26 20 : params.set<MultiMooseEnum>("matrix_tags") = "system time"; 27 : 28 10 : return params; 29 0 : } 30 : 31 5 : ShaftTimeDerivativeScalarKernel::ShaftTimeDerivativeScalarKernel(const InputParameters & parameters) 32 : : ScalarKernel(parameters), 33 10 : _u_dot(_var.uDot()), 34 5 : _du_dot_du(_var.duDotDu()), 35 10 : _uo_names(getParam<std::vector<UserObjectName>>("uo_names")), 36 10 : _n_components(_uo_names.size()) 37 : { 38 5 : _shaft_connected_uos.resize(_n_components); 39 10 : for (unsigned int i = 0; i < _n_components; ++i) 40 : { 41 5 : _shaft_connected_uos[i] = 42 5 : &getUserObjectByName<ShaftConnectableUserObjectInterface>(_uo_names[i]); 43 : } 44 5 : } 45 : 46 : void 47 30 : ShaftTimeDerivativeScalarKernel::reinit() 48 : { 49 30 : } 50 : 51 : void 52 25 : ShaftTimeDerivativeScalarKernel::computeResidual() 53 : { 54 25 : prepareVectorTag(_assembly, _var.number()); 55 : 56 : Real sum_inertias = 0; 57 50 : for (unsigned int i = 0; i < _n_components; ++i) 58 25 : sum_inertias += _shaft_connected_uos[i]->getMomentOfInertia(); 59 : 60 25 : _local_re(0) += sum_inertias * _u_dot[0]; 61 : 62 25 : accumulateTaggedLocalResidual(); 63 25 : } 64 : 65 : void 66 5 : ShaftTimeDerivativeScalarKernel::computeJacobian() 67 : { 68 5 : prepareMatrixTag(_assembly, _var.number(), _var.number()); 69 : 70 : Real sum_inertias = 0; 71 10 : for (unsigned int i = 0; i < _n_components; ++i) 72 5 : sum_inertias += _shaft_connected_uos[i]->getMomentOfInertia(); 73 : 74 : // FIXME: Add dI_domega * domega_dt 75 5 : _local_ke(0, 0) += sum_inertias * _du_dot_du[0]; 76 : 77 5 : accumulateTaggedLocalMatrix(); 78 : 79 10 : for (unsigned int i = 0; i < _n_components; ++i) 80 : { 81 5 : DenseMatrix<Real> jacobian_block; 82 : std::vector<dof_id_type> dofs_j; 83 5 : _shaft_connected_uos[i]->getMomentOfInertiaJacobianData(jacobian_block, dofs_j); 84 5 : jacobian_block.scale(_u_dot[0]); 85 5 : addJacobian(_assembly, jacobian_block, _var.dofIndices(), dofs_j, _var.scalingFactor()); 86 5 : } 87 5 : }