LCOV - code coverage report
Current view: top level - src/kernels - ScalarLMKernel.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 23 26 88.5 %
Date: 2025-07-17 01:28:37 Functions: 11 14 78.6 %
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 "ScalarLMKernel.h"
      11             : 
      12             : registerMooseObject("MooseApp", ScalarLMKernel);
      13             : registerMooseObject("MooseApp", ADScalarLMKernel);
      14             : 
      15             : template <bool is_ad>
      16             : InputParameters
      17       28818 : ScalarLMKernelTempl<is_ad>::validParams()
      18             : {
      19       28818 :   InputParameters params = GenericKernelScalar<is_ad>::validParams();
      20       28818 :   params.addClassDescription("This class is used to enforce integral of phi = V_0 with a "
      21             :                              "Lagrange multiplier approach.");
      22       28818 :   params.renameCoupledVar("scalar_variable", "kappa", "Primary coupled scalar variable");
      23       28818 :   params.addRequiredParam<PostprocessorName>(
      24             :       "pp_name", "Name of the Postprocessor containing the volume of the domain.");
      25       28818 :   params.addRequiredParam<Real>(
      26             :       "value", "Given (constant) which we want the integral of the solution variable to match.");
      27             : 
      28       28818 :   return params;
      29           0 : }
      30             : 
      31             : template <bool is_ad>
      32         150 : ScalarLMKernelTempl<is_ad>::ScalarLMKernelTempl(const InputParameters & parameters)
      33             :   : GenericKernelScalar<is_ad>(parameters),
      34         150 :     _value(this->template getParam<Real>("value")),
      35         300 :     _pp_value(this->getPostprocessorValue("pp_name"))
      36             : {
      37         150 : }
      38             : 
      39             : template <bool is_ad>
      40             : GenericReal<is_ad>
      41      322056 : ScalarLMKernelTempl<is_ad>::computeQpResidual()
      42             : {
      43      322056 :   return _kappa[0] * _test[_i][_qp];
      44             : }
      45             : 
      46             : template <bool is_ad>
      47             : GenericReal<is_ad>
      48       35784 : ScalarLMKernelTempl<is_ad>::computeScalarQpResidual()
      49             : {
      50       70416 :   return _u[_qp] - _value / _pp_value;
      51             : }
      52             : 
      53             : template <bool is_ad>
      54             : Real
      55         576 : ScalarLMKernelTempl<is_ad>::computeScalarQpJacobian()
      56             : {
      57             :   // This function will never be called for the AD version. But because C++ does
      58             :   // not support an optional function declaration based on a template parameter,
      59             :   // we must keep this template for all cases.
      60             :   mooseAssert(
      61             :       !is_ad,
      62             :       "In ADScalarLMKernel, computeScalarQpJacobian should not be called. Check computeJacobian "
      63             :       "implementation.");
      64         576 :   return 0.;
      65             : }
      66             : 
      67             : template <bool is_ad>
      68             : Real
      69        5184 : ScalarLMKernelTempl<is_ad>::computeQpOffDiagJacobianScalar(unsigned int svar)
      70             : {
      71             :   // This function will never be called for the AD version. But because C++ does
      72             :   // not support an optional function declaration based on a template parameter,
      73             :   // we must keep this template for all cases.
      74             :   mooseAssert(!is_ad,
      75             :               "In ADScalarLMKernel, computeQpOffDiagJacobianScalar should not be called. Check "
      76             :               "computeOffDiagJacobianScalar "
      77             :               "implementation.");
      78        5184 :   if (svar == _kappa_var)
      79        5184 :     return _test[_i][_qp];
      80             :   else
      81           0 :     return 0.;
      82             : }
      83             : 
      84             : template <bool is_ad>
      85             : Real
      86        5184 : ScalarLMKernelTempl<is_ad>::computeScalarQpOffDiagJacobian(unsigned int jvar)
      87             : {
      88             :   // This function will never be called for the AD version. But because C++ does
      89             :   // not support an optional function declaration based on a template parameter,
      90             :   // we must keep this template for all cases.
      91             :   mooseAssert(!is_ad,
      92             :               "In ADScalarLMKernel, computeScalarQpOffDiagJacobian should not be called. Check "
      93             :               "computeOffDiagJacobian "
      94             :               "implementation.");
      95        5184 :   if (jvar == _var.number())
      96        5184 :     return _phi[_j][_qp];
      97             :   else
      98           0 :     return 0.;
      99             : }
     100             : 
     101             : template class ScalarLMKernelTempl<false>;
     102             : template class ScalarLMKernelTempl<true>;

Generated by: LCOV version 1.14