LCOV - code coverage report
Current view: top level - src/kernels - ADACInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31730 (e8b711) with base e0c998 Lines: 34 36 94.4 %
Date: 2025-10-29 16:53:21 Functions: 3 3 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 "ADACInterface.h"
      11             : 
      12             : registerMooseObject("PhaseFieldApp", ADACInterface);
      13             : 
      14             : InputParameters
      15         339 : ADACInterface::validParams()
      16             : {
      17         339 :   InputParameters params = ADKernel::validParams();
      18         339 :   params.addClassDescription("Gradient energy Allen-Cahn Kernel");
      19         678 :   params.addParam<MaterialPropertyName>("mob_name", "L", "The mobility used with the kernel");
      20         678 :   params.addParam<MaterialPropertyName>("kappa_name", "kappa_op", "The kappa used with the kernel");
      21         678 :   params.addCoupledVar("coupled_variables",
      22             :                        "Vector of nonlinear variable arguments this object depends on");
      23             : 
      24         678 :   params.addParam<bool>("variable_L",
      25         678 :                         true,
      26             :                         "The mobility is a function of any MOOSE variable (if "
      27             :                         "this is set to false L must be constant over the "
      28             :                         "entire domain!)");
      29         339 :   return params;
      30           0 : }
      31             : 
      32         180 : ADACInterface::ADACInterface(const InputParameters & parameters)
      33             :   : ADKernel(parameters),
      34         180 :     _prop_L(getADMaterialProperty<Real>("mob_name")),
      35         360 :     _name_L(getParam<MaterialPropertyName>("mob_name")),
      36         360 :     _kappa(getADMaterialProperty<Real>("kappa_name")),
      37         360 :     _variable_L(getParam<bool>("variable_L")),
      38         360 :     _dLdop(_variable_L
      39         214 :                ? &getADMaterialProperty<Real>(derivativePropertyNameFirst(_name_L, _var.name()))
      40             :                : nullptr),
      41         180 :     _nvar(Coupleable::_coupled_standard_moose_vars.size()),
      42         180 :     _dLdarg(_nvar),
      43         360 :     _gradarg(_nvar)
      44             : {
      45             :   // Get mobility and kappa derivatives and coupled variable gradients
      46         180 :   if (_variable_L)
      47          34 :     for (unsigned int i = 0; i < _nvar; ++i)
      48             :     {
      49          17 :       MooseVariable * ivar = _coupled_standard_moose_vars[i];
      50             :       const VariableName iname = ivar->name();
      51          17 :       if (iname == _var.name())
      52           0 :         paramError("coupled_variables",
      53             :                    "The kernel variable should not be specified in the coupled `coupled_variables` "
      54             :                    "parameter.");
      55             : 
      56          34 :       _dLdarg[i] = &getADMaterialProperty<Real>(derivativePropertyNameFirst(_name_L, iname));
      57          17 :       _gradarg[i] = &(ivar->adGradSln());
      58             :     }
      59         180 : }
      60             : 
      61             : ADReal
      62   161910480 : ADACInterface::computeQpResidual()
      63             : {
      64             :   // nabla_Lpsi is the product rule gradient \f$ \nabla (L\psi) \f$
      65   161910480 :   ADRealVectorValue nabla_Lpsi = _prop_L[_qp] * _grad_test[_i][_qp];
      66             : 
      67   161910480 :   if (_variable_L)
      68             :   {
      69     2592000 :     ADRealVectorValue grad_L = _grad_u[_qp] * (*_dLdop)[_qp];
      70     5184000 :     for (unsigned int i = 0; i < _nvar; ++i)
      71     5184000 :       grad_L += (*_gradarg[i])[_qp] * (*_dLdarg[i])[_qp];
      72             : 
      73     5184000 :     nabla_Lpsi += grad_L * _test[_i][_qp];
      74             :   }
      75             : 
      76   161910480 :   return _grad_u[_qp] * _kappa[_qp] * nabla_Lpsi;
      77             : }

Generated by: LCOV version 1.14