LCOV - code coverage report
Current view: top level - src/userobjects - LMWeightedVelocitiesUserObject.C (source / functions) Hit Total Coverage
Test: idaholab/moose contact: 8601ad Lines: 43 49 87.8 %
Date: 2025-07-18 13:27:36 Functions: 10 11 90.9 %
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 "LMWeightedVelocitiesUserObject.h"
      11             : #include "MooseVariableFE.h"
      12             : #include "SystemBase.h"
      13             : 
      14             : registerMooseObject("ContactApp", LMWeightedVelocitiesUserObject);
      15             : 
      16             : InputParameters
      17         736 : LMWeightedVelocitiesUserObject::validParams()
      18             : {
      19         736 :   InputParameters params = WeightedVelocitiesUserObject::validParams();
      20         736 :   params.addClassDescription("Provides the mortar contact Lagrange multipliers (normal and "
      21             :                              "tangential) for constraint enforcement.");
      22        1472 :   params.addRequiredCoupledVar(
      23             :       "lm_variable_normal",
      24             :       "The Lagrange multiplier variable representing the normal contact pressure value.");
      25        1472 :   params.addRequiredCoupledVar(
      26             :       "lm_variable_tangential_one",
      27             :       "The Lagrange multiplier variable representing the tangential contact pressure along the "
      28             :       "first tangential direction (the only one in two dimensions).");
      29        1472 :   params.addCoupledVar("lm_variable_tangential_two",
      30             :                        "The Lagrange multiplier variable representing the tangential contact "
      31             :                        "pressure along the second tangential direction.");
      32        1472 :   params.addParam<bool>(
      33        1472 :       "use_petrov_galerkin", false, "Whether to use the Petrov-Galerkin approach.");
      34        1472 :   params.addCoupledVar("aux_lm",
      35             :                        "Auxiliary Lagrange multiplier variable that is utilized together with the "
      36             :                        "Petrov-Galerkin approach.");
      37         736 :   return params;
      38           0 : }
      39             : 
      40         368 : LMWeightedVelocitiesUserObject::LMWeightedVelocitiesUserObject(const InputParameters & parameters)
      41             :   : WeightedGapUserObject(parameters),
      42             :     WeightedVelocitiesUserObject(parameters),
      43         368 :     _lm_normal_var(getVar("lm_variable_normal", 0)),
      44         368 :     _lm_variable_tangential_one(getVar("lm_variable_tangential_one", 0)),
      45         368 :     _lm_variable_tangential_two(isParamValid("lm_variable_tangential_two")
      46         455 :                                     ? getVar("lm_variable_tangential_two", 0)
      47             :                                     : nullptr),
      48         736 :     _use_petrov_galerkin(getParam<bool>("use_petrov_galerkin")),
      49         752 :     _aux_lm_var(isCoupled("aux_lm") ? getVar("aux_lm", 0) : nullptr)
      50             : {
      51             :   // Check that user inputted a variable
      52         823 :   auto check_input = [this](const auto var, const auto & var_name)
      53             :   {
      54        1646 :     if (isCoupledConstant(var_name))
      55           0 :       paramError("lm_variable_normal",
      56             :                  "The Lagrange multiplier variable must be an actual variable and not a constant.");
      57         823 :     else if (!var)
      58           0 :       paramError(var_name,
      59             :                  "The Lagrange multiplier variables must be provided and be actual variables.");
      60        1191 :   };
      61             : 
      62         368 :   check_input(_lm_normal_var, "lm_variable_normal");
      63         368 :   check_input(_lm_variable_tangential_one, "lm_variable_tangential_one");
      64         368 :   if (_lm_variable_tangential_two)
      65          87 :     check_input(_lm_variable_tangential_two, "lm_variable_tangential_two");
      66             : 
      67             :   // Check that user inputted the right type of variable
      68         823 :   auto check_type = [this](const auto & var, const auto & var_name)
      69             :   {
      70         823 :     if (!var.isNodal())
      71           0 :       paramError(var_name,
      72             :                  "The Lagrange multiplier variables must have degrees of freedom exclusively on "
      73             :                  "nodes, e.g. they should probably be of finite element type 'Lagrange'.");
      74        1191 :   };
      75             : 
      76         368 :   check_type(*_lm_normal_var, "lm_variable_normal");
      77         368 :   check_type(*_lm_variable_tangential_one, "lm_variable_tangential_one");
      78         368 :   if (_lm_variable_tangential_two)
      79          87 :     check_type(*_lm_variable_tangential_two, "lm_variable_tangential_two");
      80             : 
      81         400 :   if (_use_petrov_galerkin && ((!isParamValid("aux_lm")) || _aux_lm_var == nullptr))
      82           0 :     paramError("use_petrov_galerkin",
      83             :                "We need to specify an auxiliary variable `aux_lm` while using the Petrov-Galerkin "
      84             :                "approach");
      85             : 
      86         368 :   if (_use_petrov_galerkin && _aux_lm_var->useDual())
      87           0 :     paramError("aux_lm",
      88             :                "Auxiliary LM variable needs to use standard shape function, i.e., set `use_dual = "
      89             :                "false`.");
      90         368 : }
      91             : 
      92             : const ADVariableValue &
      93    61696784 : LMWeightedVelocitiesUserObject::contactTangentialPressureDirOne() const
      94             : {
      95    61696784 :   return _lm_variable_tangential_one->adSlnLower();
      96             : }
      97             : 
      98             : const ADVariableValue &
      99    56831232 : LMWeightedVelocitiesUserObject::contactTangentialPressureDirTwo() const
     100             : {
     101    56831232 :   return _lm_variable_tangential_two->adSlnLower();
     102             : }
     103             : 
     104             : const ADVariableValue &
     105    61696784 : LMWeightedVelocitiesUserObject::contactPressure() const
     106             : {
     107    61696784 :   return _lm_normal_var->adSlnLower();
     108             : }
     109             : 
     110             : const VariableTestValue &
     111         366 : LMWeightedVelocitiesUserObject::test() const
     112             : {
     113         366 :   return _use_petrov_galerkin ? _aux_lm_var->phiLower() : _lm_normal_var->phiLower();
     114             : }

Generated by: LCOV version 1.14