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 : /** 35 : * @param qp The current quadrature point index 36 : * @returns The solid velocity 37 : */ 38 : virtual ADRealVectorValue solidVelocity(const unsigned int qp) const; 39 : 40 : /// The penalty factor 41 : const Real _penalty; 42 : 43 : /// Fluid velocity variable 44 : const VectorMooseVariable * const _velocity_var; 45 : 46 : /// Fluid velocity values 47 : const ADVectorVariableValue & _velocity; 48 : 49 : /// Solid velocity values 50 : std::vector<const ADVariableValue *> _solid_velocities; 51 : 52 : /// Displacement variables 53 : std::vector<const MooseVariable *> _displacements; 54 : 55 : /// JxW with displacement derivatives 56 : const MooseArray<ADReal> & _ad_JxW; 57 : 58 : /// Coordinate transformation with displacement derivatives 59 : const MooseArray<ADReal> & _ad_coord; 60 : 61 : /// Residuals data member to avoid constant heap allocation 62 : std::vector<ADReal> _residuals; 63 : 64 : /// Jump data member to avoid constant heap allocations 65 : std::vector<ADRealVectorValue> _qp_jumps; 66 : }; 67 : 68 : inline void 69 0 : ADPenaltyVelocityContinuity::computeJacobian() 70 : { 71 0 : computeResidual(); 72 0 : } 73 : 74 : inline void 75 0 : ADPenaltyVelocityContinuity::computeResidualAndJacobian() 76 : { 77 0 : computeResidual(); 78 0 : } 79 : 80 : inline void 81 36440 : ADPenaltyVelocityContinuity::computeElementOffDiagJacobian(const unsigned int jvar) 82 : { 83 36440 : if (jvar == _velocity_var->number()) 84 : // Only need to do this once because AD does everything all at once 85 7876 : computeResidual(); 86 36440 : } 87 : 88 : inline void 89 36440 : ADPenaltyVelocityContinuity::computeNeighborOffDiagJacobian(unsigned int) 90 : { 91 36440 : } 92 : 93 : inline const MooseVariableFieldBase & 94 175488 : ADPenaltyVelocityContinuity::variable() const 95 : { 96 175488 : return *_velocity_var; 97 : } 98 : 99 : inline const MooseVariableFieldBase & 100 175376 : ADPenaltyVelocityContinuity::neighborVariable() const 101 : { 102 175376 : if (_displacements.empty() || !_displacements.front()) 103 0 : mooseError("The 'neighborVariable' method was called which requires that displacements be " 104 : "actual variables."); 105 : 106 175376 : return *_displacements.front(); 107 : }