LCOV - code coverage report
Current view: top level - src/kernels - KKSSplitCHCRes.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 34 36 94.4 %
Date: 2025-09-04 07:55:36 Functions: 6 6 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 "KKSSplitCHCRes.h"
      11             : 
      12             : registerMooseObject("PhaseFieldApp", KKSSplitCHCRes);
      13             : 
      14             : InputParameters
      15         137 : KKSSplitCHCRes::validParams()
      16             : {
      17         137 :   InputParameters params = SplitCHBase::validParams();
      18         137 :   params.addClassDescription(
      19             :       "KKS model kernel for the split Bulk Cahn-Hilliard term. This kernel operates on the "
      20             :       "physical concentration 'c' as the non-linear variable");
      21         274 :   params.addRequiredParam<MaterialPropertyName>(
      22             :       "fa_name",
      23             :       "Base name of an arbitrary phase free energy function F (f_base in the corresponding "
      24             :       "KKSBaseMaterial)");
      25         274 :   params.addRequiredCoupledVar(
      26             :       "ca", "phase concentration corresponding to the non-linear variable of this kernel");
      27         274 :   params.addCoupledVar("args_a", "Vector of additional arguments to Fa");
      28         274 :   params.addRequiredCoupledVar("w",
      29             :                                "Chemical potential non-linear helper variable for the split solve");
      30         137 :   return params;
      31           0 : }
      32             : 
      33          72 : KKSSplitCHCRes::KKSSplitCHCRes(const InputParameters & parameters)
      34             :   : DerivativeMaterialInterface<JvarMapKernelInterface<SplitCHBase>>(parameters),
      35          72 :     _ca_var(coupled("ca")),
      36          72 :     _ca_name(coupledName("ca", 0)),
      37          72 :     _dFadca(getMaterialPropertyDerivative<Real>("fa_name", _ca_name)),
      38          72 :     _d2Fadcadarg(_n_args),
      39          72 :     _w_var(coupled("w")),
      40         144 :     _w(coupledValue("w"))
      41             : {
      42             :   // get the second derivative material property
      43         234 :   for (unsigned int i = 0; i < _n_args; ++i)
      44         162 :     _d2Fadcadarg[i] = &getMaterialPropertyDerivative<Real>("fa_name", _ca_name, i);
      45          72 : }
      46             : 
      47             : void
      48          36 : KKSSplitCHCRes::initialSetup()
      49             : {
      50         108 :   validateNonlinearCoupling<Real>("fa_name");
      51          36 :   validateDerivativeMaterialPropertyBase<Real>("fa_name");
      52          36 : }
      53             : 
      54             : Real
      55     4412960 : KKSSplitCHCRes::computeQpResidual()
      56             : {
      57     4412960 :   Real residual = SplitCHBase::computeQpResidual();
      58     4412960 :   residual += -_w[_qp] * _test[_i][_qp];
      59             : 
      60     4412960 :   return residual;
      61             : }
      62             : 
      63             : /**
      64             :  * Note that per product and chain rules:
      65             :  * \f$ \frac{d}{du_j}\left(F(u)\nabla u\right) = \nabla u \frac {dF(u)}{du}\frac{du}{du_j} +
      66             :  * F(u)\frac{d\nabla u}{du_j} \f$
      67             :  * which is:
      68             :  * \f$ \nabla u \frac {dF(u)}{du} \phi_j + F(u) \nabla \phi_j \f$
      69             :  */
      70             : Real
      71     6404160 : KKSSplitCHCRes::computeDFDC(PFFunctionType type)
      72             : {
      73     6404160 :   switch (type)
      74             :   {
      75     4412960 :     case Residual:
      76     4412960 :       return _dFadca[_qp]; // dFa/dca ( = dFb/dcb = dF/dc)
      77             : 
      78             :     case Jacobian:
      79             :       return 0.0;
      80             :   }
      81             : 
      82           0 :   mooseError("Invalid type passed in");
      83             : }
      84             : 
      85             : Real
      86     3982400 : KKSSplitCHCRes::computeQpOffDiagJacobian(unsigned int jvar)
      87             : {
      88             :   // treat w variable explicitly
      89     3982400 :   if (jvar == _w_var)
      90     1991200 :     return -_phi[_j][_qp] * _test[_i][_qp];
      91             : 
      92             :   // get the coupled variable jvar is referring to
      93             :   const unsigned int cvar = mapJvarToCvar(jvar);
      94     1991200 :   return _phi[_j][_qp] * _test[_i][_qp] * (*_d2Fadcadarg[cvar])[_qp];
      95             : }

Generated by: LCOV version 1.14