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 217 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 219 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 231 of file KokkosVariableValue.h.

231  : _var(var), _dof(dof)
232  {
233  checkVariable(_var, false, is_ad ? "ADVariableValue" : "VariableValue");
234  }
void checkVariable(const Variable &var, bool expect_vector, const std::string &wrapper_name)
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 241 of file KokkosVariableValue.h.

244  : _var(var, tag), _dof(dof)
245  {
246  checkVariable(_var, false, is_ad ? "ADVariableValue" : "VariableValue");
247  }
void checkVariable(const Variable &var, bool expect_vector, const std::string &wrapper_name)
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 255 of file KokkosVariableValue.h.

258  : _var(vars, tag), _dof(dof)
259  {
260  checkVariable(_var, false, is_ad ? "ADVariableValue" : "VariableValue");
261  }
void checkVariable(const Variable &var, bool expect_vector, const std::string &wrapper_name)
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 262 of file KokkosVariableValue.h.

265  : _var(vars, tag), _dof(dof)
266  {
267  checkVariable(_var, false, is_ad ? "ADVariableValue" : "VariableValue");
268  }
void checkVariable(const Variable &var, bool expect_vector, const std::string &wrapper_name)
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 341 of file KokkosVariableValue.h.

342  : _var(object._var), _seed(object._seed), _dof(object._dof)
343 {
344  if constexpr (is_ad)
345  if (_var.coupled())
346  {
347  if (!_seed.isAlloc())
349 
350  for (unsigned int comp = 0; comp < _var.components(); ++comp)
351  _seed[comp] =
352  _var.dot() ? _var.mooseVar(comp)->sys().duDotDu(_var.var(comp)) : (_var.old() ? 0 : 1);
353 
355  }
356 }
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 unsigned int components() const
Get the number of components.
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:269
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:392
void copyToDevice()
Copy data from host to device.
Definition: KokkosArray.h:1167
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 387 of file KokkosVariableValue.h.

391 {
392  KOKKOS_ASSERT(_var.initialized());
393 
395 
396  if (_var.coupled())
397  {
398  auto & sys = datum.system(_var.sys(comp));
399  auto var = _var.var(comp);
400  auto tag = _var.tag();
401 
402  if (_dof)
403  {
404  unsigned int dof;
405 
406  if (datum.isNodal())
407  {
408  auto node = datum.node();
409  dof = sys.getNodeLocalDofIndex(node, 0, var);
410  }
411  else
412  {
413  auto elem = datum.elem().id;
414  dof = sys.getElemLocalDofIndex(elem, idx, var);
415  }
416 
417  if constexpr (is_ad)
418  value = sys.getVectorDofADValue(dof, tag, seed);
419  else
420  value = sys.getVectorDofValue(dof, tag);
421  }
422  else
423  {
424  auto & elem = datum.elem();
425  auto side = datum.side();
426 
427  if constexpr (is_ad)
428  value = side == libMesh::invalid_uint
429  ? sys.getVectorQpADValue(elem, datum.qpOffset(), idx, var, tag, seed)
430  : sys.getVectorQpADValueFace(elem, side, idx, var, tag, seed);
431  else
432  value = side == libMesh::invalid_uint
433  ? sys.getVectorQpValue(elem, datum.qpOffset() + idx, var, tag)
434  : sys.getVectorQpValueFace(elem, side, idx, var, tag);
435  }
436  }
437  else
438  value = _var.value(comp);
439 
440  return value;
441 }
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 const FESystem & system(unsigned int sys) const
Get the Kokkos system.
Definition: KokkosDatum.h:281
KOKKOS_FUNCTION bool initialized() const
Get whether the variable is initialized.
KOKKOS_FUNCTION unsigned int side() const
Get the side index.
Definition: KokkosDatum.h:79
KOKKOS_FUNCTION bool coupled() const
Get whether the variable is coupled.
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:297
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:324
KOKKOS_FUNCTION const ElementInfo & elem() const
Get the element information object.
Definition: KokkosDatum.h:46
KOKKOS_FUNCTION unsigned int var(unsigned int comp=0) const
Get the variable number of a component.
KOKKOS_FUNCTION dof_id_type qpOffset() const
Get the starting offset into the global quadrature point index.
Definition: KokkosDatum.h:309
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 284 of file KokkosVariableValue.h.

284 { 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 293 of file KokkosVariableValue.h.

294  {
295  return get(datum, idx, comp);
296  }
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 370 of file KokkosVariableValue.h.

373 {
374  if constexpr (is_ad)
375  {
376  Real seed =
377  datum.do_derivatives() && _var.coupled() && _var.sys(comp) == datum.sys() ? _seed[comp] : 0;
378 
379  return get(datum, idx, comp, seed);
380  }
381  else
382  return get(datum, idx, comp);
383 }
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:671
KOKKOS_FUNCTION unsigned int sys() const
Get the system number of variable.
Definition: KokkosDatum.h:636
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 360 of file KokkosVariableValue.h.

361 {
362  _var = object._var;
363  _dof = object._dof;
364 
365  return *this;
366 }
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 337 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 333 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: