https://mooseframework.inl.gov
KokkosVariableValue.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 "KokkosDatum.h"
13 
14 #include "MooseVariableBase.h"
15 
16 namespace Moose
17 {
18 namespace Kokkos
19 {
20 
24 class VariablePhiValue
26 {
27 public:
35  KOKKOS_FUNCTION Real operator()(ResidualDatum & datum, unsigned int i, unsigned int qp) const
36  {
37  auto & elem = datum.elem();
38  auto side = datum.side();
39  auto fe = datum.jfe();
40 
41  return side == libMesh::invalid_uint
42  ? datum.assembly().getPhi(elem.subdomain, elem.type, fe)(i, qp)
43  : datum.assembly().getPhiFace(elem.subdomain, elem.type, fe)(side)(i, qp);
44  }
45 };
46 
48 {
49 public:
57  KOKKOS_FUNCTION Real3 operator()(ResidualDatum & datum, unsigned int i, unsigned int qp) const
58  {
59  auto & elem = datum.elem();
60  auto side = datum.side();
61  auto fe = datum.jfe();
62 
63  return datum.J(qp) *
64  (side == libMesh::invalid_uint
65  ? datum.assembly().getGradPhi(elem.subdomain, elem.type, fe)(i, qp)
66  : datum.assembly().getGradPhiFace(elem.subdomain, elem.type, fe)(side)(i, qp));
67  }
68 };
69 
71 {
72 public:
80  KOKKOS_FUNCTION Real operator()(ResidualDatum & datum, unsigned int i, unsigned int qp) const
81  {
82  auto & elem = datum.elem();
83  auto side = datum.side();
84  auto fe = datum.ife();
85 
86  return side == libMesh::invalid_uint
87  ? datum.assembly().getPhi(elem.subdomain, elem.type, fe)(i, qp)
88  : datum.assembly().getPhiFace(elem.subdomain, elem.type, fe)(side)(i, qp);
89  }
90 };
91 
93 {
94 public:
102  KOKKOS_FUNCTION Real3 operator()(ResidualDatum & datum, unsigned int i, unsigned int qp) const
103  {
104  auto & elem = datum.elem();
105  auto side = datum.side();
106  auto fe = datum.ife();
107 
108  return datum.J(qp) *
109  (side == libMesh::invalid_uint
110  ? datum.assembly().getGradPhi(elem.subdomain, elem.type, fe)(i, qp)
111  : datum.assembly().getGradPhiFace(elem.subdomain, elem.type, fe)(side)(i, qp));
112  }
113 };
115 
119 class VariableValue
121 {
122 public:
127  VariableValue(Variable var) : _var(var) {}
133  VariableValue(const MooseVariableBase & var, const TagName & tag = Moose::SOLUTION_TAG)
134  : _var(var, tag)
135  {
136  }
137 
142  KOKKOS_FUNCTION operator bool() const { return _var.coupled(); }
143 
151  KOKKOS_FUNCTION Real operator()(Datum & datum, unsigned int qp, unsigned int comp = 0) const
152  {
153  if (_var.coupled())
154  {
155  auto & elem = datum.elem();
156  auto side = datum.side();
157  auto qp_offset = datum.qpOffset();
158 
159  return side == libMesh::invalid_uint
160  ? datum.system(_var.sys(comp))
161  .getVectorQpValue(elem, qp_offset + qp, _var.var(comp), _var.tag())
162  : datum.system(_var.sys(comp))
163  .getVectorQpValueFace(elem, side, qp, _var.var(comp), _var.tag());
164  }
165  else
166  return _var.value(comp);
167  }
168 
169 private:
174 };
175 
177 {
178 public:
184  VariableNodalValue(Array<System> & systems, Variable var) : SystemHolder(systems), _var(var) {}
192  const MooseVariableBase & var,
193  const TagName & tag = Moose::SOLUTION_TAG)
194  : SystemHolder(systems), _var(var, tag)
195  {
196  }
197 
202  KOKKOS_FUNCTION operator bool() const { return _var.coupled(); }
203 
210  KOKKOS_FUNCTION Real operator()(ContiguousNodeID node, unsigned int comp = 0) const
211  {
212  if (_var.coupled())
213  {
214  auto dof = kokkosSystem(_var.sys(comp)).getNodeLocalDofIndex(node, _var.var(comp));
215 
216  return kokkosSystem(_var.sys(comp)).getVectorDofValue(dof, _var.tag());
217  }
218  else
219  return _var.value(comp);
220  }
221 
222 private:
227 };
228 
230 {
231 public:
242  VariableGradient(const MooseVariableBase & var, const TagName & tag = Moose::SOLUTION_TAG)
243  : _var(var, tag)
244  {
245  }
246 
251  KOKKOS_FUNCTION operator bool() const { return _var.coupled(); }
252 
260  KOKKOS_FUNCTION Real3 operator()(Datum & datum, unsigned int qp, unsigned int comp = 0) const
261  {
262  if (_var.coupled())
263  {
264  auto & elem = datum.elem();
265  auto side = datum.side();
266  auto qp_offset = datum.qpOffset();
267 
268  return side == libMesh::invalid_uint
269  ? datum.system(_var.sys(comp))
270  .getVectorQpGrad(elem, qp_offset + qp, _var.var(comp), _var.tag())
271  : datum.system(_var.sys(comp))
272  .getVectorQpGradFace(
273  elem, side, datum.J(qp), qp, _var.var(comp), _var.tag());
274  }
275  else
276  return Real3(0);
277  }
278 
279 private:
284 };
286 
287 } // namespace Kokkos
288 } // namespace Moose
KOKKOS_FUNCTION const auto & getPhi(ContiguousSubdomainID subdomain, unsigned int elem_type, unsigned int fe_type) const
Get the shape functions of a FE type for an element type and subdomain.
KOKKOS_FUNCTION TagID tag() const
Get the vector tag ID.
The Kokkos array class.
Definition: KokkosArray.h:56
Variable _var
Coupled Kokkos variable.
KOKKOS_FUNCTION unsigned int sys(unsigned int comp=0) const
Get the system number of a component.
The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object...
Definition: KokkosDatum.h:25
KOKKOS_FUNCTION Real operator()(Datum &datum, unsigned int qp, unsigned int comp=0) const
Get the current variable value.
const unsigned int invalid_uint
VariableValue(Variable var)
Constructor.
VariableNodalValue(Array< System > &systems, Variable var)
Constructor.
OutputTools< Real >::VariablePhiValue VariablePhiValue
Definition: MooseTypes.h:320
KOKKOS_FUNCTION const auto & getGradPhiFace(ContiguousSubdomainID subdomain, unsigned int elem_type, unsigned int fe_type) const
Get the gradient of face shape functions of a FE type for an element type and subdomain.
KOKKOS_FUNCTION const auto & getGradPhi(ContiguousSubdomainID subdomain, unsigned int elem_type, unsigned int fe_type) const
Get the gradient of shape functions of a FE type for an element type and subdomain.
KOKKOS_FUNCTION Real operator()(ContiguousNodeID node, unsigned int comp=0) const
Get the current variable nodal value.
The Kokkos interface that holds the host reference of the Kokkos systems and copies it to device duri...
Definition: KokkosSystem.h:576
KOKKOS_FUNCTION const auto & getPhiFace(ContiguousSubdomainID subdomain, unsigned int elem_type, unsigned int fe_type) const
Get the face shape functions of a FE type for an element type and subdomain.
VariableNodalValue(Array< System > &systems, const MooseVariableBase &var, const TagName &tag=Moose::SOLUTION_TAG)
Constructor.
KOKKOS_FUNCTION bool coupled() const
Get whether the variable is coupled.
KOKKOS_FUNCTION const Real33 & J(const unsigned int qp)
Get the inverse of Jacobian matrix | dxi/dx deta/dx dzeta/dx | | dxi/dy deta/dy dzeta/dy | | dxi/dz d...
Definition: KokkosDatum.h:115
KOKKOS_FUNCTION unsigned int side() const
Get the side index.
Definition: KokkosDatum.h:90
KOKKOS_FUNCTION Real3 operator()(Datum &datum, unsigned int qp, unsigned int comp=0) const
Get the current variable gradient.
KOKKOS_FUNCTION Real operator()(ResidualDatum &datum, unsigned int i, unsigned int qp) const
Get the current test function.
dof_id_type ContiguousNodeID
Definition: KokkosMesh.h:21
KOKKOS_FUNCTION unsigned int ife() const
Get the variable FE type ID.
Definition: KokkosDatum.h:312
KOKKOS_FUNCTION const System & kokkosSystem(unsigned int sys) const
Get the const reference of a Kokkos system.
Definition: KokkosSystem.h:615
KOKKOS_FUNCTION const Assembly & assembly() const
Get the Kokkos assembly.
Definition: KokkosDatum.h:68
VariableValue(const MooseVariableBase &var, const TagName &tag=Moose::SOLUTION_TAG)
Constructor.
VariableGradient(const MooseVariableBase &var, const TagName &tag=Moose::SOLUTION_TAG)
Constructor.
KOKKOS_FUNCTION Real3 operator()(ResidualDatum &datum, unsigned int i, unsigned int qp) const
Get the gradient of the current test function.
KOKKOS_FUNCTION Real operator()(ResidualDatum &datum, unsigned int i, unsigned int qp) const
Get the current shape function.
OutputTools< Real >::VariableValue VariableValue
Definition: MooseTypes.h:315
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
KOKKOS_FUNCTION Real value(unsigned int comp=0) const
Get the default value of a component.
The Kokkos variable object that carries the coupled variable and tag information. ...
KOKKOS_FUNCTION const ElementInfo & elem() const
Get the element information object.
Definition: KokkosDatum.h:80
Variable _var
Coupled Kokkos variable.
const TagName SOLUTION_TAG
Definition: MooseTypes.C:25
Variable _var
Coupled Kokkos variable.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
KOKKOS_FUNCTION unsigned int var(unsigned int comp=0) const
Get the variable number of a component.
VariableGradient(Variable var)
Constructor.
KOKKOS_FUNCTION const System & system(unsigned int sys) const
Get the Kokkos system.
Definition: KokkosDatum.h:74
KOKKOS_FUNCTION dof_id_type qpOffset() const
Get the starting offset into the global quadrature point index.
Definition: KokkosDatum.h:100
KOKKOS_FUNCTION unsigned int jfe() const
Get the coupled variable FE type ID.
Definition: KokkosDatum.h:317
The Kokkos object that holds thread-private data in the parallel operations of Kokkos residual object...
Definition: KokkosDatum.h:222
KOKKOS_FUNCTION Real3 operator()(ResidualDatum &datum, unsigned int i, unsigned int qp) const
Get the gradient of the current shape function.
Base variable class.