LCOV - code coverage report
Current view: top level - src/materials - ElasticEnergyMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 0 54 0.0 %
Date: 2025-09-04 07:55:36 Functions: 0 6 0.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 "ElasticEnergyMaterial.h"
      11             : #include "RankTwoTensor.h"
      12             : #include "RankFourTensor.h"
      13             : 
      14             : registerMooseObject("PhaseFieldApp", ElasticEnergyMaterial);
      15             : 
      16             : InputParameters
      17           0 : ElasticEnergyMaterial::validParams()
      18             : {
      19           0 :   InputParameters params = DerivativeFunctionMaterialBase::validParams();
      20           0 :   params.addClassDescription("Free energy material for the elastic energy contributions.");
      21           0 :   params.addParam<std::string>("base_name", "Material property base name");
      22           0 :   params.addCoupledVar("args", "Vector of variable arguments of the free energy function");
      23           0 :   params.deprecateCoupledVar("args", "coupled_variables", "02/27/2024");
      24           0 :   params.addCoupledVar("displacement_gradients",
      25             :                        "Vector of displacement gradient variables (see "
      26             :                        "Modules/PhaseField/DisplacementGradients "
      27             :                        "action)");
      28           0 :   return params;
      29           0 : }
      30             : 
      31           0 : ElasticEnergyMaterial::ElasticEnergyMaterial(const InputParameters & parameters)
      32             :   : DerivativeFunctionMaterialBase(parameters),
      33           0 :     _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
      34           0 :     _stress(getMaterialPropertyByName<RankTwoTensor>(_base_name + "stress")),
      35           0 :     _elasticity_tensor(getMaterialPropertyByName<RankFourTensor>(_base_name + "elasticity_tensor")),
      36           0 :     _strain(getMaterialPropertyByName<RankTwoTensor>(_base_name + "elastic_strain"))
      37             : {
      38           0 :   _dstrain.resize(_nargs);
      39           0 :   _d2strain.resize(_nargs);
      40           0 :   _delasticity_tensor.resize(_nargs);
      41           0 :   _d2elasticity_tensor.resize(_nargs);
      42             : 
      43             :   // fetch stress and elasticity tensor derivatives (in simple eigenstrain models this is is only
      44             :   // w.r.t. 'c')
      45           0 :   for (unsigned int i = 0; i < _nargs; ++i)
      46             :   {
      47           0 :     _dstrain[i] = &getMaterialPropertyDerivativeByName<RankTwoTensor>(_base_name + "elastic_strain",
      48           0 :                                                                       _arg_names[i]);
      49           0 :     _delasticity_tensor[i] = &getMaterialPropertyDerivativeByName<RankFourTensor>(
      50           0 :         _base_name + "elasticity_tensor", _arg_names[i]);
      51             : 
      52           0 :     _d2strain[i].resize(_nargs);
      53           0 :     _d2elasticity_tensor[i].resize(_nargs);
      54             : 
      55           0 :     for (unsigned int j = 0; j < _nargs; ++j)
      56             :     {
      57           0 :       _d2strain[i][j] = &getMaterialPropertyDerivativeByName<RankTwoTensor>(
      58           0 :           _base_name + "elastic_strain", _arg_names[i], _arg_names[j]);
      59           0 :       _d2elasticity_tensor[i][j] = &getMaterialPropertyDerivativeByName<RankFourTensor>(
      60           0 :           _base_name + "elasticity_tensor", _arg_names[i], _arg_names[j]);
      61             :     }
      62             :   }
      63           0 : }
      64             : 
      65             : void
      66           0 : ElasticEnergyMaterial::initialSetup()
      67             : {
      68           0 :   validateCoupling<RankTwoTensor>(_base_name + "elastic_strain");
      69           0 :   validateCoupling<RankFourTensor>(_base_name + "elasticity_tensor");
      70           0 : }
      71             : 
      72             : Real
      73           0 : ElasticEnergyMaterial::computeF()
      74             : {
      75           0 :   return 0.5 * _stress[_qp].doubleContraction(_strain[_qp]);
      76             : }
      77             : 
      78             : Real
      79           0 : ElasticEnergyMaterial::computeDF(unsigned int i_var)
      80             : {
      81             :   unsigned int i = argIndex(i_var);
      82             : 
      83             :   // product rule d/di computeF (doubleContraction commutes)
      84           0 :   return 0.5 * ((*_delasticity_tensor[i])[_qp] * _strain[_qp]).doubleContraction(_strain[_qp]) +
      85           0 :          (_elasticity_tensor[_qp] * (*_dstrain[i])[_qp]).doubleContraction(_strain[_qp]);
      86             : }
      87             : 
      88             : Real
      89           0 : ElasticEnergyMaterial::computeD2F(unsigned int i_var, unsigned int j_var)
      90             : {
      91             :   unsigned int i = argIndex(i_var);
      92             :   unsigned int j = argIndex(j_var);
      93             : 
      94             :   // product rule d/dj computeDF
      95             :   // TODO: simplify because doubleContraction commutes
      96           0 :   return 0.5 * (((*_d2elasticity_tensor[i][j])[_qp] * _strain[_qp] +
      97           0 :                  (*_delasticity_tensor[i])[_qp] * (*_dstrain[j])[_qp] +
      98           0 :                  (*_delasticity_tensor[j])[_qp] * (*_dstrain[i])[_qp] +
      99           0 :                  _elasticity_tensor[_qp] * (*_d2strain[i][j])[_qp])
     100           0 :                     .doubleContraction(_strain[_qp]) +
     101           0 :                 ((*_delasticity_tensor[i])[_qp] * _strain[_qp] +
     102           0 :                  _elasticity_tensor[_qp] * (*_dstrain[i])[_qp])
     103           0 :                     .doubleContraction((*_dstrain[j])[_qp])
     104             : 
     105           0 :                 + ( // dstress/dj
     106           0 :                       (*_delasticity_tensor[j])[_qp] * _strain[_qp] +
     107           0 :                       _elasticity_tensor[_qp] * (*_dstrain[j])[_qp])
     108           0 :                       .doubleContraction((*_dstrain[i])[_qp]) +
     109           0 :                 _stress[_qp].doubleContraction((*_d2strain[i][j])[_qp]));
     110             : }

Generated by: LCOV version 1.14