https://mooseframework.inl.gov
Loading...
Searching...
No Matches
KokkosIntegratedBC.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
13
14namespace Moose::Kokkos
15{
16
40{
41public:
43
48
52 virtual void computeResidual() override;
56 virtual void computeJacobian() override;
57
63
72 template <typename Derived>
73 KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int /* i */,
74 const unsigned int /* j */,
75 const unsigned int /* qp */,
76 AssemblyDatum & /* datum */) const
77 {
78 ::Kokkos::abort("Default computeQpJacobian() should never be called. Make sure you properly "
79 "redefined this method in your class without typos.");
80
81 return 0;
82 }
93 template <typename Derived>
94 KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int /* i */,
95 const unsigned int /* j */,
96 const unsigned int /* jvar */,
97 const unsigned int /* qp */,
98 AssemblyDatum & /* datum */) const
99 {
100 ::Kokkos::abort(
101 "Default computeQpOffDiagJacobian() should never be called. Make sure you properly "
102 "redefined this method in your class without typos.");
103
104 return 0;
105 }
107
114 template <typename Derived>
115 static auto defaultJacobian()
116 {
117 return &IntegratedBC::computeQpJacobian<Derived>;
118 }
119 template <typename Derived>
121 {
122 return &IntegratedBC::computeQpOffDiagJacobian<Derived>;
123 }
125
130 template <typename Derived>
131 KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const;
132 template <typename Derived>
133 KOKKOS_FUNCTION void operator()(JacobianLoop, const ThreadID tid, const Derived & bc) const;
134 template <typename Derived>
135 KOKKOS_FUNCTION void
136 operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & bc) const;
138
145
150 template <typename Derived>
151 KOKKOS_FUNCTION void computeResidualInternal(const Derived & bc, AssemblyDatum & datum) const;
157 template <typename Derived>
158 KOKKOS_FUNCTION void computeJacobianInternal(const Derived & bc, AssemblyDatum & datum) const;
164 template <typename Derived>
165 KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived & bc,
166 AssemblyDatum & datum) const;
168
169protected:
194};
195
196template <typename Derived>
197KOKKOS_FUNCTION void
198IntegratedBC::operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const
199{
200 auto [elem, side] = kokkosBoundaryElementSideID(_thread(tid, 1));
201
202 AssemblyDatum datum(
203 elem, side, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var());
204
205 datum.set_local_parallel(_thread(tid, 0), _thread.size(0));
206
207 bc.computeResidualInternal(bc, datum);
208}
209
210template <typename Derived>
211KOKKOS_FUNCTION void
212IntegratedBC::operator()(JacobianLoop, const ThreadID tid, const Derived & bc) const
213{
214 auto [elem, side] = kokkosBoundaryElementSideID(_thread(tid, 1));
215
216 AssemblyDatum datum(
217 elem, side, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var());
218
219 datum.set_local_parallel(_thread(tid, 0), _thread.size(0));
220
221 bc.computeJacobianInternal(bc, datum);
222}
223
224template <typename Derived>
225KOKKOS_FUNCTION void
226IntegratedBC::operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & bc) const
227{
228 auto [elem, side] = kokkosBoundaryElementSideID(_thread(tid, 2));
229
230 auto & sys = kokkosSystem(_kokkos_var.sys());
231 auto jvar = sys.getCoupling(_kokkos_var.var())[_thread(tid, 1)];
232
233 if (!sys.isVariableActive(jvar, kokkosMesh().getElementInfo(elem).subdomain))
234 return;
235
236 AssemblyDatum datum(elem, side, kokkosAssembly(), kokkosSystems(), _kokkos_var, jvar);
237
238 datum.set_local_parallel(_thread(tid, 0), _thread.size(0));
239
240 bc.computeOffDiagJacobianInternal(bc, datum);
241}
242
243template <typename Derived>
244KOKKOS_FUNCTION void
245IntegratedBC::computeResidualInternal(const Derived & bc, AssemblyDatum & datum) const
246{
248 datum,
249 [&](Real * local_re, const unsigned int ib, const unsigned int ie)
250 {
251 for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
252 for (unsigned int i = ib; i < ie; ++i)
253 local_re[i] += datum.JxW(qp) * bc.template computeQpResidual<Derived>(i, qp, datum);
254 });
255}
256
257template <typename Derived>
258KOKKOS_FUNCTION void
259IntegratedBC::computeJacobianInternal(const Derived & bc, AssemblyDatum & datum) const
260{
262 datum,
263 [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
264 {
265 for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
266 for (unsigned int i = ib; i < ie; ++i)
267 local_ke[i] += datum.JxW(qp) * bc.template computeQpJacobian<Derived>(i, j, qp, datum);
268 });
269}
270
271template <typename Derived>
272KOKKOS_FUNCTION void
274{
276 datum,
277 [&](Real * local_ke, const unsigned int ib, const unsigned int ie, const unsigned int j)
278 {
279 for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
280 for (unsigned int i = ib; i < ie; ++i)
281 local_ke[i] += datum.JxW(qp) * bc.template computeQpOffDiagJacobian<Derived>(
282 i, j, datum.jvar(), qp, datum);
283 });
284}
285
286} // namespace Moose::Kokkos
KOKKOS_FUNCTION auto kokkosBoundaryElementSideID(Moose::Kokkos::ThreadID tid) const
Get the contiguous element ID - side index pair this Kokkos thread is operating on.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
The Kokkos object that holds thread-private data in the parallel operations of Kokkos kernels.
KOKKOS_FUNCTION unsigned int jvar() const
Get the coupled variable number.
KOKKOS_FUNCTION const Assembly & kokkosAssembly() const
Get the const reference of the Kokkos assembly.
KOKKOS_FUNCTION Real JxW(const unsigned int qp)
Get the transformed Jacobian weight.
KOKKOS_FUNCTION void set_local_parallel(const unsigned int local_thread_id, const unsigned int num_local_threads)
Set local parallelization option.
KOKKOS_FUNCTION unsigned int n_qps() const
Get the number of local quadrature points.
The base class for Kokkos integrated boundary conditions.
The base class for a user to derive their own Kokkos integrated boundary conditions.
const VariablePhiValue _phi
Current shape function.
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...
static auto defaultJacobian()
Functions used to check if users have overriden the hook methods, whose calculations can be skipped w...
static InputParameters validParams()
KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int, const unsigned int, const unsigned int, const unsigned int, AssemblyDatum &) const
Compute off-diagonal Jacobian contribution on a quadrature point.
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...
IntegratedBC(const InputParameters &parameters)
Constructor.
KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived &bc) const
The parallel computation entry functions called by Kokkos.
const VariableGradient _grad_u
Gradient of the current solution at quadrature points.
const VariableValue _u
Current solution at quadrature points.
const VariableTestGradient _grad_test
Gradient of the current test function.
const VariablePhiGradient _grad_phi
Gradient of the current shape function.
KOKKOS_FUNCTION void computeJacobianInternal(const Derived &bc, AssemblyDatum &datum) const
Compute diagonal Jacobian.
const VariableTestValue _test
Current test function.
virtual void computeJacobian() override
Dispatch diagonal and off-diagonal Jacobian calculation.
KOKKOS_FUNCTION void computeOffDiagJacobianInternal(const Derived &bc, AssemblyDatum &datum) const
Compute off-diagonal Jacobian.
virtual void computeResidual() override
Dispatch residual calculation.
KOKKOS_FUNCTION const Mesh & kokkosMesh() const
Get the const reference of the Kokkos mesh.
Definition KokkosMesh.h:651
Variable _kokkos_var
Kokkos variable.
Thread _thread
Kokkos thread object.
KOKKOS_FUNCTION void computeJacobianInternal(AssemblyDatum &datum, function body) const
The common loop structure template for computing elemental Jacobian.
KOKKOS_FUNCTION void computeResidualInternal(AssemblyDatum &datum, function body) const
The common loop structure template for computing elemental residual.
KOKKOS_FUNCTION thread_id_type size() const
Get the total thread pool size.
The Kokkos wrapper classes for MOOSE-like shape function access.
The Kokkos wrapper classes for MOOSE-like variable value access.
KOKKOS_FUNCTION unsigned int var(unsigned int comp=0) const
Get the variable number of a component.
KOKKOS_FUNCTION unsigned int sys(unsigned int comp=0) const
Get the system number of a component.
MOOSE_KOKKOS_INDEX_TYPE ThreadID