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 "KokkosIntegratedBC.h" 13 : 14 : namespace Moose::Kokkos 15 : { 16 : 17 : /** 18 : * The base class for a user to derive their own Kokkos integrated boundary conditions where the 19 : * residual is of the form 20 : * 21 : * $(\dots, \psi_i)$ 22 : * 23 : * i.e. the test function $(\psi_i)$ can be factored out for optimization. 24 : * 25 : * The user should now define precomputeQpResidual(), precomputeQpJacobian(), and 26 : * precomputeQpOffDiagJacobian() which do not include the test function, instead of the original 27 : * hooks. The signature of precomputeQpResidual() expected to be defined in the derived class is as 28 : * follows: 29 : * 30 : * @tparam Derived The object type 31 : * @param qp The local quadrature point index 32 : * @param datum The AssemblyDatum object of the current thread 33 : * @returns The component of the residual contribution that will be multiplied by the test function 34 : * 35 : * template <typename Derived> 36 : * KOKKOS_FUNCTION Real precomputeQpResidual(const unsigned int qp, 37 : * AssemblyDatum & datum) const; 38 : * 39 : * The signature of precomputeQpJacobian() and precomputeQpOffDiagJacobian() can be found in the 40 : * code below. 41 : */ 42 : class IntegratedBCValue : public IntegratedBC 43 : { 44 : public: 45 : static InputParameters validParams(); 46 : 47 : /// IntegratedBCValue hooks factor out the test function 48 : static constexpr bool use_precompute_hooks = true; 49 : 50 : /** 51 : * Constructor 52 : */ 53 : IntegratedBCValue(const InputParameters & parameters); 54 : 55 : /** 56 : * Default methods to prevent compile errors even when these methods were not defined in the 57 : * derived class 58 : */ 59 : ///@{ 60 : /** 61 : * Compute diagonal Jacobian contribution on a quadrature point 62 : * @tparam Derived The object type 63 : * @param j The trial function DOF index 64 : * @param qp The local quadrature point index 65 : * @param datum The AssemblyDatum object of the current thread 66 : * @returns The component of the Jacobian contribution that will be multiplied by the test 67 : * function 68 : */ 69 : template <typename Derived> 70 0 : KOKKOS_FUNCTION Real precomputeQpJacobian(const unsigned int /* j */, 71 : const unsigned int /* qp */, 72 : AssemblyDatum & /* datum */) const 73 : { 74 0 : ::Kokkos::abort("Default precomputeQpJacobian() should never be called. Make sure you properly " 75 : "redefined this method in your class without typos."); 76 : 77 : return 0; 78 : } 79 : /** 80 : * Compute off-diagonal Jacobian contribution on a quadrature point 81 : * @tparam Derived The object type 82 : * @param j The trial function DOF index 83 : * @param jvar The variable number for column 84 : * @param qp The local quadrature point index 85 : * @param datum The AssemblyDatum object of the current thread 86 : * @returns The component of the off-diagonal Jacobian contribution that will be multiplied by the 87 : * test function 88 : */ 89 : template <typename Derived> 90 0 : KOKKOS_FUNCTION Real precomputeQpOffDiagJacobian(const unsigned int /* j */, 91 : const unsigned int /* jvar */, 92 : const unsigned int /* qp */, 93 : AssemblyDatum & /* datum */) const 94 : { 95 0 : ::Kokkos::abort( 96 : "Default precomputeQpOffDiagJacobian() should never be called. Make sure you properly " 97 : "redefined this method in your class without typos."); 98 : 99 : return 0; 100 : } 101 : ///@} 102 : 103 : /** 104 : * Functions used to check if users have overriden the hook methods, whose calculations can be 105 : * skipped when not overriden 106 : * @returns The function pointer of the default hook method 107 : */ 108 : ///@{ 109 : template <typename Derived> 110 248496 : static auto defaultJacobian() 111 : { 112 248496 : return &IntegratedBCValue::precomputeQpJacobian<Derived>; 113 : } 114 : template <typename Derived> 115 248496 : static auto defaultOffDiagJacobian() 116 : { 117 248496 : return &IntegratedBCValue::precomputeQpOffDiagJacobian<Derived>; 118 : } 119 : ///@} 120 : 121 : /** 122 : * The parallel computation bodies that hide the base class methods to optimize for factoring 123 : * out the test function 124 : */ 125 : ///@{ 126 : template <typename Derived> 127 : KOKKOS_FUNCTION void computeResidualInternal(const Derived & bc, AssemblyDatum & datum) const; 128 : template <typename Derived> 129 : KOKKOS_FUNCTION void computeJacobianInternal(const Derived & bc, AssemblyDatum & datum) const; 130 : template <typename Derived> 131 : KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived & bc, 132 : AssemblyDatum & datum) const; 133 : ///@} 134 : }; 135 : 136 : template <typename Derived> 137 : KOKKOS_FUNCTION void 138 82324 : IntegratedBCValue::computeResidualInternal(const Derived & bc, AssemblyDatum & datum) const 139 : { 140 82324 : ResidualObject::computeResidualInternal( 141 : datum, 142 164648 : [&](Real * local_re, const unsigned int ib, const unsigned int ie) 143 : { 144 247654 : for (unsigned int qp = 0; qp < datum.n_qps(); ++qp) 145 : { 146 165330 : Real value = datum.JxW(qp) * bc.template precomputeQpResidual<Derived>(qp, datum); 147 : 148 835358 : for (unsigned int i = ib; i < ie; ++i) 149 670028 : local_re[i] += value * _test(datum, i, qp); 150 : } 151 : }); 152 82324 : } 153 : 154 : template <typename Derived> 155 : KOKKOS_FUNCTION void 156 120 : IntegratedBCValue::computeJacobianInternal(const Derived & bc, AssemblyDatum & datum) const 157 : { 158 120 : ResidualObject::computeJacobianInternal( 159 : datum, 160 960 : [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j) 161 : { 162 1440 : for (unsigned int qp = 0; qp < datum.n_qps(); ++qp) 163 : { 164 960 : Real value = datum.JxW(qp) * bc.template precomputeQpJacobian<Derived>(j, qp, datum); 165 : 166 4800 : for (unsigned int i = ib; i < ie; ++i) 167 3840 : local_ke[i] += value * _test(datum, i, qp); 168 : } 169 : }); 170 120 : } 171 : 172 : template <typename Derived> 173 : KOKKOS_FUNCTION void 174 20 : IntegratedBCValue::computeOffDiagJacobianInternal(const Derived & bc, AssemblyDatum & datum) const 175 : { 176 20 : ResidualObject::computeJacobianInternal( 177 : datum, 178 80 : [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j) 179 : { 180 80 : for (unsigned int qp = 0; qp < datum.n_qps(); ++qp) 181 : { 182 40 : Real value = datum.JxW(qp) * 183 40 : bc.template precomputeQpOffDiagJacobian<Derived>(j, datum.jvar(), qp, datum); 184 : 185 120 : for (unsigned int i = ib; i < ie; ++i) 186 80 : local_ke[i] += value * _test(datum, i, qp); 187 : } 188 : }); 189 20 : } 190 : 191 : } // namespace Moose::Kokkos