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 "KokkosLinearFVKernel.h" 13 : #include "KokkosDatum.h" 14 : 15 : namespace Moose::Kokkos 16 : { 17 : 18 : /** 19 : * Base class for Kokkos linear finite volume kernels that contribute on elements (volumetric terms) 20 : */ 21 : class LinearFVElementalKernel : public LinearFVKernel 22 : { 23 : public: 24 : static InputParameters validParams(); 25 : 26 : LinearFVElementalKernel(const InputParameters & parameters); 27 : LinearFVElementalKernel(const LinearFVElementalKernel & object); 28 : 29 : virtual void computeRightHandSide() override; 30 : virtual void computeMatrix() override; 31 : 32 : /** 33 : * Right-hand side dispatch loop body; accumulates the elemental RHS contribution 34 : * @param tid The thread ID of the current element 35 : * @param kernel The derived kernel object whose contribution methods are invoked 36 : */ 37 : template <typename Derived> 38 : KOKKOS_FUNCTION void 39 : operator()(RightHandSideLoop, const ThreadID tid, const Derived & kernel) const; 40 : 41 : /** 42 : * Matrix dispatch loop body; accumulates the elemental matrix contribution 43 : * @param tid The thread ID of the current element 44 : * @param kernel The derived kernel object whose contribution methods are invoked 45 : */ 46 : template <typename Derived> 47 : KOKKOS_FUNCTION void operator()(MatrixLoop, const ThreadID tid, const Derived & kernel) const; 48 : }; 49 : 50 : template <typename Derived> 51 : KOKKOS_FUNCTION void 52 10610 : LinearFVElementalKernel::operator()(RightHandSideLoop, 53 : const ThreadID tid, 54 : const Derived & kernel) const 55 : { 56 10610 : const auto elem = kokkosBlockElementID(tid); 57 10610 : FVDatum datum(elem, libMesh::invalid_uint, kokkosMesh()); 58 : KOKKOS_ASSERT(_var.components() == 1); 59 10610 : const auto & sys = kokkosSystem(_var.sys()); 60 10610 : kernel.template accumulateTaggedVector<AccumulationMode::NonAtomic>( 61 : kernel.template computeRightHandSideContribution<Derived>(datum), 62 : sys.getElemLocalDofIndex(elem, 0, _var.var())); 63 10610 : } 64 : 65 : template <typename Derived> 66 : KOKKOS_FUNCTION void 67 0 : LinearFVElementalKernel::operator()(MatrixLoop, const ThreadID tid, const Derived & kernel) const 68 : { 69 0 : const auto elem = kokkosBlockElementID(tid); 70 0 : FVDatum datum(elem, libMesh::invalid_uint, kokkosMesh()); 71 : KOKKOS_ASSERT(_var.components() == 1); 72 0 : const auto & sys = kokkosSystem(_var.sys()); 73 0 : const auto var_num = _var.var(); 74 0 : const auto row = sys.getElemLocalDofIndex(elem, 0, var_num); 75 0 : kernel.template accumulateTaggedMatrix<AccumulationMode::NonAtomic>( 76 : kernel.template computeMatrixContribution<Derived>(datum), 77 : row, 78 : sys.getElemGlobalDofIndex(elem, 0, var_num)); 79 0 : } 80 : 81 : } // namespace Moose::Kokkos