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

#include <KokkosVariableValue.h>

Public Member Functions

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

Private Types

using real3_type = std::conditional_t< is_ad, ADReal3, Real3 >
 

Private Attributes

Variable _var
 Coupled Kokkos variable. More...
 
Array< Real_seed
 Derivative seed of each component for AD. More...
 
 VariableGradientTempl (const VariableGradientTempl< is_ad > &object)
 Copy constructor for parallel dispatch. More...
 
VariableGradientTempl< is_ad > & operator= (const VariableGradientTempl< is_ad > &object)
 Copy assignment operator. More...
 
KOKKOS_FUNCTION auto operator() (AssemblyDatum &datum, unsigned int qp, unsigned int comp=0) const
 Get the current variable gradient. More...
 
KOKKOS_FUNCTION auto get (Datum &datum, unsigned int qp, unsigned int comp=0, Real seed=0) const
 Get the current variable gradient. More...
 

Detailed Description

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

Definition at line 346 of file KokkosVariableValue.h.

Member Typedef Documentation

◆ real3_type

template<bool is_ad>
using Moose::Kokkos::VariableGradientTempl< is_ad >::real3_type = std::conditional_t<is_ad, ADReal3, Real3>
private

Definition at line 348 of file KokkosVariableValue.h.

Constructor & Destructor Documentation

◆ VariableGradientTempl() [1/6]

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

Default constructor.

◆ VariableGradientTempl() [2/6]

template<bool is_ad>
Moose::Kokkos::VariableGradientTempl< is_ad >::VariableGradientTempl ( Variable  var)
inline

Constructor.

Parameters
varThe Kokkos variable

Definition at line 359 of file KokkosVariableValue.h.

359 : _var(var) {}
Variable _var
Coupled Kokkos variable.

◆ VariableGradientTempl() [3/6]

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

Constructor.

Parameters
varThe MOOSE variable
tagThe vector tag name

Definition at line 365 of file KokkosVariableValue.h.

367  : _var(var, tag)
368  {
369  }
Variable _var
Coupled Kokkos variable.

◆ VariableGradientTempl() [4/6]

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

Constructor.

Parameters
varsThe MOOSE variables
tagThe vector tag name

Definition at line 376 of file KokkosVariableValue.h.

378  : _var(vars, tag)
379  {
380  }
char ** vars
Variable _var
Coupled Kokkos variable.

◆ VariableGradientTempl() [5/6]

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

Definition at line 381 of file KokkosVariableValue.h.

383  : _var(vars, tag)
384  {
385  }
char ** vars
Variable _var
Coupled Kokkos variable.

◆ VariableGradientTempl() [6/6]

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

Copy constructor for parallel dispatch.

Definition at line 454 of file KokkosVariableValue.h.

455  : _var(object._var), _seed(object._seed)
456 {
457  if constexpr (is_ad)
458  if (_var.coupled())
459  {
460  if (!_seed.isAlloc())
462 
463  for (unsigned int comp = 0; comp < _var.components(); ++comp)
464  _seed[comp] =
465  _var.dot() ? _var.mooseVar(comp)->sys().duDotDu(_var.var(comp)) : (_var.old() ? 0 : 1);
466 
468  }
469 }
KOKKOS_FUNCTION bool old() const
Get whether the tag is old/older value.
Array< Real > _seed
Derivative seed of each component for AD.
KOKKOS_FUNCTION bool dot() const
Get whether the tag is time derivative.
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.
Variable _var
Coupled Kokkos variable.
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::VariableGradientTempl< is_ad >::get ( Datum datum,
unsigned int  qp,
unsigned int  comp = 0,
Real  seed = 0 
) const
private

Get the current variable gradient.

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

Definition at line 499 of file KokkosVariableValue.h.

503 {
504  KOKKOS_ASSERT(_var.initialized());
505 
506  real3_type grad;
507 
508  if (_var.coupled())
509  {
510  KOKKOS_ASSERT(!datum.isNodal());
511 
512  auto & elem = datum.elem();
513  auto side = datum.side();
514 
515  if constexpr (is_ad)
516  grad =
517  side == libMesh::invalid_uint
518  ? datum.system(_var.sys(comp))
519  .getVectorQpADGrad(
520  elem, datum.J(qp), datum.qpOffset(), qp, _var.var(comp), _var.tag(), seed)
521  : datum.system(_var.sys(comp))
522  .getVectorQpADGradFace(
523  elem, side, datum.J(qp), qp, _var.var(comp), _var.tag(), seed);
524  else
525  grad =
526  side == libMesh::invalid_uint
527  ? datum.system(_var.sys(comp))
528  .getVectorQpGrad(elem, datum.qpOffset() + qp, _var.var(comp), _var.tag())
529  : datum.system(_var.sys(comp))
530  .getVectorQpGradFace(elem, side, datum.J(qp), qp, _var.var(comp), _var.tag());
531  }
532 
533  return grad;
534 }
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.
const unsigned int invalid_uint
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:300
KOKKOS_FUNCTION bool initialized() const
Get whether the variable is initialized.
KOKKOS_FUNCTION bool coupled() const
Get whether the variable is coupled.
std::conditional_t< is_ad, ADReal3, Real3 > real3_type
KOKKOS_FUNCTION unsigned int side() const
Get the side index.
Definition: KokkosDatum.h:108
Variable _var
Coupled Kokkos variable.
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

◆ operator bool()

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

Get whether the variable was coupled.

Returns
Whether the variable was coupled

Definition at line 401 of file KokkosVariableValue.h.

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

◆ operator()() [1/2]

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

Get the current variable gradient.

Parameters
datumThe Datum object of the current thread
qpThe local quadrature point index
compThe variable component
Returns
The variable gradient

Definition at line 410 of file KokkosVariableValue.h.

411  {
412  return get(datum, qp, comp);
413  }

◆ operator()() [2/2]

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

Get the current variable gradient.

Parameters
datumThe AssemblyDatum object of the current thread
qpThe local quadrature point index
compThe variable component
Returns
The variable gradient

Definition at line 482 of file KokkosVariableValue.h.

485 {
486  if constexpr (is_ad)
487  {
488  Real seed =
489  datum.do_derivatives() && _var.coupled() && _var.sys(comp) == datum.sys() ? _seed[comp] : 0;
490 
491  return get(datum, qp, comp, seed);
492  }
493  else
494  return get(datum, qp, comp);
495 }
KOKKOS_FUNCTION unsigned int sys(unsigned int comp=0) const
Get the system number of a component.
Array< Real > _seed
Derivative seed of each component for AD.
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
KOKKOS_FUNCTION bool coupled() const
Get whether the variable is coupled.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Variable _var
Coupled Kokkos variable.

◆ operator=()

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

Copy assignment operator.

Definition at line 473 of file KokkosVariableValue.h.

474 {
475  _var = object._var;
476 
477  return *this;
478 }
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::VariableGradientTempl< is_ad >::variable ( ) const
inline

Get the Kokkos variable.

Returns
The Kokkos variable

Definition at line 429 of file KokkosVariableValue.h.

429 { return _var; }
Variable _var
Coupled Kokkos variable.

Member Data Documentation

◆ _seed

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

Derivative seed of each component for AD.

Definition at line 450 of file KokkosVariableValue.h.

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

◆ _var

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

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