LCOV - code coverage report
Current view: top level - include/kokkos/bcs - KokkosDirichletBCBase.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31706 (f8ed4a) with base bb0a08 Lines: 25 27 92.6 %
Date: 2025-11-03 17:23:24 Functions: 11 11 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             : 
      14             : namespace Moose
      15             : {
      16             : namespace Kokkos
      17             : {
      18             : 
      19             : /**
      20             :  * The base Kokkos boundary condition of a Dirichlet type
      21             :  */
      22             : template <typename Derived>
      23             : class DirichletBCBase : public NodalBC
      24             : {
      25             : public:
      26             :   static InputParameters validParams();
      27             : 
      28             :   /**
      29             :    * Constructor
      30             :    */
      31             :   DirichletBCBase(const InputParameters & parameters);
      32             : 
      33             :   /**
      34             :    * Get whether the value is to be preset
      35             :    * @returns Whether the value is to be preset
      36             :    */
      37        1213 :   virtual bool preset() const override { return _preset; }
      38             : 
      39             :   /**
      40             :    * Dispatch solution vector preset
      41             :    * @param tag The tag associated with the solution vector to be preset
      42             :    */
      43             :   virtual void presetSolution(TagID tag) override;
      44             : 
      45             :   /**
      46             :    * The preset function called by Kokkos
      47             :    */
      48             :   KOKKOS_FUNCTION void operator()(const ThreadID tid) const;
      49             : 
      50             :   /**
      51             :    * Compute residual contribution on a node
      52             :    * @param qp The dummy quadrature point index (= 0)
      53             :    * @param datum The AssemblyDatum object of the current thread
      54             :    * @returns The residual contribution
      55             :    */
      56             :   KOKKOS_FUNCTION Real computeQpResidual(const unsigned int qp, AssemblyDatum & datum) const;
      57             : 
      58             : private:
      59             :   /**
      60             :    * Flag whether the value is to be preset
      61             :    */
      62             :   const bool _preset;
      63             :   /**
      64             :    * Tag associated with the solution vector to be preset
      65             :    */
      66             :   TagID _solution_tag;
      67             : };
      68             : 
      69             : template <typename Derived>
      70             : InputParameters
      71       20898 : DirichletBCBase<Derived>::validParams()
      72             : {
      73       20898 :   InputParameters params = NodalBC::validParams();
      74       42376 :   params.addParam<bool>(
      75       40636 :       "preset", true, "Whether or not to preset the BC (apply the value before the solve begins).");
      76       20898 :   return params;
      77           0 : }
      78             : 
      79             : template <typename Derived>
      80        1502 : DirichletBCBase<Derived>::DirichletBCBase(const InputParameters & parameters)
      81        1848 :   : NodalBC(parameters), _preset(getParam<bool>("preset"))
      82             : {
      83        1213 : }
      84             : 
      85             : template <typename Derived>
      86             : void
      87        3362 : DirichletBCBase<Derived>::presetSolution(TagID tag)
      88             : {
      89        3362 :   _solution_tag = tag;
      90             : 
      91        3362 :   ::Kokkos::parallel_for(
      92        5418 :       ::Kokkos::RangePolicy<ExecSpace, ::Kokkos::IndexType<ThreadID>>(0, numKokkosBoundaryNodes()),
      93             :       *static_cast<Derived *>(this));
      94        3362 : }
      95             : 
      96             : template <typename Derived>
      97             : KOKKOS_FUNCTION void
      98       18075 : DirichletBCBase<Derived>::operator()(const ThreadID tid) const
      99             : {
     100       18075 :   auto bc = static_cast<const Derived *>(this);
     101       18075 :   auto node = kokkosBoundaryNodeID(tid);
     102       18075 :   auto & sys = kokkosSystem(_kokkos_var.sys());
     103       18075 :   auto dof = sys.getNodeLocalDofIndex(node, 0, _kokkos_var.var());
     104             : 
     105       18075 :   if (dof == libMesh::DofObject::invalid_id)
     106           0 :     return;
     107             : 
     108       18075 :   AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var());
     109             : 
     110       18075 :   sys.getVectorDofValue(dof, _solution_tag) = bc->computeValue(0, datum);
     111             : }
     112             : 
     113             : template <typename Derived>
     114             : KOKKOS_FUNCTION Real
     115      269951 : DirichletBCBase<Derived>::computeQpResidual(const unsigned int qp, AssemblyDatum & datum) const
     116             : {
     117      269951 :   auto bc = static_cast<const Derived *>(this);
     118             : 
     119      269951 :   return _u(datum, qp) - bc->computeValue(qp, datum);
     120             : }
     121             : 
     122             : } // namespace Kokkos
     123             : } // namespace Moose
     124             : 
     125             : #define usingKokkosDirichletBCBaseMembers(T)                                                       \
     126             : public:                                                                                            \
     127             :   using Moose::Kokkos::DirichletBCBase<T>::operator();                                             \
     128             :   using Moose::Kokkos::NodalBC::operator();                                                        \
     129             :                                                                                                    \
     130             : protected:                                                                                         \
     131             :   using Moose::Kokkos::NodalBC::_u

Generated by: LCOV version 1.14