LCOV - code coverage report
Current view: top level - src/kernels - NestedKKSACBulkF.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 64 66 97.0 %
Date: 2025-09-04 07:55:36 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 "NestedKKSACBulkF.h"
      11             : 
      12             : registerMooseObject("PhaseFieldApp", NestedKKSACBulkF);
      13             : 
      14             : InputParameters
      15          46 : NestedKKSACBulkF::validParams()
      16             : {
      17          46 :   InputParameters params = KKSACBulkBase::validParams();
      18          46 :   params.addClassDescription("KKS model kernel (part 1 of 2) for the Bulk Allen-Cahn. This "
      19             :                              "includes all terms NOT dependent on chemical potential.");
      20          92 :   params.addRequiredCoupledVar("global_cs", "The interpolated concentrations c, b, etc");
      21          92 :   params.addRequiredParam<std::vector<MaterialPropertyName>>(
      22             :       "ci_names",
      23             :       "Phase concentrations. The order must match Fa, Fb, and global_cs, for example, c1, "
      24             :       "c2, b1, b2, etc");
      25          92 :   params.addRequiredParam<MaterialPropertyName>(
      26             :       "fb_name", "Free energy function Fb (fa_name is in the KKSACBulkBase).");
      27          92 :   params.addParam<MaterialPropertyName>(
      28             :       "g_name", "g", "Base name for the double well function g(eta)");
      29          92 :   params.addRequiredParam<Real>("w", "Double well height parameter");
      30          46 :   return params;
      31           0 : }
      32             : 
      33          24 : NestedKKSACBulkF::NestedKKSACBulkF(const InputParameters & parameters)
      34             :   : KKSACBulkBase(parameters),
      35          24 :     _c_map(getParameterJvarMap("global_cs")),
      36          24 :     _num_c(coupledComponents("global_cs")),
      37          24 :     _c_names(coupledNames("global_cs")),
      38          48 :     _ci_names(getParam<std::vector<MaterialPropertyName>>("ci_names")),
      39          24 :     _Fa_name(getParam<MaterialPropertyName>("fa_name")),
      40          24 :     _dFadca(_num_c),
      41          24 :     _Fb_name(getParam<MaterialPropertyName>("fb_name")),
      42          24 :     _dFbdcb(_num_c),
      43          24 :     _prop_dg(getMaterialPropertyDerivative<Real>("g_name", _eta_name)),
      44          24 :     _prop_d2g(getMaterialPropertyDerivative<Real>("g_name", _eta_name, _eta_name)),
      45          48 :     _w(getParam<Real>("w")),
      46          24 :     _prop_Fi(2),
      47          24 :     _dcideta(_num_c * 2),
      48          24 :     _dcidb(_num_c * _num_c * 2),
      49          24 :     _dFadarg(_n_args),
      50          48 :     _dFbdarg(_n_args)
      51             : {
      52             :   // _prop_Fi is computed in KKSPhaseConcentrationMaterial
      53          48 :   _prop_Fi[0] = &getMaterialPropertyByName<Real>("cp" + _Fa_name);
      54          48 :   _prop_Fi[1] = &getMaterialPropertyByName<Real>("cp" + _Fb_name);
      55             : 
      56             :   // _dcideta and _dcid are computed in KKSPhaseConcentrationDerivatives
      57          48 :   for (const auto m : make_range(_num_c))
      58             :   {
      59          24 :     _dcideta[m].resize(2);
      60          24 :     _dcidb[m].resize(2);
      61          72 :     for (const auto n : make_range(2))
      62             :     {
      63          48 :       _dcideta[m][n] = &getMaterialPropertyDerivative<Real>(_ci_names[m * 2 + n], _var.name());
      64          48 :       _dcidb[m][n].resize(_num_c);
      65             : 
      66          96 :       for (const auto l : make_range(_num_c))
      67          48 :         _dcidb[m][n][l] = &getMaterialPropertyDerivative<Real>(_ci_names[m * 2 + n], _c_names[l]);
      68             :     }
      69             :   }
      70             : 
      71             :   // _dFadca and _dFbdcb are computed in KKSPhaseConcentrationMaterial
      72          48 :   for (const auto m : make_range(_num_c))
      73             :   {
      74          24 :     _dFadca[m] = &getMaterialPropertyDerivative<Real>("cp" + _Fa_name, _ci_names[m * 2]);
      75          24 :     _dFbdcb[m] = &getMaterialPropertyDerivative<Real>("cp" + _Fb_name, _ci_names[m * 2 + 1]);
      76             :   }
      77             : 
      78             :   // _dFadarg and _dFbdarg are computed in KKSPhaseConcentrationMaterial
      79          72 :   for (const auto m : make_range(_n_args))
      80             :   {
      81          48 :     _dFadarg[m] = &getMaterialPropertyDerivative<Real>("cp" + _Fa_name, m);
      82          48 :     _dFbdarg[m] = &getMaterialPropertyDerivative<Real>("cp" + _Fb_name, m);
      83             :   }
      84          24 : }
      85             : 
      86             : Real
      87     3330900 : NestedKKSACBulkF::computeDFDOP(PFFunctionType type)
      88             : {
      89     3330900 :   const Real A1 = (*_prop_Fi[0])[_qp] - (*_prop_Fi[1])[_qp];
      90     3330900 :   switch (type)
      91             :   {
      92     2920500 :     case Residual:
      93     2920500 :       return -_prop_dh[_qp] * A1 + _w * _prop_dg[_qp];
      94             : 
      95      410400 :     case Jacobian:
      96             :       Real sum = 0.0;
      97      820800 :       for (const auto m : make_range(_num_c))
      98      410400 :         sum += (*_dFadca[m])[_qp] * (*_dcideta[m][0])[_qp] -
      99      410400 :                (*_dFbdcb[m])[_qp] * (*_dcideta[m][1])[_qp];
     100             : 
     101      410400 :       return (-(_prop_d2h[_qp] * A1 + _prop_dh[_qp] * sum) + _w * _prop_d2g[_qp]) * _phi[_j][_qp];
     102             :   }
     103           0 :   mooseError("Invalid type passed in");
     104             : }
     105             : 
     106             : Real
     107     1641600 : NestedKKSACBulkF::computeQpOffDiagJacobian(unsigned int jvar)
     108             : {
     109             :   // first get dependence of mobility _L on other variables using parent class member function
     110     1641600 :   Real res = ACBulk<Real>::computeQpOffDiagJacobian(jvar);
     111             : 
     112             :   // Then add dependence of KKSACBulkF on other variables, and treat c specially using chain rule
     113     1641600 :   auto compvar = mapJvarToCvar(jvar, _c_map);
     114             : 
     115     1641600 :   if (compvar >= 0)
     116             :   {
     117             :     Real sum = 0.0;
     118     3283200 :     for (const auto m : make_range(_num_c))
     119     1641600 :       sum += (*_dFadca[m])[_qp] * (*_dcidb[m][0][compvar])[_qp] -
     120     1641600 :              (*_dFbdcb[m])[_qp] * (*_dcidb[m][1][compvar])[_qp];
     121             : 
     122     1641600 :     res -= _L[_qp] * _prop_dh[_qp] * sum * _phi[_j][_qp] * _test[_i][_qp];
     123             :   }
     124             : 
     125             :   // for all other vars get the coupled variable jvar is referring to
     126             :   const unsigned int cvar = mapJvarToCvar(jvar);
     127             : 
     128     1641600 :   res -= _L[_qp] * _prop_dh[_qp] * ((*_dFadarg[cvar])[_qp] - (*_dFbdarg[cvar])[_qp]) *
     129     1641600 :          _phi[_j][_qp] * _test[_i][_qp];
     130             : 
     131     1641600 :   return res;
     132             : }

Generated by: LCOV version 1.14