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 "MortarConstraint.h" 13 : 14 : /** 15 : * This Constraint adds standardized methods for assembling to a primary 16 : * scalar variable associated with the major variables of the Mortar 17 : * Constraint object. Essentially, the entire row of the residual and Jacobian 18 : * associated with this scalar variable will also be assembled here 19 : * using the loops over mortar segments. 20 : * This variable is "scalar_variable" in the input file and "kappa" 21 : * within the source code. 22 : */ 23 : class MortarScalarBase : public MortarConstraint 24 : { 25 : public: 26 : static InputParameters validParams(); 27 : 28 : MortarScalarBase(const InputParameters & parameters); 29 : 30 : // Using declarations necessary to pull in computeResidual with different parameter list and avoid 31 : // hidden method warning 32 : using MortarConstraintBase::computeResidual; 33 : 34 : // Using declarations necessary to pull in computeJacobian with different parameter list and avoid 35 : // hidden method warning 36 : using MortarConstraintBase::computeJacobian; 37 : 38 : /** 39 : * The scalar variable that this kernel operates on. 40 : */ 41 : const MooseVariableScalar & scalarVariable() const 42 : { 43 : if (!_kappa_var_ptr) 44 : mooseError("kappa pointer should have been set in the constructor"); 45 : return *_kappa_var_ptr; 46 : } 47 : 48 : /** 49 : * Computes _var-residuals as well as _kappa-residual 50 : */ 51 : virtual void computeResidual() override; 52 : /** 53 : * Computes d-_var-residual / d-_var and d-_var-residual / d-jvar, 54 : * as well as d-_kappa-residual / d-_var and d-_kappa-residual / d-jvar 55 : */ 56 : virtual void computeJacobian() override; 57 : 58 : protected: 59 : /** 60 : * Method for computing the scalar part of residual at quadrature points 61 : */ 62 : virtual Real computeScalarQpResidual(); 63 : 64 : /** 65 : * Method for computing the scalar variable part of Jacobian 66 : */ 67 : virtual void computeScalarJacobian(); 68 : 69 : /** 70 : * Method for computing the scalar variable part of Jacobian at 71 : * quadrature points 72 : */ 73 112080 : virtual Real computeScalarQpJacobian() { return 0; } 74 : 75 : /** 76 : * Method for computing an off-diagonal jacobian component d-_kappa-residual / d-jvar 77 : */ 78 : void computeScalarOffDiagJacobian(); 79 : 80 : /** 81 : * Method for computing an off-diagonal jacobian component at quadrature points. 82 : */ 83 0 : virtual Real computeScalarQpOffDiagJacobian(const Moose::MortarType /*mortar_type*/, 84 : const unsigned int /*jvar_num*/) 85 : { 86 0 : return 0; 87 : } 88 : 89 : void computeOffDiagJacobianScalar(unsigned int) override final; 90 : /** 91 : * Method for computing an off-diagonal jacobian component d-_var-residual / d-scalar 92 : */ 93 : void computeOffDiagJacobianScalar(const Moose::MortarType mortar_type, 94 : const unsigned int svar_num); 95 : 96 : /** 97 : * For coupling scalar variables 98 : */ 99 0 : virtual Real computeQpOffDiagJacobianScalar(const Moose::MortarType /*mortar_type*/, 100 : unsigned int /*svar_num*/) 101 : { 102 0 : return 0; 103 : } 104 : 105 : /** 106 : * Method for computing an off-diagonal jacobian component d-_kappa-residual / d-scalar 107 : */ 108 : void computeScalarOffDiagJacobianScalar(const unsigned int svar_num); 109 : 110 : /** 111 : * Method for computing an off-diagonal jacobian component at quadrature points. 112 : */ 113 0 : virtual Real computeScalarQpOffDiagJacobianScalar(const unsigned int /*svar_num*/) { return 0; } 114 : 115 : /** 116 : * Put necessary evaluations depending on qp but independent of test functions here 117 : */ 118 19740 : virtual void initScalarQpResidual() {} 119 : 120 : /** 121 : * Put necessary evaluations depending on qp but independent of test and shape functions here 122 : */ 123 16516 : virtual void initScalarQpJacobian(const unsigned int /*jvar_num*/) {} 124 : 125 : /** 126 : * Put necessary evaluations depending on qp but independent of test and shape functions here for 127 : * off-diagonal Jacobian assembly. 128 : * If jvar_num is a scalar, then this for computeQpOffDiagJacobianScalar 129 : * If jvar_num is a variable, then this for computeScalarQpOffDiagJacobian 130 : */ 131 208016 : virtual void initScalarQpOffDiagJacobian(const Moose::MortarType /*mortar_type*/, 132 : const unsigned int /*jvar_num*/) 133 : { 134 208016 : } 135 : 136 : /// Whether a scalar variable is declared for this constraint 137 : const bool _use_scalar; 138 : 139 : /// Whether to compute scalar contributions for this instance 140 : const bool _compute_scalar_residuals; 141 : 142 : /// (Pointer to) Scalar variable this kernel operates on 143 : const MooseVariableScalar * const _kappa_var_ptr; 144 : 145 : /// The unknown scalar variable ID 146 : const unsigned int _kappa_var; 147 : 148 : /// Order of the scalar variable, used in several places 149 : const unsigned int _k_order; 150 : 151 : /// Reference to the current solution at the current quadrature point 152 : const VariableValue & _kappa; 153 : 154 : /// Used internally to iterate over each scalar component 155 : unsigned int _h; 156 : unsigned int _l; 157 : }; 158 : 159 : inline Real 160 0 : MortarScalarBase::computeScalarQpResidual() 161 : { 162 0 : mooseError( 163 : "A scalar_variable has been set and compute_scalar_residuals=true, ", 164 : "but the computeScalarQpResidual method was not overridden. Accidental call of base class?"); 165 : return 0; 166 : } 167 : 168 : inline void 169 0 : MortarScalarBase::computeOffDiagJacobianScalar(unsigned int) 170 : { 171 0 : mooseError("Must call the mortar type overload instead"); 172 : }