LCOV - code coverage report
Current view: top level - src/materials - ComputeEigenstrainFromInitialStress.C (source / functions) Hit Total Coverage
Test: idaholab/moose tensor_mechanics: d6b47a Lines: 41 43 95.3 %
Date: 2024-02-27 11:53:14 Functions: 3 3 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 "ComputeEigenstrainFromInitialStress.h"
      11             : #include "RankTwoTensor.h"
      12             : #include "Function.h"
      13             : #include "Conversion.h" // for stringify
      14             : 
      15             : registerMooseObject("TensorMechanicsApp", ComputeEigenstrainFromInitialStress);
      16             : 
      17             : InputParameters
      18        1194 : ComputeEigenstrainFromInitialStress::validParams()
      19             : {
      20        1194 :   InputParameters params = ComputeEigenstrainBase::validParams();
      21        1194 :   params.addClassDescription("Computes an eigenstrain from an initial stress");
      22        2388 :   params.addRequiredParam<std::vector<FunctionName>>(
      23             :       "initial_stress",
      24             :       "A list of functions describing the initial stress.  There must be 9 of these, corresponding "
      25             :       "to the xx, yx, zx, xy, yy, zy, xz, yz, zz components respectively.  To compute the "
      26             :       "eigenstrain correctly, your elasticity tensor should not be time-varying in the first "
      27             :       "timestep");
      28        2388 :   params.addCoupledVar("initial_stress_aux",
      29             :                        "A list of 9 AuxVariables describing the initial stress.  If provided, each "
      30             :                        "of these is multiplied by its corresponding initial_stress function to "
      31             :                        "obtain the relevant component of initial stress.");
      32        2388 :   params.addParam<std::string>("base_name",
      33             :                                "The base_name for the elasticity tensor that will be "
      34             :                                "used to compute strain from stress.  Do not provide "
      35             :                                "any base_name if your elasticity tensor does not use "
      36             :                                "one.");
      37        1194 :   return params;
      38           0 : }
      39             : 
      40         896 : ComputeEigenstrainFromInitialStress::ComputeEigenstrainFromInitialStress(
      41         896 :     const InputParameters & parameters)
      42             :   : ComputeEigenstrainBase(parameters),
      43         896 :     _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
      44        1792 :     _elasticity_tensor(getMaterialPropertyByName<RankFourTensor>(_base_name + "elasticity_tensor")),
      45         896 :     _eigenstrain_old(getMaterialPropertyOld<RankTwoTensor>(_eigenstrain_name)),
      46        1792 :     _ini_aux_provided(isParamValid("initial_stress_aux")),
      47         896 :     _ini_aux(_ini_aux_provided ? coupledValues("initial_stress_aux")
      48        1792 :                                : std::vector<const VariableValue *>())
      49             : {
      50             :   const std::vector<FunctionName> & fcn_names(
      51        1792 :       getParam<std::vector<FunctionName>>("initial_stress"));
      52             :   const std::size_t num = fcn_names.size();
      53             : 
      54         896 :   if (num != LIBMESH_DIM * LIBMESH_DIM)
      55           2 :     paramError(
      56             :         "initial_stress",
      57           1 :         "ComputeEigenstrainFromInitialStress: " + Moose::stringify(LIBMESH_DIM * LIBMESH_DIM) +
      58           1 :             " initial stress functions must be provided.  You supplied " + Moose::stringify(num) +
      59             :             "\n");
      60             : 
      61         895 :   _initial_stress_fcn.resize(num);
      62        8950 :   for (unsigned i = 0; i < num; ++i)
      63        8055 :     _initial_stress_fcn[i] = &getFunctionByName(fcn_names[i]);
      64             : 
      65         895 :   if (_ini_aux_provided)
      66             :   {
      67          10 :     const std::size_t aux_size = coupledComponents("initial_stress_aux");
      68          10 :     if (aux_size != LIBMESH_DIM * LIBMESH_DIM)
      69           2 :       paramError("initial_stress_aux",
      70           1 :                  "ComputeEigenstrainFromInitialStress: If you supply initial_stress_aux, " +
      71           0 :                      Moose::stringify(LIBMESH_DIM * LIBMESH_DIM) +
      72           1 :                      " values must be given.  You supplied " + Moose::stringify(aux_size) + "\n");
      73             :   }
      74         894 : }
      75             : 
      76             : void
      77      135312 : ComputeEigenstrainFromInitialStress::computeQpEigenstrain()
      78             : {
      79      135312 :   if (_t_step == 1)
      80             :   {
      81      135152 :     RankTwoTensor initial_stress;
      82      540608 :     for (unsigned i = 0; i < LIBMESH_DIM; ++i)
      83     1621824 :       for (unsigned j = 0; j < LIBMESH_DIM; ++j)
      84             :       {
      85     1216368 :         initial_stress(i, j) = _initial_stress_fcn[i * LIBMESH_DIM + j]->value(_t, _q_point[_qp]);
      86     1216368 :         if (_ini_aux_provided)
      87        7200 :           initial_stress(i, j) *= (*_ini_aux[i * LIBMESH_DIM + j])[_qp];
      88             :       }
      89             : 
      90      135152 :     _eigenstrain[_qp] = -_elasticity_tensor[_qp].invSymm() * initial_stress;
      91             :   }
      92             :   else
      93         160 :     _eigenstrain[_qp] = _eigenstrain_old[_qp];
      94      135312 : }

Generated by: LCOV version 1.14