LCOV - code coverage report
Current view: top level - src/dirackernels - ADDiracKernel.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 48 57 84.2 %
Date: 2026-05-29 20:35:17 Functions: 7 9 77.8 %
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 "ADDiracKernel.h"
      11             : #include "DiracKernelInfo.h"
      12             : #include "Assembly.h"
      13             : #include "SystemBase.h"
      14             : #include "Problem.h"
      15             : #include "MooseMesh.h"
      16             : 
      17             : #include "libmesh/libmesh_common.h"
      18             : #include "libmesh/quadrature.h"
      19             : 
      20             : InputParameters
      21        3105 : ADDiracKernel::validParams()
      22             : {
      23        3105 :   InputParameters params = DiracKernelBase::validParams();
      24        3105 :   params += ADFunctorInterface::validParams();
      25        3105 :   params.registerBase("DiracKernel");
      26        3105 :   return params;
      27           0 : }
      28             : 
      29          23 : ADDiracKernel::ADDiracKernel(const InputParameters & parameters)
      30             :   : DiracKernelBase(parameters),
      31             :     MooseVariableInterface<Real>(this,
      32             :                                  false,
      33             :                                  "variable",
      34             :                                  Moose::VarKindType::VAR_SOLVER,
      35             :                                  Moose::VarFieldType::VAR_FIELD_STANDARD),
      36             :     ADFunctorInterface(this),
      37          46 :     _var(this->mooseVariableField()),
      38          23 :     _phi(_assembly.phi(_var)),
      39          23 :     _test(_var.phi()),
      40          23 :     _u(_var.adSln()),
      41          92 :     _grad_u(_var.adGradSln())
      42             : {
      43          23 :   _subproblem.haveADObjects(true);
      44             : 
      45          23 :   addMooseVariableDependency(&this->mooseVariableField());
      46             : 
      47             :   // Stateful material properties are not allowed on DiracKernels
      48          23 :   statefulPropertiesAllowed(false);
      49          23 : }
      50             : 
      51             : void
      52          67 : ADDiracKernel::jacobianSetup()
      53             : {
      54          67 :   _last_jacobian_elem = nullptr;
      55          67 : }
      56             : 
      57             : void
      58         212 : ADDiracKernel::computeResidual()
      59             : {
      60         212 :   prepareVectorTag(_assembly, _var.number());
      61             : 
      62         212 :   computeADResiduals();
      63             : 
      64         636 :   for (const auto i : index_range(_ad_residuals))
      65         424 :     _local_re(i) = raw_value(_ad_residuals[i]);
      66             : 
      67         212 :   accumulateTaggedLocalResidual();
      68         212 : }
      69             : 
      70             : void
      71           0 : ADDiracKernel::computeJacobian()
      72             : {
      73           0 :   computeFullJacobian();
      74           0 : }
      75             : 
      76             : void
      77          86 : ADDiracKernel::computeOffDiagJacobian(const unsigned int /*jvar*/)
      78             : {
      79          86 :   if (_last_jacobian_elem != _current_elem)
      80             :   {
      81          43 :     computeFullJacobian();
      82          43 :     _last_jacobian_elem = _current_elem;
      83             :   }
      84          86 : }
      85             : 
      86             : void
      87          43 : ADDiracKernel::computeFullJacobian()
      88             : {
      89          43 :   computeADResiduals();
      90          43 :   addJacobian(_assembly, _ad_residuals, _var.dofIndices(), _var.scalingFactor());
      91          43 : }
      92             : 
      93             : void
      94           0 : ADDiracKernel::computeResidualAndJacobian()
      95             : {
      96           0 :   computeADResiduals();
      97           0 :   addResidualsAndJacobian(_assembly, _ad_residuals, _var.dofIndices(), _var.scalingFactor());
      98           0 : }
      99             : 
     100             : void
     101         255 : ADDiracKernel::computeADResiduals()
     102             : {
     103         255 :   _ad_residuals.resize(_test.size());
     104         255 :   std::fill(_ad_residuals.begin(), _ad_residuals.end(), 0);
     105             : 
     106         255 :   precalculateResidual();
     107             : 
     108             :   const std::vector<Real> * point_values =
     109         255 :       _drop_duplicate_points ? NULL : &_local_dirac_kernel_info.getPoints()[_current_elem].second;
     110         255 :   unsigned int local_qp = 0;
     111         255 :   Real point_value = 1.0;
     112             : 
     113         510 :   for (_qp = 0; _qp < _qrule->n_points(); _qp++)
     114             :   {
     115         255 :     _current_point = _physical_point[_qp];
     116         255 :     if (isActiveAtPoint(_current_elem, _current_point))
     117             :     {
     118         255 :       if (!_drop_duplicate_points)
     119           0 :         point_value = (*point_values)[local_qp++];
     120             : 
     121         765 :       for (_i = 0; _i < _test.size(); _i++)
     122         510 :         _ad_residuals[_i] += point_value * computeQpResidual();
     123             :     }
     124             :   }
     125         255 : }

Generated by: LCOV version 1.14