https://mooseframework.inl.gov
KokkosVectorIntegratedBC.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 "KokkosIntegratedBCBase.h"
13 
14 namespace Moose::Kokkos
15 {
16 
22 {
23 public:
25 
30 
34  virtual void computeResidual() override;
38  virtual void computeJacobian() override;
39 
44  template <typename Derived>
46  KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int /* i */,
47  const unsigned int /* j */,
48  const unsigned int /* qp */,
49  AssemblyDatum & /* datum */) const
50  {
51  ::Kokkos::abort("Default computeQpJacobian() should never be called. Make sure you properly "
52  "redefined this method in your class without typos.");
53 
54  return 0;
55  }
56  template <typename Derived>
57  KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int /* i */,
58  const unsigned int /* j */,
59  const unsigned int /* jvar */,
60  const unsigned int /* qp */,
61  AssemblyDatum & /* datum */) const
62  {
63  ::Kokkos::abort(
64  "Default computeQpOffDiagJacobian() should never be called. Make sure you properly "
65  "redefined this method in your class without typos.");
66 
67  return 0;
68  }
70 
75  template <typename Derived>
77  static auto defaultJacobian()
78  {
79  return &VectorIntegratedBC::computeQpJacobian<Derived>;
80  }
81  template <typename Derived>
82  static auto defaultOffDiagJacobian()
83  {
84  return &VectorIntegratedBC::computeQpOffDiagJacobian<Derived>;
85  }
87 
91  template <typename Derived>
93  KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const;
94  template <typename Derived>
95  KOKKOS_FUNCTION void operator()(JacobianLoop, const ThreadID tid, const Derived & bc) const;
96  template <typename Derived>
97  KOKKOS_FUNCTION void
98  operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & bc) const;
100 
105  template <typename Derived>
107  KOKKOS_FUNCTION void computeResidualInternal(const Derived & bc, AssemblyDatum & datum) const;
108  template <typename Derived>
109  KOKKOS_FUNCTION void computeJacobianInternal(const Derived & bc, AssemblyDatum & datum) const;
110  template <typename Derived>
111  KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived & bc,
112  AssemblyDatum & datum) const;
114 
115 protected:
140 };
141 
142 template <typename Derived>
143 KOKKOS_FUNCTION void
144 VectorIntegratedBC::operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const
145 {
146  auto [elem, side] = kokkosBoundaryElementSideID(_thread(tid, 1));
147 
148  AssemblyDatum datum(
149  elem, side, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var());
150 
151  datum.set_local_parallel(_thread(tid, 0), _thread.size(0));
152 
153  bc.computeResidualInternal(bc, datum);
154 }
155 
156 template <typename Derived>
157 KOKKOS_FUNCTION void
158 VectorIntegratedBC::operator()(JacobianLoop, const ThreadID tid, const Derived & bc) const
159 {
160  auto [elem, side] = kokkosBoundaryElementSideID(_thread(tid, 1));
161 
162  AssemblyDatum datum(
163  elem, side, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var());
164 
165  datum.set_local_parallel(_thread(tid, 0), _thread.size(0));
166 
167  bc.computeJacobianInternal(bc, datum);
168 }
169 
170 template <typename Derived>
171 KOKKOS_FUNCTION void
172 VectorIntegratedBC::operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & bc) const
173 {
174  auto [elem, side] = kokkosBoundaryElementSideID(_thread(tid, 2));
175 
176  auto & sys = kokkosSystem(_kokkos_var.sys());
177  auto jvar = sys.getCoupling(_kokkos_var.var())[_thread(tid, 1)];
178 
179  if (!sys.isVariableActive(jvar, kokkosMesh().getElementInfo(elem).subdomain))
180  return;
181 
182  AssemblyDatum datum(elem, side, kokkosAssembly(), kokkosSystems(), _kokkos_var, jvar);
183 
184  datum.set_local_parallel(_thread(tid, 0), _thread.size(0));
185 
186  bc.computeOffDiagJacobianInternal(bc, datum);
187 }
188 
189 template <typename Derived>
190 KOKKOS_FUNCTION void
192 {
194  datum,
195  [&](Real * local_re, const unsigned int ib, const unsigned int ie)
196  {
197  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
198  for (unsigned int i = ib; i < ie; ++i)
199  local_re[i] += datum.JxW(qp) * bc.template computeQpResidual<Derived>(i, qp, datum);
200  });
201 }
202 
203 template <typename Derived>
204 KOKKOS_FUNCTION void
206 {
208  datum,
209  [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
210  {
211  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
212  for (unsigned int i = ib; i < ie; ++i)
213  local_ke[i] += datum.JxW(qp) * bc.template computeQpJacobian<Derived>(i, j, qp, datum);
214  });
215 }
216 
217 template <typename Derived>
218 KOKKOS_FUNCTION void
220 {
222  datum,
223  [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
224  {
225  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
226  for (unsigned int i = ib; i < ie; ++i)
227  local_ke[i] += datum.JxW(qp) * bc.template computeQpOffDiagJacobian<Derived>(
228  i, j, datum.jvar(), qp, datum);
229  });
230 }
231 
232 } // namespace Moose::Kokkos
KOKKOS_FUNCTION unsigned int sys(unsigned int comp=0) const
Get the system number of a component.
KOKKOS_FUNCTION void computeJacobianInternal(AssemblyDatum &datum, function body) const
The common loop structure template for computing elemental Jacobian.
KOKKOS_FUNCTION void set_local_parallel(const unsigned int local_thread_id, const unsigned int num_local_threads)
Set local parallelization option.
Definition: KokkosDatum.h:369
KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived &bc, AssemblyDatum &datum) const
KOKKOS_FUNCTION const Assembly & kokkosAssembly() const
Get the const reference of the Kokkos assembly.
KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived &bc) const
The parallel computation entry functions called by Kokkos.
static InputParameters validParams()
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int, const unsigned int, const unsigned int, const unsigned int, AssemblyDatum &) const
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
KOKKOS_FUNCTION void computeJacobianInternal(const Derived &bc, AssemblyDatum &datum) const
Thread _thread
Kokkos thread object.
The base class for Kokkos integrated boundary conditions.
KOKKOS_FUNCTION unsigned int jvar() const
Get the coupled variable number.
Definition: KokkosDatum.h:651
MOOSE_KOKKOS_INDEX_TYPE ThreadID
Definition: KokkosThread.h:22
const VectorVariablePhiValue _phi
Current vector shape function.
const VectorVariablePhiGradient _grad_phi
Gradient of the current vector shape function.
KOKKOS_FUNCTION unsigned int n_qps() const
Get the number of local quadrature points.
Definition: KokkosDatum.h:303
const VectorVariableValue _u
Current vector solution at quadrature points.
const VectorVariableTestGradient _grad_test
Gradient of the current vector test function.
KOKKOS_FUNCTION const Mesh & kokkosMesh() const
Get the const reference of the Kokkos mesh.
Definition: KokkosMesh.h:651
KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int, const unsigned int, const unsigned int, AssemblyDatum &) const
Default methods to prevent compile errors even when these methods were not defined in the derived cla...
KOKKOS_FUNCTION auto kokkosBoundaryElementSideID(Moose::Kokkos::ThreadID tid) const
Get the contiguous element ID - side index pair this Kokkos thread is operating on.
KOKKOS_FUNCTION void computeResidualInternal(const Derived &bc, AssemblyDatum &datum) const
The parallel computation bodies that can be customized in the derived class by defining them in the d...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
The base class for a user to derive their own Kokkos integrated boundary conditions on vector variabl...
virtual void computeJacobian() override
Dispatch diagonal and off-diagonal Jacobian calculation.
static auto defaultJacobian()
Functions used to check if users have overriden the hook methods, whose calculations can be skipped w...
The Kokkos object that holds thread-private data in the parallel operations of Kokkos kernels...
Definition: KokkosDatum.h:559
VectorIntegratedBC(const InputParameters &parameters)
Constructor.
KOKKOS_FUNCTION Real JxW(const unsigned int qp)
Get the transformed Jacobian weight.
Definition: KokkosDatum.h:506
Variable _kokkos_var
Kokkos variable.
KOKKOS_FUNCTION unsigned int var(unsigned int comp=0) const
Get the variable number of a component.
KOKKOS_FUNCTION thread_id_type size() const
Get the total thread pool size.
Definition: KokkosThread.h:50
virtual void computeResidual() override
Dispatch residual calculation.
KOKKOS_FUNCTION void computeResidualInternal(AssemblyDatum &datum, function body) const
The common loop structure template for computing elemental residual.
const VectorVariableTestValue _test
Current vector test function.
const VectorVariableGradient _grad_u
Gradient of the current vector solution at quadrature points.