LCOV - code coverage report
Current view: top level - src/materials - StrainAdjustedDensity.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 31 36 86.1 %
Date: 2025-07-25 05:00:39 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          72 : StrainAdjustedDensityTempl<is_ad>::validParams()
      18             : {
      19          72 :   InputParameters params = Material::validParams();
      20             : 
      21         144 :   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         144 :   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         144 :   params.addRequiredParam<MaterialPropertyName>("strain_free_density",
      32             :                                                 "Material property for strain-free density");
      33          72 :   params.addClassDescription("Creates density material property");
      34             : 
      35          72 :   return params;
      36           0 : }
      37             : 
      38             : template <bool is_ad>
      39          54 : StrainAdjustedDensityTempl<is_ad>::StrainAdjustedDensityTempl(const InputParameters & parameters)
      40             :   : Material(parameters),
      41         108 :     _coord_system(getBlockCoordSystem()),
      42          54 :     _disp_r(this->template coupledGenericValue<is_ad>("displacements", 0)),
      43         108 :     _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
      44          54 :     _strain_free_density(
      45          54 :         this->template getGenericMaterialProperty<Real, is_ad>("strain_free_density")),
      46          54 :     _grad_disp(this->template coupledGenericGradients<is_ad>("displacements")),
      47         162 :     _density(declareGenericProperty<Real, is_ad>(_base_name + "density"))
      48             : {
      49         108 :   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          54 :   _grad_disp.resize(3, &genericZeroGradient<is_ad>());
      57          54 : }
      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        1500 : StrainAdjustedDensityTempl<is_ad>::computeQpProperties()
      69             : {
      70        1500 :   auto A = GenericRankTwoTensor<is_ad>::initializeFromRows(
      71        1500 :       (*_grad_disp[0])[_qp], (*_grad_disp[1])[_qp], (*_grad_disp[2])[_qp]);
      72        1500 :   A.addIa(1.0);
      73             : 
      74        1500 :   switch (_coord_system)
      75             :   {
      76             :     case Moose::COORD_XYZ:
      77             :       break;
      78             : 
      79         500 :     case Moose::COORD_RZ:
      80         500 :       if (_q_point[_qp](0) != 0.0)
      81         500 :         A(2, 2) = _disp_r[_qp] / _q_point[_qp](0) + 1.0;
      82             :       break;
      83             : 
      84         292 :     case Moose::COORD_RSPHERICAL:
      85         292 :       if (_q_point[_qp](0) != 0.0)
      86         292 :         A(1, 1) = A(2, 2) = _disp_r[_qp] / _q_point[_qp](0) + 1.0;
      87             :       break;
      88             :   }
      89             : 
      90        1500 :   _density[_qp] = _strain_free_density[_qp] / A.det();
      91        1500 : }
      92             : 
      93             : template class StrainAdjustedDensityTempl<false>;
      94             : template class StrainAdjustedDensityTempl<true>;

Generated by: LCOV version 1.14