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

Generated by: LCOV version 1.14