LCOV - code coverage report
Current view: top level - src/kernels/lagrangian - LagrangianStressDivergenceBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 62 64 96.9 %
Date: 2025-07-25 05:00:39 Functions: 6 6 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 "LagrangianStressDivergenceBase.h"
      11             : 
      12             : InputParameters
      13        5996 : LagrangianStressDivergenceBase::validParams()
      14             : {
      15        5996 :   InputParameters params = Kernel::validParams();
      16             : 
      17       11992 :   params.addRequiredParam<unsigned int>("component", "Which direction this kernel acts in");
      18       11992 :   params.addRequiredCoupledVar("displacements", "The displacement components");
      19             : 
      20       11992 :   params.addParam<bool>("large_kinematics", false, "Use large displacement kinematics");
      21       11992 :   params.addParam<bool>("stabilize_strain", false, "Average the volumetric strains");
      22             : 
      23       11992 :   params.addParam<std::string>("base_name", "Material property base name");
      24             : 
      25       11992 :   params.addCoupledVar("temperature",
      26             :                        "The name of the temperature variable used in the "
      27             :                        "ComputeThermalExpansionEigenstrain.  (Not required for "
      28             :                        "simulations without temperature coupling.)");
      29             : 
      30       11992 :   params.addParam<std::vector<MaterialPropertyName>>(
      31             :       "eigenstrain_names",
      32             :       {},
      33             :       "List of eigenstrains used in the strain calculation. Used for computing their derivatives "
      34             :       "for off-diagonal Jacobian terms.");
      35             : 
      36       11992 :   params.addCoupledVar("out_of_plane_strain",
      37             :                        "The out-of-plane strain variable for weak plane stress formulation.");
      38             : 
      39        5996 :   return params;
      40           0 : }
      41             : 
      42        2998 : LagrangianStressDivergenceBase::LagrangianStressDivergenceBase(const InputParameters & parameters)
      43             :   : JvarMapKernelInterface<DerivativeMaterialInterface<Kernel>>(parameters),
      44        2998 :     _large_kinematics(getParam<bool>("large_kinematics")),
      45        5996 :     _stabilize_strain(getParam<bool>("stabilize_strain")),
      46        6068 :     _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
      47        5996 :     _alpha(getParam<unsigned int>("component")),
      48        2998 :     _ndisp(coupledComponents("displacements")),
      49        2998 :     _disp_nums(_ndisp),
      50        2998 :     _avg_grad_trial(_ndisp),
      51        2998 :     _F_ust(
      52        2998 :         getMaterialPropertyByName<RankTwoTensor>(_base_name + "unstabilized_deformation_gradient")),
      53        5996 :     _F_avg(getMaterialPropertyByName<RankTwoTensor>(_base_name + "average_deformation_gradient")),
      54        5996 :     _f_inv(getMaterialPropertyByName<RankTwoTensor>(_base_name +
      55             :                                                     "inverse_incremental_deformation_gradient")),
      56        5996 :     _F_inv(getMaterialPropertyByName<RankTwoTensor>(_base_name + "inverse_deformation_gradient")),
      57        5996 :     _F(getMaterialPropertyByName<RankTwoTensor>(_base_name + "deformation_gradient")),
      58        3202 :     _temperature(isCoupled("temperature") ? getVar("temperature", 0) : nullptr),
      59        3058 :     _out_of_plane_strain(isCoupled("out_of_plane_strain") ? getVar("out_of_plane_strain", 0)
      60        5996 :                                                           : nullptr)
      61             : {
      62             :   // Do the vector coupling of the displacements
      63       10770 :   for (unsigned int i = 0; i < _ndisp; i++)
      64        7772 :     _disp_nums[i] = coupled("displacements", i);
      65             : 
      66             :   // We need to use identical discretizations for all displacement components
      67        2998 :   auto order_x = getVar("displacements", 0)->order();
      68        7772 :   for (unsigned int i = 1; i < _ndisp; i++)
      69             :   {
      70        9548 :     if (getVar("displacements", i)->order() != order_x)
      71           0 :       mooseError("The Lagrangian StressDivergence kernels require equal "
      72             :                  "order interpolation for all displacements.");
      73             :   }
      74             : 
      75             :   // fetch eigenstrain derivatives
      76             :   const auto nvar = _coupled_moose_vars.size();
      77        2998 :   _deigenstrain_dargs.resize(nvar);
      78       11034 :   for (std::size_t i = 0; i < nvar; ++i)
      79       17008 :     for (auto eigenstrain_name : getParam<std::vector<MaterialPropertyName>>("eigenstrain_names"))
      80        2808 :       _deigenstrain_dargs[i].push_back(&getMaterialPropertyDerivative<RankTwoTensor>(
      81         936 :           eigenstrain_name, _coupled_moose_vars[i]->name()));
      82        2998 : }
      83             : 
      84             : void
      85      620816 : LagrangianStressDivergenceBase::precalculateJacobian()
      86             : {
      87             :   // Skip if we are not doing stabilization
      88      620816 :   if (!_stabilize_strain)
      89             :     return;
      90             : 
      91             :   // We need the gradients of shape functions in the reference frame
      92       57976 :   _fe_problem.prepareShapes(_var.number(), _tid);
      93       57976 :   _avg_grad_trial[_alpha].resize(_phi.size());
      94       57976 :   precalculateJacobianDisplacement(_alpha);
      95             : }
      96             : 
      97             : void
      98     1102832 : LagrangianStressDivergenceBase::precalculateOffDiagJacobian(unsigned int jvar)
      99             : {
     100             :   // Skip if we are not doing stabilization
     101     1102832 :   if (!_stabilize_strain)
     102             :     return;
     103             : 
     104      407488 :   for (auto beta : make_range(_ndisp))
     105      301632 :     if (jvar == _disp_nums[beta])
     106             :     {
     107             :       // We need the gradients of shape functions in the reference frame
     108      102080 :       _fe_problem.prepareShapes(jvar, _tid);
     109      102080 :       _avg_grad_trial[beta].resize(_phi.size());
     110      102080 :       precalculateJacobianDisplacement(beta);
     111             :     }
     112             : }
     113             : 
     114             : Real
     115   269787728 : LagrangianStressDivergenceBase::computeQpJacobian()
     116             : {
     117   269787728 :   return computeQpJacobianDisplacement(_alpha, _alpha);
     118             : }
     119             : 
     120             : Real
     121   524411344 : LagrangianStressDivergenceBase::computeQpOffDiagJacobian(unsigned int jvar)
     122             : {
     123             :   // Bail if jvar not coupled
     124   524411344 :   if (getJvarMap()[jvar] < 0)
     125             :     return 0.0;
     126             : 
     127             :   // Off diagonal terms for other displacements
     128  1048998328 :   for (auto beta : make_range(_ndisp))
     129  1047460792 :     if (jvar == _disp_nums[beta])
     130   522873808 :       return computeQpJacobianDisplacement(_alpha, beta);
     131             : 
     132             :   // Off diagonal temperature term due to eigenstrain
     133     1537536 :   if (_temperature && jvar == _temperature->number())
     134     1368576 :     return computeQpJacobianTemperature(mapJvarToCvar(jvar));
     135             : 
     136             :   // Off diagonal term due to weak plane stress
     137      168960 :   if (_out_of_plane_strain && jvar == _out_of_plane_strain->number())
     138      168960 :     return computeQpJacobianOutOfPlaneStrain();
     139             : 
     140             :   return 0;
     141             : }

Generated by: LCOV version 1.14