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 "KokkosNodalBC.h" 13 : 14 : namespace Moose 15 : { 16 : namespace Kokkos 17 : { 18 : 19 : /** 20 : * The base Kokkos boundary condition of a Dirichlet type 21 : */ 22 : template <typename Derived> 23 : class DirichletBCBase : public NodalBC 24 : { 25 : public: 26 : static InputParameters validParams(); 27 : 28 : /** 29 : * Constructor 30 : */ 31 : DirichletBCBase(const InputParameters & parameters); 32 : 33 : /** 34 : * Get whether the value is to be preset 35 : * @returns Whether the value is to be preset 36 : */ 37 1281 : virtual bool preset() const override { return _preset; } 38 : 39 : /** 40 : * Dispatch solution vector preset 41 : * @param tag The tag associated with the solution vector to be preset 42 : */ 43 : virtual void presetSolution(TagID tag) override; 44 : 45 : /** 46 : * The preset function called by Kokkos 47 : */ 48 : KOKKOS_FUNCTION void operator()(const ThreadID tid) const; 49 : 50 : /** 51 : * Compute residual contribution on a node 52 : * @param qp The dummy quadrature point index (= 0) 53 : * @param datum The AssemblyDatum object of the current thread 54 : * @returns The residual contribution 55 : */ 56 : KOKKOS_FUNCTION Real computeQpResidual(const unsigned int qp, AssemblyDatum & datum) const; 57 : 58 : private: 59 : /** 60 : * Flag whether the value is to be preset 61 : */ 62 : const bool _preset; 63 : /** 64 : * Tag associated with the solution vector to be preset 65 : */ 66 : TagID _solution_tag; 67 : }; 68 : 69 : template <typename Derived> 70 : InputParameters 71 21274 : DirichletBCBase<Derived>::validParams() 72 : { 73 21274 : InputParameters params = NodalBC::validParams(); 74 43134 : params.addParam<bool>( 75 41376 : "preset", true, "Whether or not to preset the BC (apply the value before the solve begins)."); 76 21274 : return params; 77 0 : } 78 : 79 : template <typename Derived> 80 1573 : DirichletBCBase<Derived>::DirichletBCBase(const InputParameters & parameters) 81 1978 : : NodalBC(parameters), _preset(getParam<bool>("preset")) 82 : { 83 1281 : } 84 : 85 : template <typename Derived> 86 : void 87 3949 : DirichletBCBase<Derived>::presetSolution(TagID tag) 88 : { 89 3949 : _solution_tag = tag; 90 : 91 3949 : ::Kokkos::parallel_for( 92 6552 : ::Kokkos::RangePolicy<ExecSpace, ::Kokkos::IndexType<ThreadID>>(0, numKokkosBoundaryNodes()), 93 : *static_cast<Derived *>(this)); 94 3949 : } 95 : 96 : template <typename Derived> 97 : KOKKOS_FUNCTION void 98 22772 : DirichletBCBase<Derived>::operator()(const ThreadID tid) const 99 : { 100 22772 : auto bc = static_cast<const Derived *>(this); 101 22772 : auto node = kokkosBoundaryNodeID(tid); 102 22772 : auto & sys = kokkosSystem(_kokkos_var.sys()); 103 22772 : auto dof = sys.getNodeLocalDofIndex(node, 0, _kokkos_var.var()); 104 : 105 22772 : if (dof == libMesh::DofObject::invalid_id) 106 0 : return; 107 : 108 22772 : AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var()); 109 : 110 22772 : sys.getVectorDofValue(dof, _solution_tag) = bc->computeValue(0, datum); 111 : } 112 : 113 : template <typename Derived> 114 : KOKKOS_FUNCTION Real 115 330638 : DirichletBCBase<Derived>::computeQpResidual(const unsigned int qp, AssemblyDatum & datum) const 116 : { 117 330638 : auto bc = static_cast<const Derived *>(this); 118 : 119 330638 : return _u(datum, qp) - bc->computeValue(qp, datum); 120 : } 121 : 122 : } // namespace Kokkos 123 : } // namespace Moose 124 : 125 : #define usingKokkosDirichletBCBaseMembers(T) \ 126 : public: \ 127 : using Moose::Kokkos::DirichletBCBase<T>::operator(); \ 128 : using Moose::Kokkos::NodalBC::operator(); \ 129 : \ 130 : protected: \ 131 : using Moose::Kokkos::NodalBC::_u