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 : #include "MortarConstraint.h" 11 : 12 : // MOOSE includes 13 : #include "Assembly.h" 14 : #include "MooseVariable.h" 15 : #include "SystemBase.h" 16 : 17 : InputParameters 18 16066 : MortarConstraint::validParams() 19 : { 20 16066 : InputParameters params = MortarConstraintBase::validParams(); 21 16066 : return params; 22 : } 23 : 24 381 : MortarConstraint::MortarConstraint(const InputParameters & parameters) 25 : : MortarConstraintBase(parameters), 26 381 : _lambda_dummy(), 27 381 : _lambda(_var ? _var->slnLower() : _lambda_dummy), 28 381 : _u_secondary(_secondary_var.sln()), 29 381 : _u_primary(_primary_var.slnNeighbor()), 30 381 : _grad_u_secondary(_secondary_var.gradSln()), 31 381 : _grad_u_primary(_primary_var.gradSlnNeighbor()), 32 381 : _phi(nullptr), 33 381 : _grad_phi(nullptr) 34 : { 35 381 : } 36 : 37 : void 38 114380 : MortarConstraint::computeResidual(Moose::MortarType mortar_type) 39 : { 40 114380 : unsigned int test_space_size = 0; 41 114380 : switch (mortar_type) 42 : { 43 55604 : case Moose::MortarType::Secondary: 44 55604 : prepareVectorTag(_assembly, _secondary_var.number()); 45 55604 : test_space_size = _test_secondary.size(); 46 55604 : break; 47 : 48 55604 : case Moose::MortarType::Primary: 49 55604 : prepareVectorTagNeighbor(_assembly, _primary_var.number()); 50 55604 : test_space_size = _test_primary.size(); 51 55604 : break; 52 : 53 3172 : case Moose::MortarType::Lower: 54 : mooseAssert(_var, "LM variable is null"); 55 3172 : prepareVectorTagLower(_assembly, _var->number()); 56 3172 : test_space_size = _test.size(); 57 3172 : break; 58 : } 59 : 60 718064 : for (_qp = 0; _qp < _qrule_msm->n_points(); _qp++) 61 9199444 : for (_i = 0; _i < test_space_size; _i++) 62 8595760 : _local_re(_i) += _JxW_msm[_qp] * _coord[_qp] * computeQpResidual(mortar_type); 63 : 64 114380 : accumulateTaggedLocalResidual(); 65 114380 : } 66 : 67 : void 68 66516 : MortarConstraint::computeJacobian(Moose::MortarType mortar_type) 69 : { 70 66516 : std::size_t test_space_size = 0; 71 : typedef Moose::ConstraintJacobianType JType; 72 : typedef Moose::MortarType MType; 73 : std::array<JType, 3> jacobian_types; 74 : 75 66516 : switch (mortar_type) 76 : { 77 32244 : case MType::Secondary: 78 32244 : test_space_size = _secondary_var.dofIndices().size(); 79 32244 : jacobian_types = { 80 : {JType::SecondarySecondary, JType::SecondaryPrimary, JType::SecondaryLower}}; 81 32244 : break; 82 : 83 32244 : case MType::Primary: 84 32244 : test_space_size = _primary_var.dofIndicesNeighbor().size(); 85 32244 : jacobian_types = {{JType::PrimarySecondary, JType::PrimaryPrimary, JType::PrimaryLower}}; 86 32244 : break; 87 : 88 2028 : case MType::Lower: 89 2028 : test_space_size = _var ? _var->dofIndicesLower().size() : 0; 90 2028 : jacobian_types = {{JType::LowerSecondary, JType::LowerPrimary, JType::LowerLower}}; 91 2028 : break; 92 : } 93 : 94 66516 : auto & ce = _assembly.couplingEntries(); 95 217992 : for (const auto & it : ce) 96 : { 97 151476 : MooseVariableFEBase & ivariable = *(it.first); 98 151476 : MooseVariableFEBase & jvariable = *(it.second); 99 : 100 151476 : unsigned int ivar = ivariable.number(); 101 151476 : unsigned int jvar = jvariable.number(); 102 : 103 151476 : switch (mortar_type) 104 : { 105 60564 : case MType::Secondary: 106 60564 : if (ivar != _secondary_var.number()) 107 67608 : continue; 108 38028 : break; 109 : 110 60564 : case MType::Primary: 111 60564 : if (ivar != _primary_var.number()) 112 22536 : continue; 113 38028 : break; 114 : 115 30348 : case MType::Lower: 116 30348 : if (!_var || _var->number() != ivar) 117 22536 : continue; 118 7812 : break; 119 : } 120 : 121 83868 : std::array<size_t, 3> shape_space_sizes{{jvariable.dofIndices().size(), 122 83868 : jvariable.dofIndicesNeighbor().size(), 123 167736 : jvariable.dofIndicesLower().size()}}; 124 : std::array<const VariablePhiValue *, 3> phis; 125 : std::array<const VariablePhiGradient *, 3> grad_phis; 126 : std::array<const VectorVariablePhiValue *, 3> vector_phis; 127 : std::array<const VectorVariablePhiGradient *, 3> vector_grad_phis; 128 83868 : if (jvariable.isVector()) 129 : { 130 0 : const auto & temp_var = static_cast<MooseVariableFE<RealVectorValue> &>(jvariable); 131 0 : vector_phis = {{&temp_var.phiFace(), &temp_var.phiFaceNeighbor(), &temp_var.phiLower()}}; 132 0 : vector_grad_phis = { 133 0 : {&temp_var.gradPhiFace(), &temp_var.gradPhiFaceNeighbor(), &temp_var.gradPhiLower()}}; 134 : } 135 : else 136 : { 137 83868 : const auto & temp_var = static_cast<MooseVariableFE<Real> &>(jvariable); 138 83868 : phis = {{&temp_var.phiFace(), &temp_var.phiFaceNeighbor(), &temp_var.phiLower()}}; 139 83868 : grad_phis = { 140 83868 : {&temp_var.gradPhiFace(), &temp_var.gradPhiFaceNeighbor(), &temp_var.gradPhiLower()}}; 141 : } 142 : 143 335472 : for (MooseIndex(3) type_index = 0; type_index < 3; ++type_index) 144 : { 145 251604 : const auto jacobian_type = jacobian_types[type_index]; 146 : 147 251604 : prepareMatrixTagLower(_assembly, ivar, jvar, jacobian_type); 148 : 149 : /// Set the proper phis 150 251604 : if (jvariable.isVector()) 151 : { 152 0 : _vector_phi = vector_phis[type_index]; 153 0 : _vector_grad_phi = vector_grad_phis[type_index]; 154 : } 155 : else 156 : { 157 251604 : _phi = phis[type_index]; 158 251604 : _grad_phi = grad_phis[type_index]; 159 : } 160 : 161 3616260 : for (_i = 0; _i < test_space_size; _i++) 162 30382272 : for (_j = 0; _j < shape_space_sizes[type_index]; _j++) 163 204963392 : for (_qp = 0; _qp < _qrule_msm->n_points(); _qp++) 164 177945776 : _local_ke(_i, _j) += 165 177945776 : _JxW_msm[_qp] * _coord[_qp] * computeQpJacobian(jacobian_type, jvar); 166 251604 : accumulateTaggedLocalMatrix(); 167 : } 168 : } 169 66516 : }