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 MooseVariableFieldBase &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 Variablevariable () const
 Get the Kokkos variable.
 
 VariableValueTempl (const std::vector< const MooseVariableFieldBase * > &vars, const TagName &tag=Moose::SOLUTION_TAG, bool dof=false)
 Constructor.
 
 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.
 
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/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 }
bool _dof
Flag whether DOF values are requested.
Variable _var
Coupled Kokkos variable.
void checkVariable(const Variable &var, bool expect_vector, const std::string &wrapper_name)

◆ 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 }

◆ 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 }
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 }

◆ 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}
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.
KOKKOS_FUNCTION bool dot() const
Get whether the tag is time derivative.
const MooseVariableFieldBase * mooseVar(unsigned int comp=0)
Get the MOOSE variable of a component.
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 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
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 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 284 of file KokkosVariableValue.h.

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

294 {
295 return get(datum, idx, comp);
296 }

◆ 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}
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: