LCOV - code coverage report
Current view: top level - src/constraints - ADPenaltyPeriodicSegmentalConstraint.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 74 80 92.5 %
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 "ADPenaltyPeriodicSegmentalConstraint.h"
      11             : 
      12             : registerMooseObject("MooseApp", ADPenaltyPeriodicSegmentalConstraint);
      13             : 
      14             : InputParameters
      15       14379 : ADPenaltyPeriodicSegmentalConstraint::validParams()
      16             : {
      17       14379 :   InputParameters params = ADMortarScalarBase::validParams();
      18       14379 :   params.addClassDescription(
      19             :       "ADPenaltyPeriodicSegmentalConstraint enforces macro-micro periodic conditions between "
      20             :       "secondary and primary sides of a mortar interface using a penalty approach "
      21             :       "(no Lagrange multipliers needed). Must be used alongside PenaltyEqualValueConstraint.");
      22       14379 :   params.renameCoupledVar("scalar_variable", "epsilon", "Primary coupled scalar variable");
      23       14379 :   params.addRequiredCoupledVar("sigma", "Controlled scalar averaging variable");
      24       43137 :   params.addParam<Real>(
      25             :       "penalty_value",
      26       28758 :       1.0,
      27             :       "Penalty value used to impose a generalized force capturing the mortar constraint equation");
      28             : 
      29       14379 :   return params;
      30           0 : }
      31             : 
      32          57 : ADPenaltyPeriodicSegmentalConstraint::ADPenaltyPeriodicSegmentalConstraint(
      33          57 :     const InputParameters & parameters)
      34             :   : DerivativeMaterialInterface<ADMortarScalarBase>(parameters),
      35          57 :     _temp_jump_global(),
      36          57 :     _tau_s(),
      37          57 :     _kappa_aux_ptr(getScalarVar("sigma", 0)),
      38          57 :     _ka_order(_kappa_aux_ptr->order()),
      39          57 :     _kappa_aux(coupledScalarValue("sigma")),
      40         114 :     _pen_scale(getParam<Real>("penalty_value"))
      41             : {
      42          57 :   if (_kappa_aux_ptr->kind() != Moose::VarKindType::VAR_AUXILIARY)
      43           0 :     paramError("sigma",
      44             :                "Must assign auxiliary scalar variable to sigma, rather than nonlinear variable");
      45          57 : }
      46             : 
      47             : // Compute the stability parameters to use for all quadrature points
      48             : void
      49        2152 : ADPenaltyPeriodicSegmentalConstraint::precalculateResidual()
      50             : {
      51        2152 :   precalculateStability();
      52        2152 : }
      53             : 
      54             : // Compute the temperature jump for current quadrature point
      55             : void
      56        5600 : ADPenaltyPeriodicSegmentalConstraint::initScalarQpResidual()
      57             : {
      58        5600 :   precalculateMaterial();
      59        5600 : }
      60             : 
      61             : ADReal
      62       65536 : ADPenaltyPeriodicSegmentalConstraint::computeQpResidual(const Moose::MortarType mortar_type)
      63             : {
      64             :   // Compute penalty parameter times x-jump times average heat flux
      65       65536 :   RealVectorValue dx(_phys_points_primary[_qp] - _phys_points_secondary[_qp]);
      66       65536 :   ADRealVectorValue kappa_vec(_kappa[0], 0, 0);
      67       65536 :   Moose::derivInsert(kappa_vec(0).derivatives(), _kappa_var_ptr->dofIndices()[0], 1);
      68       65536 :   if (_k_order == 2)
      69             :   {
      70       24064 :     kappa_vec(1) = _kappa[1];
      71       24064 :     Moose::derivInsert(kappa_vec(1).derivatives(), _kappa_var_ptr->dofIndices()[1], 1);
      72             :   }
      73       41472 :   else if (_k_order == 3)
      74             :   {
      75       41472 :     kappa_vec(1) = _kappa[1];
      76       41472 :     kappa_vec(2) = _kappa[2];
      77       41472 :     Moose::derivInsert(kappa_vec(1).derivatives(), _kappa_var_ptr->dofIndices()[1], 1);
      78       41472 :     Moose::derivInsert(kappa_vec(2).derivatives(), _kappa_var_ptr->dofIndices()[2], 1);
      79             :   }
      80       65536 :   ADReal r = _tau_s * (kappa_vec * dx);
      81             : 
      82       65536 :   switch (mortar_type)
      83             :   {
      84       32768 :     case Moose::MortarType::Secondary:
      85       32768 :       r *= _test_secondary[_i][_qp];
      86       32768 :       break;
      87       32768 :     case Moose::MortarType::Primary:
      88       32768 :       r *= -_test_primary[_i][_qp];
      89       32768 :       break;
      90           0 :     case Moose::MortarType::Lower:
      91           0 :       return 0;
      92           0 :     default:
      93           0 :       return 0;
      94             :   }
      95       65536 :   return r;
      96       65536 : }
      97             : 
      98             : ADReal
      99       13792 : ADPenaltyPeriodicSegmentalConstraint::computeScalarQpResidual()
     100             : {
     101             :   // Stability/penalty term for residual of scalar variable
     102       13792 :   ADReal r = _tau_s * _temp_jump_global;
     103       13792 :   RealVectorValue dx(_phys_points_primary[_qp] - _phys_points_secondary[_qp]);
     104             : 
     105       13792 :   r *= -dx(_h);
     106             : 
     107       13792 :   ADRealVectorValue kappa_vec(_kappa[0], 0, 0);
     108       13792 :   RealVectorValue kappa_aux_vec(_kappa_aux[0], 0, 0);
     109       13792 :   Moose::derivInsert(kappa_vec(0).derivatives(), _kappa_var_ptr->dofIndices()[0], 1);
     110       13792 :   if (_k_order == 2)
     111             :   {
     112        6016 :     kappa_vec(1) = _kappa[1];
     113        6016 :     Moose::derivInsert(kappa_vec(1).derivatives(), _kappa_var_ptr->dofIndices()[1], 1);
     114        6016 :     kappa_aux_vec(1) = _kappa_aux[1];
     115             :   }
     116        7776 :   else if (_k_order == 3)
     117             :   {
     118        7776 :     kappa_vec(1) = _kappa[1];
     119        7776 :     kappa_vec(2) = _kappa[2];
     120        7776 :     Moose::derivInsert(kappa_vec(1).derivatives(), _kappa_var_ptr->dofIndices()[1], 1);
     121        7776 :     Moose::derivInsert(kappa_vec(2).derivatives(), _kappa_var_ptr->dofIndices()[2], 1);
     122        7776 :     kappa_aux_vec(1) = _kappa_aux[1];
     123        7776 :     kappa_aux_vec(2) = _kappa_aux[2];
     124             :   }
     125             : 
     126       13792 :   r += dx(_h) * _tau_s * (kappa_vec * dx);
     127       13792 :   r -= dx(_h) * (kappa_aux_vec * _normals[_qp]);
     128             : 
     129       27584 :   return r;
     130       13792 : }
     131             : 
     132             : void
     133        2152 : ADPenaltyPeriodicSegmentalConstraint::precalculateStability()
     134             : {
     135             :   // Example showing how the penalty could be loaded from some function
     136        2152 :   _tau_s = _pen_scale;
     137        2152 : }
     138             : 
     139             : // Compute temperature jump and flux average/jump
     140             : void
     141        5600 : ADPenaltyPeriodicSegmentalConstraint::precalculateMaterial()
     142             : {
     143        5600 :   _temp_jump_global = (_u_primary[_qp] - _u_secondary[_qp]);
     144        5600 : }

Generated by: LCOV version 1.14