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 : #pragma once 11 : 12 : #include "NodalKernelBase.h" 13 : #include "MooseVariableInterface.h" 14 : 15 : /** 16 : * Base class for creating nodal kernels with hand-coded Jacobians 17 : */ 18 : class ADArrayNodalKernel : public NodalKernelBase, public MooseVariableInterface<RealEigenVector> 19 : { 20 : public: 21 : /** 22 : * Class constructor. 23 : * @param parameters The InputParameters for the object 24 : */ 25 : static InputParameters validParams(); 26 : 27 : ADArrayNodalKernel(const InputParameters & parameters); 28 : 29 : /** 30 : * Compute the residual at the current node. 31 : * 32 : * Note: This is NOT what a user would normally want to override. 33 : * Usually a user would override computeQpResidual() 34 : */ 35 : virtual void computeResidual() override; 36 : 37 : /** 38 : * Compute the Jacobian at one node. 39 : * 40 : * Note: This is NOT what a user would normally want to override. 41 : * Usually a user would override computeQpJacobian() 42 : */ 43 : virtual void computeJacobian() override; 44 : 45 : /** 46 : * Compute the off-diagonal Jacobian at one node. 47 : * 48 : * Note: This is NOT what a user would normally want to override. 49 : * Usually a user would override computeQpOffDiagJacobian() 50 : */ 51 : virtual void computeOffDiagJacobian(unsigned int jvar) override; 52 : 53 : /** 54 : * Gets the variable this is active on 55 : * @return the variable 56 : */ 57 195 : const MooseVariableFE<RealEigenVector> & variable() const override { return _var; } 58 : 59 45 : virtual void jacobianSetup() override { _my_node = nullptr; } 60 : 61 : protected: 62 : /** 63 : * The user can override this function to compute the residual at a node. 64 : */ 65 : virtual void computeQpResidual(ADRealEigenVector & residual) = 0; 66 : 67 : /** 68 : * Dummy method so we can make derived generic classes that template on <bool is_ad> */ 69 0 : virtual void computeQpJacobian() 70 : { 71 0 : mooseError("I'm an AD object, so computeQpJacobian should never be called"); 72 : } 73 : 74 0 : void setJacobian(unsigned int, unsigned int, Real) 75 : { 76 0 : mooseError("I'm an AD object, so setJacobian should never be called"); 77 : } 78 : 79 : /// variable this works on 80 : MooseVariableFE<RealEigenVector> & _var; 81 : 82 : /// Value of the unknown variable this is acting on 83 : const ADArrayVariableValue & _u; 84 : 85 : /// Number of components of the array variable 86 : const unsigned int _count; 87 : 88 : private: 89 : /// Work vector for residual 90 : ADRealEigenVector _work_vector; 91 : 92 : /// Cache variable to make sure we don't do duplicate AD computations 93 : const Node * _my_node = nullptr; 94 : };