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 ArrayNodalKernel : 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 : ArrayNodalKernel(const InputParameters & parameters); 28 : 29 : /** 30 : * Compute and assemble 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 and assemble 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 : * @param jvar Coupled variable for the off-diagonal Jacobian contribution 51 : */ 52 : virtual void computeOffDiagJacobian(unsigned int jvar) override; 53 : 54 : /** 55 : * Gets the variable this is active on 56 : * @return the variable 57 : */ 58 585 : const MooseVariableFE<RealEigenVector> & variable() const override { return _var; } 59 : 60 : protected: 61 : /** 62 : * The user must override this function to compute the residual at a node. 63 : * @param residual Reference to the residual, computed by this method 64 : */ 65 : virtual void computeQpResidual(RealEigenVector & residual) = 0; 66 : 67 : /** 68 : * The user can override this function to compute the intra-variable 69 : * off-diagonal Jacobian contribution (the coupling between array 70 : * components of the variable itself). Use setJacobian in this function. 71 : */ 72 0 : virtual void computeQpJacobian() {} 73 : 74 : /** 75 : * The user can override this function to compute the inter-variable 76 : * off-diagonal Jacobian contribution (the coupling between array 77 : * components of of the kernel variable and the coupled variable jvar). 78 : * Use setJacobian in this function. 79 : */ 80 0 : virtual void computeQpOffDiagJacobian(unsigned int /*jvar*/) {} 81 : 82 : /** 83 : * Add a Jacobian entry for the current nodal kernel contribution. 84 : * @param i Component index for the kernel variable (row) 85 : * @param j Component index for the coupled variable (column) 86 : * @param value Jacobian entry value for this component pair 87 : */ 88 : void setJacobian(unsigned int i, unsigned int j, Real value); 89 : 90 : /// variable this works on 91 : MooseVariableFE<RealEigenVector> & _var; 92 : 93 : /// Value of the unknown variable this is acting on 94 : const ArrayVariableValue & _u; 95 : 96 : /// Number of components of the array variable 97 : const unsigned int _count; 98 : 99 : private: 100 : /// Work vector for residual 101 : RealEigenVector _work_vector; 102 : 103 : /// DOF indices 104 : const std::vector<dof_id_type> * _ivar_indices; 105 : const std::vector<dof_id_type> * _jvar_indices; 106 : 107 : /// scaling factors 108 : const std::vector<Real> & _scaling; 109 : };