LCOV - code coverage report
Current view: top level - include/userobjects - WeightedGapUserObject.h (source / functions) Hit Total Coverage
Test: idaholab/moose contact: 8601ad Lines: 6 14 42.9 %
Date: 2025-07-18 13:27:36 Functions: 0 4 0.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             : #pragma once
      11             : 
      12             : #include "MortarUserObject.h"
      13             : 
      14             : /**
      15             :  * Creates dof object to weighted gap map
      16             :  */
      17             : class WeightedGapUserObject : public MortarUserObject
      18             : {
      19             : public:
      20             :   static InputParameters validParams();
      21             : 
      22             :   WeightedGapUserObject(const InputParameters & parameters);
      23             : 
      24             :   virtual void initialize() override;
      25             :   virtual void execute() override;
      26             :   virtual void finalize() override;
      27             :   virtual void initialSetup() override;
      28             : 
      29             :   /**
      30             :    * Get the degree of freedom to weighted gap information
      31             :    */
      32             :   const std::unordered_map<const DofObject *, std::pair<ADReal, Real>> & dofToWeightedGap() const;
      33             : 
      34             :   /**
      35             :    * @return The contact force at quadrature points on the mortar segment
      36             :    */
      37             :   virtual const ADVariableValue & contactPressure() const = 0;
      38             : 
      39             :   /**
      40             :    * @param node Node pointer
      41             :    * @return The normal contact pressure at the node
      42             :    */
      43           0 :   virtual Real getNormalContactPressure(const Node * const /*node*/) const
      44             :   {
      45           0 :     mooseError("Not available in base class.");
      46             :   }
      47             : 
      48             :   /**
      49             :    * @param node Node pointer
      50             :    * @return The normal gap at the node
      51             :    */
      52             :   virtual Real getNormalGap(const Node * const /*node*/) const;
      53             : 
      54             :   /**
      55             :    * Compute physical gap from integration gap quantity
      56             :    */
      57             :   Real physicalGap(const std::pair<ADReal, Real> & gap) const
      58             :   {
      59       20413 :     return MetaPhysicL::raw_value(gap.first) / gap.second;
      60             :   }
      61             : 
      62      127893 :   ADReal adPhysicalGap(const std::pair<ADReal, Real> & gap) const { return gap.first / gap.second; }
      63             : 
      64             :   /**
      65             :    * @param node Node pointer
      66             :    * @param component Component of the frictional pressure vector
      67             :    * @return The frictional contact pressure at the node
      68             :    */
      69           0 :   virtual Real getFrictionalContactPressure(const Node * const /*node*/,
      70             :                                             const unsigned int /*component*/) const
      71             :   {
      72           0 :     mooseError("Not available in base class.");
      73             :   }
      74             : 
      75             :   /**
      76             :    * @param node Node pointer
      77             :    * @param component Component of the local slip vector
      78             :    * @return The accumulated slip at the node
      79             :    */
      80           0 :   virtual Real getAccumulatedSlip(const Node * const /*node*/,
      81             :                                   const unsigned int /*component*/) const
      82             :   {
      83           0 :     mooseError("Not available in base class.");
      84             :   }
      85             : 
      86             :   /**
      87             :    * @param node Node pointer
      88             :    * @param component Component of the local slip vector
      89             :    * @return The tangential velocity at the node with local components
      90             :    */
      91           0 :   virtual Real getTangentialVelocity(const Node * const /*node*/,
      92             :                                      const unsigned int /*component*/) const
      93             :   {
      94           0 :     mooseError("Not available in base class.");
      95             :   }
      96             : 
      97             : protected:
      98             :   /**
      99             :    * Computes properties that are functions only of the current quadrature point (\p _qp), e.g.
     100             :    * indepedent of shape functions
     101             :    */
     102             :   virtual void computeQpProperties();
     103             : 
     104             :   /**
     105             :    * Computes properties that are functions both of \p _qp and \p _i, for example the weighted gap
     106             :    */
     107             :   virtual void computeQpIProperties();
     108             : 
     109             :   /**
     110             :    * @return The test function associated with the weighted gap
     111             :    */
     112             :   virtual const VariableTestValue & test() const = 0;
     113             : 
     114             :   /**
     115             :    * @return Whether the gap constraint will be enforced solely by the owner of the weighted gap or
     116             :    * will be enforced in a distributed way (like in a penalty method)
     117             :    */
     118             :   virtual bool constrainedByOwner() const = 0;
     119             : 
     120             :   /**
     121             :    * Find a value in a map or return a default if the key doesn't exist
     122             :    */
     123             :   template <typename K, typename V>
     124             :   V
     125             :   findValue(const std::unordered_map<K, V> & map, const K & key, const V & default_value = 0) const
     126             :   {
     127             :     const auto it = map.find(key);
     128      542797 :     if (it == map.end())
     129      470435 :       return default_value;
     130       72362 :     return it->second;
     131             :   }
     132             : 
     133             :   /// The base finite element problem
     134             :   FEProblemBase & _fe_problem;
     135             : 
     136             :   /// The value of the gap at the current quadrature point
     137             :   ADReal _qp_gap;
     138             : 
     139             :   /// The value of the LM at the current quadrature point
     140             :   Real _qp_factor;
     141             : 
     142             :   /// Whether the dof objects are nodal; if they're not, then they're elemental
     143             :   const bool _nodal;
     144             : 
     145             :   /// The x displacement variable
     146             :   const MooseVariable * const _disp_x_var;
     147             :   /// The y displacement variable
     148             :   const MooseVariable * const _disp_y_var;
     149             :   /// For 2D mortar contact no displacement will be specified, so const pointers used
     150             :   const bool _has_disp_z;
     151             :   /// The z displacement variable
     152             :   const MooseVariable * const _disp_z_var;
     153             : 
     154             :   /// x-displacement on the secondary face
     155             :   const ADVariableValue & _secondary_disp_x;
     156             :   /// x-displacement on the primary face
     157             :   const ADVariableValue & _primary_disp_x;
     158             :   /// y-displacement on the secondary face
     159             :   const ADVariableValue & _secondary_disp_y;
     160             :   /// y-displacement on the primary face
     161             :   const ADVariableValue & _primary_disp_y;
     162             :   /// z-displacement on the secondary face
     163             :   const ADVariableValue * const _secondary_disp_z;
     164             :   /// z-displacement on the primary face
     165             :   const ADVariableValue * const _primary_disp_z;
     166             : 
     167             :   /// Member for handling change of coordinate systems (xyz, rz, spherical)
     168             :   const MooseArray<Real> & _coord;
     169             : 
     170             :   /// Vector for computation of weighted gap with nodal normals
     171             :   ADRealVectorValue _qp_gap_nodal;
     172             : 
     173             :   /// Vector for computation of relative displacement (determines mixity ratio in interface problems)
     174             :   ADRealVectorValue _qp_displacement_nodal;
     175             : 
     176             :   /// A map from node to weighted gap and normalization (if requested)
     177             :   std::unordered_map<const DofObject *, std::pair<ADReal, Real>> _dof_to_weighted_gap;
     178             : 
     179             :   /// A map from node to weighted displacements
     180             :   std::unordered_map<const DofObject *, ADRealVectorValue> _dof_to_weighted_displacements;
     181             : 
     182             :   /// A pointer members that can be used to help avoid copying ADReals
     183             :   const ADReal * _weighted_gap_ptr = nullptr;
     184             :   const Real * _normalization_ptr = nullptr;
     185             : 
     186             :   /// A pointer to the test function associated with the weighted gap. We have this member so that
     187             :   /// we don't do virtual calls during inner quadrature-point/test-function loops
     188             :   const VariableTestValue * _test = nullptr;
     189             : 
     190             :   /// Whether the weighted gap is associated with nodes or elements (like for a CONSTANT MONOMIAL
     191             :   /// Lagrange multiplier). We have this member so that we don't do virtual calls during inner
     192             :   /// quadrature-point/test-function loops
     193             :   bool _is_weighted_gap_nodal = true;
     194             : 
     195             :   /// Quadrature point index for the mortar segments
     196             :   unsigned int _qp = 0;
     197             : 
     198             :   /// Test function index
     199             :   unsigned int _i = 0;
     200             : };
     201             : 
     202             : inline const std::unordered_map<const DofObject *, std::pair<ADReal, Real>> &
     203             : WeightedGapUserObject::dofToWeightedGap() const
     204             : {
     205       32052 :   return _dof_to_weighted_gap;
     206             : }

Generated by: LCOV version 1.14