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::Kokkos
15 {
16 
36 class NodalBC : public NodalBCBase
37 {
38 public:
40 
45 
49  virtual void computeResidual() override;
53  virtual void computeJacobian() override;
54 
59 
67  template <typename Derived>
68  KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int /* qp */,
69  AssemblyDatum & /* datum */) const
70  {
71  return 1;
72  }
81  template <typename Derived>
82  KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int /* jvar */,
83  const unsigned int /* qp */,
84  AssemblyDatum & /* datum */) const
85  {
86  ::Kokkos::abort(
87  "Default computeQpOffDiagJacobian() should never be called. Make sure you properly "
88  "redefined this method in your class without typos.");
89 
90  return 0;
91  }
93 
99  template <typename Derived>
101  static auto defaultJacobian()
102  {
103  return &NodalBC::computeQpJacobian<Derived>;
104  }
105  template <typename Derived>
107  {
108  return &NodalBC::computeQpOffDiagJacobian<Derived>;
109  }
111 
115  template <typename Derived>
117  KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const;
118  template <typename Derived>
119  KOKKOS_FUNCTION void operator()(JacobianLoop, const ThreadID tid, const Derived & bc) const;
120  template <typename Derived>
121  KOKKOS_FUNCTION void
122  operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & bc) const;
124 
125 protected:
130 };
131 
132 template <typename Derived>
133 KOKKOS_FUNCTION void
134 NodalBC::operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const
135 {
136  auto node = kokkosBoundaryNodeID(tid);
137  auto & sys = kokkosSystem(_kokkos_var.sys());
138 
139  if (!sys.isNodalDefined(node, _kokkos_var.var()))
140  return;
141 
143 
144  Real local_re = bc.template computeQpResidual<Derived>(0, datum);
145 
146  accumulateTaggedNodalResidual(false, local_re, node);
147 }
148 
149 template <typename Derived>
150 KOKKOS_FUNCTION void
151 NodalBC::operator()(JacobianLoop, const ThreadID tid, const Derived & bc) const
152 {
153  auto node = kokkosBoundaryNodeID(tid);
154  auto & sys = kokkosSystem(_kokkos_var.sys());
155 
156  if (!sys.isNodalDefined(node, _kokkos_var.var()))
157  return;
158 
160 
161  Real local_ke = bc.template computeQpJacobian<Derived>(0, datum);
162 
163  // This initializes the row to zero except the diagonal
164  accumulateTaggedNodalMatrix(false, local_ke, node, _kokkos_var.var());
165 }
166 
167 template <typename Derived>
168 KOKKOS_FUNCTION void
169 NodalBC::operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & bc) const
170 {
171  auto node = kokkosBoundaryNodeID(_thread(tid, 1));
172  auto & sys = kokkosSystem(_kokkos_var.sys());
173  auto jvar = sys.getCoupling(_kokkos_var.var())[_thread(tid, 0)];
174 
175  if (!sys.isNodalDefined(node, _kokkos_var.var()))
176  return;
177 
178  AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, jvar);
179 
180  Real local_ke = bc.template computeQpOffDiagJacobian<Derived>(jvar, 0, datum);
181 
182  accumulateTaggedNodalMatrix(true, local_ke, node, jvar);
183 }
184 
185 } // namespace Moose::Kokkos
KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int, AssemblyDatum &) const
Default methods to prevent compile errors even when these methods were not defined in the derived cla...
Definition: KokkosNodalBC.h:68
KOKKOS_FUNCTION unsigned int sys(unsigned int comp=0) const
Get the system number of a component.
KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived &bc) const
The parallel computation entry functions called by Kokkos.
NodalBC(const InputParameters &parameters)
Constructor.
KOKKOS_FUNCTION const Assembly & kokkosAssembly() const
Get the const reference of the Kokkos assembly.
KOKKOS_FUNCTION ContiguousNodeID kokkosBoundaryNodeID(Moose::Kokkos::ThreadID tid) const
Get the contiguous node ID this Kokkos thread is operating on.
static InputParameters validParams()
static auto defaultOffDiagJacobian()
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
KOKKOS_FUNCTION void accumulateTaggedNodalResidual(const bool add, const Real local_re, const ContiguousNodeID node, const unsigned int comp=0) const
Accumulate or set local nodal residual contribution to tagged vectors.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Thread _thread
Kokkos thread object.
KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int, const unsigned int, AssemblyDatum &) const
Compute off-diagonal Jacobian contribution on a node.
Definition: KokkosNodalBC.h:82
static auto defaultJacobian()
Functions used to check if users have overriden the hook methods, whose calculations can be skipped w...
virtual void computeResidual() override
Dispatch residual calculation.
KOKKOS_FUNCTION const System & kokkosSystem(unsigned int sys) const
Get the const reference of a Kokkos system.
Definition: KokkosSystem.h:792
The Kokkos wrapper classes for MOOSE-like variable value access.
The base class for Kokkos nodal boundary conditions.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const VariableValue _u
Current solution at nodes.
The Kokkos object that holds thread-private data in the parallel operations of Kokkos kernels...
Definition: KokkosDatum.h:364
Variable _kokkos_var
Kokkos variable.
virtual void computeJacobian() override
Dispatch diagonal and off-diagonal Jacobian calculation.
KOKKOS_FUNCTION unsigned int var(unsigned int comp=0) const
Get the variable number of a component.
KOKKOS_FUNCTION const auto & getCoupling(unsigned int var) const
Get the list of off-diagonal coupled variable numbers of a variable.
Definition: KokkosSystem.h:146
KOKKOS_FUNCTION void accumulateTaggedNodalMatrix(const bool add, const Real local_ke, const ContiguousNodeID node, const unsigned int jvar, const unsigned int comp=0) const
Accumulate or set local nodal Jacobian contribution to tagged matrices.
The base class for a user to derive their own Kokkos nodal boundary conditions.
Definition: KokkosNodalBC.h:36
KOKKOS_FUNCTION const Array< System > & kokkosSystems() const
Get the const reference of the Kokkos systems.
Definition: KokkosSystem.h:775
dof_id_type ThreadID
Definition: KokkosThread.h:22