https://mooseframework.inl.gov
Loading...
Searching...
No Matches
KokkosVectorNodalBC.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
22{
23public:
25
30
34 virtual void computeResidual() override;
38 virtual void computeJacobian() override;
39
45 template <typename Derived>
46 KOKKOS_FUNCTION Real3 computeQpJacobian(const unsigned int /* qp */,
47 AssemblyDatum & /* datum */) const
48 {
49 return Real3(1);
50 }
51 template <typename Derived>
52 KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int /* jvar */,
53 const unsigned int /* qp */,
54 AssemblyDatum & /* datum */) const
55 {
56 ::Kokkos::abort(
57 "Default computeQpOffDiagJacobian() should never be called. Make sure you properly "
58 "redefined this method in your class without typos.");
59
60 return 0;
61 }
63
69 template <typename Derived>
70 static auto defaultJacobian()
71 {
72 return &VectorNodalBC::computeQpJacobian<Derived>;
73 }
74 template <typename Derived>
76 {
77 return &VectorNodalBC::computeQpOffDiagJacobian<Derived>;
78 }
80
85 template <typename Derived>
86 KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const;
87 template <typename Derived>
88 KOKKOS_FUNCTION void operator()(JacobianLoop, const ThreadID tid, const Derived & bc) const;
89 template <typename Derived>
90 KOKKOS_FUNCTION void
91 operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & bc) const;
93
94protected:
99};
100
101template <typename Derived>
102KOKKOS_FUNCTION void
103VectorNodalBC::operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const
104{
105 auto node = kokkosBoundaryNodeID(tid);
106 auto & sys = kokkosSystem(_kokkos_var.sys());
107
108 if (!sys.isNodalDefined(node, _kokkos_var.var()))
109 return;
110
111 AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var());
112
113 Real3 local_re = bc.template computeQpResidual<Derived>(0, datum);
114
115 for (unsigned int comp = 0; comp < _dimension; ++comp)
116 accumulateTaggedVectorNodalResidual(false, local_re(comp), node, comp);
117}
118
119template <typename Derived>
120KOKKOS_FUNCTION void
121VectorNodalBC::operator()(JacobianLoop, const ThreadID tid, const Derived & bc) const
122{
123 auto node = kokkosBoundaryNodeID(tid);
124 auto & sys = kokkosSystem(_kokkos_var.sys());
125
126 if (!sys.isNodalDefined(node, _kokkos_var.var()))
127 return;
128
129 AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var());
130
131 Real3 local_ke = bc.template computeQpJacobian<Derived>(0, datum);
132
133 for (unsigned int comp = 0; comp < _dimension; ++comp)
134 accumulateTaggedVectorNodalMatrix(false, local_ke(comp), node, comp, comp, _kokkos_var.var());
135}
136
137template <typename Derived>
138KOKKOS_FUNCTION void
139VectorNodalBC::operator()(OffDiagJacobianLoop, const ThreadID tid, const Derived & bc) const
140{
141 auto node = kokkosBoundaryNodeID(_thread(tid, 1));
142 auto & sys = kokkosSystem(_kokkos_var.sys());
143 auto jvar = sys.getCoupling(_kokkos_var.var())[_thread(tid, 0)];
144
145 if (!sys.isNodalDefined(node, _kokkos_var.var()))
146 return;
147
148 AssemblyDatum datum(node, kokkosAssembly(), kokkosSystems(), _kokkos_var, jvar);
149
150 Real3 local_ke = bc.template computeQpOffDiagJacobian<Derived>(jvar, 0, datum);
151
152 for (unsigned int comp = 0; comp < _dimension; ++comp)
153 accumulateTaggedVectorNodalMatrix(true, local_ke(comp), node, comp, 0, jvar);
154}
155
156} // 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.
KOKKOS_FUNCTION void accumulateTaggedVectorNodalMatrix(const bool add, const Real local_ke, const ContiguousNodeID node, const unsigned int i, const unsigned int j, const unsigned int jvar) const
Accumulate or set local nodal Jacobian contribution to tagged matrices for vector FE variables.
Variable _kokkos_var
Kokkos variable.
Thread _thread
Kokkos thread object.
const unsigned int _dimension
Mesh dimension.
KOKKOS_FUNCTION void accumulateTaggedVectorNodalResidual(const bool add, const Real local_re, const ContiguousNodeID node, const unsigned int i) const
Accumulate or set local nodal residual contribution to tagged vectors for vector FE variables.
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.
The base class for a user to derive their own Kokkos nodal boundary conditions on vector variables.
static auto defaultJacobian()
Functions used to check if users have overriden the hook methods, whose calculations can be skipped w...
KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived &bc) const
The parallel computation entry functions called by Kokkos.
KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int, const unsigned int, AssemblyDatum &) const
VectorNodalBC(const InputParameters &parameters)
Constructor.
const VectorVariableValue _u
Current vector solution at nodes.
virtual void computeResidual() override
Dispatch residual calculation.
static InputParameters validParams()
virtual void computeJacobian() override
Dispatch diagonal and off-diagonal Jacobian calculation.
KOKKOS_FUNCTION Real3 computeQpJacobian(const unsigned int, AssemblyDatum &) const
Default methods to prevent compile errors even when these methods were not defined in the derived cla...
Vector3< Real > Real3
Definition KokkosTypes.h:32
MOOSE_KOKKOS_INDEX_TYPE ThreadID