LCOV - code coverage report
Current view: top level - include/kokkos/bcs - KokkosDirichletBCBase.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 11 12 91.7 %
Date: 2026-05-29 20:35:17 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://www.mooseframework.org
       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             : #pragma once
      11             : 
      12             : #include "KokkosNodalBC.h"
      13             : #include "KokkosADNodalBC.h"
      14             : 
      15             : namespace Moose::Kokkos
      16             : {
      17             : 
      18             : /**
      19             :  * The base Kokkos boundary condition of a Dirichlet type
      20             :  */
      21             : template <bool is_ad>
      22             : class DirichletBCBaseTempl : public std::conditional_t<is_ad, ADNodalBC, NodalBC>
      23             : {
      24             :   using real_type = std::conditional_t<is_ad, ADReal, Real>;
      25             : 
      26             : public:
      27             :   static InputParameters validParams();
      28             : 
      29             :   /**
      30             :    * Constructor
      31             :    */
      32             :   DirichletBCBaseTempl(const InputParameters & parameters);
      33             : 
      34             :   /**
      35             :    * Get whether the value is to be preset
      36             :    * @returns Whether the value is to be preset
      37             :    */
      38        3377 :   virtual bool preset() const override { return _preset; }
      39             : 
      40             :   /**
      41             :    * Dispatch solution vector preset
      42             :    * @param tag The tag associated with the solution vector to be preset
      43             :    */
      44             :   virtual void presetSolution(TagID tag) override;
      45             : 
      46             :   /**
      47             :    * Function tag for preset loop
      48             :    */
      49             :   struct PresetLoop
      50             :   {
      51             :   };
      52             : 
      53             :   /**
      54             :    * The preset function called by Kokkos
      55             :    */
      56             :   template <typename Derived>
      57             :   KOKKOS_FUNCTION void operator()(PresetLoop, const ThreadID tid, const Derived & bc) const;
      58             : 
      59             :   template <typename Derived>
      60             :   KOKKOS_FUNCTION auto computeQpResidual(const unsigned int qp, AssemblyDatum & datum) const;
      61             : 
      62             :   using Base = std::conditional_t<is_ad, ADNodalBC, NodalBC>;
      63             :   using Base::operator();
      64             : 
      65             : protected:
      66             :   using Base::_kokkos_var;
      67             :   using Base::_u;
      68             :   using Base::kokkosAssembly;
      69             :   using Base::kokkosBoundaryNodeID;
      70             :   using Base::kokkosSystem;
      71             :   using Base::kokkosSystems;
      72             :   using Base::numKokkosBoundaryNodes;
      73             : 
      74             : private:
      75             :   /**
      76             :    * Flag whether the value is to be preset
      77             :    */
      78             :   const bool _preset;
      79             :   /**
      80             :    * Tag associated with the solution vector to be preset
      81             :    */
      82             :   TagID _solution_tag;
      83             : };
      84             : 
      85             : template <bool is_ad>
      86             : template <typename Derived>
      87             : KOKKOS_FUNCTION void
      88       27909 : DirichletBCBaseTempl<is_ad>::operator()(PresetLoop, const ThreadID tid, const Derived & bc) const
      89             : {
      90       27909 :   auto node = kokkosBoundaryNodeID(tid);
      91       27909 :   auto & sys = kokkosSystem(_kokkos_var.sys());
      92       27909 :   auto dof = sys.getNodeLocalDofIndex(node, 0, _kokkos_var.var());
      93             : 
      94       27909 :   if (dof == libMesh::DofObject::invalid_id)
      95           0 :     return;
      96             : 
      97       27909 :   AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var());
      98             : 
      99       27909 :   sys.getVectorDofValue(dof, _solution_tag) = bc.computeValue(0, datum);
     100             : }
     101             : 
     102             : template <bool is_ad>
     103             : template <typename Derived>
     104             : KOKKOS_FUNCTION auto
     105      458802 : DirichletBCBaseTempl<is_ad>::computeQpResidual(const unsigned int qp, AssemblyDatum & datum) const
     106             : {
     107      458802 :   auto bc = static_cast<const Derived *>(this);
     108             : 
     109      458802 :   return _u(datum, qp) - real_type(bc->computeValue(qp, datum));
     110             : }
     111             : 
     112             : typedef DirichletBCBaseTempl<false> DirichletBCBase;
     113             : typedef DirichletBCBaseTempl<true> ADDirichletBCBase;
     114             : 
     115             : } // namespace Moose::Kokkos
     116             : 
     117             : #define registerKokkosDirichletBC(app, classname)                                                  \
     118             :   registerKokkosResidualObject(app, classname);                                                    \
     119             :   registerKokkosAdditionalOperation(classname, PresetLoop)
     120             : 
     121             : #define registerKokkosADDirichletBC(app, classname)                                                \
     122             :   registerKokkosADResidualObject(app, classname);                                                  \
     123             :   registerKokkosAdditionalOperation(classname, PresetLoop)

Generated by: LCOV version 1.14