LCOV - code coverage report
Current view: top level - src/dirackernels - ADDiracKernel.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: d8769b Lines: 48 57 84.2 %
Date: 2025-11-07 20:01:30 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       15035 : ADDiracKernel::validParams()
      22             : {
      23       15035 :   InputParameters params = DiracKernelBase::validParams();
      24       15035 :   params += ADFunctorInterface::validParams();
      25       15035 :   params.registerBase("DiracKernel");
      26       15035 :   return params;
      27           0 : }
      28             : 
      29          25 : 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          50 :     _var(this->mooseVariableField()),
      38          25 :     _phi(_assembly.phi(_var)),
      39          25 :     _test(_var.phi()),
      40          25 :     _u(_var.adSln()),
      41         100 :     _grad_u(_var.adGradSln())
      42             : {
      43          25 :   _subproblem.haveADObjects(true);
      44             : 
      45          25 :   addMooseVariableDependency(&this->mooseVariableField());
      46             : 
      47             :   // Stateful material properties are not allowed on DiracKernels
      48          25 :   statefulPropertiesAllowed(false);
      49          25 : }
      50             : 
      51             : void
      52          73 : ADDiracKernel::jacobianSetup()
      53             : {
      54          73 :   _last_jacobian_elem = nullptr;
      55          73 : }
      56             : 
      57             : void
      58         245 : ADDiracKernel::computeResidual()
      59             : {
      60         245 :   prepareVectorTag(_assembly, _var.number());
      61             : 
      62         245 :   computeADResiduals();
      63             : 
      64         735 :   for (const auto i : index_range(_ad_residuals))
      65         490 :     _local_re(i) = raw_value(_ad_residuals[i]);
      66             : 
      67         245 :   accumulateTaggedLocalResidual();
      68         245 : }
      69             : 
      70             : void
      71           0 : ADDiracKernel::computeJacobian()
      72             : {
      73           0 :   computeFullJacobian();
      74           0 : }
      75             : 
      76             : void
      77          98 : ADDiracKernel::computeOffDiagJacobian(const unsigned int /*jvar*/)
      78             : {
      79          98 :   if (_last_jacobian_elem != _current_elem)
      80             :   {
      81          49 :     computeFullJacobian();
      82          49 :     _last_jacobian_elem = _current_elem;
      83             :   }
      84          98 : }
      85             : 
      86             : void
      87          49 : ADDiracKernel::computeFullJacobian()
      88             : {
      89          49 :   computeADResiduals();
      90          49 :   addJacobian(_assembly, _ad_residuals, _var.dofIndices(), _var.scalingFactor());
      91          49 : }
      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         294 : ADDiracKernel::computeADResiduals()
     102             : {
     103         294 :   _ad_residuals.resize(_test.size());
     104         294 :   std::fill(_ad_residuals.begin(), _ad_residuals.end(), 0);
     105             : 
     106         294 :   precalculateResidual();
     107             : 
     108             :   const std::vector<unsigned int> * multiplicities =
     109         294 :       _drop_duplicate_points ? NULL : &_local_dirac_kernel_info.getPoints()[_current_elem].second;
     110         294 :   unsigned int local_qp = 0;
     111         294 :   Real multiplicity = 1.0;
     112             : 
     113         588 :   for (_qp = 0; _qp < _qrule->n_points(); _qp++)
     114             :   {
     115         294 :     _current_point = _physical_point[_qp];
     116         294 :     if (isActiveAtPoint(_current_elem, _current_point))
     117             :     {
     118         294 :       if (!_drop_duplicate_points)
     119           0 :         multiplicity = (*multiplicities)[local_qp++];
     120             : 
     121         882 :       for (_i = 0; _i < _test.size(); _i++)
     122         588 :         _ad_residuals[_i] += multiplicity * computeQpResidual();
     123             :     }
     124             :   }
     125         294 : }

Generated by: LCOV version 1.14