LCOV - code coverage report
Current view: top level - src/scalarkernels - GlobalStrain.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: #32971 (54bef8) with base c6cf66 Lines: 57 65 87.7 %
Date: 2026-05-29 20:40:07 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          64 : GlobalStrain::validParams()
      26             : {
      27          64 :   InputParameters params = ScalarKernel::validParams();
      28          64 :   params.addClassDescription("Scalar Kernel to solve for the global strain");
      29         128 :   params.addRequiredParam<UserObjectName>("global_strain_uo",
      30             :                                           "The name of the GlobalStrainUserObject");
      31             : 
      32          64 :   return params;
      33           0 : }
      34             : 
      35          32 : GlobalStrain::GlobalStrain(const InputParameters & parameters)
      36             :   : ScalarKernel(parameters),
      37          32 :     _pst(getUserObject<GlobalStrainUserObjectInterface>("global_strain_uo")),
      38          32 :     _pst_residual(_pst.getResidual()),
      39          32 :     _pst_jacobian(_pst.getJacobian()),
      40          32 :     _periodic_dir(_pst.getPeriodicDirections()),
      41          32 :     _components(_var.order()),
      42          64 :     _dim(_mesh.dimension())
      43             : {
      44          32 :   if ((_dim == 1 && _var.order() != FIRST) || (_dim == 2 && _var.order() != THIRD) ||
      45          32 :       (_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          32 :   assignComponentIndices(_var.order());
      51          32 : }
      52             : 
      53             : void
      54         230 : GlobalStrain::computeResidual()
      55             : {
      56         230 :   prepareVectorTag(_assembly, _var.number());
      57        1442 :   for (_i = 0; _i < _local_re.size(); ++_i)
      58             :   {
      59        1212 :     if (_periodic_dir(_components[_i].first) || _periodic_dir(_components[_i].second))
      60         923 :       _local_re(_i) += _pst_residual(_components[_i].first, _components[_i].second);
      61             :   }
      62         230 :   accumulateTaggedLocalResidual();
      63         230 : }
      64             : 
      65             : void
      66          57 : GlobalStrain::computeJacobian()
      67             : {
      68          57 :   prepareMatrixTag(_assembly, _var.number(), _var.number());
      69         357 :   for (_i = 0; _i < _local_ke.m(); ++_i)
      70        1974 :     for (_j = 0; _j < _local_ke.m(); ++_j)
      71             :       // periodic direction check is not done for jacobian calculations to avoid zero pivot error
      72        1674 :       _local_ke(_i, _j) += _pst_jacobian(_components[_i].first,
      73        1674 :                                          _components[_i].second,
      74             :                                          _components[_j].first,
      75        1674 :                                          _components[_j].second);
      76          57 :   accumulateTaggedLocalMatrix();
      77          57 : }
      78             : 
      79             : void
      80          32 : GlobalStrain::assignComponentIndices(Order order)
      81             : {
      82          32 :   switch (order)
      83             :   {
      84           0 :     case 1:
      85           0 :       _components[0].first = 0;
      86           0 :       _components[0].second = 0;
      87           0 :       break;
      88             : 
      89           8 :     case 3:
      90           8 :       _components[0].first = 0;
      91           8 :       _components[0].second = 0;
      92           8 :       _components[1].first = 1;
      93           8 :       _components[1].second = 1;
      94           8 :       _components[2].first = 0;
      95           8 :       _components[2].second = 1;
      96           8 :       break;
      97             : 
      98          24 :     case 6:
      99          24 :       _components[0].first = 0;
     100          24 :       _components[0].second = 0;
     101          24 :       _components[1].first = 1;
     102          24 :       _components[1].second = 1;
     103          24 :       _components[2].first = 2;
     104          24 :       _components[2].second = 2;
     105          24 :       _components[3].first = 1;
     106          24 :       _components[3].second = 2;
     107          24 :       _components[4].first = 0;
     108          24 :       _components[4].second = 2;
     109          24 :       _components[5].first = 0;
     110          24 :       _components[5].second = 1;
     111          24 :       break;
     112             : 
     113           0 :     default:
     114           0 :       mooseError("PerdiodicStrain ScalarKernel is only compatible with FIRST, THIRD, and SIXTH "
     115             :                  "order scalar variables.");
     116             :   }
     117          32 : }

Generated by: LCOV version 1.14