LCOV - code coverage report
Current view: top level - src/materials - ComputeVolumetricEigenstrain.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 34 61 55.7 %
Date: 2025-07-25 05:00:39 Functions: 4 4 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 "ComputeVolumetricEigenstrain.h"
      11             : #include "RankTwoTensor.h"
      12             : 
      13             : registerMooseObject("SolidMechanicsApp", ComputeVolumetricEigenstrain);
      14             : 
      15             : InputParameters
      16          24 : ComputeVolumetricEigenstrain::validParams()
      17             : {
      18          24 :   InputParameters params = ComputeEigenstrainBase::validParams();
      19          24 :   params.addClassDescription("Computes an eigenstrain that is defined by a set of scalar material "
      20             :                              "properties that summed together define the volumetric change.  This "
      21             :                              "also computes the derivatives of that eigenstrain with respect to a "
      22             :                              "supplied set of variable dependencies.");
      23          48 :   params.addRequiredParam<std::vector<MaterialPropertyName>>(
      24             :       "volumetric_materials", "List of scalar material properties defining the volumetric change");
      25          48 :   params.addRequiredCoupledVar("args", "variable dependencies for the volumetric_expansion");
      26          24 :   return params;
      27           0 : }
      28             : 
      29          18 : ComputeVolumetricEigenstrain::ComputeVolumetricEigenstrain(const InputParameters & parameters)
      30             :   : DerivativeMaterialInterface<ComputeEigenstrainBase>(parameters),
      31          18 :     _num_args(coupledComponents("args")),
      32          36 :     _volumetric_material_names(getParam<std::vector<MaterialPropertyName>>("volumetric_materials")),
      33          18 :     _volumetric_materials(_volumetric_material_names.size()),
      34          18 :     _dvolumetric_materials(_volumetric_material_names.size()),
      35          18 :     _d2volumetric_materials(_volumetric_material_names.size()),
      36          18 :     _delastic_strain(_num_args),
      37          36 :     _d2elastic_strain(_num_args)
      38             : {
      39          36 :   for (unsigned int i = 0; i < _volumetric_material_names.size(); ++i)
      40          18 :     _volumetric_materials[i] = &getMaterialProperty<Real>(_volumetric_material_names[i]);
      41             : 
      42             :   // fetch prerequisite derivatives and build elastic_strain derivatives and cross-derivatives
      43          36 :   for (unsigned int i = 0; i < _volumetric_material_names.size(); ++i)
      44             :   {
      45             :     const MaterialPropertyName & vol_matl_name = _volumetric_material_names[i];
      46          18 :     _dvolumetric_materials[i].resize(_num_args);
      47          18 :     _d2volumetric_materials[i].resize(_num_args);
      48          18 :     for (unsigned int j = 0; j < _num_args; ++j)
      49             :     {
      50           0 :       const VariableName & jname = coupledName("args", j);
      51           0 :       _dvolumetric_materials[i][j] = &getMaterialPropertyDerivative<Real>(vol_matl_name, jname);
      52           0 :       _d2volumetric_materials[i][j].resize(_num_args);
      53             : 
      54           0 :       for (unsigned int k = j; k < _num_args; ++k)
      55             :       {
      56           0 :         const VariableName & kname = coupledName("args", k);
      57           0 :         _d2volumetric_materials[i][j][k] =
      58           0 :             &getMaterialPropertyDerivative<Real>("prefactor", jname, kname);
      59             :       }
      60             :     }
      61             :   }
      62             : 
      63          18 :   for (unsigned int j = 0; j < _num_args; ++j)
      64             :   {
      65           0 :     const VariableName & jname = coupledName("args", j);
      66           0 :     _delastic_strain[j] =
      67           0 :         &declarePropertyDerivative<RankTwoTensor>(_base_name + "elastic_strain", jname);
      68           0 :     _d2elastic_strain[j].resize(_num_args);
      69             : 
      70           0 :     for (unsigned int k = j; k < _num_args; ++k)
      71             :     {
      72           0 :       const VariableName & kname = coupledName("args", k);
      73           0 :       _d2elastic_strain[j][k] =
      74           0 :           &declarePropertyDerivative<RankTwoTensor>(_base_name + "elastic_strain", jname, kname);
      75             :     }
      76             :   }
      77          18 : }
      78             : 
      79             : void
      80          18 : ComputeVolumetricEigenstrain::initialSetup()
      81             : {
      82          36 :   for (auto vmn : _volumetric_material_names)
      83          54 :     validateCoupling<Real>(vmn);
      84             : 
      85          18 :   for (unsigned int i = 0; i < _num_args; ++i)
      86             :   {
      87           0 :     const VariableName & iname = coupledName("args", i);
      88           0 :     if (_fe_problem.isMatPropRequested(
      89           0 :             derivativePropertyNameFirst(_base_name + "elastic_strain", iname)))
      90           0 :       mooseError("Derivative of elastic_strain requested, but not yet implemented");
      91             :     else
      92           0 :       _delastic_strain[i] = nullptr;
      93           0 :     for (unsigned int j = 0; j < _num_args; ++j)
      94             :     {
      95           0 :       const VariableName & jname = coupledName("args", j);
      96           0 :       if (_fe_problem.isMatPropRequested(
      97           0 :               derivativePropertyNameSecond(_base_name + "elastic_strain", iname, jname)))
      98           0 :         mooseError("Second Derivative of elastic_strain requested, but not yet implemented");
      99             :       else
     100           0 :         _d2elastic_strain[i][j] = nullptr;
     101             :     }
     102             :   }
     103          18 : }
     104             : 
     105             : void
     106        2336 : ComputeVolumetricEigenstrain::computeQpEigenstrain()
     107             : {
     108             :   Real volumetric_strain = 0;
     109        4672 :   for (unsigned int i = 0; i < _volumetric_materials.size(); ++i)
     110        2336 :     volumetric_strain += (*_volumetric_materials[i])[_qp];
     111             : 
     112        2336 :   const Real eigenstrain_comp = computeVolumetricStrainComponent(volumetric_strain);
     113        2336 :   _eigenstrain[_qp].zero();
     114        2336 :   _eigenstrain[_qp].addIa(eigenstrain_comp);
     115             : 
     116             :   // TODO: Compute derivatives of the elastic strain wrt the variables specified in args
     117        2336 : }

Generated by: LCOV version 1.14