LCOV - code coverage report
Current view: top level - src/kernels - NestedKKSACBulkC.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 69 71 97.2 %
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 "NestedKKSACBulkC.h"
      11             : 
      12             : registerMooseObject("PhaseFieldApp", NestedKKSACBulkC);
      13             : 
      14             : InputParameters
      15          46 : NestedKKSACBulkC::validParams()
      16             : {
      17          46 :   InputParameters params = KKSACBulkBase::validParams();
      18          46 :   params.addClassDescription("KKS model kernel (part 2 of 2) for the Bulk Allen-Cahn. This "
      19             :                              "includes all terms 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          46 :   return params;
      26           0 : }
      27             : 
      28          24 : NestedKKSACBulkC::NestedKKSACBulkC(const InputParameters & parameters)
      29             :   : KKSACBulkBase(parameters),
      30          24 :     _c_names(coupledNames("global_cs")),
      31          24 :     _c_map(getParameterJvarMap("global_cs")),
      32          24 :     _num_c(coupledComponents("global_cs")),
      33          48 :     _ci_names(getParam<std::vector<MaterialPropertyName>>("ci_names")),
      34          24 :     _prop_ci(_num_c),
      35          24 :     _dcideta(_num_c * 2),
      36          24 :     _dcidb(_num_c * 2),
      37          24 :     _Fa_name(getParam<MaterialPropertyName>("fa_name")),
      38          24 :     _dFadca(_num_c),
      39          24 :     _d2Fadcadba(_num_c),
      40          48 :     _d2Fadcadarg(_n_args)
      41             : {
      42             :   // Declare _prop_ci to be a matrix for easy reference. In _prop_ci[m][n], m is species index, n
      43             :   // is the phase index.
      44          48 :   for (const auto m : make_range(_num_c))
      45             :   {
      46          24 :     _prop_ci[m].resize(2);
      47          72 :     for (const auto n : make_range(2))
      48          48 :       _prop_ci[m][n] = &getMaterialPropertyByName<Real>(_ci_names[m * 2 + n]);
      49             :   }
      50             : 
      51             :   // _dcideta and _dcidb are computed in KKSPhaseConcentrationDerivatives
      52          48 :   for (const auto m : make_range(_num_c))
      53             :   {
      54          24 :     _dcideta[m].resize(2);
      55          24 :     _dcidb[m].resize(2);
      56          72 :     for (const auto n : make_range(2))
      57             :     {
      58          48 :       _dcideta[m][n] = &getMaterialPropertyDerivative<Real>(_ci_names[m * 2 + n], _var.name());
      59          48 :       _dcidb[m][n].resize(_num_c);
      60          96 :       for (const auto l : make_range(_num_c))
      61          48 :         _dcidb[m][n][l] = &getMaterialPropertyDerivative<Real>(_ci_names[m * 2 + n], _c_names[l]);
      62             :     }
      63             :   }
      64             : 
      65             :   // _dFadca and _d2Fadcadba are computed in KKSPhaseConcentrationMaterial
      66          48 :   for (const auto m : make_range(_num_c))
      67             :   {
      68          24 :     _dFadca[m] = &getMaterialPropertyDerivative<Real>("cp" + _Fa_name, _ci_names[m * 2]);
      69          24 :     _d2Fadcadba[m].resize(_num_c);
      70          48 :     for (const auto n : make_range(_num_c))
      71          24 :       _d2Fadcadba[m][n] =
      72          48 :           &getMaterialPropertyDerivative<Real>("cp" + _Fa_name, _ci_names[m * 2], _ci_names[n * 2]);
      73             :   }
      74             : 
      75             :   // _d2Fadcadarg are computed in KKSPhaseConcentrationMaterial
      76          48 :   for (const auto m : make_range(_num_c))
      77             :   {
      78          24 :     _d2Fadcadarg[m].resize(_n_args);
      79          72 :     for (const auto n : make_range(_n_args))
      80          48 :       _d2Fadcadarg[m][n] =
      81          96 :           &getMaterialPropertyDerivative<Real>("cp" + _Fa_name, _ci_names[m * 2], n);
      82             :   }
      83          24 : }
      84             : 
      85             : Real
      86     3330900 : NestedKKSACBulkC::computeDFDOP(PFFunctionType type)
      87             : {
      88             :   Real sum = 0.0;
      89     3330900 :   switch (type)
      90             :   {
      91             :     case Residual:
      92     5841000 :       for (unsigned int m = 0; m < _num_c; ++m)
      93     2920500 :         sum += (*_dFadca[m])[_qp] * ((*_prop_ci[m][0])[_qp] - (*_prop_ci[m][1])[_qp]);
      94             : 
      95     2920500 :       return _prop_dh[_qp] * sum;
      96             : 
      97             :     case Jacobian:
      98             :       Real sum1 = 0.0;
      99      820800 :       for (unsigned int m = 0; m < _num_c; ++m)
     100      410400 :         sum1 += (*_dFadca[m])[_qp] * ((*_prop_ci[m][0])[_qp] - (*_prop_ci[m][1])[_qp]);
     101             : 
     102             :       Real sum2 = 0.0;
     103      820800 :       for (unsigned int m = 0; m < _num_c; ++m)
     104             :       {
     105             :         Real sum3 = 0.0;
     106      820800 :         for (unsigned int n = 0; n < _num_c; ++n)
     107      410400 :           sum3 += (*_d2Fadcadba[m][n])[_qp] * (*_dcideta[n][0])[_qp];
     108             : 
     109      410400 :         sum2 += sum3 * ((*_prop_ci[m][0])[_qp] - (*_prop_ci[m][1])[_qp]) +
     110      410400 :                 (*_dFadca[m])[_qp] * ((*_dcideta[m][0])[_qp] - (*_dcideta[m][1])[_qp]);
     111             :       }
     112             : 
     113      410400 :       return (_prop_d2h[_qp] * sum1 + _prop_dh[_qp] * sum2) * _phi[_j][_qp];
     114             :   }
     115             : 
     116           0 :   mooseError("Invalid type passed in");
     117             : }
     118             : 
     119             : Real
     120     1641600 : NestedKKSACBulkC::computeQpOffDiagJacobian(unsigned int jvar)
     121             : {
     122             :   // first get dependence of mobility _L on other variables using parent class member function
     123     1641600 :   Real res = ACBulk<Real>::computeQpOffDiagJacobian(jvar);
     124             : 
     125             :   // Then add dependence of KKSACBulkF on other variables.
     126             :   // Treat c specially using chain rule.
     127     1641600 :   auto compvar = mapJvarToCvar(jvar, _c_map);
     128     1641600 :   if (compvar >= 0)
     129             :   {
     130             :     Real sum1 = 0.0;
     131     3283200 :     for (unsigned int m = 0; m < _num_c; ++m)
     132             :     {
     133             :       Real sum2 = 0.0;
     134     3283200 :       for (unsigned int n = 0; n < _num_c; ++n)
     135     1641600 :         sum2 += (*_d2Fadcadba[m][n])[_qp] * (*_dcidb[n][0][compvar])[_qp];
     136             : 
     137     1641600 :       sum1 += sum2 * ((*_prop_ci[m][0])[_qp] - (*_prop_ci[m][1])[_qp]) +
     138     1641600 :               (*_dFadca[m])[_qp] * ((*_dcidb[m][0][compvar])[_qp] - (*_dcidb[m][1][compvar])[_qp]);
     139             :     }
     140             : 
     141     1641600 :     res += _L[_qp] * _prop_dh[_qp] * sum1 * _phi[_j][_qp] * _test[_i][_qp];
     142             :   }
     143             : 
     144             :   //  for all other vars get the coupled variable jvar is referring to
     145             :   const unsigned int cvar = mapJvarToCvar(jvar);
     146     3283200 :   for (unsigned int n = 0; n < _num_c; ++n)
     147     1641600 :     res += _L[_qp] * _prop_dh[_qp] * (*_d2Fadcadarg[n][cvar])[_qp] *
     148     1641600 :            ((*_prop_ci[n][0])[_qp] - (*_prop_ci[n][1])[_qp]) * _phi[_j][_qp] * _test[_i][_qp];
     149             : 
     150     1641600 :   return res;
     151             : }

Generated by: LCOV version 1.14