LCOV - code coverage report
Current view: top level - include/kokkos/nodalkernels - KokkosBoundNodalKernel.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 6f668f Lines: 32 34 94.1 %
Date: 2025-09-22 20:01:15 Functions: 12 12 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             : #pragma once
      11             : 
      12             : #include "KokkosNodalKernel.h"
      13             : 
      14             : template <typename Derived>
      15             : class KokkosBoundNodalKernel : public Moose::Kokkos::NodalKernel<Derived>
      16             : {
      17             :   usingKokkosNodalKernelMembers(Derived);
      18             : 
      19             : public:
      20             :   static InputParameters validParams();
      21             : 
      22             :   KokkosBoundNodalKernel(const InputParameters & parameters);
      23             : 
      24             :   KOKKOS_FUNCTION Real computeQpResidual(const ContiguousNodeID node) const;
      25             :   KOKKOS_FUNCTION Real computeQpJacobian(const ContiguousNodeID node) const;
      26             :   KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int jvar,
      27             :                                                 const ContiguousNodeID node) const;
      28             : 
      29             : protected:
      30             :   /// The number of the coupled variable
      31             :   const unsigned int _v_var;
      32             : 
      33             :   /// The value of the coupled variable
      34             :   const Moose::Kokkos::VariableNodalValue _v;
      35             : 
      36             : private:
      37             :   KOKKOS_FUNCTION bool skipOnBoundary(const ContiguousNodeID node) const;
      38             : 
      39             :   /// Boundaries on which we should not execute this object
      40             :   Moose::Kokkos::Array<ContiguousBoundaryID> _bnd_ids;
      41             : };
      42             : 
      43             : template <typename Derived>
      44             : InputParameters
      45       18380 : KokkosBoundNodalKernel<Derived>::validParams()
      46             : {
      47       18380 :   InputParameters params = Moose::Kokkos::NodalKernel<Derived>::validParams();
      48       73520 :   params.addRequiredCoupledVar(
      49             :       "v", "The coupled variable we require to be greater than the lower bound");
      50       55140 :   params.addParam<std::vector<BoundaryName>>(
      51             :       "exclude_boundaries",
      52             :       {},
      53             :       "Boundaries on which not to execute the nodal kernel. This can be useful for avoiding "
      54             :       "singuarility in the matrix in case a constraint is active in the same place that a "
      55             :       "Dirichlet BC is set");
      56       18380 :   return params;
      57           0 : }
      58             : 
      59             : template <typename Derived>
      60         144 : KokkosBoundNodalKernel<Derived>::KokkosBoundNodalKernel(const InputParameters & parameters)
      61             :   : Moose::Kokkos::NodalKernel<Derived>(parameters),
      62          64 :     _v_var(this->coupled("v")),
      63         256 :     _v(this->kokkosCoupledNodalValue("v"))
      64             : {
      65          80 :   if (_var.number() == _v_var)
      66           0 :     this->paramError("v", "Coupled variable needs to be different from 'variable'");
      67             : 
      68          80 :   std::set<ContiguousBoundaryID> bnd_ids;
      69             : 
      70         160 :   const auto & bnd_names = this->template getParam<std::vector<BoundaryName>>("exclude_boundaries");
      71         240 :   for (const auto & bnd_id : this->_mesh.getBoundaryIDs(bnd_names))
      72         160 :     bnd_ids.insert(this->kokkosMesh().getContiguousBoundaryID(bnd_id));
      73             : 
      74          80 :   _bnd_ids = bnd_ids;
      75          80 : }
      76             : 
      77             : template <typename Derived>
      78             : KOKKOS_FUNCTION bool
      79      334110 : KokkosBoundNodalKernel<Derived>::skipOnBoundary(const ContiguousNodeID node) const
      80             : {
      81      991080 :   for (dof_id_type b = 0; b < _bnd_ids.size(); ++b)
      82      664470 :     if (this->kokkosMesh().isBoundaryNode(node, _bnd_ids[b]))
      83        7500 :       return true;
      84             : 
      85      326610 :   return false;
      86             : }
      87             : 
      88             : template <typename Derived>
      89             : KOKKOS_FUNCTION Real
      90      117744 : KokkosBoundNodalKernel<Derived>::computeQpResidual(const ContiguousNodeID node) const
      91             : {
      92      117744 :   if (skipOnBoundary(node))
      93        2688 :     return _u(node);
      94             : 
      95      115056 :   return static_cast<const Derived *>(this)->getResidual(node);
      96             : }
      97             : 
      98             : template <typename Derived>
      99             : KOKKOS_FUNCTION Real
     100       91816 : KokkosBoundNodalKernel<Derived>::computeQpJacobian(const ContiguousNodeID node) const
     101             : {
     102       91816 :   if (skipOnBoundary(node))
     103        2032 :     return 1;
     104             : 
     105       89784 :   return static_cast<const Derived *>(this)->getJacobian(node);
     106             : }
     107             : 
     108             : template <typename Derived>
     109             : KOKKOS_FUNCTION Real
     110      124550 : KokkosBoundNodalKernel<Derived>::computeQpOffDiagJacobian(const unsigned int jvar,
     111             :                                                           const ContiguousNodeID node) const
     112             : {
     113      124550 :   if (skipOnBoundary(node))
     114        2780 :     return 0;
     115             : 
     116      121770 :   return static_cast<const Derived *>(this)->getOffDiagJacobian(jvar, node);
     117             : }

Generated by: LCOV version 1.14