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 444 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 446 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 457 of file KokkosVariableValue.h.

457  : _var(var)
458  {
459  checkVariable(_var, false, is_ad ? "ADVariableGradient" : "VariableGradient");
460  }
void checkVariable(const Variable &var, bool expect_vector, const std::string &wrapper_name)
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 466 of file KokkosVariableValue.h.

468  : _var(var, tag)
469  {
470  checkVariable(_var, false, is_ad ? "ADVariableGradient" : "VariableGradient");
471  }
void checkVariable(const Variable &var, bool expect_vector, const std::string &wrapper_name)
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 478 of file KokkosVariableValue.h.

480  : _var(vars, tag)
481  {
482  checkVariable(_var, false, is_ad ? "ADVariableGradient" : "VariableGradient");
483  }
void checkVariable(const Variable &var, bool expect_vector, const std::string &wrapper_name)
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 484 of file KokkosVariableValue.h.

486  : _var(vars, tag)
487  {
488  checkVariable(_var, false, is_ad ? "ADVariableGradient" : "VariableGradient");
489  }
void checkVariable(const Variable &var, bool expect_vector, const std::string &wrapper_name)
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 558 of file KokkosVariableValue.h.

559  : _var(object._var), _seed(object._seed)
560 {
561  if constexpr (is_ad)
562  if (_var.coupled())
563  {
564  if (!_seed.isAlloc())
566 
567  for (unsigned int comp = 0; comp < _var.components(); ++comp)
568  _seed[comp] =
569  _var.dot() ? _var.mooseVar(comp)->sys().duDotDu(_var.var(comp)) : (_var.old() ? 0 : 1);
570 
572  }
573 }
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 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
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 603 of file KokkosVariableValue.h.

607 {
608  KOKKOS_ASSERT(_var.initialized());
609 
610  real3_type grad;
611 
612  if (_var.coupled())
613  {
614  KOKKOS_ASSERT(!datum.isNodal());
615 
616  auto & elem = datum.elem();
617  auto side = datum.side();
618 
619  if constexpr (is_ad)
620  grad =
621  side == libMesh::invalid_uint
622  ? datum.system(_var.sys(comp))
623  .getVectorQpADGrad(
624  elem, datum.J(qp), datum.qpOffset(), qp, _var.var(comp), _var.tag(), seed)
625  : datum.system(_var.sys(comp))
626  .getVectorQpADGradFace(
627  elem, side, datum.J(qp), qp, _var.var(comp), _var.tag(), seed);
628  else
629  grad =
630  side == libMesh::invalid_uint
631  ? datum.system(_var.sys(comp))
632  .getVectorQpGrad(elem, datum.qpOffset() + qp, _var.var(comp), _var.tag())
633  : datum.system(_var.sys(comp))
634  .getVectorQpGradFace(elem, side, datum.J(qp), qp, _var.var(comp), _var.tag());
635  }
636 
637  return grad;
638 }
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 FESystem & system(unsigned int sys) const
Get the Kokkos system.
Definition: KokkosDatum.h:281
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:495
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.
std::conditional_t< is_ad, ADReal3, Real3 > real3_type
Variable _var
Coupled Kokkos variable.
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

◆ 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 505 of file KokkosVariableValue.h.

505 { 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 514 of file KokkosVariableValue.h.

515  {
516  return get(datum, qp, comp);
517  }

◆ 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 586 of file KokkosVariableValue.h.

589 {
590  if constexpr (is_ad)
591  {
592  Real seed =
593  datum.do_derivatives() && _var.coupled() && _var.sys(comp) == datum.sys() ? _seed[comp] : 0;
594 
595  return get(datum, qp, comp, seed);
596  }
597  else
598  return get(datum, qp, comp);
599 }
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:671
KOKKOS_FUNCTION unsigned int sys() const
Get the system number of variable.
Definition: KokkosDatum.h:636
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 577 of file KokkosVariableValue.h.

578 {
579  _var = object._var;
580 
581  return *this;
582 }
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 533 of file KokkosVariableValue.h.

533 { 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 554 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: