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 "MooseObject.h" 13 : #include "SetupInterface.h" 14 : #include "FunctionInterface.h" 15 : #include "UserObjectInterface.h" 16 : #include "TransientInterface.h" 17 : #include "PostprocessorInterface.h" 18 : #include "VectorPostprocessorInterface.h" 19 : #include "RandomInterface.h" 20 : #include "Restartable.h" 21 : #include "MeshChangedInterface.h" 22 : #include "TaggingInterface.h" 23 : 24 : class FEProblemBase; 25 : class MooseMesh; 26 : class SubProblem; 27 : class Assembly; 28 : class MooseVariableBase; 29 : class MooseVariableFieldBase; 30 : class InputParameters; 31 : class SystemBase; 32 : 33 : /** 34 : * This is the common base class for objects that give residual contributions. 35 : */ 36 : class ResidualObject : public MooseObject, 37 : public SetupInterface, 38 : public FunctionInterface, 39 : public UserObjectInterface, 40 : public TransientInterface, 41 : public PostprocessorInterface, 42 : public VectorPostprocessorInterface, 43 : public RandomInterface, 44 : public Restartable, 45 : public MeshChangedInterface, 46 : public TaggingInterface 47 : { 48 : public: 49 : static InputParameters validParams(); 50 : 51 : /** 52 : * Class constructor. 53 : * @param parameters The InputParameters for the object 54 : * @param nodal Whether this object is applied to nodes or not 55 : */ 56 : ResidualObject(const InputParameters & parameters, bool nodal = false); 57 : 58 : /// Compute this object's contribution to the residual 59 : virtual void computeResidual() = 0; 60 : 61 : /// Compute this object's contribution to the diagonal Jacobian entries 62 : virtual void computeJacobian() = 0; 63 : 64 : /// Compute this object's contribution to the residual and Jacobian simultaneously 65 : virtual void computeResidualAndJacobian(); 66 : 67 : /** 68 : * Computes this object's contribution to off-diagonal blocks of the system Jacobian matrix 69 : * @param jvar The number of the coupled variable. We pass the number of the coupled variable 70 : * instead of an actual variable object because we can query our system and obtain the variable 71 : * object associated with it. E.g. we need to make sure we are getting undisplaced variables if we 72 : * are working on the undisplaced mesh, and displaced variables if we are working on the displaced 73 : * mesh 74 : */ 75 280 : virtual void computeOffDiagJacobian(unsigned int /*jvar*/) {} 76 : 77 : /** 78 : * Computes jacobian block with respect to a scalar variable 79 : * @param jvar The number of the scalar variable 80 : */ 81 0 : virtual void computeOffDiagJacobianScalar(unsigned int /*jvar*/) {} 82 : 83 : /** 84 : * Compute this object's contribution to the diagonal Jacobian entries 85 : * corresponding to nonlocal dofs of the variable 86 : */ 87 0 : virtual void computeNonlocalJacobian() {} 88 : 89 : /** 90 : * Computes Jacobian entries corresponding to nonlocal dofs of the jvar 91 : */ 92 0 : virtual void computeNonlocalOffDiagJacobian(unsigned int /* jvar */) {} 93 : 94 : /** 95 : * Returns the variable that this object operates on. 96 : */ 97 : virtual const MooseVariableBase & variable() const = 0; 98 : 99 : /** 100 : * Returns a reference to the SubProblem for which this Kernel is active 101 : */ 102 37375 : const SubProblem & subProblem() const { return _subproblem; } 103 : 104 : /** 105 : * Prepare shape functions 106 : * @param var_num The variable number whose shape functions should be prepared 107 : */ 108 : virtual void prepareShapes(unsigned int var_num); 109 : 110 : /** 111 : * @returns Additional variables covered by this residual object in addition to \p variable(). A 112 : * covered variable here means a variable for whom this object computes residuals/Jacobians 113 : */ 114 75737 : virtual std::set<std::string> additionalROVariables() { return {}; } 115 : 116 : protected: 117 658589235 : virtual void precalculateResidual() {} 118 108802727 : virtual void precalculateJacobian() {} 119 18311180 : virtual void precalculateOffDiagJacobian(unsigned int /* jvar */) {} 120 : 121 : /** 122 : * Retrieve the variable object from our system associated with \p jvar_num 123 : */ 124 19420610 : const MooseVariableFieldBase & getVariable(unsigned int jvar_num) const 125 : { 126 19420610 : return _sys.getVariable(_tid, jvar_num); 127 : } 128 : 129 : protected: 130 : /// Reference to this kernel's SubProblem 131 : SubProblem & _subproblem; 132 : 133 : /// Reference to this kernel's FEProblemBase 134 : FEProblemBase & _fe_problem; 135 : 136 : /// Reference to the EquationSystem object 137 : SystemBase & _sys; 138 : 139 : /// The thread ID for this kernel 140 : THREAD_ID _tid; 141 : 142 : /// Reference to this Kernel's assembly object 143 : Assembly & _assembly; 144 : 145 : /// Reference to this Kernel's mesh object 146 : MooseMesh & _mesh; 147 : };