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://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
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 node = kokkosBoundaryNodeID(tid);
137 auto & sys = kokkosSystem(_kokkos_var.sys());
138
139 if (!sys.isNodalDefined(node, _kokkos_var.var()))
140 return;
141
142 AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var());
143
144 Real local_re = bc.template computeQpResidual<Derived>(0, datum);
145
146 accumulateTaggedNodalResidual(false, local_re, node);
147}
148
149template <typename Derived>
150KOKKOS_FUNCTION void
151NodalBC::operator()(JacobianLoop, const ThreadID tid, const Derived & bc) const
152{
153 auto node = kokkosBoundaryNodeID(tid);
154 auto & sys = kokkosSystem(_kokkos_var.sys());
155
156 if (!sys.isNodalDefined(node, _kokkos_var.var()))
157 return;
158
159 AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var());
160
161 Real local_ke = bc.template computeQpJacobian<Derived>(0, datum);
162
163 // This initializes the row to zero except the diagonal
164 accumulateTaggedNodalMatrix(false, local_ke, node, _kokkos_var.var());
165}
166
167template <typename Derived>
168KOKKOS_FUNCTION void
169NodalBC::operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & bc) const
170{
171 auto node = kokkosBoundaryNodeID(_thread(tid, 1));
172 auto & sys = kokkosSystem(_kokkos_var.sys());
173 auto jvar = sys.getCoupling(_kokkos_var.var())[_thread(tid, 0)];
174
175 if (!sys.isNodalDefined(node, _kokkos_var.var()))
176 return;
177
178 AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, jvar);
179
180 Real local_ke = bc.template computeQpOffDiagJacobian<Derived>(jvar, 0, datum);
181
182 accumulateTaggedNodalMatrix(true, local_ke, node, jvar);
183}
184
185} // 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=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