LCOV - code coverage report
Current view: top level - src/kernels - KKSMultiPhaseConcentration.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #32971 (54bef8) with base c6cf66 Lines: 51 56 91.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 "KKSMultiPhaseConcentration.h"
      11             : 
      12             : registerMooseObject("PhaseFieldApp", KKSMultiPhaseConcentration);
      13             : 
      14             : InputParameters
      15          60 : KKSMultiPhaseConcentration::validParams()
      16             : {
      17          60 :   InputParameters params = KernelValue::validParams();
      18          60 :   params.addClassDescription(
      19             :       "KKS multi-phase model kernel to enforce $c = h_1c_1 + h_2c_2 + h_3c_3 + \\dots$"
      20             :       ". The non-linear variable of this kernel is $c_n$, the final phase "
      21             :       "concentration in the list.");
      22         120 :   params.addRequiredCoupledVar(
      23             :       "cj", "Array of phase concentrations cj. Place in same order as hj_names!");
      24         120 :   params.addRequiredCoupledVar("c", "Physical concentration");
      25         120 :   params.addCoupledVar("etas", "Order parameters for all phases");
      26         120 :   params.addRequiredParam<std::vector<MaterialPropertyName>>(
      27             :       "hj_names", "Switching Function Materials that provide $h(\\eta_1, \\eta_2,\\dots)$");
      28          60 :   return params;
      29           0 : }
      30             : 
      31             : // Phase interpolation func
      32          32 : KKSMultiPhaseConcentration::KKSMultiPhaseConcentration(const InputParameters & parameters)
      33             :   : DerivativeMaterialInterface<JvarMapKernelInterface<KernelValue>>(parameters),
      34          32 :     _num_j(coupledComponents("cj")),
      35          32 :     _cj(coupledValues("cj")),
      36          32 :     _cj_map(getParameterJvarMap("cj")),
      37          32 :     _k(-1),
      38          32 :     _c(coupledValue("c")),
      39          32 :     _c_var(coupled("c")),
      40          64 :     _hj_names(getParam<std::vector<MaterialPropertyName>>("hj_names")),
      41          32 :     _prop_hj(_hj_names.size()),
      42          32 :     _eta_names(coupledComponents("etas")),
      43          32 :     _eta_map(getParameterJvarMap("etas")),
      44          64 :     _prop_dhjdetai(_num_j)
      45             : {
      46             :   // Check to make sure the the number of hj's is the same as the number of cj's
      47          32 :   if (_num_j != _hj_names.size())
      48           0 :     paramError("hj_names", "Need to pass in as many hj_names as cjs");
      49             :   // Check to make sure the the number of etas is the same as the number of cj's
      50          32 :   if (_num_j != _eta_names.size())
      51           0 :     paramError("etas", "Need to pass in as many etas as cjs");
      52             : 
      53          32 :   if (_num_j == 0)
      54           0 :     mooseError("Need to supply at least 1 phase concentration cj in KKSMultiPhaseConcentration",
      55             :                name());
      56             : 
      57             :   // get order parameter names and variable indices
      58         104 :   for (unsigned int i = 0; i < _num_j; ++i)
      59         144 :     _eta_names[i] = coupledName("etas", i);
      60             : 
      61             :   // Load concentration variables into the arrays
      62         104 :   for (unsigned int m = 0; m < _num_j; ++m)
      63             :   {
      64          72 :     _prop_hj[m] = &getMaterialPropertyByName<Real>(_hj_names[m]);
      65          72 :     _prop_dhjdetai[m].resize(_num_j);
      66             :     // Set _k to the position of the nonlinear variable in the list of cj's
      67          72 :     if (coupled("cj", m) == _var.number())
      68          32 :       _k = m;
      69             : 
      70             :     // Get derivatives of switching functions wrt order parameters
      71         240 :     for (unsigned int n = 0; n < _num_j; ++n)
      72         168 :       _prop_dhjdetai[m][n] = &getMaterialPropertyDerivative<Real>(_hj_names[m], _eta_names[n]);
      73             :   }
      74             : 
      75             :   // Check to make sure the nonlinear variable is set to one of the cj's
      76          32 :   if (_k < 0)
      77           0 :     mooseError("Need to set nonlinear variable to one of the cj's in KKSMultiPhaseConcentration",
      78             :                name());
      79          32 : }
      80             : 
      81             : Real
      82      550560 : KKSMultiPhaseConcentration::precomputeQpResidual()
      83             : {
      84             :   // R = sum_i (h_i * c_i) - c
      85             :   Real sum_ch = 0.0;
      86     2024480 :   for (unsigned int m = 0; m < _num_j; ++m)
      87     1473920 :     sum_ch += (*_cj[m])[_qp] * (*_prop_hj[m])[_qp];
      88             : 
      89      550560 :   return sum_ch - _c[_qp];
      90             : }
      91             : 
      92             : Real
      93      387920 : KKSMultiPhaseConcentration::precomputeQpJacobian()
      94             : {
      95      387920 :   return (*_prop_hj[_k])[_qp] * _phi[_j][_qp];
      96             : }
      97             : 
      98             : Real
      99     7548960 : KKSMultiPhaseConcentration::computeQpOffDiagJacobian(unsigned int jvar)
     100             : {
     101     7548960 :   if (jvar == _c_var)
     102     1339040 :     return -_test[_i][_qp] * _phi[_j][_qp];
     103             : 
     104     6209920 :   auto cjvar = mapJvarToCvar(jvar, _cj_map);
     105     6209920 :   if (cjvar >= 0)
     106     2465440 :     return _test[_i][_qp] * (*_prop_hj[cjvar])[_qp] * _phi[_j][_qp];
     107             : 
     108     3744480 :   auto etavar = mapJvarToCvar(jvar, _eta_map);
     109     3744480 :   if (etavar >= 0)
     110             :   {
     111             :     Real sum = 0.0;
     112             : 
     113    14612640 :     for (unsigned int n = 0; n < _num_j; ++n)
     114    10868160 :       sum += (*_prop_dhjdetai[n][etavar])[_qp] * (*_cj[n])[_qp];
     115             : 
     116     3744480 :     return _test[_i][_qp] * sum * _phi[_j][_qp];
     117             :   }
     118             : 
     119             :   return 0.0;
     120             : }

Generated by: LCOV version 1.14