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 
36 class NodalBC : public NodalBCBase
37 {
38 public:
40 
45 
49  virtual void computeResidual() override;
53  virtual void computeJacobian() override;
54 
59 
66  KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int /* qp */,
67  ResidualDatum & /* datum */) const
68  {
69  return 1;
70  }
78  KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int /* jvar */,
79  const unsigned int /* qp */,
80  ResidualDatum & /* datum */) const
81  {
82  return 0;
83  }
88  static auto defaultJacobian() { return &NodalBC::computeQpJacobian; }
95 
99  template <typename Derived>
101  KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const;
102  template <typename Derived>
103  KOKKOS_FUNCTION void operator()(JacobianLoop, const ThreadID tid, const Derived & bc) const;
104  template <typename Derived>
105  KOKKOS_FUNCTION void
106  operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & bc) const;
108 
109 protected:
114 };
115 
116 template <typename Derived>
117 KOKKOS_FUNCTION void
118 NodalBC::operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const
119 {
120  auto node = kokkosBoundaryNodeID(tid);
121  auto & sys = kokkosSystem(_kokkos_var.sys());
122 
123  if (!sys.isNodalDefined(node, _kokkos_var.var()))
124  return;
125 
127 
128  Real local_re = bc.computeQpResidual(0, datum);
129 
130  accumulateTaggedNodalResidual(false, local_re, node);
131 }
132 
133 template <typename Derived>
134 KOKKOS_FUNCTION void
135 NodalBC::operator()(JacobianLoop, const ThreadID tid, const Derived & bc) const
136 {
137  auto node = kokkosBoundaryNodeID(tid);
138  auto & sys = kokkosSystem(_kokkos_var.sys());
139 
140  if (!sys.isNodalDefined(node, _kokkos_var.var()))
141  return;
142 
144 
145  Real local_ke = bc.computeQpJacobian(0, datum);
146 
147  // This initializes the row to zero except the diagonal
148  accumulateTaggedNodalMatrix(false, local_ke, node, _kokkos_var.var());
149 }
150 
151 template <typename Derived>
152 KOKKOS_FUNCTION void
153 NodalBC::operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & bc) const
154 {
155  auto node = kokkosBoundaryNodeID(_thread(tid, 1));
156  auto & sys = kokkosSystem(_kokkos_var.sys());
157  auto jvar = sys.getCoupling(_kokkos_var.var())[_thread(tid, 0)];
158 
159  if (!sys.isNodalDefined(node, _kokkos_var.var()))
160  return;
161 
162  ResidualDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, jvar);
163 
164  Real local_ke = bc.computeQpOffDiagJacobian(jvar, 0, datum);
165 
166  accumulateTaggedNodalMatrix(true, local_ke, node, jvar);
167 }
168 
169 } // namespace Kokkos
170 } // namespace Moose
KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int, const unsigned int, ResidualDatum &) const
Compute off-diagonal Jacobian contribution on a node.
Definition: KokkosNodalBC.h:78
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.
KOKKOS_FUNCTION ContiguousNodeID kokkosBoundaryNodeID(ThreadID tid) const
Get the contiguous node ID this Kokkos thread is operating on.
NodalBC(const InputParameters &parameters)
Constructor.
KOKKOS_FUNCTION const Assembly & kokkosAssembly() const
Get the const reference of the Kokkos assembly.
dof_id_type ThreadID
Definition: KokkosThread.h:18
static InputParameters validParams()
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.
static auto defaultJacobian()
Get the function pointer of the default computeQpJacobian()
Definition: KokkosNodalBC.h:88
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:615
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.
KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int, ResidualDatum &) const
Default methods to prevent compile errors even when these methods were not defined in the derived cla...
Definition: KokkosNodalBC.h:66
Variable _kokkos_var
Kokkos variable.
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.
The Kokkos wrapper classes for MOOSE-like variable value access.
static auto defaultOffDiagJacobian()
Get the function pointer of the default computeQpOffDiagJacobian()
Definition: KokkosNodalBC.h:93
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:140
The Kokkos object that holds thread-private data in the parallel operations of Kokkos residual object...
Definition: KokkosDatum.h:245
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:598