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 "FVElementalKernel.h" 11 : #include "MooseVariableFV.h" 12 : #include "Assembly.h" 13 : #include "SubProblem.h" 14 : #include "NonlinearSystemBase.h" 15 : #include "ADUtils.h" 16 : 17 : #include "libmesh/elem.h" 18 : 19 : #include "metaphysicl/raw_type.h" 20 : 21 : InputParameters 22 45822 : FVElementalKernel::validParams() 23 : { 24 45822 : InputParameters params = FVKernel::validParams(); 25 45822 : params.registerSystemAttributeName("FVElementalKernel"); 26 45822 : params += MaterialPropertyInterface::validParams(); 27 45822 : return params; 28 0 : } 29 : 30 2898 : FVElementalKernel::FVElementalKernel(const InputParameters & parameters) 31 : : FVKernel(parameters), 32 : MooseVariableInterface(this, 33 : false, 34 : "variable", 35 : Moose::VarKindType::VAR_SOLVER, 36 : Moose::VarFieldType::VAR_FIELD_STANDARD), 37 : CoupleableMooseVariableDependencyIntermediateInterface(this, false, /*is_fv=*/true), 38 : MaterialPropertyInterface(this, blockIDs(), Moose::EMPTY_BOUNDARY_IDS), 39 5796 : _var(*mooseVariableFV()), 40 2898 : _u_functor(getFunctor<ADReal>(_var.name())), 41 5796 : _current_elem(_assembly.elem()), 42 11592 : _q_point(_assembly.qPoints()) 43 : { 44 2898 : addMooseVariableDependency(&_var); 45 2898 : } 46 : 47 : // Note the lack of quadrature point loops in the residual/jacobian compute 48 : // functions. This is because finite volumes currently only works with 49 : // constant monomial elements. We only have one quadrature point regardless of 50 : // problem dimension and just multiply by the element volume. 51 : 52 : void 53 6020534 : FVElementalKernel::computeResidual() 54 : { 55 6020534 : prepareVectorTag(_assembly, _var.number()); 56 6020534 : _local_re(0) += MetaPhysicL::raw_value(computeQpResidual()) * _assembly.elemVolume(); 57 6020534 : accumulateTaggedLocalResidual(); 58 6020534 : } 59 : 60 : void 61 54024 : FVElementalKernel::computeResidualAndJacobian() 62 : { 63 54024 : const auto r = computeQpResidual() * _assembly.elemVolume(); 64 216096 : addResidualsAndJacobian( 65 54024 : _assembly, std::array<ADReal, 1>{{r}}, _var.dofIndices(), _var.scalingFactor()); 66 54024 : } 67 : 68 : void 69 2489094 : FVElementalKernel::computeJacobian() 70 : { 71 2489094 : const auto r = computeQpResidual() * _assembly.elemVolume(); 72 : 73 : mooseAssert(_var.dofIndices().size() == 1, "We're currently built to use CONSTANT MONOMIALS"); 74 : 75 2489094 : addJacobian(_assembly, std::array<ADReal, 1>{{r}}, _var.dofIndices(), _var.scalingFactor()); 76 2489094 : } 77 : 78 : void 79 2488894 : FVElementalKernel::computeOffDiagJacobian() 80 : { 81 2488894 : computeJacobian(); 82 2488894 : } 83 : 84 : void 85 0 : FVElementalKernel::computeOffDiagJacobian(unsigned int) 86 : { 87 0 : mooseError("FVElementalKernel::computeOffDiagJacobian should be called with no arguments"); 88 : }