LCOV - code coverage report
Current view: top level - src/kernels - NestedKKSSplitCHCRes.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #32971 (54bef8) with base c6cf66 Lines: 58 63 92.1 %
Date: 2026-05-29 20:38:39 Functions: 5 5 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 "NestedKKSSplitCHCRes.h"
      11             : 
      12             : registerMooseObject("PhaseFieldApp", NestedKKSSplitCHCRes);
      13             : 
      14             : InputParameters
      15          30 : NestedKKSSplitCHCRes::validParams()
      16             : {
      17          30 :   InputParameters params = JvarMapKernelInterface<Kernel>::validParams();
      18          30 :   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          60 :   params.addCoupledVar("all_etas", "Phase parameters for all phases.");
      22          60 :   params.addRequiredCoupledVar("global_cs", "The interpolated concentrations c, b, etc.");
      23          60 :   params.addCoupledVar("w", "Chemical potential non-linear helper variable for the split solve.");
      24          60 :   params.addParam<std::vector<MaterialPropertyName>>(
      25             :       "ca_names",
      26             :       "Phase concentrations in the frist phase of all_etas. The order must match global_cs, for "
      27             :       "example, c1, b1, etc.");
      28          60 :   params.addParam<MaterialPropertyName>("fa_name", "Free energy of the first phase in all_etas.");
      29          30 :   return params;
      30           0 : }
      31             : 
      32          16 : NestedKKSSplitCHCRes::NestedKKSSplitCHCRes(const InputParameters & parameters)
      33             :   : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters),
      34          32 :     _eta_names(coupledNames("all_etas")),
      35          16 :     _num_j(_eta_names.size()),
      36          16 :     _eta_map(getParameterJvarMap("all_etas")),
      37          16 :     _c_names(coupledNames("global_cs")),
      38          16 :     _num_c(coupledComponents("global_cs")),
      39          16 :     _c_map(getParameterJvarMap("global_cs")),
      40          16 :     _o(-1),
      41          16 :     _w_var(coupled("w")),
      42          16 :     _w(coupledValue("w")),
      43          32 :     _ca_names(getParam<std::vector<MaterialPropertyName>>("ca_names")),
      44          16 :     _Fa_name(getParam<MaterialPropertyName>("fa_name")),
      45          16 :     _dFadca(_num_c),
      46          16 :     _d2Fadcadba(_num_c),
      47          16 :     _dcadb(_num_c),
      48          16 :     _dcadetaj(_num_c),
      49          32 :     _d2Fadcadarg(_n_args)
      50             : 
      51             : {
      52          32 :   for (const auto i : make_range(_num_c))
      53             :   {
      54             :     // Set _o to the position of the nonlinear variable in the list of global_cs
      55          16 :     if (coupled("global_cs", i) == _var.number())
      56          16 :       _o = i;
      57             :   }
      58             : 
      59             :   // _dcideta and _dcidb are computed in KKSPhaseConcentrationDerivatives
      60          32 :   for (const auto m : make_range(_num_c))
      61             :   {
      62          16 :     _dcadetaj[m].resize(_num_j);
      63          32 :     for (const auto n : make_range(_num_j))
      64          16 :       _dcadetaj[m][n] = &getMaterialPropertyDerivative<Real>(_ca_names[m], _eta_names[n]);
      65             : 
      66          16 :     _dcadb[m].resize(_num_c);
      67          32 :     for (const auto n : make_range(_num_c))
      68          16 :       _dcadb[m][n] = &getMaterialPropertyDerivative<Real>(_ca_names[m], _c_names[n]);
      69             :   }
      70             : 
      71             :   // _dFaca and _d2Fadcadba are computed in KKSPhaseConcentrationMaterial
      72          32 :   for (const auto m : make_range(_num_c))
      73             :   {
      74          16 :     _dFadca[m] = &getMaterialPropertyDerivative<Real>(_Fa_name, _ca_names[m]);
      75          16 :     _d2Fadcadba[m] = &getMaterialPropertyDerivative<Real>(_Fa_name, _ca_names[_o], _ca_names[m]);
      76             :   }
      77             : 
      78             :   // _d2Fadcadarg is computed in KKSPhaseConcentrationMaterial
      79          96 :   for (const auto m : make_range(_n_args))
      80          80 :     _d2Fadcadarg[m] = &getMaterialPropertyDerivative<Real>(_Fa_name, _ca_names[_o], m);
      81          16 : }
      82             : 
      83             : Real
      84     2754000 : NestedKKSSplitCHCRes::computeQpResidual()
      85             : {
      86     2754000 :   return ((*_dFadca[_o])[_qp] - _w[_qp]) * _test[_i][_qp];
      87             : }
      88             : 
      89             : Real
      90     1382400 : NestedKKSSplitCHCRes::computeQpJacobian()
      91             : {
      92             :   Real sum = 0.0;
      93             : 
      94     2764800 :   for (const auto m : make_range(_num_c))
      95     1382400 :     sum += (*_d2Fadcadba[m])[_qp] * (*_dcadb[m][_o])[_qp];
      96             : 
      97     1382400 :   return sum * _phi[_j][_qp] * _test[_i][_qp];
      98             : }
      99             : 
     100             : Real
     101     2764800 : NestedKKSSplitCHCRes::computeQpOffDiagJacobian(unsigned int jvar)
     102             : {
     103             :   Real sum = 0.0;
     104             : 
     105             :   // treat w variable explicitly
     106     2764800 :   if (jvar == _w_var)
     107     1382400 :     return -_phi[_j][_qp] * _test[_i][_qp];
     108             : 
     109             :   // if b is the coupled variable
     110     1382400 :   auto compvar = mapJvarToCvar(jvar, _c_map);
     111     1382400 :   if (compvar >= 0)
     112             :   {
     113           0 :     for (const auto m : make_range(_num_c))
     114           0 :       sum += (*_d2Fadcadba[m])[_qp] * (*_dcadb[m][compvar])[_qp];
     115             : 
     116           0 :     return sum * _phi[_j][_qp] * _test[_i][_qp];
     117             :   }
     118             : 
     119             :   // if order parameters are the coupled variables
     120     1382400 :   auto etavar = mapJvarToCvar(jvar, _eta_map);
     121     1382400 :   if (etavar >= 0)
     122             :   {
     123     2764800 :     for (const auto m : make_range(_num_c))
     124     1382400 :       sum += (*_d2Fadcadba[m])[_qp] * (*_dcadetaj[m][etavar])[_qp];
     125             : 
     126     1382400 :     return sum * _phi[_j][_qp] * _test[_i][_qp];
     127             :   }
     128             : 
     129             :   // for all other vars get the coupled variable jvar is referring to
     130             :   const unsigned int cvar = mapJvarToCvar(jvar);
     131           0 :   return (*_d2Fadcadarg[cvar])[_qp] * _phi[_j][_qp] * _test[_i][_qp];
     132             : }

Generated by: LCOV version 1.14