https://mooseframework.inl.gov
KokkosNodalBC.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 "KokkosNodalBCBase.h"
13 
14 namespace Moose
15 {
16 namespace Kokkos
17 {
18 
48 template <typename Derived>
49 class NodalBC : public NodalBCBase
50 {
51 public:
53 
58 
62  virtual void computeResidual() override;
66  virtual void computeJacobian() override;
67 
72 
78  KOKKOS_FUNCTION Real computeQpJacobian(const ContiguousNodeID /* node */) const { return 1; }
85  KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int /* jvar */,
86  const ContiguousNodeID /* node */) const
87  {
88  return 0;
89  }
91 
95  KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid) const;
97  KOKKOS_FUNCTION void operator()(JacobianLoop, const ThreadID tid) const;
98  KOKKOS_FUNCTION void operator()(OffDiagJacobianLoop, const ThreadID tid) const;
100 
101 protected:
106 
107 private:
111  const bool _default_offdiag;
112 };
113 
114 template <typename Derived>
117 {
119  return params;
120 }
121 
122 template <typename Derived>
125  _u(kokkosSystems(), _var),
126  _default_offdiag(&Derived::computeQpOffDiagJacobian == &NodalBC::computeQpOffDiagJacobian)
127 {
129 }
130 
131 template <typename Derived>
132 void
134 {
135  ::Kokkos::RangePolicy<ResidualLoop, ExecSpace, ::Kokkos::IndexType<ThreadID>> policy(
136  0, numKokkosBoundaryNodes());
137  ::Kokkos::parallel_for(policy, *static_cast<Derived *>(this));
138  ::Kokkos::fence();
139 }
140 
141 template <typename Derived>
142 void
144 {
145  ::Kokkos::RangePolicy<JacobianLoop, ExecSpace, ::Kokkos::IndexType<ThreadID>> policy(
146  0, numKokkosBoundaryNodes());
147  ::Kokkos::parallel_for(policy, *static_cast<Derived *>(this));
148  ::Kokkos::fence();
149 
150  if (!_default_offdiag)
151  {
152  auto & sys = kokkosSystem(_kokkos_var.sys());
153 
154  _thread.resize({sys.getCoupling(_kokkos_var.var()).size(), numKokkosBoundaryNodes()});
155 
156  ::Kokkos::RangePolicy<OffDiagJacobianLoop, ExecSpace, ::Kokkos::IndexType<ThreadID>> policy(
157  0, _thread.size());
158  ::Kokkos::parallel_for(policy, *static_cast<Derived *>(this));
159  ::Kokkos::fence();
160  }
161 }
162 
163 template <typename Derived>
164 KOKKOS_FUNCTION void
166 {
167  auto bc = static_cast<const Derived *>(this);
168  auto node = kokkosBoundaryNodeID(tid);
169  auto & sys = kokkosSystem(_kokkos_var.sys());
170 
171  if (!sys.isNodalDefined(node, _kokkos_var.var()))
172  return;
173 
174  Real local_re = bc->computeQpResidual(node);
175 
176  accumulateTaggedNodalResidual(false, local_re, node);
177 }
178 
179 template <typename Derived>
180 KOKKOS_FUNCTION void
182 {
183  auto bc = static_cast<const Derived *>(this);
184  auto node = kokkosBoundaryNodeID(tid);
185  auto & sys = kokkosSystem(_kokkos_var.sys());
186 
187  if (!sys.isNodalDefined(node, _kokkos_var.var()))
188  return;
189 
190  Real local_ke = bc->computeQpJacobian(node);
191 
192  // This initializes the row to zero except the diagonal
193  accumulateTaggedNodalMatrix(false, local_ke, node, _kokkos_var.var());
194 }
195 
196 template <typename Derived>
197 KOKKOS_FUNCTION void
199 {
200  auto bc = static_cast<const Derived *>(this);
201  auto node = kokkosBoundaryNodeID(_thread(tid, 1));
202  auto & sys = kokkosSystem(_kokkos_var.sys());
203  auto jvar = sys.getCoupling(_kokkos_var.var())[_thread(tid, 0)];
204 
205  if (!sys.isNodalDefined(node, _kokkos_var.var()))
206  return;
207 
208  Real local_ke = bc->computeQpOffDiagJacobian(jvar, node);
209 
210  accumulateTaggedNodalMatrix(true, local_ke, node, jvar);
211 }
212 
213 } // namespace Kokkos
214 } // namespace Moose
215 
216 #define usingKokkosNodalBCMembers(T) \
217  usingKokkosNodalBCBaseMembers; \
218  \
219 protected: \
220  using Moose::Kokkos::NodalBC<T>::_u; \
221  \
222 public: \
223  using Moose::Kokkos::NodalBC<T>::operator()
virtual void computeResidual() override
Dispatch residual calculation.
VarFieldType
Definition: MooseTypes.h:722
dof_id_type ThreadID
Definition: KokkosThread.h:18
KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid) const
The parallel computation entry functions called by Kokkos.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void computeResidual() override
Compute this object&#39;s contribution to the residual.
Definition: NodalBC.C:78
NodalBC(const InputParameters &parameters)
Constructor.
static InputParameters validParams()
MooseVariable & _var
Definition: NodalBC.h:38
dof_id_type ContiguousNodeID
Definition: KokkosMesh.h:21
The base class for Kokkos nodal boundary conditions.
void addMooseVariableDependency(MooseVariableFieldBase *var)
Call this function to add the passed in MooseVariableFieldBase as a variable that this object depends...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
KOKKOS_FUNCTION Real computeQpJacobian(const ContiguousNodeID) const
Default methods to prevent compile errors even when these methods were not defined in the derived cla...
Definition: KokkosNodalBC.h:78
KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int, const ContiguousNodeID) const
Compute off-diagonal Jacobian contribution on a node.
Definition: KokkosNodalBC.h:85
static InputParameters validParams()
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
virtual void computeJacobian() override
Dispatch diagonal and off-diagonal Jacobian calculation.
virtual void computeJacobian() override
Compute this object&#39;s contribution to the diagonal Jacobian entries.
Definition: NodalBC.C:92
const VariableNodalValue _u
Current solution at nodes.
The base class for a user to derive their own Kokkos nodal boundary conditions.
Definition: KokkosNodalBC.h:49
const bool _default_offdiag
Flag whether computeQpOffDiagJacobian() was not defined in the derived class.