LCOV - code coverage report
Current view: top level - src/scalarkernels - GlobalStrain.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: #31405 (292dce) with base fef103 Lines: 57 65 87.7 %
Date: 2025-09-04 07:57:23 Functions: 5 5 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 "GlobalStrain.h"
      11             : #include "GlobalStrainUserObjectInterface.h"
      12             : 
      13             : // MOOSE includes
      14             : #include "Assembly.h"
      15             : #include "MooseVariableScalar.h"
      16             : #include "SystemBase.h"
      17             : #include "RankTwoTensor.h"
      18             : #include "RankFourTensor.h"
      19             : 
      20             : using namespace libMesh;
      21             : 
      22             : registerMooseObject("SolidMechanicsApp", GlobalStrain);
      23             : 
      24             : InputParameters
      25         112 : GlobalStrain::validParams()
      26             : {
      27         112 :   InputParameters params = ScalarKernel::validParams();
      28         112 :   params.addClassDescription("Scalar Kernel to solve for the global strain");
      29         224 :   params.addRequiredParam<UserObjectName>("global_strain_uo",
      30             :                                           "The name of the GlobalStrainUserObject");
      31             : 
      32         112 :   return params;
      33           0 : }
      34             : 
      35          56 : GlobalStrain::GlobalStrain(const InputParameters & parameters)
      36             :   : ScalarKernel(parameters),
      37          56 :     _pst(getUserObject<GlobalStrainUserObjectInterface>("global_strain_uo")),
      38          56 :     _pst_residual(_pst.getResidual()),
      39          56 :     _pst_jacobian(_pst.getJacobian()),
      40          56 :     _periodic_dir(_pst.getPeriodicDirections()),
      41          56 :     _components(_var.order()),
      42         112 :     _dim(_mesh.dimension())
      43             : {
      44          56 :   if ((_dim == 1 && _var.order() != FIRST) || (_dim == 2 && _var.order() != THIRD) ||
      45          56 :       (_dim == 3 && _var.order() != SIXTH))
      46           0 :     mooseError("PerdiodicStrain ScalarKernel is only compatible with scalar variables of order "
      47             :                "FIRST in 1D, THIRD in 2D, and SIXTH in 3D. Please change the order of the scalar"
      48             :                "variable according to the mesh dimension.");
      49             : 
      50          56 :   assignComponentIndices(_var.order());
      51          56 : }
      52             : 
      53             : void
      54         360 : GlobalStrain::computeResidual()
      55             : {
      56         360 :   prepareVectorTag(_assembly, _var.number());
      57        2265 :   for (_i = 0; _i < _local_re.size(); ++_i)
      58             :   {
      59        1905 :     if (_periodic_dir(_components[_i].first) || _periodic_dir(_components[_i].second))
      60        1448 :       _local_re(_i) += _pst_residual(_components[_i].first, _components[_i].second);
      61             :   }
      62         360 :   accumulateTaggedLocalResidual();
      63         360 : }
      64             : 
      65             : void
      66          88 : GlobalStrain::computeJacobian()
      67             : {
      68          88 :   prepareMatrixTag(_assembly, _var.number(), _var.number());
      69         553 :   for (_i = 0; _i < _local_ke.m(); ++_i)
      70        3066 :     for (_j = 0; _j < _local_ke.m(); ++_j)
      71             :       // periodic direction check is not done for jacobian calculations to avoid zero pivot error
      72        2601 :       _local_ke(_i, _j) += _pst_jacobian(_components[_i].first,
      73        2601 :                                          _components[_i].second,
      74             :                                          _components[_j].first,
      75        2601 :                                          _components[_j].second);
      76          88 :   accumulateTaggedLocalMatrix();
      77          88 : }
      78             : 
      79             : void
      80          56 : GlobalStrain::assignComponentIndices(Order order)
      81             : {
      82          56 :   switch (order)
      83             :   {
      84           0 :     case 1:
      85           0 :       _components[0].first = 0;
      86           0 :       _components[0].second = 0;
      87           0 :       break;
      88             : 
      89          14 :     case 3:
      90          14 :       _components[0].first = 0;
      91          14 :       _components[0].second = 0;
      92          14 :       _components[1].first = 1;
      93          14 :       _components[1].second = 1;
      94          14 :       _components[2].first = 0;
      95          14 :       _components[2].second = 1;
      96          14 :       break;
      97             : 
      98          42 :     case 6:
      99          42 :       _components[0].first = 0;
     100          42 :       _components[0].second = 0;
     101          42 :       _components[1].first = 1;
     102          42 :       _components[1].second = 1;
     103          42 :       _components[2].first = 2;
     104          42 :       _components[2].second = 2;
     105          42 :       _components[3].first = 1;
     106          42 :       _components[3].second = 2;
     107          42 :       _components[4].first = 0;
     108          42 :       _components[4].second = 2;
     109          42 :       _components[5].first = 0;
     110          42 :       _components[5].second = 1;
     111          42 :       break;
     112             : 
     113           0 :     default:
     114           0 :       mooseError("PerdiodicStrain ScalarKernel is only compatible with FIRST, THIRD, and SIXTH "
     115             :                  "order scalar variables.");
     116             :   }
     117          56 : }

Generated by: LCOV version 1.14