LCOV - code coverage report
Current view: top level - src/kernels - NestedKKSACBulkF.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #32971 (54bef8) with base c6cf66 Lines: 64 66 97.0 %
Date: 2026-05-29 20:38: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 "NestedKKSACBulkF.h"
      11             : 
      12             : registerMooseObject("PhaseFieldApp", NestedKKSACBulkF);
      13             : 
      14             : InputParameters
      15          30 : NestedKKSACBulkF::validParams()
      16             : {
      17          30 :   InputParameters params = KKSACBulkBase::validParams();
      18          30 :   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          60 :   params.addRequiredCoupledVar("global_cs", "The interpolated concentrations c, b, etc");
      21          60 :   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          60 :   params.addRequiredParam<MaterialPropertyName>(
      26             :       "fb_name", "Free energy function Fb (fa_name is in the KKSACBulkBase).");
      27          60 :   params.addParam<MaterialPropertyName>(
      28             :       "g_name", "g", "Base name for the double well function g(eta)");
      29          60 :   params.addRequiredParam<Real>("w", "Double well height parameter");
      30          30 :   return params;
      31           0 : }
      32             : 
      33          16 : NestedKKSACBulkF::NestedKKSACBulkF(const InputParameters & parameters)
      34             :   : KKSACBulkBase(parameters),
      35          16 :     _c_map(getParameterJvarMap("global_cs")),
      36          16 :     _num_c(coupledComponents("global_cs")),
      37          16 :     _c_names(coupledNames("global_cs")),
      38          32 :     _ci_names(getParam<std::vector<MaterialPropertyName>>("ci_names")),
      39          16 :     _Fa_name(getParam<MaterialPropertyName>("fa_name")),
      40          16 :     _dFadca(_num_c),
      41          16 :     _Fb_name(getParam<MaterialPropertyName>("fb_name")),
      42          16 :     _dFbdcb(_num_c),
      43          16 :     _prop_dg(getMaterialPropertyDerivative<Real>("g_name", _eta_name)),
      44          16 :     _prop_d2g(getMaterialPropertyDerivative<Real>("g_name", _eta_name, _eta_name)),
      45          32 :     _w(getParam<Real>("w")),
      46          16 :     _prop_Fi(2),
      47          16 :     _dcideta(_num_c * 2),
      48          16 :     _dcidb(_num_c * _num_c * 2),
      49          16 :     _dFadarg(_n_args),
      50          32 :     _dFbdarg(_n_args)
      51             : {
      52             :   // _prop_Fi is computed in KKSPhaseConcentrationMaterial
      53          32 :   _prop_Fi[0] = &getMaterialPropertyByName<Real>("cp" + _Fa_name);
      54          32 :   _prop_Fi[1] = &getMaterialPropertyByName<Real>("cp" + _Fb_name);
      55             : 
      56             :   // _dcideta and _dcid are computed in KKSPhaseConcentrationDerivatives
      57          32 :   for (const auto m : make_range(_num_c))
      58             :   {
      59          16 :     _dcideta[m].resize(2);
      60          16 :     _dcidb[m].resize(2);
      61          48 :     for (const auto n : make_range(2))
      62             :     {
      63          32 :       _dcideta[m][n] = &getMaterialPropertyDerivative<Real>(_ci_names[m * 2 + n], _var.name());
      64          32 :       _dcidb[m][n].resize(_num_c);
      65             : 
      66          64 :       for (const auto l : make_range(_num_c))
      67          32 :         _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          32 :   for (const auto m : make_range(_num_c))
      73             :   {
      74          16 :     _dFadca[m] = &getMaterialPropertyDerivative<Real>("cp" + _Fa_name, _ci_names[m * 2]);
      75          16 :     _dFbdcb[m] = &getMaterialPropertyDerivative<Real>("cp" + _Fb_name, _ci_names[m * 2 + 1]);
      76             :   }
      77             : 
      78             :   // _dFadarg and _dFbdarg are computed in KKSPhaseConcentrationMaterial
      79          48 :   for (const auto m : make_range(_n_args))
      80             :   {
      81          32 :     _dFadarg[m] = &getMaterialPropertyDerivative<Real>("cp" + _Fa_name, m);
      82          32 :     _dFbdarg[m] = &getMaterialPropertyDerivative<Real>("cp" + _Fb_name, m);
      83             :   }
      84          16 : }
      85             : 
      86             : Real
      87     2762100 : NestedKKSACBulkF::computeDFDOP(PFFunctionType type)
      88             : {
      89     2762100 :   const Real A1 = (*_prop_Fi[0])[_qp] - (*_prop_Fi[1])[_qp];
      90     2762100 :   switch (type)
      91             :   {
      92     2416500 :     case Residual:
      93     2416500 :       return -_prop_dh[_qp] * A1 + _w * _prop_dg[_qp];
      94             : 
      95      345600 :     case Jacobian:
      96             :       Real sum = 0.0;
      97      691200 :       for (const auto m : make_range(_num_c))
      98      345600 :         sum += (*_dFadca[m])[_qp] * (*_dcideta[m][0])[_qp] -
      99      345600 :                (*_dFbdcb[m])[_qp] * (*_dcideta[m][1])[_qp];
     100             : 
     101      345600 :       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     1382400 : NestedKKSACBulkF::computeQpOffDiagJacobian(unsigned int jvar)
     108             : {
     109             :   // first get dependence of mobility _L on other variables using parent class member function
     110     1382400 :   Real res = ACBulk<Real>::computeQpOffDiagJacobian(jvar);
     111             : 
     112             :   // Then add dependence of KKSACBulkF on other variables, and treat c specially using chain rule
     113     1382400 :   auto compvar = mapJvarToCvar(jvar, _c_map);
     114             : 
     115     1382400 :   if (compvar >= 0)
     116             :   {
     117             :     Real sum = 0.0;
     118     2764800 :     for (const auto m : make_range(_num_c))
     119     1382400 :       sum += (*_dFadca[m])[_qp] * (*_dcidb[m][0][compvar])[_qp] -
     120     1382400 :              (*_dFbdcb[m])[_qp] * (*_dcidb[m][1][compvar])[_qp];
     121             : 
     122     1382400 :     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     1382400 :   res -= _L[_qp] * _prop_dh[_qp] * ((*_dFadarg[cvar])[_qp] - (*_dFbdarg[cvar])[_qp]) *
     129     1382400 :          _phi[_j][_qp] * _test[_i][_qp];
     130             : 
     131     1382400 :   return res;
     132             : }

Generated by: LCOV version 1.14