https://mooseframework.inl.gov
Public Member Functions | Private Types | Private Attributes | List of all members
Moose::Kokkos::VariableValueTempl< is_ad > Class Template Reference

The Kokkos wrapper classes for MOOSE-like variable value access. More...

#include <KokkosVariableValue.h>

Public Member Functions

 VariableValueTempl ()=default
 Default constructor. More...
 
 VariableValueTempl (Variable var, bool dof=false)
 Constructor. More...
 
 VariableValueTempl (const MooseVariableFieldBase &var, const TagName &tag=Moose::SOLUTION_TAG, bool dof=false)
 Constructor. More...
 
KOKKOS_FUNCTION operator bool () const
 Get whether the variable was coupled. More...
 
KOKKOS_FUNCTION auto operator() (Datum &datum, unsigned int idx, unsigned int comp=0) const
 Get the current variable value. More...
 
KOKKOS_FUNCTION const Variablevariable () const
 Get the Kokkos variable. More...
 
 VariableValueTempl (const std::vector< const MooseVariableFieldBase *> &vars, const TagName &tag=Moose::SOLUTION_TAG, bool dof=false)
 Constructor. More...
 
 VariableValueTempl (const std::vector< MooseVariableFieldBase *> &vars, const TagName &tag=Moose::SOLUTION_TAG, bool dof=false)
 

Private Types

using real_type = std::conditional_t< is_ad, ADReal, Real >
 

Private Attributes

Variable _var
 Coupled Kokkos variable. More...
 
Array< Real_seed
 Derivative seed of each component for AD. More...
 
bool _dof = false
 Flag whether DOF values are requested. More...
 
 VariableValueTempl (const VariableValueTempl< is_ad > &object)
 Copy constructor for parallel dispatch. More...
 
VariableValueTempl< is_ad > & operator= (const VariableValueTempl< is_ad > &object)
 Copy assignment operator. More...
 
KOKKOS_FUNCTION auto operator() (AssemblyDatum &datum, unsigned int idx, unsigned int comp=0) const
 Get the current variable value. More...
 
KOKKOS_FUNCTION auto get (Datum &datum, unsigned int idx, unsigned int comp=0, Real seed=0) const
 Get the current variable value. More...
 

Detailed Description

template<bool is_ad>
class Moose::Kokkos::VariableValueTempl< is_ad >

The Kokkos wrapper classes for MOOSE-like variable value access.

Definition at line 125 of file KokkosVariableValue.h.

Member Typedef Documentation

◆ real_type

template<bool is_ad>
using Moose::Kokkos::VariableValueTempl< is_ad >::real_type = std::conditional_t<is_ad, ADReal, Real>
private

Definition at line 127 of file KokkosVariableValue.h.

Constructor & Destructor Documentation

◆ VariableValueTempl() [1/6]

template<bool is_ad>
Moose::Kokkos::VariableValueTempl< is_ad >::VariableValueTempl ( )
default

Default constructor.

◆ VariableValueTempl() [2/6]

template<bool is_ad>
Moose::Kokkos::VariableValueTempl< is_ad >::VariableValueTempl ( Variable  var,
bool  dof = false 
)
inline

Constructor.

Parameters
varThe Kokkos variable
dofWhether to get DOF values

Definition at line 139 of file KokkosVariableValue.h.

139 : _var(var), _dof(dof) {}
bool _dof
Flag whether DOF values are requested.
Variable _var
Coupled Kokkos variable.

◆ VariableValueTempl() [3/6]

template<bool is_ad>
Moose::Kokkos::VariableValueTempl< is_ad >::VariableValueTempl ( const MooseVariableFieldBase var,
const TagName &  tag = Moose::SOLUTION_TAG,
bool  dof = false 
)
inline

Constructor.

Parameters
varThe MOOSE variable
tagThe vector tag name
dofWhether to get DOF values

Definition at line 146 of file KokkosVariableValue.h.

149  : _var(var, tag), _dof(dof)
150  {
151  }
bool _dof
Flag whether DOF values are requested.
Variable _var
Coupled Kokkos variable.

◆ VariableValueTempl() [4/6]

template<bool is_ad>
Moose::Kokkos::VariableValueTempl< is_ad >::VariableValueTempl ( const std::vector< const MooseVariableFieldBase *> &  vars,
const TagName &  tag = Moose::SOLUTION_TAG,
bool  dof = false 
)
inline

Constructor.

Parameters
varsThe MOOSE variables
tagThe vector tag name
dofWhether to get DOF values

Definition at line 159 of file KokkosVariableValue.h.

162  : _var(vars, tag), _dof(dof)
163  {
164  }
bool _dof
Flag whether DOF values are requested.
Variable _var
Coupled Kokkos variable.
char ** vars

◆ VariableValueTempl() [5/6]

template<bool is_ad>
Moose::Kokkos::VariableValueTempl< is_ad >::VariableValueTempl ( const std::vector< MooseVariableFieldBase *> &  vars,
const TagName &  tag = Moose::SOLUTION_TAG,
bool  dof = false 
)
inline

Definition at line 165 of file KokkosVariableValue.h.

168  : _var(vars, tag), _dof(dof)
169  {
170  }
bool _dof
Flag whether DOF values are requested.
Variable _var
Coupled Kokkos variable.
char ** vars

◆ VariableValueTempl() [6/6]

template<bool is_ad>
Moose::Kokkos::VariableValueTempl< is_ad >::VariableValueTempl ( const VariableValueTempl< is_ad > &  object)

Copy constructor for parallel dispatch.

Definition at line 243 of file KokkosVariableValue.h.

244  : _var(object._var), _seed(object._seed), _dof(object._dof)
245 {
246  if constexpr (is_ad)
247  if (_var.coupled())
248  {
249  if (!_seed.isAlloc())
251 
252  for (unsigned int comp = 0; comp < _var.components(); ++comp)
253  _seed[comp] =
254  _var.dot() ? _var.mooseVar(comp)->sys().duDotDu(_var.var(comp)) : (_var.old() ? 0 : 1);
255 
257  }
258 }
KOKKOS_FUNCTION bool old() const
Get whether the tag is old/older value.
bool _dof
Flag whether DOF values are requested.
Variable _var
Coupled Kokkos variable.
KOKKOS_FUNCTION bool dot() const
Get whether the tag is time derivative.
Array< Real > _seed
Derivative seed of each component for AD.
KOKKOS_FUNCTION bool coupled() const
Get whether the variable is coupled.
KOKKOS_FUNCTION bool isAlloc() const
Get whether the array was allocated either on host or device.
Definition: KokkosArray.h:180
virtual const Number & duDotDu(unsigned int var_num=0) const
Definition: SystemBase.C:1690
void create(const std::vector< index_type > &n)
Allocate array on host and device.
Definition: KokkosArray.h:303
void copyToDevice()
Copy data from host to device.
Definition: KokkosArray.h:947
KOKKOS_FUNCTION unsigned int components()
Get the number of components.
const MooseVariableFieldBase * mooseVar(unsigned int comp=0)
Get the MOOSE variable of a component.
KOKKOS_FUNCTION unsigned int var(unsigned int comp=0) const
Get the variable number of a component.
SystemBase & sys()
Get the system this variable is part of.

Member Function Documentation

◆ get()

template<bool is_ad>
KOKKOS_FUNCTION auto Moose::Kokkos::VariableValueTempl< is_ad >::get ( Datum datum,
unsigned int  idx,
unsigned int  comp = 0,
Real  seed = 0 
) const
private

Get the current variable value.

Parameters
datumThe Datum object of the current thread
idxThe local quadrature point or DOF index
compThe variable component
seedThe derivative seed (only meaningful for AD)
Returns
The variable value

Definition at line 289 of file KokkosVariableValue.h.

293 {
294  KOKKOS_ASSERT(_var.initialized());
295 
297 
298  if (_var.coupled())
299  {
300  auto & sys = datum.system(_var.sys(comp));
301  auto var = _var.var(comp);
302  auto tag = _var.tag();
303 
304  if (_dof)
305  {
306  unsigned int dof;
307 
308  if (datum.isNodal())
309  {
310  auto node = datum.node();
311  dof = sys.getNodeLocalDofIndex(node, 0, var);
312  }
313  else
314  {
315  auto elem = datum.elem().id;
316  dof = sys.getElemLocalDofIndex(elem, idx, var);
317  }
318 
319  if constexpr (is_ad)
320  value = sys.getVectorDofADValue(dof, tag, seed);
321  else
322  value = sys.getVectorDofValue(dof, tag);
323  }
324  else
325  {
326  auto & elem = datum.elem();
327  auto side = datum.side();
328 
329  if constexpr (is_ad)
330  value = side == libMesh::invalid_uint
331  ? sys.getVectorQpADValue(elem, datum.qpOffset(), idx, var, tag, seed)
332  : sys.getVectorQpADValueFace(elem, side, idx, var, tag, seed);
333  else
334  value = side == libMesh::invalid_uint
335  ? sys.getVectorQpValue(elem, datum.qpOffset() + idx, var, tag)
336  : sys.getVectorQpValueFace(elem, side, idx, var, tag);
337  }
338  }
339  else
340  value = _var.value(comp);
341 
342  return value;
343 }
KOKKOS_FUNCTION TagID tag() const
Get the vector tag ID.
KOKKOS_FUNCTION unsigned int sys(unsigned int comp=0) const
Get the system number of a component.
bool _dof
Flag whether DOF values are requested.
const unsigned int invalid_uint
Variable _var
Coupled Kokkos variable.
KOKKOS_FUNCTION bool initialized() const
Get whether the variable is initialized.
KOKKOS_FUNCTION bool coupled() const
Get whether the variable is coupled.
KOKKOS_FUNCTION unsigned int side() const
Get the side index.
Definition: KokkosDatum.h:108
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
std::conditional_t< is_ad, ADReal, Real > real_type
KOKKOS_FUNCTION ContiguousNodeID node() const
Get the contiguous node ID.
Definition: KokkosDatum.h:113
KOKKOS_FUNCTION Real value(unsigned int comp=0) const
Get the default value of a component.
KOKKOS_FUNCTION bool isNodal() const
Get whether the current datum is on a node.
Definition: KokkosDatum.h:146
KOKKOS_FUNCTION const ElementInfo & elem() const
Get the element information object.
Definition: KokkosDatum.h:84
KOKKOS_FUNCTION unsigned int var(unsigned int comp=0) const
Get the variable number of a component.
KOKKOS_FUNCTION const System & system(unsigned int sys) const
Get the Kokkos system.
Definition: KokkosDatum.h:73
KOKKOS_FUNCTION dof_id_type qpOffset() const
Get the starting offset into the global quadrature point index.
Definition: KokkosDatum.h:123
ContiguousElementID id
Contiguous element ID.
Definition: KokkosMesh.h:42
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)

◆ operator bool()

template<bool is_ad>
KOKKOS_FUNCTION Moose::Kokkos::VariableValueTempl< is_ad >::operator bool ( ) const
inline

Get whether the variable was coupled.

Returns
Whether the variable was coupled

Definition at line 186 of file KokkosVariableValue.h.

186 { return _var.coupled(); }
Variable _var
Coupled Kokkos variable.
KOKKOS_FUNCTION bool coupled() const
Get whether the variable is coupled.

◆ operator()() [1/2]

template<bool is_ad>
KOKKOS_FUNCTION auto Moose::Kokkos::VariableValueTempl< is_ad >::operator() ( Datum datum,
unsigned int  idx,
unsigned int  comp = 0 
) const
inline

Get the current variable value.

Parameters
datumThe Datum object of the current thread
idxThe local quadrature point or DOF index
compThe variable component
Returns
The variable value

Definition at line 195 of file KokkosVariableValue.h.

196  {
197  return get(datum, idx, comp);
198  }
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)

◆ operator()() [2/2]

template<bool is_ad>
KOKKOS_FUNCTION auto Moose::Kokkos::VariableValueTempl< is_ad >::operator() ( AssemblyDatum datum,
unsigned int  idx,
unsigned int  comp = 0 
) const

Get the current variable value.

Parameters
datumThe AssemblyDatum object of the current thread
idxThe local quadrature point or DOF index
compThe variable component
Returns
The variable value

Definition at line 272 of file KokkosVariableValue.h.

275 {
276  if constexpr (is_ad)
277  {
278  Real seed =
279  datum.do_derivatives() && _var.coupled() && _var.sys(comp) == datum.sys() ? _seed[comp] : 0;
280 
281  return get(datum, idx, comp, seed);
282  }
283  else
284  return get(datum, idx, comp);
285 }
KOKKOS_FUNCTION unsigned int sys(unsigned int comp=0) const
Get the system number of a component.
Variable _var
Coupled Kokkos variable.
KOKKOS_FUNCTION void do_derivatives(const bool flag)
Set whether to compute derivatives for automatic differentiation (AD)
Definition: KokkosDatum.h:476
KOKKOS_FUNCTION unsigned int sys() const
Get the system number of variable.
Definition: KokkosDatum.h:441
Array< Real > _seed
Derivative seed of each component for AD.
KOKKOS_FUNCTION bool coupled() const
Get whether the variable is coupled.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)

◆ operator=()

template<bool is_ad>
VariableValueTempl< is_ad > & Moose::Kokkos::VariableValueTempl< is_ad >::operator= ( const VariableValueTempl< is_ad > &  object)

Copy assignment operator.

Definition at line 262 of file KokkosVariableValue.h.

263 {
264  _var = object._var;
265  _dof = object._dof;
266 
267  return *this;
268 }
bool _dof
Flag whether DOF values are requested.
Variable _var
Coupled Kokkos variable.
Array< unsigned int > _var
Variable number of each component.

◆ variable()

template<bool is_ad>
KOKKOS_FUNCTION const Variable& Moose::Kokkos::VariableValueTempl< is_ad >::variable ( ) const
inline

Member Data Documentation

◆ _dof

template<bool is_ad>
bool Moose::Kokkos::VariableValueTempl< is_ad >::_dof = false
private

Flag whether DOF values are requested.

Definition at line 239 of file KokkosVariableValue.h.

◆ _seed

template<bool is_ad>
Array<Real> Moose::Kokkos::VariableValueTempl< is_ad >::_seed
private

Derivative seed of each component for AD.

Definition at line 235 of file KokkosVariableValue.h.

Referenced by Moose::Kokkos::VariableValueTempl< is_ad >::VariableValueTempl().

◆ _var

template<bool is_ad>
Variable Moose::Kokkos::VariableValueTempl< is_ad >::_var
private

The documentation for this class was generated from the following file: