https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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.
 
 VariableValueTempl (Variable var, bool dof=false)
 Constructor.
 
 VariableValueTempl (const MooseVariableBase &var, const TagName &tag=Moose::SOLUTION_TAG, bool dof=false)
 Constructor.
 
KOKKOS_FUNCTION operator bool () const
 Get whether the variable was coupled.
 
KOKKOS_FUNCTION auto operator() (Datum &datum, unsigned int idx, unsigned int comp=0) const
 Get the current variable value.
 
KOKKOS_FUNCTION const Variable & variable () const
 Get the Kokkos variable.
 

Private Types

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

Private Attributes

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

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/4]

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

Default constructor.

◆ VariableValueTempl() [2/4]

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 || _var.scalar())
232 {
233 checkVariable(_var, false, is_ad ? "ADVariableValue" : "VariableValue");
234 }
bool _dof
Flag whether DOF values are requested.
Variable _var
Coupled Kokkos variable.
KOKKOS_FUNCTION bool scalar() const
Get whether the variable is scalar.
void checkVariable(const Variable &var, bool expect_vector, const std::string &wrapper_name)

◆ VariableValueTempl() [3/4]

template<bool is_ad>
Moose::Kokkos::VariableValueTempl< is_ad >::VariableValueTempl ( const MooseVariableBase &  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 || _var.scalar())
245 {
246 checkVariable(_var, false, is_ad ? "ADVariableValue" : "VariableValue");
247 }

◆ VariableValueTempl() [4/4]

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

Copy constructor for parallel dispatch.

Definition at line 319 of file KokkosVariableValue.h.

320 : _var(object._var), _seed(object._seed), _dof(object._dof)
321{
322 if constexpr (is_ad)
323 if (_var.coupled())
324 {
325 if (!_seed.isAlloc())
327
328 for (unsigned int comp = 0; comp < _var.components(); ++comp)
329 _seed[comp] =
330 _var.dot() ? _var.mooseVar(comp)->sys().duDotDu(_var.var(comp)) : (_var.old() ? 0 : 1);
331
333 }
334}
SystemBase & sys()
Get the system this variable is part of.
void copyToDevice()
Copy data from host to device.
KOKKOS_FUNCTION bool isAlloc() const
Get whether the array was allocated either on host or device.
void create(const std::vector< index_type > &n)
Allocate array on host and device.
Array< Real > _seed
Derivative seed of each component for AD.
KOKKOS_FUNCTION unsigned int components() const
Get the number of components.
KOKKOS_FUNCTION unsigned int var(unsigned int comp=0) const
Get the variable number of a component.
KOKKOS_FUNCTION bool coupled() const
Get whether the variable is coupled.
const MooseVariableBase * mooseVar(unsigned int comp=0)
Get the MOOSE variable of a component.
KOKKOS_FUNCTION bool dot() const
Get whether the tag is time derivative.
virtual const Number & duDotDu(unsigned int var_num=0) const

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

369{
370 KOKKOS_ASSERT(_var.initialized());
371
373
374 if (_var.coupled())
375 {
376 auto & sys = datum.system(_var.sys(comp));
377 auto var = _var.var(comp);
378 auto tag = _var.tag();
379
380 if (_dof)
381 {
382 unsigned int dof;
383
384 if (_var.scalar())
385 dof = sys.getScalarLocalDofIndex(idx, var);
386 else if (datum.isNodal())
387 {
388 auto node = datum.node();
389 dof = sys.getNodeLocalDofIndex(node, 0, var);
390 }
391 else
392 {
393 auto elem = datum.elem().id;
394 dof = sys.getElemLocalDofIndex(elem, idx, var);
395 }
396
397 if constexpr (is_ad)
398 value = sys.getVectorDofADValue(dof, tag, seed);
399 else
400 value = sys.getVectorDofValue(dof, tag);
401 }
402 else
403 {
404 auto & elem = datum.elem();
405 auto side = datum.side();
406
407 if constexpr (is_ad)
408 value = side == libMesh::invalid_uint
409 ? sys.getVectorQpADValue(elem, datum.qpOffset(), idx, var, tag, seed)
410 : sys.getVectorQpADValueFace(elem, side, idx, var, tag, seed);
411 else
413 ? sys.getVectorQpValue(elem, datum.qpOffset() + idx, var, tag)
414 : sys.getVectorQpValueFace(elem, side, idx, var, tag);
415 }
416 }
417 else
418 value = _var.value(_var.scalar() ? idx : comp);
419
420 return value;
421}
KOKKOS_FUNCTION const FESystem & system(unsigned int sys) const
Get the Kokkos system.
KOKKOS_FUNCTION ContiguousNodeID node() const
Get the contiguous node ID.
KOKKOS_FUNCTION dof_id_type qpOffset() const
Get the starting offset into the global quadrature point index.
KOKKOS_FUNCTION bool isNodal() const
Get whether the current datum is on a node.
KOKKOS_FUNCTION unsigned int side() const
Get the side index.
Definition KokkosDatum.h:79
KOKKOS_FUNCTION const ElementInfo & elem() const
Get the element information object.
Definition KokkosDatum.h:46
std::conditional_t< is_ad, ADReal, Real > real_type
KOKKOS_FUNCTION Real value(unsigned int comp=0) const
Get the default value of a component.
KOKKOS_FUNCTION TagID tag() const
Get the vector tag ID.
KOKKOS_FUNCTION bool initialized() const
Get whether the variable is initialized.
KOKKOS_FUNCTION unsigned int sys(unsigned int comp=0) const
Get the system number of a component.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
const unsigned int invalid_uint
ContiguousElementID id
Contiguous element ID.
Definition KokkosMesh.h:42

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

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

262{ return _var.coupled(); }

◆ operator()() [1/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 348 of file KokkosVariableValue.h.

351{
352 if constexpr (is_ad)
353 {
354 Real seed =
355 datum.do_derivatives() && _var.coupled() && _var.sys(comp) == datum.sys() ? _seed[comp] : 0;
356
357 return get(datum, idx, comp, seed);
358 }
359 else
360 return get(datum, idx, comp);
361}
KOKKOS_FUNCTION unsigned int sys() const
Get the system number of variable.
KOKKOS_FUNCTION void do_derivatives(const bool flag)
Set whether to compute derivatives for automatic differentiation (AD)
KOKKOS_FUNCTION auto get(Datum &datum, unsigned int idx, unsigned int comp=0, Real seed=0) const
Get the current variable value.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ operator()() [2/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 271 of file KokkosVariableValue.h.

272 {
273 return get(datum, idx, comp);
274 }

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

339{
340 _var = object._var;
341 _dof = object._dof;
342
343 return *this;
344}
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 315 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 311 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: