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 14396 : LowerDIntegratedBC::validParams() 22 : { 23 14396 : InputParameters params = IntegratedBC::validParams(); 24 14396 : params.addRequiredCoupledVar("lowerd_variable", "Lagrange multiplier"); 25 14396 : return params; 26 0 : } 27 : 28 70 : LowerDIntegratedBC::LowerDIntegratedBC(const InputParameters & parameters) 29 : : IntegratedBC(parameters), 30 70 : _lowerd_var(*getVar("lowerd_variable", 0)), 31 70 : _lambda(_is_implicit ? _lowerd_var.slnLower() : _lowerd_var.slnLowerOld()), 32 : 33 70 : _phi_lambda(_lowerd_var.phiLower()), 34 140 : _test_lambda(_lowerd_var.phiLower()) 35 : { 36 70 : const auto & lower_domains = _lowerd_var.activeSubdomains(); 37 153 : for (const auto & id : _mesh.boundaryLowerDBlocks()) 38 87 : 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 132 : for (const auto & id : _var.activeSubdomains()) 48 66 : 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 66 : } 56 : 57 : void 58 1760 : LowerDIntegratedBC::computeResidual() 59 : { 60 1760 : IntegratedBC::computeResidual(); 61 : 62 1760 : prepareVectorTagLower(_assembly, _lowerd_var.number()); 63 : 64 24288 : for (_qp = 0; _qp < _qrule->n_points(); _qp++) 65 : { 66 22528 : initLowerDQpResidual(); 67 45056 : for (_i = 0; _i < _test_lambda.size(); _i++) 68 22528 : _local_re(_i) += _JxW[_qp] * _coord[_qp] * computeLowerDQpResidual(); 69 : } 70 : 71 1760 : accumulateTaggedLocalResidual(); 72 1760 : } 73 : 74 : void 75 0 : LowerDIntegratedBC::computeJacobian() 76 : { 77 0 : IntegratedBC::computeJacobian(); 78 : 79 0 : computeLowerDJacobian(Moose::LowerLower); 80 0 : } 81 : 82 : void 83 2640 : 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 4400 : const auto & test_space = 90 1760 : (type == Moose::LowerLower || type == Moose::LowerPrimary) ? _test_lambda : _test; 91 1760 : unsigned int ivar = (type == Moose::LowerLower || type == Moose::LowerPrimary) 92 3520 : ? _lowerd_var.number() 93 880 : : _var.number(); 94 : 95 4400 : const auto & loc_phi = 96 1760 : (type == Moose::LowerLower || type == Moose::PrimaryLower) ? _phi_lambda : _phi; 97 1760 : const auto jvar = (type == Moose::LowerLower || type == Moose::PrimaryLower) 98 3520 : ? _lowerd_var.number() 99 880 : : _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 2640 : Moose::ConstraintJacobianType type_tr = 104 : (type == Moose::LowerLower 105 4400 : ? type 106 1760 : : (type == Moose::LowerPrimary ? Moose::LowerSecondary : Moose::SecondaryLower)); 107 2640 : prepareMatrixTagLower(_assembly, ivar, jvar, type_tr); 108 : 109 2640 : if (_local_ke.n() == 0 || _local_ke.m() == 0) 110 0 : return; 111 : 112 36432 : for (_qp = 0; _qp < _qrule->n_points(); _qp++) 113 : { 114 33792 : initLowerDQpJacobian(type); 115 273920 : for (_i = 0; _i < test_space.size(); _i++) 116 686592 : for (_j = 0; _j < loc_phi.size(); _j++) 117 446464 : _local_ke(_i, _j) += _JxW[_qp] * _coord[_qp] * computeLowerDQpJacobian(type); 118 : } 119 : 120 2640 : accumulateTaggedLocalMatrix(); 121 : } 122 : 123 : void 124 2640 : LowerDIntegratedBC::computeOffDiagJacobian(const unsigned int jvar_num) 125 : { 126 2640 : if (jvar_num == variable().number()) 127 : { 128 880 : IntegratedBC::computeJacobian(); 129 880 : computeLowerDJacobian(Moose::LowerPrimary); 130 : } 131 1760 : else if (jvar_num == _lowerd_var.number()) 132 : { 133 880 : computeLowerDJacobian(Moose::LowerLower); 134 880 : computeLowerDJacobian(Moose::PrimaryLower); 135 : } 136 : else 137 : { 138 880 : IntegratedBC::computeOffDiagJacobian(jvar_num); 139 880 : computeLowerDOffDiagJacobian(Moose::LowerLower, jvar_num); 140 880 : computeLowerDOffDiagJacobian(Moose::LowerPrimary, jvar_num); 141 880 : computeLowerDOffDiagJacobian(Moose::PrimaryLower, jvar_num); 142 : } 143 2640 : } 144 : 145 : void 146 2640 : 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 4400 : const auto & test_space = 154 1760 : (type == Moose::LowerLower || type == Moose::LowerPrimary) ? _test_lambda : _test; 155 1760 : const auto ivar = (type == Moose::LowerLower || type == Moose::LowerPrimary) 156 3520 : ? _lowerd_var.number() 157 880 : : _var.number(); 158 : 159 2640 : const auto & jvar = getVariable(jvar_num); 160 : 161 2640 : prepareMatrixTagLower(_assembly, ivar, jvar_num, type); 162 2640 : if (_local_ke.n() == 0 || _local_ke.m() == 0) 163 880 : return; 164 : 165 1760 : if (jvar.fieldType() == Moose::VarFieldType::VAR_FIELD_STANDARD) 166 : { 167 1760 : const auto & jv0 = static_cast<const MooseVariable &>(jvar); 168 : const auto & loc_phi = 169 1760 : (type == Moose::LowerLower || type == Moose::PrimaryLower) ? jv0.phiLower() : jv0.phiFace(); 170 : 171 24288 : for (_qp = 0; _qp < _qrule->n_points(); _qp++) 172 : { 173 22528 : initLowerDQpOffDiagJacobian(type, jvar); 174 251392 : for (_i = 0; _i < test_space.size(); _i++) 175 457728 : for (_j = 0; _j < loc_phi.size(); _j++) 176 228864 : _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 1760 : accumulateTaggedLocalMatrix(); 185 : }