https://mooseframework.inl.gov
Loading...
Searching...
No Matches
KokkosNodalKernel.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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
37{
38public:
40
45
49 virtual void computeResidual() override;
53 virtual void computeJacobian() override;
54
60
67 template <typename Derived>
68 KOKKOS_FUNCTION Real computeQpJacobian(const unsigned int /* qp */,
69 AssemblyDatum & /* datum */) const
70 {
71 ::Kokkos::abort("Default computeQpJacobian() should never be called. Make sure you properly "
72 "redefined this method in your class without typos.");
73
74 return 0;
75 }
84 template <typename Derived>
85 KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int /* jvar */,
86 const unsigned int /* qp */,
87 AssemblyDatum & /* datum */) const
88 {
89 ::Kokkos::abort(
90 "Default computeQpOffDiagJacobian() should never be called. Make sure you properly "
91 "redefined this method in your class without typos.");
92
93 return 0;
94 }
96
103 template <typename Derived>
104 static auto defaultJacobian()
105 {
106 return &NodalKernel::computeQpJacobian<Derived>;
107 }
108 template <typename Derived>
110 {
111 return &NodalKernel::computeQpOffDiagJacobian<Derived>;
112 }
114
119 template <typename Derived>
120 KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived & kernel) const;
121 template <typename Derived>
122 KOKKOS_FUNCTION void operator()(JacobianLoop, const ThreadID tid, const Derived & kernel) const;
123 template <typename Derived>
124 KOKKOS_FUNCTION void
125 operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & kernel) const;
127
128protected:
133
134private:
139};
140
141template <typename Derived>
142KOKKOS_FUNCTION void
143NodalKernel::operator()(ResidualLoop, const ThreadID tid, const Derived & kernel) const
144{
146 auto & sys = kokkosSystem(_kokkos_var.sys());
147
148 if (!sys.isNodalDefined(node, _kokkos_var.var()))
149 return;
150
151 AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var());
152
153 Real local_re = kernel.template computeQpResidual<Derived>(0, datum);
154
155 accumulateTaggedNodalResidual(true, local_re, node);
156}
157
158template <typename Derived>
159KOKKOS_FUNCTION void
160NodalKernel::operator()(JacobianLoop, const ThreadID tid, const Derived & kernel) const
161{
163 auto & sys = kokkosSystem(_kokkos_var.sys());
164
165 if (!sys.isNodalDefined(node, _kokkos_var.var()))
166 return;
167
168 AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var());
169
170 Real local_ke = kernel.template computeQpJacobian<Derived>(0, datum);
171
172 accumulateTaggedNodalMatrix(true, local_ke, node, _kokkos_var.var());
173}
174
175template <typename Derived>
176KOKKOS_FUNCTION void
177NodalKernel::operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & kernel) const
178{
180 : kokkosBlockNodeID(_thread(tid, 1));
181 auto & sys = kokkosSystem(_kokkos_var.sys());
182 auto jvar = sys.getCoupling(_kokkos_var.var())[_thread(tid, 0)];
183
184 if (!sys.isNodalDefined(node, _kokkos_var.var()))
185 return;
186
187 AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, jvar);
188
189 Real local_ke = kernel.template computeQpOffDiagJacobian<Derived>(jvar, 0, datum);
190
191 accumulateTaggedNodalMatrix(true, local_ke, node, jvar);
192}
193
194} // namespace Moose::Kokkos
KOKKOS_FUNCTION ContiguousElementID kokkosBlockNodeID(Moose::Kokkos::ThreadID tid) const
Get the contiguous node index this Kokkos thread is operating on.
KOKKOS_FUNCTION ContiguousNodeID kokkosBoundaryNodeID(Moose::Kokkos::ThreadID tid) const
Get the contiguous node ID 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 const Assembly & kokkosAssembly() const
Get the const reference of the Kokkos assembly.
The base class for Kokkos nodal kernels.
The base class for a user to derive their own Kokkos nodal kernels.
NodalKernel(const InputParameters &parameters)
Constructor.
static InputParameters validParams()
KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived &kernel) const
The parallel computation entry functions called by Kokkos.
const bool _boundary_restricted
Flag whether this kernel is boundary-restricted.
static auto defaultJacobian()
Functions used to check if users have overriden the hook methods, whose calculations can be skipped w...
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...
virtual void computeJacobian() override
Dispatch diagonal and off-diagonal Jacobian calculation.
KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int, const unsigned int, AssemblyDatum &) const
Compute off-diagonal Jacobian contribution on a node.
const VariableValue _u
Current solution at nodes.
virtual void computeResidual() override
Dispatch residual calculation.
Variable _kokkos_var
Kokkos variable.
Thread _thread
Kokkos thread object.
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.
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 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