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 193253 : FVElementalKernel::validParams() 23 : { 24 193253 : InputParameters params = FVKernel::validParams(); 25 193253 : params.registerSystemAttributeName("FVElementalKernel"); 26 193253 : params += MaterialPropertyInterface::validParams(); 27 193253 : return params; 28 0 : } 29 : 30 3956 : 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 7912 : _var(*mooseVariableFV()), 40 3956 : _u(_var.adSln()), 41 3956 : _u_functor(getFunctor<ADReal>(_var.name())), 42 7912 : _current_elem(_assembly.elem()), 43 7912 : _q_point(_assembly.qPoints()) 44 : { 45 3956 : addMooseVariableDependency(&_var); 46 3956 : } 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 15063972 : FVElementalKernel::computeResidual() 55 : { 56 15063972 : prepareVectorTag(_assembly, _var.number()); 57 15063972 : _local_re(0) += MetaPhysicL::raw_value(computeQpResidual()) * _assembly.elemVolume(); 58 15063972 : accumulateTaggedLocalResidual(); 59 15063972 : } 60 : 61 : void 62 61482 : FVElementalKernel::computeResidualAndJacobian() 63 : { 64 61482 : const auto r = computeQpResidual() * _assembly.elemVolume(); 65 245928 : addResidualsAndJacobian( 66 122964 : _assembly, std::array<ADReal, 1>{{r}}, _var.dofIndices(), _var.scalingFactor()); 67 122964 : } 68 : 69 : void 70 4915722 : FVElementalKernel::computeJacobian() 71 : { 72 4915722 : const auto r = computeQpResidual() * _assembly.elemVolume(); 73 : 74 : mooseAssert(_var.dofIndices().size() == 1, "We're currently built to use CONSTANT MONOMIALS"); 75 : 76 9831444 : addJacobian(_assembly, std::array<ADReal, 1>{{r}}, _var.dofIndices(), _var.scalingFactor()); 77 9831444 : } 78 : 79 : void 80 4915722 : FVElementalKernel::computeOffDiagJacobian() 81 : { 82 4915722 : computeJacobian(); 83 4915722 : } 84 : 85 : void 86 0 : FVElementalKernel::computeOffDiagJacobian(unsigned int) 87 : { 88 0 : mooseError("FVElementalKernel::computeOffDiagJacobian should be called with no arguments"); 89 : }