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.
 
 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)
 
KOKKOS_FUNCTION auto operator() (AssemblyDatum &datum, unsigned int idx, unsigned int comp) const
 Get the current variable value.
 
KOKKOS_FUNCTION auto operator() (AssemblyDatum &datum, unsigned int idx) const
 

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 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 || _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/6]

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

347 : _var(object._var), _seed(object._seed), _dof(object._dof)
348{
349 if constexpr (is_ad)
350 if (_var.coupled())
351 {
352 if (!_seed.isAlloc())
354
355 for (unsigned int comp = 0; comp < _var.components(); ++comp)
356 _seed[comp] =
357 _var.dot() ? _var.mooseVar(comp)->sys().duDotDu(_var.var(comp)) : (_var.old() ? 0 : 1);
358
360 }
361}
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 392 of file KokkosVariableValue.h.

396{
397 KOKKOS_ASSERT(_var.initialized());
398
400
401 if (_var.coupled())
402 {
403 auto & sys = datum.system(_var.sys(comp));
404 auto var = _var.var(comp);
405 auto tag = _var.tag();
406
407 if (_dof)
408 {
409 unsigned int dof;
410
411 if (_var.scalar())
412 dof = sys.getScalarLocalDofIndex(idx, var);
413 else if (datum.isNodal())
414 {
415 auto node = datum.node();
416 dof = sys.getNodeLocalDofIndex(node, 0, var);
417 }
418 else
419 {
420 auto elem = datum.elem().id;
421 dof = sys.getElemLocalDofIndex(elem, idx, var);
422 }
423
424 if constexpr (is_ad)
425 value = sys.getVectorDofADValue(dof, tag, seed);
426 else
427 value = sys.getVectorDofValue(dof, tag);
428 }
429 else
430 {
431 auto & elem = datum.elem();
432 auto side = datum.side();
433
434 if constexpr (is_ad)
435 value = side == libMesh::invalid_uint
436 ? sys.getVectorQpADValue(elem, datum.qpOffset(), idx, var, tag, seed)
437 : sys.getVectorQpADValueFace(elem, side, idx, var, tag, seed);
438 else
440 ? sys.getVectorQpValue(elem, datum.qpOffset() + idx, var, tag)
441 : sys.getVectorQpValueFace(elem, side, idx, var, tag);
442 }
443 }
444 else
445 value = _var.value(_var.scalar() ? idx : comp);
446
447 return value;
448}
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/3]

template<bool is_ad>
KOKKOS_FUNCTION auto Moose::Kokkos::VariableValueTempl< is_ad >::operator() ( AssemblyDatum &  datum,
unsigned int  idx 
) const
inline

Definition at line 307 of file KokkosVariableValue.h.

308 {
309 return this->operator()(datum, idx, datum.comp());
310 }
KOKKOS_FUNCTION unsigned int comp() const
Get the variable component.
KOKKOS_FUNCTION auto operator()(Datum &datum, unsigned int idx, unsigned int comp=0) const
Get the current variable value.

◆ operator()() [2/3]

template<bool is_ad>
KOKKOS_FUNCTION auto Moose::Kokkos::VariableValueTempl< is_ad >::operator() ( AssemblyDatum &  datum,
unsigned int  idx,
unsigned int  comp 
) 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 375 of file KokkosVariableValue.h.

378{
379 if constexpr (is_ad)
380 {
381 Real seed =
382 datum.do_derivatives() && _var.coupled() && _var.sys(comp) == datum.sys() ? _seed[comp] : 0;
383
384 return get(datum, idx, comp, seed);
385 }
386 else
387 return get(datum, idx, comp);
388}
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()() [3/3]

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 }

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

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

366{
367 _var = object._var;
368 _dof = object._dof;
369
370 return *this;
371}
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 342 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 338 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: