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 "KokkosNodalBCBase.h" 13 : 14 : namespace Moose::Kokkos 15 : { 16 : 17 : /** 18 : * The base class for a user to derive their own Kokkos nodal boundary conditions using automatic 19 : * differentiation (AD). 20 : * 21 : * The user should define computeQpResidual() as inlined public methods in their derived class (not 22 : * virtual override). The signature of computeQpResidual() expected to be defined in the derived 23 : * class is as follows: 24 : * 25 : * @tparam Derived The object type 26 : * @param qp The dummy quadrature point index (= 0) 27 : * @param datum The AssemblyDatum object of the current thread 28 : * @returns The residual contribution 29 : * 30 : * template <typename Derived> 31 : * KOKKOS_FUNCTION Moose::Kokkos::ADReal computeQpResidual(const unsigned int qp, 32 : * AssemblyDatum & datum) const; 33 : * 34 : * Note that computeQpJacobian() and computeQpOffDiagJacobian() are unused for AD nodal boundary 35 : * conditions. 36 : */ 37 : class ADNodalBC : public NodalBCBase 38 : { 39 : public: 40 : static InputParameters validParams(); 41 : 42 : /** 43 : * Constructor 44 : */ 45 : ADNodalBC(const InputParameters & parameters); 46 : 47 : virtual void computeResidual() override; 48 : virtual void computeJacobian() override; 49 : virtual void computeResidualAndJacobian() override; 50 : 51 : /** 52 : * The parallel computation entry function called by Kokkos 53 : */ 54 : template <typename Derived> 55 : KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const; 56 : 57 : protected: 58 : /** 59 : * Dispatch parallel calculation 60 : */ 61 : virtual void dispatch(); 62 : 63 : /** 64 : * Current solution at nodes 65 : */ 66 : const ADVariableValue _u; 67 : /** 68 : * Whether computing residual 69 : */ 70 : bool _computing_residual = false; 71 : /** 72 : * Whether computing Jacobian 73 : */ 74 : bool _computing_jacobian = false; 75 : }; 76 : 77 : template <typename Derived> 78 : KOKKOS_FUNCTION void 79 68852 : ADNodalBC::operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const 80 : { 81 68852 : auto node = kokkosBoundaryNodeID(tid); 82 68852 : auto & sys = kokkosSystem(_kokkos_var.sys()); 83 : 84 68852 : if (!sys.isNodalDefined(node, _kokkos_var.var())) 85 0 : return; 86 : 87 68852 : AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var()); 88 : 89 68852 : datum.do_derivatives(_computing_jacobian); 90 : 91 68852 : ADReal local_re = bc.template computeQpResidual<Derived>(0, datum); 92 : 93 68852 : if (_computing_residual) 94 35462 : accumulateTaggedNodalResidual(false, local_re.value(), node); 95 68852 : if (_computing_jacobian) 96 33390 : accumulateTaggedNodalMatrix(false, local_re.derivatives(), node); 97 68852 : } 98 : 99 : } // namespace Moose::Kokkos