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 "KokkosTimeKernel.h" 13 : 14 : template <typename Derived> 15 : class KokkosTimeDerivative : public Moose::Kokkos::TimeKernel<Derived> 16 : { 17 : usingKokkosTimeKernelMembers(Derived); 18 : 19 : public: 20 : static InputParameters validParams(); 21 : 22 : KokkosTimeDerivative(const InputParameters & parameters); 23 : 24 : KOKKOS_FUNCTION void computeJacobianInternal(const Derived * kernel, ResidualDatum & datum) const; 25 : 26 : KOKKOS_FUNCTION Real computeQpResidual(const unsigned int i, 27 : const unsigned int qp, 28 : ResidualDatum & datum) const; 29 : KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int i, 30 : const unsigned int j, 31 : const unsigned int qp, 32 : ResidualDatum & datum) const; 33 : 34 : protected: 35 : const bool _lumping; 36 : }; 37 : 38 : template <typename Derived> 39 : InputParameters 40 9654 : KokkosTimeDerivative<Derived>::validParams() 41 : { 42 9654 : InputParameters params = Moose::Kokkos::TimeKernel<Derived>::validParams(); 43 28962 : params.addParam<bool>("lumping", false, "True for mass matrix lumping, false otherwise"); 44 9654 : return params; 45 0 : } 46 : 47 : template <typename Derived> 48 334 : KokkosTimeDerivative<Derived>::KokkosTimeDerivative(const InputParameters & parameters) 49 : : Moose::Kokkos::TimeKernel<Derived>(parameters), 50 420 : _lumping(this->template getParam<bool>("lumping")) 51 : { 52 272 : } 53 : 54 : template <typename Derived> 55 : KOKKOS_FUNCTION void 56 192050 : KokkosTimeDerivative<Derived>::computeJacobianInternal(const Derived * kernel, 57 : ResidualDatum & datum) const 58 : { 59 : using Moose::Kokkos::MAX_CACHED_DOF; 60 : 61 : Real local_ke[MAX_CACHED_DOF]; 62 : 63 192050 : unsigned int num_batches = datum.n_idofs() * datum.n_jdofs() / MAX_CACHED_DOF; 64 : 65 192050 : if ((datum.n_idofs() * datum.n_jdofs()) % MAX_CACHED_DOF) 66 192050 : ++num_batches; 67 : 68 407908 : for (unsigned int batch = 0; batch < num_batches; ++batch) 69 : { 70 215858 : unsigned int ijb = batch * MAX_CACHED_DOF; 71 215858 : unsigned int ije = ::Kokkos::min(ijb + MAX_CACHED_DOF, datum.n_idofs() * datum.n_jdofs()); 72 : 73 2964610 : for (unsigned int ij = ijb; ij < ije; ++ij) 74 2748752 : local_ke[ij - ijb] = 0; 75 : 76 1072898 : for (unsigned int qp = 0; qp < datum.n_qps(); ++qp) 77 : { 78 857040 : datum.reinit(); 79 : 80 14302512 : for (unsigned int ij = ijb; ij < ije; ++ij) 81 : { 82 13445472 : unsigned int i = ij % datum.n_jdofs(); 83 13445472 : unsigned int j = ij / datum.n_jdofs(); 84 : 85 13445472 : local_ke[ij - ijb] += datum.JxW(qp) * kernel->computeQpJacobian(i, j, qp, datum); 86 : } 87 : } 88 : 89 2964610 : for (unsigned int ij = ijb; ij < ije; ++ij) 90 : { 91 2748752 : unsigned int i = ij % datum.n_jdofs(); 92 2748752 : unsigned int j = ij / datum.n_jdofs(); 93 : 94 5497504 : accumulateTaggedElementalMatrix( 95 5497504 : local_ke[ij - ijb], datum.elem().id, i, _lumping ? i : j, datum.jvar()); 96 : } 97 : } 98 192050 : } 99 : 100 : template <typename Derived> 101 : KOKKOS_FUNCTION Real 102 17933936 : KokkosTimeDerivative<Derived>::computeQpResidual(const unsigned int i, 103 : const unsigned int qp, 104 : ResidualDatum & datum) const 105 : { 106 17933936 : return _test(datum, i, qp) * _u_dot(datum, qp); 107 : } 108 : 109 : template <typename Derived> 110 : KOKKOS_FUNCTION Real 111 13445472 : KokkosTimeDerivative<Derived>::computeQpJacobian(const unsigned int i, 112 : const unsigned int j, 113 : const unsigned int qp, 114 : ResidualDatum & datum) const 115 : { 116 13445472 : return _test(datum, i, qp) * _phi(datum, j, qp) * _du_dot_du; 117 : } 118 : 119 : class KokkosTimeDerivativeKernel final : public KokkosTimeDerivative<KokkosTimeDerivativeKernel> 120 : { 121 : public: 122 : static InputParameters validParams(); 123 : 124 : KokkosTimeDerivativeKernel(const InputParameters & parameters); 125 : };