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 "InterfaceKernelBase.h" 13 : #include "MooseVariableFE.h" 14 : 15 : /** 16 : * Interface kernel for enforcing continuity of stress and velocity 17 : */ 18 : class ADPenaltyVelocityContinuity : public InterfaceKernelBase 19 : { 20 : public: 21 : static InputParameters validParams(); 22 : 23 : ADPenaltyVelocityContinuity(const InputParameters & parameters); 24 : 25 : virtual void computeResidual() override; 26 : virtual void computeResidualAndJacobian() override; 27 : virtual void computeJacobian() override; 28 : virtual void computeElementOffDiagJacobian(unsigned int jvar) override; 29 : virtual void computeNeighborOffDiagJacobian(unsigned int jvar) override; 30 : virtual const MooseVariableFieldBase & variable() const override; 31 : virtual const MooseVariableFieldBase & neighborVariable() const override; 32 : 33 : protected: 34 : /// The penalty factor 35 : const Real _penalty; 36 : 37 : /// Fluid velocity variable 38 : const VectorMooseVariable * const _velocity_var; 39 : 40 : /// Fluid velocity values 41 : const ADVectorVariableValue & _velocity; 42 : 43 : /// Solid velocity values 44 : std::vector<const ADVariableValue *> _solid_velocities; 45 : 46 : /// Displacement variables 47 : std::vector<const MooseVariable *> _displacements; 48 : 49 : /// JxW with displacement derivatives 50 : const MooseArray<ADReal> & _ad_JxW; 51 : 52 : /// Coordinate transformation with displacement derivatives 53 : const MooseArray<ADReal> & _ad_coord; 54 : 55 : /// Residuals data member to avoid constant heap allocation 56 : std::vector<ADReal> _residuals; 57 : 58 : /// Jump data member to avoid constant heap allocations 59 : std::vector<ADRealVectorValue> _qp_jumps; 60 : }; 61 : 62 : inline void 63 0 : ADPenaltyVelocityContinuity::computeJacobian() 64 : { 65 0 : computeResidual(); 66 0 : } 67 : 68 : inline void 69 0 : ADPenaltyVelocityContinuity::computeResidualAndJacobian() 70 : { 71 0 : computeResidual(); 72 0 : } 73 : 74 : inline void 75 14856 : ADPenaltyVelocityContinuity::computeElementOffDiagJacobian(const unsigned int jvar) 76 : { 77 14856 : if (jvar == _velocity_var->number()) 78 : // Only need to do this once because AD does everything all at once 79 2476 : computeResidual(); 80 14856 : } 81 : 82 : inline void 83 14856 : ADPenaltyVelocityContinuity::computeNeighborOffDiagJacobian(unsigned int) 84 : { 85 14856 : } 86 : 87 : inline const MooseVariableFieldBase & 88 89224 : ADPenaltyVelocityContinuity::variable() const 89 : { 90 89224 : return *_velocity_var; 91 : } 92 : 93 : inline const MooseVariableFieldBase & 94 89136 : ADPenaltyVelocityContinuity::neighborVariable() const 95 : { 96 89136 : if (_displacements.empty() || !_displacements.front()) 97 0 : mooseError("The 'neighborVariable' method was called which requires that displacements be " 98 : "actual variables."); 99 : 100 89136 : return *_displacements.front(); 101 : }