https://mooseframework.inl.gov
KokkosDirichletBCBase.h
Go to the documentation of this file.
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 
22 template <typename Derived>
23 class DirichletBCBase : public NodalBC
24 {
25 public:
27 
32 
37  virtual bool preset() const override { return _preset; }
38 
43  virtual void presetSolution(TagID tag) override;
44 
48  KOKKOS_FUNCTION void operator()(const ThreadID tid) const;
49 
56  KOKKOS_FUNCTION Real computeQpResidual(const unsigned int qp, ResidualDatum & datum) const;
57 
58 private:
62  const bool _preset;
67 };
68 
69 template <typename Derived>
72 {
74  params.addParam<bool>(
75  "preset", true, "Whether or not to preset the BC (apply the value before the solve begins).");
76  return params;
77 }
78 
79 template <typename Derived>
81  : NodalBC(parameters), _preset(getParam<bool>("preset"))
82 {
83 }
84 
85 template <typename Derived>
86 void
88 {
89  _solution_tag = tag;
90 
91  ::Kokkos::parallel_for(
92  ::Kokkos::RangePolicy<ExecSpace, ::Kokkos::IndexType<ThreadID>>(0, numKokkosBoundaryNodes()),
93  *static_cast<Derived *>(this));
94 }
95 
96 template <typename Derived>
97 KOKKOS_FUNCTION void
99 {
100  auto bc = static_cast<const Derived *>(this);
101  auto node = kokkosBoundaryNodeID(tid);
102  auto & sys = kokkosSystem(_kokkos_var.sys());
103  auto dof = sys.getNodeLocalDofIndex(node, _kokkos_var.var());
104 
106  return;
107 
108  ResidualDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var());
109 
110  sys.getVectorDofValue(dof, _solution_tag) = bc->computeValue(0, datum);
111 }
112 
113 template <typename Derived>
114 KOKKOS_FUNCTION Real
115 DirichletBCBase<Derived>::computeQpResidual(const unsigned int qp, ResidualDatum & datum) const
116 {
117  auto bc = static_cast<const Derived *>(this);
118 
119  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
virtual bool preset() const override
Get whether the value is to be preset.
const bool _preset
Flag whether the value is to be preset.
unsigned int TagID
Definition: MooseTypes.h:210
dof_id_type ThreadID
Definition: KokkosThread.h:18
static InputParameters validParams()
virtual void presetSolution(TagID tag) override
Dispatch solution vector preset.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
virtual Real computeQpResidual() override
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
TagID _solution_tag
Tag associated with the solution vector to be preset.
DirichletBCBase(const InputParameters &parameters)
Constructor.
static const dof_id_type invalid_id
static InputParameters validParams()
KOKKOS_FUNCTION void operator()(const ThreadID tid) const
The preset function called by Kokkos.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
KOKKOS_FUNCTION Real computeQpResidual(const unsigned int qp, ResidualDatum &datum) const
Compute residual contribution on a node.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
The Kokkos object that holds thread-private data in the parallel operations of Kokkos residual object...
Definition: KokkosDatum.h:245
The base class for a user to derive their own Kokkos nodal boundary conditions.
Definition: KokkosNodalBC.h:36
The base Kokkos boundary condition of a Dirichlet type.