LCOV - code coverage report
Current view: top level - src/raykernels - ADRayKernel.C (source / functions) Hit Total Coverage
Test: idaholab/moose ray_tracing: #31405 (292dce) with base fef103 Lines: 44 45 97.8 %
Date: 2025-09-04 07:56:07 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 "ADRayKernel.h"
      11             : 
      12             : // Local includes
      13             : #include "RayTracingStudy.h"
      14             : 
      15             : // MOOSE includes
      16             : #include "Assembly.h"
      17             : #include "NonlinearSystemBase.h"
      18             : #include "ADUtils.h"
      19             : 
      20             : template <typename T>
      21             : InputParameters
      22         105 : ADRayKernelTempl<T>::validParams()
      23             : {
      24         105 :   auto params = IntegralRayKernelBase::validParams();
      25         105 :   params += TaggingInterface::validParams();
      26             : 
      27         210 :   params.template addRequiredParam<NonlinearVariableName>(
      28             :       "variable", "The name of the variable that this ADRayKernel operates on");
      29             : 
      30         105 :   return params;
      31           0 : }
      32             : 
      33             : template <typename T>
      34          59 : ADRayKernelTempl<T>::ADRayKernelTempl(const InputParameters & params)
      35             :   : IntegralRayKernelBase(params),
      36             :     MooseVariableInterface<T>(this,
      37             :                               false,
      38             :                               "variable",
      39             :                               Moose::VarKindType::VAR_SOLVER,
      40             :                               std::is_same<T, Real>::value ? Moose::VarFieldType::VAR_FIELD_STANDARD
      41             :                                                            : Moose::VarFieldType::VAR_FIELD_VECTOR),
      42             :     TaggingInterface(this),
      43         118 :     _var(this->mooseVariableField()),
      44          59 :     _test(_var.phi()),
      45          59 :     _u(_var.adSln()),
      46          59 :     _grad_u(_var.adGradSln()),
      47         177 :     _phi(_assembly.phi(_var))
      48             : {
      49             :   // We do not allow RZ/RSPHERICAL because in the context of these coord
      50             :   // systems there is no way to represent a line source - we would end up
      51             :   // with a plane/surface source or a volumetric source, respectively.
      52             :   // This is also why we do not multiply by _coord[_qp] in any of the
      53             :   // integrations that follow.
      54         116 :   for (const auto & subdomain_id : _mesh.meshSubdomains())
      55          59 :     if (_fe_problem.getCoordSystem(subdomain_id) != Moose::COORD_XYZ)
      56           2 :       mooseError("Not valid on coordinate systems other than XYZ");
      57             : 
      58          57 :   _subproblem.haveADObjects(true);
      59             : 
      60          57 :   addMooseVariableDependency(&variable());
      61             : 
      62          57 :   if (!isImplicit())
      63           2 :     mooseError("ADRayKernels do not currently support explicit solves.");
      64          55 : }
      65             : 
      66             : template <typename T>
      67             : void
      68       14224 : ADRayKernelTempl<T>::onSegment()
      69             : {
      70             :   mooseAssert(_current_subdomain_id == _assembly.currentSubdomainID(), "Subdomain IDs not in sync");
      71             :   mooseAssert(_fe_problem.currentlyComputingJacobian() || _fe_problem.currentlyComputingResidual(),
      72             :               "Not computing residual or Jacobian");
      73             : 
      74       14224 :   if (_fe_problem.currentlyComputingJacobian())
      75         606 :     computeJacobian();
      76       13618 :   else if (_fe_problem.currentlyComputingResidual())
      77       13618 :     computeResidual();
      78       14224 : }
      79             : 
      80             : template <typename T>
      81             : void
      82       13618 : ADRayKernelTempl<T>::computeResidual()
      83             : {
      84       13618 :   prepareVectorTag(_assembly, _var.number());
      85             : 
      86       13618 :   precalculateResidual();
      87       40062 :   for (_qp = 0; _qp < _JxW.size(); _qp++)
      88      129844 :     for (_i = 0; _i < _test.size(); _i++)
      89      206800 :       _local_re(_i) += raw_value(_JxW[_qp] * computeQpResidual());
      90             : 
      91       13618 :   accumulateTaggedLocalResidual();
      92       13618 : }
      93             : 
      94             : template <typename T>
      95             : void
      96         606 : ADRayKernelTempl<T>::computeJacobian()
      97             : {
      98         606 :   _subproblem.prepareShapes(_var.number(), _tid);
      99             : 
     100        2479 :   for (auto & r : _residuals)
     101        1873 :     r = 0;
     102         606 :   _residuals.resize(_test.size(), 0);
     103             : 
     104         606 :   precalculateResidual();
     105        1674 :   for (_qp = 0; _qp < _JxW.size(); _qp++)
     106        4908 :     for (_i = 0; _i < _test.size(); _i++)
     107        7680 :       _residuals[_i] += _JxW[_qp] * computeQpResidual();
     108             : 
     109         606 :   addJacobian(_assembly, _residuals, _var.dofIndices(), _var.scalingFactor());
     110         606 : }
     111             : 
     112             : template class ADRayKernelTempl<Real>;
     113             : 
     114             : // Not implementing this until there is a use case and tests for it!
     115             : // template class ADRayKernelTempl<RealVectorValue>;

Generated by: LCOV version 1.14