LCOV - code coverage report
Current view: top level - src/kernels - KKSSplitCHCRes.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #32971 (54bef8) with base c6cf66 Lines: 34 36 94.4 %
Date: 2026-05-29 20:38:39 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          97 : KKSSplitCHCRes::validParams()
      16             : {
      17          97 :   InputParameters params = SplitCHBase::validParams();
      18          97 :   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         194 :   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         194 :   params.addRequiredCoupledVar(
      26             :       "ca", "phase concentration corresponding to the non-linear variable of this kernel");
      27         194 :   params.addCoupledVar("args_a", "Vector of additional arguments to Fa");
      28         194 :   params.addRequiredCoupledVar("w",
      29             :                                "Chemical potential non-linear helper variable for the split solve");
      30          97 :   return params;
      31           0 : }
      32             : 
      33          52 : KKSSplitCHCRes::KKSSplitCHCRes(const InputParameters & parameters)
      34             :   : DerivativeMaterialInterface<JvarMapKernelInterface<SplitCHBase>>(parameters),
      35          52 :     _ca_var(coupled("ca")),
      36          52 :     _ca_name(coupledName("ca", 0)),
      37          52 :     _dFadca(getMaterialPropertyDerivative<Real>("fa_name", _ca_name)),
      38          52 :     _d2Fadcadarg(_n_args),
      39          52 :     _w_var(coupled("w")),
      40         104 :     _w(coupledValue("w"))
      41             : {
      42             :   // get the second derivative material property
      43         170 :   for (unsigned int i = 0; i < _n_args; ++i)
      44         118 :     _d2Fadcadarg[i] = &getMaterialPropertyDerivative<Real>("fa_name", _ca_name, i);
      45          52 : }
      46             : 
      47             : void
      48          24 : KKSSplitCHCRes::initialSetup()
      49             : {
      50          72 :   validateNonlinearCoupling<Real>("fa_name");
      51          24 :   validateDerivativeMaterialPropertyBase<Real>("fa_name");
      52          24 : }
      53             : 
      54             : Real
      55     3594560 : KKSSplitCHCRes::computeQpResidual()
      56             : {
      57     3594560 :   Real residual = SplitCHBase::computeQpResidual();
      58     3594560 :   residual += -_w[_qp] * _test[_i][_qp];
      59             : 
      60     3594560 :   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     5290560 : KKSSplitCHCRes::computeDFDC(PFFunctionType type)
      72             : {
      73     5290560 :   switch (type)
      74             :   {
      75     3594560 :     case Residual:
      76     3594560 :       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     3392000 : KKSSplitCHCRes::computeQpOffDiagJacobian(unsigned int jvar)
      87             : {
      88             :   // treat w variable explicitly
      89     3392000 :   if (jvar == _w_var)
      90     1696000 :     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     1696000 :   return _phi[_j][_qp] * _test[_i][_qp] * (*_d2Fadcadarg[cvar])[_qp];
      95             : }

Generated by: LCOV version 1.14