LCOV - code coverage report
Current view: top level - src/materials - StrainAdjustedDensity.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: #31405 (292dce) with base fef103 Lines: 31 36 86.1 %
Date: 2025-09-04 07:57:23 Functions: 3 8 37.5 %
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 "StrainAdjustedDensity.h"
      11             : 
      12             : registerMooseObject("SolidMechanicsApp", StrainAdjustedDensity);
      13             : registerMooseObject("SolidMechanicsApp", ADStrainAdjustedDensity);
      14             : 
      15             : template <bool is_ad>
      16             : InputParameters
      17          84 : StrainAdjustedDensityTempl<is_ad>::validParams()
      18             : {
      19          84 :   InputParameters params = Material::validParams();
      20             : 
      21         168 :   params.addRequiredCoupledVar(
      22             :       "displacements",
      23             :       "The displacements appropriate for the simulation geometry and coordinate system. If "
      24             :       "displacements are not coupled, a different material class such as GenericMaterialProperty "
      25             :       "or ParsedMaterial should be used.");
      26             : 
      27         168 :   params.addParam<std::string>("base_name",
      28             :                                "Optional parameter that allows the user to define "
      29             :                                "multiple material systems on the same block, "
      30             :                                "e.g. for multiple phases");
      31         168 :   params.addRequiredParam<MaterialPropertyName>("strain_free_density",
      32             :                                                 "Material property for strain-free density");
      33          84 :   params.addClassDescription("Creates density material property");
      34             : 
      35          84 :   return params;
      36           0 : }
      37             : 
      38             : template <bool is_ad>
      39          63 : StrainAdjustedDensityTempl<is_ad>::StrainAdjustedDensityTempl(const InputParameters & parameters)
      40             :   : Material(parameters),
      41         126 :     _coord_system(getBlockCoordSystem()),
      42          63 :     _disp_r(this->template coupledGenericValue<is_ad>("displacements", 0)),
      43         126 :     _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
      44          63 :     _strain_free_density(
      45          63 :         this->template getGenericMaterialProperty<Real, is_ad>("strain_free_density")),
      46          63 :     _grad_disp(this->template coupledGenericGradients<is_ad>("displacements")),
      47         189 :     _density(declareGenericProperty<Real, is_ad>(_base_name + "density"))
      48             : {
      49         126 :   if (getParam<bool>("use_displaced_mesh"))
      50           0 :     paramError("use_displaced_mesh",
      51             :                "StrainAdjustedDensity needs to act on an undisplaced mesh. Use of a displaced mesh "
      52             :                "leads to "
      53             :                "incorrect gradient values");
      54             : 
      55             :   // fill remaining components with zero
      56          63 :   _grad_disp.resize(3, &genericZeroGradient<is_ad>());
      57          63 : }
      58             : 
      59             : template <bool is_ad>
      60             : void
      61           0 : StrainAdjustedDensityTempl<is_ad>::initQpStatefulProperties()
      62             : {
      63           0 :   computeQpProperties();
      64           0 : }
      65             : 
      66             : template <bool is_ad>
      67             : void
      68        1875 : StrainAdjustedDensityTempl<is_ad>::computeQpProperties()
      69             : {
      70        1875 :   auto A = GenericRankTwoTensor<is_ad>::initializeFromRows(
      71        1875 :       (*_grad_disp[0])[_qp], (*_grad_disp[1])[_qp], (*_grad_disp[2])[_qp]);
      72        1875 :   A.addIa(1.0);
      73             : 
      74        1875 :   switch (_coord_system)
      75             :   {
      76             :     case Moose::COORD_XYZ:
      77             :       break;
      78             : 
      79         625 :     case Moose::COORD_RZ:
      80         625 :       if (_q_point[_qp](0) != 0.0)
      81         625 :         A(2, 2) = _disp_r[_qp] / _q_point[_qp](0) + 1.0;
      82             :       break;
      83             : 
      84         365 :     case Moose::COORD_RSPHERICAL:
      85         365 :       if (_q_point[_qp](0) != 0.0)
      86         365 :         A(1, 1) = A(2, 2) = _disp_r[_qp] / _q_point[_qp](0) + 1.0;
      87             :       break;
      88             :   }
      89             : 
      90        1875 :   _density[_qp] = _strain_free_density[_qp] / A.det();
      91        1875 : }
      92             : 
      93             : template class StrainAdjustedDensityTempl<false>;
      94             : template class StrainAdjustedDensityTempl<true>;

Generated by: LCOV version 1.14