LCOV - code coverage report
Current view: top level - include/kokkos/kernels - KokkosBodyForce.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 6f668f Lines: 13 14 92.9 %
Date: 2025-09-22 20:01:15 Functions: 6 6 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 "KokkosKernel.h"
      13             : 
      14             : template <typename Derived>
      15             : class KokkosBodyForce : public Moose::Kokkos::Kernel<Derived>
      16             : {
      17             :   usingKokkosKernelMembers(Derived);
      18             : 
      19             : public:
      20             :   static InputParameters validParams();
      21             : 
      22             :   KokkosBodyForce(const InputParameters & parameters);
      23             : 
      24             :   KOKKOS_FUNCTION Real computeQpResidual(const unsigned int i,
      25             :                                          const unsigned int qp,
      26             :                                          ResidualDatum & datum) const;
      27             : 
      28             : protected:
      29             :   /// Scale factor
      30             :   const Moose::Kokkos::Scalar<const Real> _scale;
      31             : 
      32             :   /// Optional Postprocessor value
      33             :   const Moose::Kokkos::PostprocessorValue _postprocessor;
      34             : };
      35             : 
      36             : template <typename Derived>
      37             : InputParameters
      38       18380 : KokkosBodyForce<Derived>::validParams()
      39             : {
      40       18380 :   InputParameters params = Moose::Kokkos::Kernel<Derived>::validParams();
      41       73520 :   params.addParam<Real>("value", 1.0, "Coefficient to multiply by the body force term");
      42       36796 :   params.addParam<PostprocessorName>(
      43       36688 :       "postprocessor", 1, "A postprocessor whose value is multiplied by the body force");
      44       55140 :   params.declareControllable("value");
      45       18380 :   return params;
      46           0 : }
      47             : 
      48             : template <typename Derived>
      49         135 : KokkosBodyForce<Derived>::KokkosBodyForce(const InputParameters & parameters)
      50             :   : Moose::Kokkos::Kernel<Derived>(parameters),
      51          63 :     _scale(this->template getParam<Real>("value")),
      52         189 :     _postprocessor(getPostprocessorValue("postprocessor"))
      53             : {
      54          81 : }
      55             : 
      56             : template <typename Derived>
      57             : KOKKOS_FUNCTION Real
      58      580880 : KokkosBodyForce<Derived>::computeQpResidual(const unsigned int i,
      59             :                                             const unsigned int qp,
      60             :                                             ResidualDatum & datum) const
      61             : {
      62      580880 :   return -_test(datum, i, qp) * _scale * _postprocessor;
      63             : }
      64             : 
      65             : class KokkosBodyForceKernel final : public KokkosBodyForce<KokkosBodyForceKernel>
      66             : {
      67             : public:
      68             :   static InputParameters validParams();
      69             : 
      70             :   KokkosBodyForceKernel(const InputParameters & parameters);
      71             : };

Generated by: LCOV version 1.14