LCOV - code coverage report
Current view: top level - src/kernels - SwitchingFunctionConstraintEta.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 31 34 91.2 %
Date: 2025-09-04 07:55:36 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 "SwitchingFunctionConstraintEta.h"
      11             : 
      12             : registerMooseObject("PhaseFieldApp", SwitchingFunctionConstraintEta);
      13             : 
      14             : InputParameters
      15         379 : SwitchingFunctionConstraintEta::validParams()
      16             : {
      17         379 :   InputParameters params = Kernel::validParams();
      18         379 :   params.addClassDescription("Lagrange multiplier kernel to constrain the sum of all switching "
      19             :                              "functions in a multiphase system. This kernel acts on a "
      20             :                              "non-conserved order parameter eta_i.");
      21         758 :   params.addParam<MaterialPropertyName>("h_name",
      22             :                                         "Switching Function Materials that provides h(eta_i)");
      23         758 :   params.addRequiredCoupledVar("lambda", "Lagrange multiplier");
      24         758 :   params.addCoupledVar("args", "Vector of further variable arguments to the switching function");
      25         758 :   params.deprecateCoupledVar("args", "coupled_variables", "02/27/2024");
      26         379 :   return params;
      27           0 : }
      28             : 
      29         198 : SwitchingFunctionConstraintEta::SwitchingFunctionConstraintEta(const InputParameters & parameters)
      30             :   : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters),
      31         198 :     _eta_name(_var.name()),
      32         198 :     _dh(getMaterialPropertyDerivative<Real>("h_name", _eta_name)),
      33         198 :     _d2h(getMaterialPropertyDerivative<Real>("h_name", _eta_name, _eta_name)),
      34         396 :     _d2ha(isCoupled("args") ? coupledComponents("args") : coupledComponents("coupled_variables")),
      35         396 :     _d2ha_map(isCoupled("args") ? getParameterJvarMap("args")
      36         282 :                                 : getParameterJvarMap("coupled_variables")),
      37         198 :     _lambda(coupledValue("lambda")),
      38         396 :     _lambda_var(coupled("lambda"))
      39             : {
      40         384 :   for (std::size_t i = 0; i < _d2ha.size(); ++i)
      41             :   {
      42         372 :     if (isCoupled("args"))
      43         372 :       _d2ha[i] = &getMaterialPropertyDerivative<Real>("h_name", _eta_name, coupledName("args", i));
      44             :     else
      45           0 :       _d2ha[i] = &getMaterialPropertyDerivative<Real>(
      46           0 :           "h_name", _eta_name, coupledName("coupled_variables", i));
      47             :   }
      48         198 : }
      49             : 
      50             : Real
      51    24950160 : SwitchingFunctionConstraintEta::computeQpResidual()
      52             : {
      53    24950160 :   return _lambda[_qp] * _dh[_qp] * _test[_i][_qp];
      54             : }
      55             : 
      56             : Real
      57    13279040 : SwitchingFunctionConstraintEta::computeQpJacobian()
      58             : {
      59    13279040 :   return _lambda[_qp] * _d2h[_qp] * _phi[_j][_qp] * _test[_i][_qp];
      60             : }
      61             : 
      62             : Real
      63    29532800 : SwitchingFunctionConstraintEta::computeQpOffDiagJacobian(unsigned int jvar)
      64             : {
      65    29532800 :   if (jvar == _lambda_var)
      66    13279040 :     return _phi[_j][_qp] * _dh[_qp] * _test[_i][_qp];
      67             : 
      68    16253760 :   auto k = mapJvarToCvar(jvar, _d2ha_map);
      69    16253760 :   if (k >= 0)
      70    16253760 :     return _lambda[_qp] * (*_d2ha[k])[_qp] * _phi[_j][_qp] * _test[_i][_qp];
      71             : 
      72             :   return 0.0;
      73             : }

Generated by: LCOV version 1.14