LCOV - code coverage report
Current view: top level - src/kernels - SLKKSChemicalPotential.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 36 37 97.3 %
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 "SLKKSChemicalPotential.h"
      11             : #include "MathUtils.h"
      12             : 
      13             : using namespace MathUtils;
      14             : 
      15             : registerMooseObject("PhaseFieldApp", SLKKSChemicalPotential);
      16             : 
      17             : InputParameters
      18         172 : SLKKSChemicalPotential::validParams()
      19             : {
      20         172 :   InputParameters params = Kernel::validParams();
      21         172 :   params.addClassDescription(
      22             :       "SLKKS model kernel to enforce the pointwise equality of sublattice chemical "
      23             :       "potentials in the same phase.");
      24         344 :   params.addRequiredCoupledVar("cs", "other sublattice concentration in the same phase");
      25         344 :   params.addRequiredParam<Real>("a", "sublattice site fraction for the kernel variable");
      26         344 :   params.addRequiredParam<Real>("as", "other sublattice site fraction in the same phase");
      27         344 :   params.addRequiredParam<MaterialPropertyName>("F", "Base name of the free energy function");
      28         344 :   params.addCoupledVar("args", "Vector of variable arguments to the free energy function");
      29         344 :   params.deprecateCoupledVar("args", "coupled_variables", "02/27/2024");
      30             : 
      31         172 :   return params;
      32           0 : }
      33             : 
      34          90 : SLKKSChemicalPotential::SLKKSChemicalPotential(const InputParameters & parameters)
      35             :   : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters),
      36          90 :     _cs_var(coupled("cs")),
      37          90 :     _cs_name(coupledName("cs", 0)),
      38             :     // first derivatives
      39          90 :     _dFdu(getMaterialPropertyDerivative<Real>("F", _var.name())),
      40          90 :     _dFdcs(getMaterialPropertyDerivative<Real>("F", _cs_name)),
      41             :     // second derivatives d2F/dx*dca for jacobian diagonal elements
      42          90 :     _d2Fdu2(getMaterialPropertyDerivative<Real>("F", _var.name(), _var.name())),
      43          90 :     _d2Fdcsu(getMaterialPropertyDerivative<Real>("F", _cs_name, _var.name())),
      44             :     // site fractions
      45         180 :     _a_u(getParam<Real>("a")),
      46         270 :     _a_cs(getParam<Real>("as"))
      47             : {
      48             :   const auto nvar = _coupled_moose_vars.size();
      49          90 :   _d2Fdudarg.resize(nvar);
      50          90 :   _d2Fdcsdarg.resize(nvar);
      51             : 
      52         270 :   for (std::size_t i = 0; i < nvar; ++i)
      53             :   {
      54             :     // get the moose variable
      55         180 :     const auto & arg_name = _coupled_moose_vars[i]->name();
      56             : 
      57             :     // lookup table for the material properties representing the derivatives
      58             :     // needed for the off-diagonal Jacobian
      59         180 :     _d2Fdudarg[i] = &getMaterialPropertyDerivative<Real>("F", _var.name(), arg_name);
      60         180 :     _d2Fdcsdarg[i] = &getMaterialPropertyDerivative<Real>("F", _cs_name, arg_name);
      61             :   }
      62          90 : }
      63             : 
      64             : void
      65          72 : SLKKSChemicalPotential::initialSetup()
      66             : {
      67         216 :   validateNonlinearCoupling<Real>("F");
      68          72 : }
      69             : 
      70             : Real
      71    10146320 : SLKKSChemicalPotential::computeQpResidual()
      72             : {
      73    10146320 :   return _test[_i][_qp] * (_dFdu[_qp] / _a_u - _dFdcs[_qp] / _a_cs);
      74             : }
      75             : 
      76             : Real
      77     7959360 : SLKKSChemicalPotential::computeQpJacobian()
      78             : {
      79     7959360 :   return _test[_i][_qp] * _phi[_j][_qp] * (_d2Fdu2[_qp] / _a_u - _d2Fdcsu[_qp] / _a_cs);
      80             : }
      81             : 
      82             : Real
      83    15918720 : SLKKSChemicalPotential::computeQpOffDiagJacobian(unsigned int jvar)
      84             : {
      85             :   // get the coupled variable jvar is referring to
      86             :   const unsigned int cvar = mapJvarToCvar(jvar);
      87             : 
      88    15918720 :   return _test[_i][_qp] * _phi[_j][_qp] *
      89    15918720 :          ((*_d2Fdudarg[cvar])[_qp] / _a_u - (*_d2Fdcsdarg[cvar])[_qp] / _a_cs);
      90             : }

Generated by: LCOV version 1.14