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 192965 : FVElementalKernel::validParams() 23 : { 24 192965 : InputParameters params = FVKernel::validParams(); 25 192965 : params.registerSystemAttributeName("FVElementalKernel"); 26 192965 : params += MaterialPropertyInterface::validParams(); 27 192965 : return params; 28 0 : } 29 : 30 3812 : 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 7624 : _var(*mooseVariableFV()), 40 3812 : _u(_var.adSln()), 41 3812 : _u_functor(getFunctor<ADReal>(_var.name())), 42 7624 : _current_elem(_assembly.elem()), 43 7624 : _q_point(_assembly.qPoints()) 44 : { 45 3812 : addMooseVariableDependency(&_var); 46 3812 : } 47 : 48 : // Note the lack of quadrature point loops in the residual/jacobian compute 49 : // functions. This is because finite volumes currently only works with 50 : // constant monomial elements. We only have one quadrature point regardless of 51 : // problem dimension and just multiply by the element volume. 52 : 53 : void 54 14491712 : FVElementalKernel::computeResidual() 55 : { 56 14491712 : prepareVectorTag(_assembly, _var.number()); 57 14491712 : _local_re(0) += MetaPhysicL::raw_value(computeQpResidual()) * _assembly.elemVolume(); 58 14491712 : accumulateTaggedLocalResidual(); 59 14491712 : } 60 : 61 : void 62 55119 : FVElementalKernel::computeResidualAndJacobian() 63 : { 64 55119 : const auto r = computeQpResidual() * _assembly.elemVolume(); 65 220476 : addResidualsAndJacobian( 66 110238 : _assembly, std::array<ADReal, 1>{{r}}, _var.dofIndices(), _var.scalingFactor()); 67 110238 : } 68 : 69 : void 70 4664455 : FVElementalKernel::computeJacobian() 71 : { 72 4664455 : const auto r = computeQpResidual() * _assembly.elemVolume(); 73 : 74 : mooseAssert(_var.dofIndices().size() == 1, "We're currently built to use CONSTANT MONOMIALS"); 75 : 76 9328910 : addJacobian(_assembly, std::array<ADReal, 1>{{r}}, _var.dofIndices(), _var.scalingFactor()); 77 9328910 : } 78 : 79 : void 80 4664455 : FVElementalKernel::computeOffDiagJacobian() 81 : { 82 4664455 : computeJacobian(); 83 4664455 : } 84 : 85 : void 86 0 : FVElementalKernel::computeOffDiagJacobian(unsigned int) 87 : { 88 0 : mooseError("FVElementalKernel::computeOffDiagJacobian should be called with no arguments"); 89 : }