https://mooseframework.inl.gov
Loading...
Searching...
No Matches
KokkosLinearFVFluxKernel.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
14#include "KokkosDatum.h"
15
16namespace Moose::Kokkos
17{
18
25{
26public:
28
31
32 virtual void computeRightHandSide() override;
33 virtual void computeMatrix() override;
34 virtual void initialSetup() override;
35
37 virtual bool needsBoundaryValueData() const { return false; }
39 virtual bool needsBoundaryNormalGradientData() const { return false; }
41 virtual bool hasInternalRightHandSideContribution() const { return true; }
42
45 {
46 };
49 {
50 };
53 {
54 };
57 {
58 };
59
60 template <typename Derived>
61 KOKKOS_FUNCTION void
62 operator()(InternalRightHandSideLoop, const ThreadID tid, const Derived & kernel) const;
63
64 template <typename Derived>
65 KOKKOS_FUNCTION void
66 operator()(BoundaryRightHandSideLoop, const ThreadID tid, const Derived & kernel) const;
67
68 template <typename Derived>
69 KOKKOS_FUNCTION void
70 operator()(InternalMatrixLoop, const ThreadID tid, const Derived & kernel) const;
71
72 template <typename Derived>
73 KOKKOS_FUNCTION void
74 operator()(BoundaryMatrixLoop, const ThreadID tid, const Derived & kernel) const;
75
81 template <typename Derived>
82 KOKKOS_FUNCTION Real computeInternalMatrixContribution(const FVDatum & datum) const;
83 template <typename Derived>
84 KOKKOS_FUNCTION Real computeInternalNeighborMatrixContribution(const FVDatum & datum) const;
85 template <typename Derived>
86 KOKKOS_FUNCTION Real computeBoundaryMatrixContribution(
87 const FVDatum & datum, const int bc_index, const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const;
88 template <typename Derived>
89 KOKKOS_FUNCTION Real computeInternalRightHandSideContribution(const FVDatum & datum) const;
90 template <typename Derived>
92 const FVDatum & datum, const int bc_index, const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const;
94
101 template <typename Derived>
103 {
104 return &LinearFVFluxKernel::computeInternalMatrixContribution<Derived>;
105 }
106
107 template <typename Derived>
109 {
110 return &LinearFVFluxKernel::computeInternalNeighborMatrixContribution<Derived>;
111 }
112
113 template <typename Derived>
115 {
116 return &LinearFVFluxKernel::computeBoundaryMatrixContribution<Derived>;
117 }
119
120protected:
125 {
127 unsigned int side;
129 MOOSE_KOKKOS_INDEX_TYPE bc_face_index;
130
131 bool operator<(const BoundaryFaceID & other) const
132 {
133 if (bc_index != other.bc_index)
134 return bc_index < other.bc_index;
135 if (elem != other.elem)
136 return elem < other.elem;
137 return side < other.side;
138 }
139 };
140
141#ifndef NDEBUG
147 KOKKOS_FUNCTION bool hasFaceNeighbor(const FVDatum & datum) const;
148
150 KOKKOS_FUNCTION bool hasBoundaryData(const FVDatum & datum, const int bc_index) const;
151#endif
152
154 KOKKOS_FUNCTION Real boundaryValueCoefficient(const int bc_index,
155 const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const;
157 KOKKOS_FUNCTION Real boundaryValueSource(const int bc_index,
158 const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const;
160 KOKKOS_FUNCTION Real boundaryNormalGradientCoefficient(
161 const int bc_index, const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const;
163 KOKKOS_FUNCTION Real boundaryNormalGradientSource(
164 const int bc_index, const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const;
165
174
175 std::unique_ptr<DispatcherBase> _internal_rhs_dispatcher;
176 std::unique_ptr<DispatcherBase> _boundary_rhs_dispatcher;
177 std::unique_ptr<DispatcherBase> _internal_matrix_dispatcher;
178 std::unique_ptr<DispatcherBase> _boundary_matrix_dispatcher;
179};
180
181#ifndef NDEBUG
182KOKKOS_FUNCTION inline bool
184{
185 if (!datum.hasNeighbor())
186 return false;
187
188 const auto & sys = kokkosSystem(_var.sys());
189 return sys.isVariableActive(_var.var(), datum.neighborSubdomain());
190}
191
192KOKKOS_FUNCTION inline bool
193LinearFVFluxKernel::hasBoundaryData(const FVDatum & datum, const int bc_index) const
194{
195 return bc_index >= 0 && _bc_index.isAlloc() &&
196 _bc_index(datum.side(), datum.elemID()) == bc_index;
197}
198#endif
199
200KOKKOS_FUNCTION inline Real
202 const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const
203{
204 KOKKOS_ASSERT(bc_index >= 0);
205 return _bc_data[bc_index].value.coefficient[bc_face_index];
206}
207
208KOKKOS_FUNCTION inline Real
210 const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const
211{
212 KOKKOS_ASSERT(bc_index >= 0);
213 return _bc_data[bc_index].value.source[bc_face_index];
214}
215
216KOKKOS_FUNCTION inline Real
218 const int bc_index, const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const
219{
220 KOKKOS_ASSERT(bc_index >= 0);
221 return _bc_data[bc_index].normal_gradient.coefficient[bc_face_index];
222}
223
224KOKKOS_FUNCTION inline Real
226 const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const
227{
228 KOKKOS_ASSERT(bc_index >= 0);
229 return _bc_data[bc_index].normal_gradient.source[bc_face_index];
230}
231
232template <typename Derived>
233KOKKOS_FUNCTION Real
235{
236 ::Kokkos::abort("Default computeInternalMatrixContribution() should never be called. Make sure "
237 "you properly redefined this method in your class without typos.");
238
239 return 0;
240}
241
242template <typename Derived>
243KOKKOS_FUNCTION Real
245{
246 ::Kokkos::abort("Default computeInternalNeighborMatrixContribution() should never be called. "
247 "Make sure you properly redefined this method in your class without typos.");
248
249 return 0;
250}
251
252template <typename Derived>
253KOKKOS_FUNCTION Real
255 const int,
256 const MOOSE_KOKKOS_INDEX_TYPE) const
257{
258 ::Kokkos::abort("Default computeBoundaryMatrixContribution() should never be called. Make sure "
259 "you properly redefined this method in your class without typos.");
260
261 return 0;
262}
263
264template <typename Derived>
265KOKKOS_FUNCTION Real
267{
268 ::Kokkos::abort("Default computeInternalRightHandSideContribution() should never be called. Make "
269 "sure you properly redefined this method in your class without typos.");
270
271 return 0;
272}
273
274template <typename Derived>
275KOKKOS_FUNCTION Real
277 const int,
278 const MOOSE_KOKKOS_INDEX_TYPE) const
279{
280 ::Kokkos::abort("Default computeBoundaryRightHandSideContribution() should never be called. Make "
281 "sure you properly redefined this method in your class without typos.");
282
283 return 0;
284}
285
286template <typename Derived>
287KOKKOS_FUNCTION void
289 const ThreadID tid,
290 const Derived & kernel) const
291{
292 const auto [elem, side] = _internal_face_ids[tid];
293 FVDatum datum(elem, side, kokkosMesh());
294 KOKKOS_ASSERT(hasFaceNeighbor(datum));
295
296 KOKKOS_ASSERT(_var.components() == 1);
297 const auto & sys = kokkosSystem(_var.sys());
298 kernel.accumulateTaggedVector(
299 kernel.template computeInternalRightHandSideContribution<Derived>(datum),
300 sys.getElemLocalDofIndex(elem, 0, _var.var()));
301}
302
303template <typename Derived>
304KOKKOS_FUNCTION void
306 const ThreadID tid,
307 const Derived & kernel) const
308{
309 const auto [elem, side, bc_index, bc_face_index] = _boundary_face_ids[tid];
310 FVDatum datum(elem, side, kokkosMesh());
311 KOKKOS_ASSERT(hasBoundaryData(datum, bc_index));
312
313 KOKKOS_ASSERT(_var.components() == 1);
314 const auto & sys = kokkosSystem(_var.sys());
315 kernel.accumulateTaggedVector(kernel.template computeBoundaryRightHandSideContribution<Derived>(
316 datum, bc_index, bc_face_index),
317 sys.getElemLocalDofIndex(elem, 0, _var.var()));
318}
319
320template <typename Derived>
321KOKKOS_FUNCTION void
322LinearFVFluxKernel::operator()(InternalMatrixLoop, const ThreadID tid, const Derived & kernel) const
323{
324 const auto [elem, side] = _internal_face_ids[tid];
325 FVDatum datum(elem, side, kokkosMesh());
326 KOKKOS_ASSERT(hasFaceNeighbor(datum));
327
328 KOKKOS_ASSERT(_var.components() == 1);
329 const auto var_num = _var.var();
330 const auto & sys = kokkosSystem(_var.sys());
331 const auto row = sys.getElemLocalDofIndex(elem, 0, var_num);
332 kernel.accumulateTaggedMatrix(kernel.template computeInternalMatrixContribution<Derived>(datum),
333 row,
334 sys.getElemGlobalDofIndex(elem, 0, var_num));
335 kernel.accumulateTaggedMatrix(
336 kernel.template computeInternalNeighborMatrixContribution<Derived>(datum),
337 row,
338 sys.getElemGlobalDofIndex(datum.neighborID(), 0, var_num));
339}
340
341template <typename Derived>
342KOKKOS_FUNCTION void
343LinearFVFluxKernel::operator()(BoundaryMatrixLoop, const ThreadID tid, const Derived & kernel) const
344{
345 const auto [elem, side, bc_index, bc_face_index] = _boundary_face_ids[tid];
346 FVDatum datum(elem, side, kokkosMesh());
347 KOKKOS_ASSERT(hasBoundaryData(datum, bc_index));
348
349 KOKKOS_ASSERT(_var.components() == 1);
350 const auto var_num = _var.var();
351 const auto & sys = kokkosSystem(_var.sys());
352 const auto row = sys.getElemLocalDofIndex(elem, 0, var_num);
353 kernel.accumulateTaggedMatrix(
354 kernel.template computeBoundaryMatrixContribution<Derived>(datum, bc_index, bc_face_index),
355 row,
356 sys.getElemGlobalDofIndex(elem, 0, var_num));
357}
358
359} // namespace Moose::Kokkos
dof_id_type ContiguousElementID
Definition KokkosMesh.h:20
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 array class.
Device-side geometric context for finite volume kernels and boundary conditions.
Base class for Kokkos linear finite volume kernels that contribute on faces (flux terms).
std::unique_ptr< DispatcherBase > _boundary_matrix_dispatcher
KOKKOS_FUNCTION Real computeInternalMatrixContribution(const FVDatum &datum) const
Default methods to prevent compile errors when matrix/RHS contributions are not defined in the derive...
KOKKOS_FUNCTION void operator()(InternalRightHandSideLoop, const ThreadID tid, const Derived &kernel) const
KOKKOS_FUNCTION bool hasFaceNeighbor(const FVDatum &datum) const
Whether this face has a mesh neighbor on a subdomain where this kernel's variable is active.
KOKKOS_FUNCTION Real computeBoundaryRightHandSideContribution(const FVDatum &datum, const int bc_index, const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const
KOKKOS_FUNCTION Real computeInternalRightHandSideContribution(const FVDatum &datum) const
static auto defaultInternalMatrixContribution()
Functions used to check if users have overriden the matrix hook methods, whose calculations can be sk...
std::unique_ptr< DispatcherBase > _internal_rhs_dispatcher
KOKKOS_FUNCTION Real computeInternalNeighborMatrixContribution(const FVDatum &datum) const
static InputParameters validParams()
Array2D< int > _bc_index
Setup/debug map from (side, element) to compact boundary condition index.
virtual bool needsBoundaryNormalGradientData() const
Whether this kernel needs boundary normal gradient data from its boundary conditions.
KOKKOS_FUNCTION Real boundaryNormalGradientCoefficient(const int bc_index, const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const
Boundary normal gradient coefficient for this boundary face.
KOKKOS_FUNCTION Real boundaryValueSource(const int bc_index, const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const
Boundary value source for this boundary face.
virtual void computeRightHandSide() override
Compute the right-hand side contributions of this object.
KOKKOS_FUNCTION Real computeBoundaryMatrixContribution(const FVDatum &datum, const int bc_index, const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const
virtual bool hasInternalRightHandSideContribution() const
Whether this kernel has nonzero internal-face RHS contributions.
LinearFVFluxKernel(const InputParameters &parameters)
std::unique_ptr< DispatcherBase > _internal_matrix_dispatcher
std::unique_ptr< DispatcherBase > _boundary_rhs_dispatcher
KOKKOS_FUNCTION Real boundaryValueCoefficient(const int bc_index, const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const
Boundary value coefficient for this boundary face.
Array< FaceID > _internal_face_ids
Directed internal element sides with an active variable on the neighbor element.
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
LinearFVFluxKernel(const LinearFVFluxKernel &object)
KOKKOS_FUNCTION Real boundaryNormalGradientSource(const int bc_index, const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const
Boundary normal gradient source for this boundary face.
Array< LinearFVBoundaryCondition::BoundaryData > _bc_data
Boundary condition data handles indexed by compact boundary condition index.
Array< BoundaryFaceID > _boundary_face_ids
Directed boundary element sides with active Kokkos boundary data.
KOKKOS_FUNCTION bool hasBoundaryData(const FVDatum &datum, const int bc_index) const
Whether this boundary face has a boundary condition data provider.
virtual void computeMatrix() override
Compute the matrix contributions of this object.
virtual bool needsBoundaryValueData() const
Whether this kernel needs boundary value data from its boundary conditions.
Base class for Kokkos linear finite volume kernels that contribute to the linear system.
KOKKOS_FUNCTION ContiguousElementID neighborID() const
Get the contiguous neighbor element ID.
Definition KokkosDatum.h:73
KOKKOS_FUNCTION ContiguousSubdomainID neighborSubdomain() const
Get the contiguous neighbor subdomain ID.
Definition KokkosDatum.h:97
KOKKOS_FUNCTION unsigned int side() const
Get the side index.
Definition KokkosDatum.h:79
KOKKOS_FUNCTION ContiguousElementID elemID() const
Get the contiguous element ID.
Definition KokkosDatum.h:52
KOKKOS_FUNCTION bool hasNeighbor() const
Get whether the current side has a neighbor.
KOKKOS_FUNCTION const Mesh & kokkosMesh() const
Get the const reference of the Kokkos mesh.
Definition KokkosMesh.h:651
KOKKOS_FUNCTION unsigned int components() const
Get the number of components.
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
Directed boundary side and its compact boundary condition and BC-local face indices.
bool operator<(const BoundaryFaceID &other) const
Tag dispatch type for boundary-face matrix computation.
Tag dispatch type for boundary-face right-hand side computation.
Tag dispatch type for internal-face matrix computation.
Tag dispatch type for internal-face right-hand side computation.