LCOV - code coverage report
Current view: top level - src/bcs - ArrayLowerDIntegratedBC.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 92 118 78.0 %
Date: 2025-07-17 01:28:37 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          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 "ArrayLowerDIntegratedBC.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       28678 : ArrayLowerDIntegratedBC::validParams()
      22             : {
      23       28678 :   InputParameters params = ArrayIntegratedBC::validParams();
      24       28678 :   params.addRequiredCoupledVar("lowerd_variable", "Lagrange multiplier");
      25       28678 :   return params;
      26           0 : }
      27             : 
      28          78 : ArrayLowerDIntegratedBC::ArrayLowerDIntegratedBC(const InputParameters & parameters)
      29             :   : ArrayIntegratedBC(parameters),
      30          78 :     _lowerd_var(*getArrayVar("lowerd_variable", 0)),
      31          78 :     _lambda(_is_implicit ? _lowerd_var.slnLower() : _lowerd_var.slnLowerOld()),
      32             : 
      33          78 :     _phi_lambda(_lowerd_var.phiLower()),
      34          78 :     _test_lambda(_lowerd_var.phiLower()),
      35         156 :     _work_vector(_count)
      36             : {
      37          78 :   const auto & lower_domains = _lowerd_var.activeSubdomains();
      38         156 :   for (const auto & id : _mesh.boundaryLowerDBlocks())
      39          78 :     if (lower_domains.count(id) == 0)
      40           0 :       mooseDocumentedError(
      41             :           "moose",
      42             :           29151,
      43           0 :           "'lowerd_variable' must be defined on the boundary lower-dimensional subdomain '" +
      44           0 :               _mesh.getSubdomainName(id) +
      45             :               "' that is added by Mesh/build_all_side_lowerd_mesh=true.\nThe check could be overly "
      46             :               "restrictive.");
      47             : 
      48         156 :   for (const auto & id : _var.activeSubdomains())
      49          78 :     if (_mesh.boundaryLowerDBlocks().count(id) > 0)
      50           0 :       paramError("variable",
      51           0 :                  "Must not be defined on the boundary lower-dimensional subdomain '" +
      52           0 :                      _mesh.getSubdomainName(id) + "'");
      53             : 
      54          78 :   if (_lowerd_var.count() != _count)
      55           0 :     paramError("lowerd_variable",
      56             :                "The number of components must be equal to the number of "
      57             :                "components of 'variable'");
      58          78 : }
      59             : 
      60             : void
      61        4500 : ArrayLowerDIntegratedBC::computeResidual()
      62             : {
      63        4500 :   ArrayIntegratedBC::computeResidual();
      64             : 
      65        4500 :   prepareVectorTagLower(_assembly, _lowerd_var.number());
      66             : 
      67       22500 :   for (_qp = 0; _qp < _qrule->n_points(); _qp++)
      68             :   {
      69       18000 :     initLowerDQpResidual();
      70       36000 :     for (_i = 0; _i < _test_lambda.size(); _i++)
      71             :     {
      72       18000 :       _work_vector.setZero();
      73       18000 :       computeLowerDQpResidual(_work_vector);
      74             :       mooseAssert(_work_vector.size() == _count,
      75             :                   "Size of local residual is not equal to the number of array variable compoments");
      76       18000 :       _work_vector *= _JxW[_qp] * _coord[_qp];
      77       18000 :       _assembly.saveLocalArrayResidual(_local_re, _i, _test_lambda.size(), _work_vector);
      78             :     }
      79             :   }
      80             : 
      81        4500 :   accumulateTaggedLocalResidual();
      82        4500 : }
      83             : 
      84             : void
      85         192 : ArrayLowerDIntegratedBC::computeJacobian()
      86             : {
      87         192 :   ArrayIntegratedBC::computeJacobian();
      88             : 
      89         192 :   computeLowerDJacobian(Moose::LowerLower);
      90         192 : }
      91             : 
      92             : void
      93         192 : ArrayLowerDIntegratedBC::computeLowerDJacobian(Moose::ConstraintJacobianType type)
      94             : {
      95             :   mooseAssert(type == Moose::LowerLower || type == Moose::LowerPrimary ||
      96             :                   type == Moose::PrimaryLower,
      97             :               "Jacobian types must have lower in computeLowerDJacobian");
      98             : 
      99         192 :   const ArrayVariableTestValue & test_space =
     100         192 :       (type == Moose::LowerLower || type == Moose::LowerPrimary) ? _test_lambda : _test;
     101           0 :   unsigned int ivar = (type == Moose::LowerLower || type == Moose::LowerPrimary)
     102         192 :                           ? _lowerd_var.number()
     103           0 :                           : _var.number();
     104             : 
     105         192 :   const ArrayVariableTestValue & loc_phi =
     106           0 :       (type == Moose::LowerLower || type == Moose::PrimaryLower) ? _phi_lambda : _phi;
     107           0 :   unsigned int jvar = (type == Moose::LowerLower || type == Moose::PrimaryLower)
     108         192 :                           ? _lowerd_var.number()
     109           0 :                           : _var.number();
     110             : 
     111             :   // need to transform the type for assembling Jacobian on boundary to be consistent with
     112             :   // Assembly::addJacobianLowerD() and Assembly::prepareLowerD().
     113         192 :   Moose::ConstraintJacobianType type_transformed =
     114             :       (type == Moose::LowerLower
     115         192 :            ? type
     116           0 :            : (type == Moose::LowerPrimary ? Moose::LowerSecondary : Moose::SecondaryLower));
     117         192 :   prepareMatrixTagLower(_assembly, ivar, jvar, type_transformed);
     118             : 
     119         192 :   if (_local_ke.n() == 0 || _local_ke.m() == 0)
     120           0 :     return;
     121             : 
     122         960 :   for (_qp = 0; _qp < _qrule->n_points(); _qp++)
     123             :   {
     124         768 :     initLowerDQpJacobian(type);
     125        1536 :     for (_i = 0; _i < test_space.size(); _i++)
     126        1536 :       for (_j = 0; _j < loc_phi.size(); _j++)
     127             :       {
     128         768 :         RealEigenVector v = _JxW[_qp] * _coord[_qp] * computeLowerDQpJacobian(type);
     129         768 :         _assembly.saveDiagLocalArrayJacobian(
     130         768 :             _local_ke, _i, test_space.size(), _j, loc_phi.size(), ivar, v);
     131         768 :       }
     132             :   }
     133             : 
     134         192 :   accumulateTaggedLocalMatrix();
     135             : }
     136             : 
     137             : void
     138        1056 : ArrayLowerDIntegratedBC::computeOffDiagJacobian(const unsigned int jvar_num)
     139             : {
     140        1056 :   ArrayIntegratedBC::computeOffDiagJacobian(jvar_num);
     141             : 
     142        1056 :   computeLowerDOffDiagJacobian(Moose::LowerLower, jvar_num);
     143        1056 :   computeLowerDOffDiagJacobian(Moose::LowerPrimary, jvar_num);
     144        1056 :   computeLowerDOffDiagJacobian(Moose::PrimaryLower, jvar_num);
     145        1056 : }
     146             : 
     147             : void
     148        3168 : ArrayLowerDIntegratedBC::computeLowerDOffDiagJacobian(Moose::ConstraintJacobianType type,
     149             :                                                       const unsigned int jvar_num)
     150             : {
     151             :   mooseAssert(type == Moose::LowerLower || type == Moose::LowerPrimary ||
     152             :                   type == Moose::PrimaryLower,
     153             :               "Jacobian types must have lower in computeLowerDJacobian");
     154             : 
     155        3168 :   const ArrayVariableTestValue & test_space =
     156        3168 :       (type == Moose::LowerLower || type == Moose::LowerPrimary) ? _test_lambda : _test;
     157        2112 :   unsigned int ivar = (type == Moose::LowerLower || type == Moose::LowerPrimary)
     158        4224 :                           ? _lowerd_var.number()
     159        1056 :                           : _var.number();
     160             : 
     161        3168 :   const auto & jvar = getVariable(jvar_num);
     162             : 
     163             :   // need to transform the type for assembling Jacobian on boundary to be consistent with
     164             :   // Assembly::addJacobianLowerD() and Assembly::prepareLowerD().
     165        3168 :   Moose::ConstraintJacobianType type_transformed =
     166             :       (type == Moose::LowerLower
     167        5280 :            ? type
     168        2112 :            : (type == Moose::LowerPrimary ? Moose::LowerSecondary : Moose::SecondaryLower));
     169        3168 :   prepareMatrixTagLower(_assembly, ivar, jvar_num, type_transformed);
     170        3168 :   if (_local_ke.n() == 0 || _local_ke.m() == 0)
     171        1536 :     return;
     172             : 
     173        1632 :   if (jvar.fieldType() == Moose::VarFieldType::VAR_FIELD_STANDARD)
     174             :   {
     175           0 :     const auto & jv0 = static_cast<const MooseVariable &>(jvar);
     176             :     const VariableTestValue & loc_phi =
     177           0 :         (type == Moose::LowerLower || type == Moose::PrimaryLower) ? jv0.phiLower() : jv0.phiFace();
     178             : 
     179           0 :     for (_qp = 0; _qp < _qrule->n_points(); _qp++)
     180             :     {
     181           0 :       initLowerDQpOffDiagJacobian(type, jvar);
     182           0 :       for (_i = 0; _i < test_space.size(); _i++)
     183           0 :         for (_j = 0; _j < loc_phi.size(); _j++)
     184             :         {
     185           0 :           RealEigenMatrix v = _JxW[_qp] * _coord[_qp] * computeLowerDQpOffDiagJacobian(type, jvar);
     186           0 :           _assembly.saveFullLocalArrayJacobian(
     187           0 :               _local_ke, _i, test_space.size(), _j, loc_phi.size(), ivar, jvar_num, v);
     188           0 :         }
     189             :     }
     190             :   }
     191        1632 :   else if (jvar.fieldType() == Moose::VarFieldType::VAR_FIELD_ARRAY)
     192             :   {
     193        1632 :     const auto & jv1 = static_cast<const ArrayMooseVariable &>(jvar);
     194             :     const ArrayVariableTestValue & loc_phi =
     195        1632 :         (type == Moose::LowerLower || type == Moose::PrimaryLower) ? jv1.phiLower() : jv1.phiFace();
     196             : 
     197        8160 :     for (_qp = 0; _qp < _qrule->n_points(); _qp++)
     198             :     {
     199        6528 :       initLowerDQpOffDiagJacobian(type, jvar);
     200       33792 :       for (_i = 0; _i < test_space.size(); _i++)
     201       71808 :         for (_j = 0; _j < loc_phi.size(); _j++)
     202             :         {
     203       44544 :           RealEigenMatrix v = _JxW[_qp] * _coord[_qp] * computeLowerDQpOffDiagJacobian(type, jvar);
     204       44544 :           _assembly.saveFullLocalArrayJacobian(
     205       44544 :               _local_ke, _i, test_space.size(), _j, loc_phi.size(), ivar, jvar_num, v);
     206       44544 :         }
     207             :     }
     208             :   }
     209             :   else
     210           0 :     mooseError("Vector variable cannot be coupled into array DG kernel currently");
     211             : 
     212        1632 :   accumulateTaggedLocalMatrix();
     213             : }
     214             : 
     215             : RealEigenMatrix
     216       36096 : ArrayLowerDIntegratedBC::computeLowerDQpOffDiagJacobian(Moose::ConstraintJacobianType type,
     217             :                                                         const MooseVariableFEBase & jvar)
     218             : {
     219       36096 :   if (jvar.number() == _var.number())
     220             :   {
     221       15360 :     if (type == Moose::LowerPrimary)
     222       30720 :       return computeLowerDQpJacobian(type).asDiagonal();
     223             :   }
     224       20736 :   else if (jvar.number() == _lowerd_var.number())
     225             :   {
     226       16896 :     if (type == Moose::PrimaryLower || type == Moose::LowerLower)
     227       33792 :       return computeLowerDQpJacobian(type).asDiagonal();
     228             :   }
     229             : 
     230        7680 :   return RealEigenMatrix::Zero(_count, jvar.count());
     231             : }

Generated by: LCOV version 1.14