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 "LowerDIntegratedBC.h" 11 : 12 : #include "Assembly.h" 13 : #include "SubProblem.h" 14 : #include "SystemBase.h" 15 : #include "MooseVariableFE.h" 16 : #include "MooseVariableScalar.h" 17 : 18 : #include "libmesh/quadrature.h" 19 : 20 : InputParameters 21 14406 : LowerDIntegratedBC::validParams() 22 : { 23 14406 : InputParameters params = IntegratedBC::validParams(); 24 14406 : params.addRequiredCoupledVar("lowerd_variable", "Lagrange multiplier"); 25 14406 : return params; 26 0 : } 27 : 28 75 : LowerDIntegratedBC::LowerDIntegratedBC(const InputParameters & parameters) 29 : : IntegratedBC(parameters), 30 75 : _lowerd_var(*getVar("lowerd_variable", 0)), 31 75 : _lambda(_is_implicit ? _lowerd_var.slnLower() : _lowerd_var.slnLowerOld()), 32 : 33 75 : _phi_lambda(_lowerd_var.phiLower()), 34 150 : _test_lambda(_lowerd_var.phiLower()) 35 : { 36 75 : const auto & lower_domains = _lowerd_var.activeSubdomains(); 37 164 : for (const auto & id : _mesh.boundaryLowerDBlocks()) 38 93 : if (lower_domains.count(id) == 0) 39 4 : mooseDocumentedError( 40 : "moose", 41 : 29151, 42 0 : "'lowerd_variable' must be defined on the boundary lower-dimensional subdomain '" + 43 4 : _mesh.getSubdomainName(id) + 44 : "' that is added by Mesh/build_all_side_lowerd_mesh=true.\nThe check could be overly " 45 : "restrictive."); 46 : 47 142 : for (const auto & id : _var.activeSubdomains()) 48 71 : if (_mesh.boundaryLowerDBlocks().count(id) > 0) 49 0 : paramError("variable", 50 0 : "Must not be defined on the boundary lower-dimensional subdomain '" + 51 0 : _mesh.getSubdomainName(id) + "'"); 52 : 53 : // Note: the above two conditions also ensure that the variable and lower-d variable are 54 : // different. 55 71 : } 56 : 57 : void 58 1980 : LowerDIntegratedBC::computeResidual() 59 : { 60 1980 : IntegratedBC::computeResidual(); 61 : 62 1980 : prepareVectorTagLower(_assembly, _lowerd_var.number()); 63 : 64 27324 : for (_qp = 0; _qp < _qrule->n_points(); _qp++) 65 : { 66 25344 : initLowerDQpResidual(); 67 50688 : for (_i = 0; _i < _test_lambda.size(); _i++) 68 25344 : _local_re(_i) += _JxW[_qp] * _coord[_qp] * computeLowerDQpResidual(); 69 : } 70 : 71 1980 : accumulateTaggedLocalResidual(); 72 1980 : } 73 : 74 : void 75 0 : LowerDIntegratedBC::computeJacobian() 76 : { 77 0 : IntegratedBC::computeJacobian(); 78 : 79 0 : computeLowerDJacobian(Moose::LowerLower); 80 0 : } 81 : 82 : void 83 2970 : LowerDIntegratedBC::computeLowerDJacobian(Moose::ConstraintJacobianType type) 84 : { 85 : mooseAssert(type == Moose::LowerLower || type == Moose::LowerPrimary || 86 : type == Moose::PrimaryLower, 87 : "Jacobian types must have lower in computeLowerDJacobian"); 88 : 89 4950 : const auto & test_space = 90 1980 : (type == Moose::LowerLower || type == Moose::LowerPrimary) ? _test_lambda : _test; 91 1980 : unsigned int ivar = (type == Moose::LowerLower || type == Moose::LowerPrimary) 92 3960 : ? _lowerd_var.number() 93 990 : : _var.number(); 94 : 95 4950 : const auto & loc_phi = 96 1980 : (type == Moose::LowerLower || type == Moose::PrimaryLower) ? _phi_lambda : _phi; 97 1980 : const auto jvar = (type == Moose::LowerLower || type == Moose::PrimaryLower) 98 3960 : ? _lowerd_var.number() 99 990 : : _var.number(); 100 : 101 : // need to transform the type for assembling Jacobian on boundary to be consistent with 102 : // Assembly::addJacobianLowerD() and Assembly::prepareLowerD(). 103 2970 : Moose::ConstraintJacobianType type_tr = 104 : (type == Moose::LowerLower 105 4950 : ? type 106 1980 : : (type == Moose::LowerPrimary ? Moose::LowerSecondary : Moose::SecondaryLower)); 107 2970 : prepareMatrixTagLower(_assembly, ivar, jvar, type_tr); 108 : 109 2970 : if (_local_ke.n() == 0 || _local_ke.m() == 0) 110 0 : return; 111 : 112 40986 : for (_qp = 0; _qp < _qrule->n_points(); _qp++) 113 : { 114 38016 : initLowerDQpJacobian(type); 115 308160 : for (_i = 0; _i < test_space.size(); _i++) 116 772416 : for (_j = 0; _j < loc_phi.size(); _j++) 117 502272 : _local_ke(_i, _j) += _JxW[_qp] * _coord[_qp] * computeLowerDQpJacobian(type); 118 : } 119 : 120 2970 : accumulateTaggedLocalMatrix(); 121 : } 122 : 123 : void 124 2970 : LowerDIntegratedBC::computeOffDiagJacobian(const unsigned int jvar_num) 125 : { 126 2970 : if (jvar_num == variable().number()) 127 : { 128 990 : IntegratedBC::computeJacobian(); 129 990 : computeLowerDJacobian(Moose::LowerPrimary); 130 : } 131 1980 : else if (jvar_num == _lowerd_var.number()) 132 : { 133 990 : computeLowerDJacobian(Moose::LowerLower); 134 990 : computeLowerDJacobian(Moose::PrimaryLower); 135 : } 136 : else 137 : { 138 990 : IntegratedBC::computeOffDiagJacobian(jvar_num); 139 990 : computeLowerDOffDiagJacobian(Moose::LowerLower, jvar_num); 140 990 : computeLowerDOffDiagJacobian(Moose::LowerPrimary, jvar_num); 141 990 : computeLowerDOffDiagJacobian(Moose::PrimaryLower, jvar_num); 142 : } 143 2970 : } 144 : 145 : void 146 2970 : LowerDIntegratedBC::computeLowerDOffDiagJacobian(Moose::ConstraintJacobianType type, 147 : const unsigned int jvar_num) 148 : { 149 : mooseAssert(type == Moose::LowerLower || type == Moose::LowerPrimary || 150 : type == Moose::PrimaryLower, 151 : "Jacobian types must have lower in computeLowerDJacobian"); 152 : 153 4950 : const auto & test_space = 154 1980 : (type == Moose::LowerLower || type == Moose::LowerPrimary) ? _test_lambda : _test; 155 1980 : const auto ivar = (type == Moose::LowerLower || type == Moose::LowerPrimary) 156 3960 : ? _lowerd_var.number() 157 990 : : _var.number(); 158 : 159 2970 : const auto & jvar = getVariable(jvar_num); 160 : 161 2970 : prepareMatrixTagLower(_assembly, ivar, jvar_num, type); 162 2970 : if (_local_ke.n() == 0 || _local_ke.m() == 0) 163 990 : return; 164 : 165 1980 : if (jvar.fieldType() == Moose::VarFieldType::VAR_FIELD_STANDARD) 166 : { 167 1980 : const auto & jv0 = static_cast<const MooseVariable &>(jvar); 168 : const auto & loc_phi = 169 1980 : (type == Moose::LowerLower || type == Moose::PrimaryLower) ? jv0.phiLower() : jv0.phiFace(); 170 : 171 27324 : for (_qp = 0; _qp < _qrule->n_points(); _qp++) 172 : { 173 25344 : initLowerDQpOffDiagJacobian(type, jvar); 174 282816 : for (_i = 0; _i < test_space.size(); _i++) 175 514944 : for (_j = 0; _j < loc_phi.size(); _j++) 176 257472 : _local_ke(_i, _j) += _JxW[_qp] * _coord[_qp] * computeLowerDQpOffDiagJacobian(type, jvar); 177 : } 178 : } 179 0 : else if (jvar.fieldType() == Moose::VarFieldType::VAR_FIELD_ARRAY) 180 0 : mooseError("Array variable cannot be coupled into integrated BC currently"); 181 : else 182 0 : mooseError("Vector variable cannot be coupled into integrated BC currently"); 183 : 184 1980 : accumulateTaggedLocalMatrix(); 185 : }