LCOV - code coverage report
Current view: top level - src/materials - DerivativeTwoPhaseMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31706 (f8ed4a) with base bb0a08 Lines: 63 89 70.8 %
Date: 2025-11-03 17:26:54 Functions: 6 7 85.7 %
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 "DerivativeTwoPhaseMaterial.h"
      11             : 
      12             : registerMooseObject("PhaseFieldApp", DerivativeTwoPhaseMaterial);
      13             : 
      14             : InputParameters
      15         141 : DerivativeTwoPhaseMaterial::validParams()
      16             : {
      17         141 :   InputParameters params = DerivativeFunctionMaterialBase::validParams();
      18         141 :   params.addClassDescription(
      19             :       "Two phase material that combines two single phase materials using a switching function.");
      20             : 
      21             :   // Two base materials
      22         282 :   params.addRequiredParam<MaterialPropertyName>("fa_name", "Phase A material (at eta=0)");
      23         282 :   params.addRequiredParam<MaterialPropertyName>("fb_name", "Phase A material (at eta=1)");
      24         282 :   params.addParam<MaterialPropertyName>(
      25             :       "h", "h", "Switching Function Material that provides h(eta)");
      26         282 :   params.addParam<MaterialPropertyName>("g", "g", "Barrier Function Material that provides g(eta)");
      27             : 
      28             :   // All arguments of the phase free energies
      29         282 :   params.addCoupledVar("coupled_variables", "Vector of variable arguments of fa and fb");
      30         282 :   params.addCoupledVar("displacement_gradients",
      31             :                        "Vector of displacement gradient variables (see "
      32             :                        "Modules/PhaseField/DisplacementGradients "
      33             :                        "action)");
      34             : 
      35             :   // Order parameter which determines the phase
      36         282 :   params.addRequiredCoupledVar("eta", "Order parameter");
      37             : 
      38             :   // Variables with applied tolerances and their tolerance values
      39         282 :   params.addParam<Real>("W", 0.0, "Energy barrier for the phase transformation from A to B");
      40             : 
      41         141 :   return params;
      42           0 : }
      43             : 
      44         108 : DerivativeTwoPhaseMaterial::DerivativeTwoPhaseMaterial(const InputParameters & parameters)
      45             :   : DerivativeFunctionMaterialBase(parameters),
      46         108 :     _eta(coupledValue("eta")),
      47         108 :     _eta_name(coupledName("eta", 0)),
      48         108 :     _eta_var(coupled("eta")),
      49         216 :     _h(getMaterialProperty<Real>("h")),
      50         108 :     _dh(getMaterialPropertyDerivative<Real>("h", _eta_name)),
      51         108 :     _d2h(getMaterialPropertyDerivative<Real>("h", _eta_name, _eta_name)),
      52         108 :     _d3h(getMaterialPropertyDerivative<Real>("h", _eta_name, _eta_name, _eta_name)),
      53         216 :     _g(getMaterialProperty<Real>("g")),
      54         108 :     _dg(getMaterialPropertyDerivative<Real>("g", _eta_name)),
      55         108 :     _d2g(getMaterialPropertyDerivative<Real>("g", _eta_name, _eta_name)),
      56         108 :     _d3g(getMaterialPropertyDerivative<Real>("g", _eta_name, _eta_name, _eta_name)),
      57         216 :     _W(getParam<Real>("W")),
      58         216 :     _prop_Fa(getMaterialProperty<Real>("fa_name")),
      59         324 :     _prop_Fb(getMaterialProperty<Real>("fb_name"))
      60             : {
      61             :   // reserve space for phase A and B material properties
      62         108 :   _prop_dFa.resize(_nargs);
      63         108 :   _prop_d2Fa.resize(_nargs);
      64         108 :   _prop_d3Fa.resize(_nargs);
      65         108 :   _prop_dFb.resize(_nargs);
      66         108 :   _prop_d2Fb.resize(_nargs);
      67         108 :   _prop_d3Fb.resize(_nargs);
      68         288 :   for (unsigned int i = 0; i < _nargs; ++i)
      69             :   {
      70         180 :     _prop_dFa[i] = &getMaterialPropertyDerivative<Real>("fa_name", _arg_names[i]);
      71         180 :     _prop_dFb[i] = &getMaterialPropertyDerivative<Real>("fb_name", _arg_names[i]);
      72             : 
      73         180 :     _prop_d2Fa[i].resize(_nargs);
      74         180 :     _prop_d2Fb[i].resize(_nargs);
      75             : 
      76             :     // TODO: maybe we should reserve and initialize to NULL...
      77         180 :     if (_third_derivatives)
      78             :     {
      79           0 :       _prop_d3Fa[i].resize(_nargs);
      80           0 :       _prop_d3Fb[i].resize(_nargs);
      81             :     }
      82             : 
      83         504 :     for (unsigned int j = 0; j < _nargs; ++j)
      84             :     {
      85         324 :       _prop_d2Fa[i][j] =
      86         648 :           &getMaterialPropertyDerivative<Real>("fa_name", _arg_names[i], _arg_names[j]);
      87         324 :       _prop_d2Fb[i][j] =
      88         648 :           &getMaterialPropertyDerivative<Real>("fb_name", _arg_names[i], _arg_names[j]);
      89             : 
      90         324 :       if (_third_derivatives)
      91             :       {
      92           0 :         _prop_d3Fa[i][j].resize(_nargs);
      93           0 :         _prop_d3Fb[i][j].resize(_nargs);
      94             : 
      95           0 :         for (unsigned int k = 0; k < _nargs; ++k)
      96             :         {
      97           0 :           _prop_d3Fa[i][j][k] = &getMaterialPropertyDerivative<Real>(
      98           0 :               "fa_name", _arg_names[i], _arg_names[j], _arg_names[k]);
      99           0 :           _prop_d3Fb[i][j][k] = &getMaterialPropertyDerivative<Real>(
     100             :               "fb_name", _arg_names[i], _arg_names[j], _arg_names[k]);
     101             :         }
     102             :       }
     103             :     }
     104             :   }
     105         108 : }
     106             : 
     107             : void
     108         108 : DerivativeTwoPhaseMaterial::initialSetup()
     109             : {
     110         324 :   validateCoupling<Real>("fa_name");
     111         216 :   validateCoupling<Real>("fb_name");
     112         108 : }
     113             : 
     114             : Real
     115     1346592 : DerivativeTwoPhaseMaterial::computeF()
     116             : {
     117     1346592 :   return _h[_qp] * _prop_Fb[_qp] + (1.0 - _h[_qp]) * _prop_Fa[_qp] + _W * _g[_qp];
     118             : }
     119             : 
     120             : Real
     121     1691584 : DerivativeTwoPhaseMaterial::computeDF(unsigned int i_var)
     122             : {
     123     1691584 :   if (i_var == _eta_var)
     124     1346592 :     return _dh[_qp] * (_prop_Fb[_qp] - _prop_Fa[_qp]) + _W * _dg[_qp];
     125             :   else
     126             :   {
     127             :     unsigned int i = argIndex(i_var);
     128      344992 :     return _h[_qp] * (*_prop_dFb[i])[_qp] + (1.0 - _h[_qp]) * (*_prop_dFa[i])[_qp];
     129             :   }
     130             : }
     131             : 
     132             : Real
     133     2036576 : DerivativeTwoPhaseMaterial::computeD2F(unsigned int i_var, unsigned int j_var)
     134             : {
     135     2036576 :   if (i_var == _eta_var && j_var == _eta_var)
     136     1346592 :     return _d2h[_qp] * (_prop_Fb[_qp] - _prop_Fa[_qp]) + _W * _d2g[_qp];
     137             : 
     138             :   unsigned int i = argIndex(i_var);
     139             :   unsigned int j = argIndex(j_var);
     140             : 
     141      689984 :   if (i_var == _eta_var)
     142           0 :     return _dh[_qp] * ((*_prop_dFb[j])[_qp] - (*_prop_dFa[j])[_qp]);
     143      689984 :   if (j_var == _eta_var)
     144      344992 :     return _dh[_qp] * ((*_prop_dFb[i])[_qp] - (*_prop_dFa[i])[_qp]);
     145             : 
     146      344992 :   return _h[_qp] * (*_prop_d2Fb[i][j])[_qp] + (1.0 - _h[_qp]) * (*_prop_d2Fa[i][j])[_qp];
     147             : }
     148             : 
     149             : Real
     150           0 : DerivativeTwoPhaseMaterial::computeD3F(unsigned int i_var, unsigned int j_var, unsigned int k_var)
     151             : {
     152           0 :   if (i_var == _eta_var && j_var == _eta_var && k_var == _eta_var)
     153           0 :     return _d3h[_qp] * (_prop_Fb[_qp] - _prop_Fa[_qp]) + _W * _d3g[_qp];
     154             : 
     155             :   unsigned int i = argIndex(i_var);
     156             :   unsigned int j = argIndex(j_var);
     157             :   unsigned int k = argIndex(k_var);
     158             : 
     159           0 :   if (j_var == _eta_var && k_var == _eta_var)
     160           0 :     return _d2h[_qp] * ((*_prop_dFb[i])[_qp] - (*_prop_dFa[i])[_qp]);
     161           0 :   if (i_var == _eta_var && k_var == _eta_var)
     162           0 :     return _d2h[_qp] * ((*_prop_dFb[j])[_qp] - (*_prop_dFa[j])[_qp]);
     163           0 :   if (i_var == _eta_var && j_var == _eta_var)
     164           0 :     return _d2h[_qp] * ((*_prop_dFb[k])[_qp] - (*_prop_dFa[k])[_qp]);
     165             : 
     166           0 :   if (i_var == _eta_var)
     167           0 :     return _dh[_qp] * (*_prop_d2Fb[j][k])[_qp] + (1.0 - _dh[_qp]) * (*_prop_d2Fa[j][k])[_qp];
     168           0 :   if (j_var == _eta_var)
     169           0 :     return _dh[_qp] * (*_prop_d2Fb[i][k])[_qp] + (1.0 - _dh[_qp]) * (*_prop_d2Fa[i][k])[_qp];
     170           0 :   if (k_var == _eta_var)
     171           0 :     return _dh[_qp] * (*_prop_d2Fb[i][j])[_qp] + (1.0 - _dh[_qp]) * (*_prop_d2Fa[i][j])[_qp];
     172             : 
     173           0 :   return _h[_qp] * (*_prop_d3Fb[i][j][k])[_qp] + (1.0 - _h[_qp]) * (*_prop_d3Fa[i][j][k])[_qp];
     174             : }

Generated by: LCOV version 1.14