https://mooseframework.inl.gov
Loading...
Searching...
No Matches
KokkosNodalBC.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
12#include "KokkosNodalBCBase.h"
13
14namespace Moose::Kokkos
15{
16
36class NodalBC : public NodalBCBase
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 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
100 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
116 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
125protected:
130};
131
132template <typename Derived>
133KOKKOS_FUNCTION void
134NodalBC::operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const
135{
136 auto comp = _thread(tid, 0);
137 auto node = kokkosBoundaryNodeID(_thread(tid, 1));
138 auto & sys = kokkosSystem(_kokkos_var.sys(comp));
139
140 if (!sys.isNodalDefined(node, _kokkos_var.var(comp)))
141 return;
142
143 AssemblyDatum datum(
144 node, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var(comp), comp);
145
146 Real local_re = bc.template computeQpResidual<Derived>(0, datum);
147
148 accumulateTaggedNodalResidual(false, local_re, node, comp);
149}
150
151template <typename Derived>
152KOKKOS_FUNCTION void
153NodalBC::operator()(JacobianLoop, const ThreadID tid, const Derived & bc) const
154{
155 auto comp = _thread(tid, 0);
156 auto node = kokkosBoundaryNodeID(_thread(tid, 1));
157 auto & sys = kokkosSystem(_kokkos_var.sys(comp));
158
159 if (!sys.isNodalDefined(node, _kokkos_var.var(comp)))
160 return;
161
162 AssemblyDatum datum(
163 node, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var(comp), comp);
164
165 Real local_ke = bc.template computeQpJacobian<Derived>(0, datum);
166
167 // This initializes the row to zero except the diagonal
168 accumulateTaggedNodalMatrix(false, local_ke, node, _kokkos_var.var(comp), comp);
169}
170
171template <typename Derived>
172KOKKOS_FUNCTION void
173NodalBC::operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & bc) const
174{
175 auto comp = _thread(tid, 0);
176 auto node = kokkosBoundaryNodeID(_thread(tid, 2));
177 auto & sys = kokkosSystem(_kokkos_var.sys(comp));
178 auto jvar = sys.getFieldCoupling(_kokkos_var.var(comp))[_thread(tid, 1)];
179
180 if (!sys.isNodalDefined(node, _kokkos_var.var(comp)))
181 return;
182
183 AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, jvar, comp);
184
185 Real local_ke = bc.template computeQpOffDiagJacobian<Derived>(jvar, 0, datum);
186
187 accumulateTaggedNodalMatrix(true, local_ke, node, jvar, comp);
188}
189
190} // namespace Moose::Kokkos
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 boundary conditions.
The base class for a user to derive their own Kokkos nodal boundary conditions.
KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int, const unsigned int, AssemblyDatum &) const
Compute off-diagonal Jacobian contribution on a node.
KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived &bc) const
The parallel computation entry functions called by Kokkos.
const VariableValue _u
Current solution at nodes.
static auto defaultJacobian()
Functions used to check if users have overriden the hook methods, whose calculations can be skipped w...
NodalBC(const InputParameters &parameters)
Constructor.
virtual void computeResidual() override
Dispatch residual calculation.
static InputParameters validParams()
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.
static auto defaultOffDiagJacobian()
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) 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) 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