LCOV - code coverage report
Current view: top level - src/kernels - KKSMultiACBulkC.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 44 47 93.6 %
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 "KKSMultiACBulkC.h"
      11             : 
      12             : registerMooseObject("PhaseFieldApp", KKSMultiACBulkC);
      13             : 
      14             : InputParameters
      15         230 : KKSMultiACBulkC::validParams()
      16             : {
      17         230 :   InputParameters params = KKSMultiACBulkBase::validParams();
      18         230 :   params.addClassDescription("Multi-phase KKS model kernel (part 2 of 2) for the Bulk Allen-Cahn. "
      19             :                              "This includes all terms dependent on chemical potential.");
      20         460 :   params.addRequiredCoupledVar(
      21             :       "cj_names", "Array of phase concentrations cj. Place in same order as Fj_names!");
      22         230 :   return params;
      23           0 : }
      24             : 
      25         120 : KKSMultiACBulkC::KKSMultiACBulkC(const InputParameters & parameters)
      26             :   : KKSMultiACBulkBase(parameters),
      27             :     // Can use any dFj/dcj since they are equal so pick first cj in the list
      28         120 :     _c1_name(coupledName("cj_names", 0)),
      29         120 :     _cjs(coupledValues("cj_names")),
      30         120 :     _cjs_var(coupledIndices("cj_names")),
      31         120 :     _prop_dF1dc1(getMaterialPropertyDerivative<Real>(_Fj_names[0],
      32             :                                                      _c1_name)), // Use first Fj in list for dFj/dcj
      33         120 :     _prop_d2F1dc12(getMaterialPropertyDerivative<Real>(_Fj_names[0], _c1_name, _c1_name)),
      34         240 :     _prop_d2F1dc1darg(_n_args)
      35             : {
      36         240 :   if (_num_j != coupledComponents("cj_names"))
      37           0 :     paramError("cj_names", "Need to pass in as many cj_names as Fj_names");
      38             : 
      39             :   // get second partial derivatives wrt c1 and other coupled variable
      40         720 :   for (unsigned int i = 0; i < _n_args; ++i)
      41         600 :     _prop_d2F1dc1darg[i] = &getMaterialPropertyDerivative<Real>(_Fj_names[0], _c1_name, i);
      42         120 : }
      43             : 
      44             : Real
      45    45647240 : KKSMultiACBulkC::computeDFDOP(PFFunctionType type)
      46             : {
      47             :   Real sum = 0.0;
      48             : 
      49    45647240 :   switch (type)
      50             :   {
      51             :     case Residual:
      52   172380440 :       for (unsigned int n = 0; n < _num_j; ++n)
      53   128638160 :         sum += (*_prop_dhjdetai[n])[_qp] * (*_cjs[n])[_qp];
      54             : 
      55    43742280 :       return -_prop_dF1dc1[_qp] * sum;
      56             : 
      57     1904960 :     case Jacobian:
      58             :       // For when this kernel is used in the Lagrange multiplier equation
      59             :       // In that case the Lagrange multiplier is the nonlinear variable
      60     3809920 :       if (_etai_var != _var.number())
      61             :         return 0.0;
      62             : 
      63             :       // For when eta_i is the nonlinear variable
      64     3044480 :       for (unsigned int n = 0; n < _num_j; ++n)
      65     2251520 :         sum += (*_prop_d2hjdetai2[n])[_qp] * (*_cjs[n])[_qp];
      66             : 
      67      792960 :       return -_phi[_j][_qp] * _prop_dF1dc1[_qp] * sum;
      68             :   }
      69             : 
      70           0 :   mooseError("Invalid type passed in");
      71             : }
      72             : 
      73             : Real
      74    38874880 : KKSMultiACBulkC::computeQpOffDiagJacobian(unsigned int jvar)
      75             : {
      76             :   // first get dependence of mobility _L on other variables using parent class
      77             :   // member function
      78    38874880 :   Real res = ACBulk<Real>::computeQpOffDiagJacobian(jvar);
      79             : 
      80             :   Real sum = 0.0;
      81             :   // Then add dependence of KKSACBulkC on other variables
      82             :   // Treat cj variables specially, as they appear in the residual
      83    38874880 :   if (jvar == _cjs_var[0])
      84             :   {
      85    28069760 :     for (unsigned int n = 0; n < _num_j; ++n)
      86    20931840 :       sum += (*_prop_dhjdetai[n])[_qp] * (*_cjs[n])[_qp];
      87             : 
      88     7137920 :     res -= _L[_qp] * (sum * _prop_d2F1dc12[_qp] + _prop_dF1dc1[_qp] * (*_prop_dhjdetai[0])[_qp]) *
      89     7137920 :            _phi[_j][_qp] * _test[_i][_qp];
      90     7137920 :     return res;
      91             :   }
      92             : 
      93    73641600 :   for (unsigned int i = 1; i < _num_j; ++i)
      94             :   {
      95    55698560 :     if (jvar == _cjs_var[i])
      96             :     {
      97    13793920 :       res -=
      98    13793920 :           _L[_qp] * _prop_dF1dc1[_qp] * (*_prop_dhjdetai[i])[_qp] * _phi[_j][_qp] * _test[_i][_qp];
      99    13793920 :       return res;
     100             :     }
     101             :   }
     102             : 
     103             :   //  for all other vars get the coupled variable jvar is referring to
     104             :   const unsigned int cvar = mapJvarToCvar(jvar);
     105             : 
     106    71134720 :   for (unsigned int n = 0; n < _num_j; ++n)
     107    53191680 :     sum += _prop_dF1dc1[_qp] * (*_prop_d2hjdetaidarg[n][cvar])[_qp] * (*_cjs[n])[_qp] +
     108    53191680 :            (*_prop_d2F1dc1darg[cvar])[_qp] * (*_prop_dhjdetai[n])[_qp] * (*_cjs[n])[_qp];
     109             : 
     110    17943040 :   res -= _L[_qp] * sum * _phi[_j][_qp] * _test[_i][_qp];
     111             : 
     112    17943040 :   return res;
     113             : }

Generated by: LCOV version 1.14