LCOV - code coverage report
Current view: top level - src/constraints - ADPeriodicSegmentalConstraint.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 44 47 93.6 %
Date: 2025-07-17 01:28:37 Functions: 4 4 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 "ADPeriodicSegmentalConstraint.h"
      11             : 
      12             : registerMooseObject("MooseApp", ADPeriodicSegmentalConstraint);
      13             : 
      14             : InputParameters
      15       14295 : ADPeriodicSegmentalConstraint::validParams()
      16             : {
      17       14295 :   InputParameters params = ADMortarScalarBase::validParams();
      18       14295 :   params.addClassDescription(
      19             :       "ADPeriodicSegmentalConstraint enforces macro-micro periodic conditions between "
      20             :       "secondary and primary sides of a mortar interface using Lagrange multipliers."
      21             :       "Must be used alongside EqualValueConstraint.");
      22       14295 :   params.renameCoupledVar("scalar_variable", "epsilon", "Primary coupled scalar variable");
      23       14295 :   params.addRequiredCoupledVar("sigma", "Controlled scalar averaging variable");
      24             : 
      25       14295 :   return params;
      26           0 : }
      27             : 
      28          15 : ADPeriodicSegmentalConstraint::ADPeriodicSegmentalConstraint(const InputParameters & parameters)
      29             :   : DerivativeMaterialInterface<ADMortarScalarBase>(parameters),
      30          15 :     _kappa_aux_ptr(getScalarVar("sigma", 0)),
      31          15 :     _ka_order(_kappa_aux_ptr->order()),
      32          30 :     _kappa_aux(coupledScalarValue("sigma"))
      33             : {
      34          15 :   if (_kappa_aux_ptr->kind() != Moose::VarKindType::VAR_AUXILIARY)
      35           0 :     paramError("sigma",
      36             :                "Must assign auxiliary scalar variable to sigma, rather than nonlinear variable");
      37          15 : }
      38             : 
      39             : ADReal
      40     1405536 : ADPeriodicSegmentalConstraint::computeQpResidual(const Moose::MortarType mortar_type)
      41             : {
      42     1405536 :   RealVectorValue dx(_phys_points_primary[_qp] - _phys_points_secondary[_qp]);
      43     1405536 :   ADRealVectorValue kappa_vec(_kappa[0], 0, 0);
      44     1405536 :   Moose::derivInsert(kappa_vec(0).derivatives(), _kappa_var_ptr->dofIndices()[0], 1);
      45     1405536 :   if (_k_order == 2)
      46             :   {
      47        2400 :     kappa_vec(1) = _kappa[1];
      48        2400 :     Moose::derivInsert(kappa_vec(1).derivatives(), _kappa_var_ptr->dofIndices()[1], 1);
      49             :   }
      50     1403136 :   else if (_k_order == 3)
      51             :   {
      52     1403136 :     kappa_vec(1) = _kappa[1];
      53     1403136 :     kappa_vec(2) = _kappa[2];
      54     1403136 :     Moose::derivInsert(kappa_vec(1).derivatives(), _kappa_var_ptr->dofIndices()[1], 1);
      55     1403136 :     Moose::derivInsert(kappa_vec(2).derivatives(), _kappa_var_ptr->dofIndices()[2], 1);
      56             :   }
      57     1405536 :   ADReal r = -(kappa_vec * dx);
      58             : 
      59     1405536 :   switch (mortar_type)
      60             :   {
      61       97008 :     case Moose::MortarType::Lower:
      62       97008 :       r *= _test[_i][_qp];
      63       97008 :       break;
      64     1308528 :     default:
      65     1308528 :       return 0;
      66             :   }
      67       97008 :   return r;
      68     1405536 : }
      69             : 
      70             : ADReal
      71       72816 : ADPeriodicSegmentalConstraint::computeScalarQpResidual()
      72             : {
      73             :   // Stability/penalty term for residual of scalar variable
      74       72816 :   RealVectorValue dx(_phys_points_primary[_qp] - _phys_points_secondary[_qp]);
      75       72816 :   ADReal r = -dx(_h) * _lambda[_qp];
      76             : 
      77       72816 :   RealVectorValue kappa_aux_vec(_kappa_aux[0], 0, 0);
      78       72816 :   if (_k_order == 2)
      79             :   {
      80         240 :     kappa_aux_vec(1) = _kappa_aux[1];
      81             :   }
      82       72576 :   else if (_k_order == 3)
      83             :   {
      84       72576 :     kappa_aux_vec(1) = _kappa_aux[1];
      85       72576 :     kappa_aux_vec(2) = _kappa_aux[2];
      86             :   }
      87             : 
      88       72816 :   r -= dx(_h) * (kappa_aux_vec * _normals[_qp]);
      89             : 
      90      145632 :   return r;
      91           0 : }

Generated by: LCOV version 1.14