https://mooseframework.inl.gov
KokkosLinearFVBoundaryCondition.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 "KokkosDispatcher.h"
13 #include "KokkosDatum.h"
14 #include "KokkosMesh.h"
15 #include "KokkosSystem.h"
16 #include "KokkosVariable.h"
17 
19 #include "FunctionInterface.h"
20 #include "MeshChangedInterface.h"
21 #include "MooseObject.h"
22 #include "PostprocessorInterface.h"
23 #include "Restartable.h"
24 #include "SetupInterface.h"
25 #include "TransientInterface.h"
26 #include "UserObjectInterface.h"
28 
29 class FEProblemBase;
30 class InputParameters;
31 
32 namespace Moose::Kokkos
33 {
34 
41  public SetupInterface,
42  public FunctionInterface,
43  public UserObjectInterface,
44  public TransientInterface,
47  public Restartable,
48  public MeshChangedInterface,
50  public MeshHolder,
51  public SystemHolder
52 {
53 public:
55 
58 
61  {
62  };
65  {
66  };
67 
73  {
75  Real source = 0;
76  };
77 
80  {
83  };
84 
86  struct BoundaryData
87  {
90  };
91 
92  virtual void initialSetup() override;
93 
98  Variable variable() const { return _var; }
99 
103  const BoundaryData & boundaryData() const { return _boundary_data; }
104 
106  MOOSE_KOKKOS_INDEX_TYPE numBoundaryFaces() const;
107 
110  boundaryFaceID(const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const;
111 
113  bool hasBoundaryValue() const;
115  bool hasBoundaryNormalGradient() const;
116 
121 
126  template <typename Derived>
127  KOKKOS_FUNCTION BoundaryRelation computeBoundaryValue(const FVDatum &) const
128  {
129  ::Kokkos::abort("Default computeBoundaryValue() should never be called. Make sure you "
130  "properly redefined this method in your class without typos.");
131 
132  return {};
133  }
134 
139  template <typename Derived>
141  {
142  ::Kokkos::abort("Default computeBoundaryNormalGradient() should never be called. Make sure "
143  "you properly redefined this method in your class without typos.");
144 
145  return {};
146  }
147 
151  template <typename Derived>
153  static auto defaultBoundaryValue()
154  {
155  return &LinearFVBoundaryCondition::computeBoundaryValue<Derived>;
156  }
157 
158  template <typename Derived>
160  {
161  return &LinearFVBoundaryCondition::computeBoundaryNormalGradient<Derived>;
162  }
164 
170  template <typename Derived>
171  KOKKOS_FUNCTION void operator()(BoundaryValueLoop, const ThreadID tid, const Derived & bc) const;
172 
179  template <typename Derived>
180  KOKKOS_FUNCTION void
181  operator()(BoundaryNormalGradientLoop, const ThreadID tid, const Derived & bc) const;
182 
183 protected:
186 
189 
192 
194  std::unique_ptr<DispatcherBase> _boundary_value_dispatcher;
196  std::unique_ptr<DispatcherBase> _boundary_normal_gradient_dispatcher;
197 
213 };
214 
215 template <typename Derived>
216 KOKKOS_FUNCTION void
218  const ThreadID tid,
219  const Derived & bc) const
220 {
221  const auto [elem, side] = kokkosBoundaryElementSideID(tid);
222  FVDatum datum(elem, side, kokkosMesh());
223  const auto relation = bc.template computeBoundaryValue<Derived>(datum);
224  _boundary_data.value.coefficient[tid] = relation.coefficient;
225  _boundary_data.value.source[tid] = relation.source;
226 }
227 
228 template <typename Derived>
229 KOKKOS_FUNCTION void
231  const ThreadID tid,
232  const Derived & bc) const
233 {
234  const auto [elem, side] = kokkosBoundaryElementSideID(tid);
235  FVDatum datum(elem, side, kokkosMesh());
236  const auto relation = bc.template computeBoundaryNormalGradient<Derived>(datum);
237  _boundary_data.normal_gradient.coefficient[tid] = relation.coefficient;
238  _boundary_data.normal_gradient.source[tid] = relation.source;
239 }
240 
241 } // namespace Moose::Kokkos
Affine boundary relation used by Kokkos linear FV kernels: boundary_quantity = coefficient * cell_unk...
Tag dispatch type for boundary normal gradient relation computation.
A class for requiring an object to be boundary restricted.
A class for creating restricted objects.
Definition: Restartable.h:28
Tag dispatch type for boundary value relation computation.
Variable variable() const
Get the Kokkos variable this boundary condition supplies data for.
Scalar< Real > _t
TODO: Move to TransientInterface.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
KOKKOS_FUNCTION BoundaryRelation computeBoundaryValue(const FVDatum &) const
Default boundary value relation hook.
Base class for Kokkos linear finite volume boundary conditions.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
KOKKOS_FUNCTION BoundaryRelation computeBoundaryNormalGradient(const FVDatum &) const
Default boundary normal gradient relation hook.
Boundary relation data indexed by relation type and BC-local boundary face.
The Kokkos interface that holds the host reference of the Kokkos mesh and copies it to device during ...
Definition: KokkosMesh.h:629
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
MOOSE_KOKKOS_INDEX_TYPE numBoundaryFaces() const
Number of faces in this boundary condition&#39;s existing worklist.
void computeBoundaryNormalGradientData()
Dispatch boundary normal gradient relation computation.
Interface for objects that needs transient capabilities.
std::unique_ptr< DispatcherBase > _boundary_value_dispatcher
Dispatcher for boundary value computation.
MOOSE_KOKKOS_INDEX_TYPE ThreadID
Definition: KokkosThread.h:22
Pair< ContiguousElementID, unsigned int > boundaryFaceID(const MOOSE_KOKKOS_INDEX_TYPE bc_face_index) const
Face at a BC-local worklist index.
static InputParameters validParams()
Interface for notifications that the mesh has changed.
Boundary relation coefficient/source arrays indexed by BC-local boundary face.
Scalar< Real > _dt_old
Previous time step size.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
LinearFVBoundaryCondition(const InputParameters &parameters)
Interface for objects that need to use UserObjects.
Scalar< const Real > _t_old
Old (previous time step) time.
bool hasBoundaryNormalGradient() const
Whether this boundary condition overrides the boundary normal gradient relation hook.
KOKKOS_FUNCTION const Mesh & kokkosMesh() const
Get the const reference of the Kokkos mesh.
Definition: KokkosMesh.h:651
KOKKOS_FUNCTION auto kokkosBoundaryElementSideID(Moose::Kokkos::ThreadID tid) const
Get the contiguous element ID - side index pair this Kokkos thread is operating on.
void computeBoundaryValueData()
Dispatch boundary value relation computation.
Scalar< int > _t_step
Current time step number.
FEProblemBase & _fe_problem
Reference to the finite element problem.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
The Kokkos variable object that carries the coupled variable and tag information. ...
static auto defaultBoundaryValue()
Functions used to check whether derived boundary conditions override the boundary data hooks...
Device-side geometric context for finite volume kernels and boundary conditions.
Definition: KokkosDatum.h:167
KOKKOS_FUNCTION void operator()(BoundaryValueLoop, const ThreadID tid, const Derived &bc) const
Boundary value dispatch loop body; writes the per-face boundary value relation.
std::unique_ptr< DispatcherBase > _boundary_normal_gradient_dispatcher
Dispatcher for boundary normal gradient computation.
Interface for objects that need to use functions.
const BoundaryData & boundaryData() const
Get the boundary data relation arrays owned by this boundary condition.
Interface class for classes which interact with Postprocessors.
bool hasBoundaryValue() const
Whether this boundary condition overrides the boundary value relation hook.
BoundaryData _boundary_data
Boundary relation arrays owned by this boundary condition.