https://mooseframework.inl.gov
KokkosVariable.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "KokkosTypes.h"
13 
14 #include "MooseTypes.h"
15 #include "MooseVariableBase.h"
16 #include "MoosePassKey.h"
17 
18 class Coupleable;
19 
20 namespace Moose::Kokkos
21 {
22 
26 class Variable
27 {
28 public:
30 
34  Variable() = default;
41  Variable(const MooseVariableFieldBase & variable, const TagID tag) { init(variable, tag); }
48  Variable(const MooseVariableFieldBase & variable, const TagName & tag_name = Moose::SOLUTION_TAG)
49  {
50  init(variable, tag_name);
51  }
58  Variable(const std::vector<const MooseVariableFieldBase *> & variables, const TagID tag)
60  {
61  init(variables, tag);
62  }
63  Variable(const std::vector<MooseVariableFieldBase *> & variables, const TagID tag)
64  {
65  init(variables, tag);
66  }
68 
74  Variable(const std::vector<const MooseVariableFieldBase *> & variables,
76  const TagName & tag_name = Moose::SOLUTION_TAG)
77  {
78  init(variables, tag_name);
79  }
80  Variable(const std::vector<MooseVariableFieldBase *> & variables,
81  const TagName & tag_name = Moose::SOLUTION_TAG)
82  {
83  init(variables, tag_name);
84  }
86 
91  void init(const MooseVariableFieldBase & variable, const TagID tag);
97  void init(const MooseVariableFieldBase & variable,
98  const TagName & tag_name = Moose::SOLUTION_TAG);
104  void init(const std::vector<const MooseVariableFieldBase *> & variables, const TagID tag);
106  void init(const std::vector<MooseVariableFieldBase *> & variables, const TagID tag);
108 
113  void init(const std::vector<const MooseVariableFieldBase *> & variables,
115  const TagName & tag_name = Moose::SOLUTION_TAG);
116  void init(const std::vector<MooseVariableFieldBase *> & variables,
117  const TagName & tag_name = Moose::SOLUTION_TAG);
119 
123  void init(const std::vector<Real> & values, CoupleableKey);
124 
130  const MooseVariableFieldBase * mooseVar(unsigned int comp = 0)
131  {
132  return _moose_var.size() ? _moose_var[comp] : nullptr;
133  }
134 
139  KOKKOS_FUNCTION bool initialized() const { return _initialized; }
144  KOKKOS_FUNCTION bool coupled() const { return _coupled; }
149  KOKKOS_FUNCTION bool nodal() const { return _nodal; }
154  KOKKOS_FUNCTION bool dot() const { return _dot; }
159  KOKKOS_FUNCTION bool old() const { return _old; }
164  KOKKOS_FUNCTION unsigned int components() { return _components; }
169  KOKKOS_FUNCTION TagID tag() const { return _tag; }
175  KOKKOS_FUNCTION unsigned int var(unsigned int comp = 0) const { return _var[comp]; }
181  KOKKOS_FUNCTION unsigned int sys(unsigned int comp = 0) const { return _sys[comp]; }
187  KOKKOS_FUNCTION Real value(unsigned int comp = 0) const
188  {
189  KOKKOS_ASSERT(!_coupled);
190 
191  return _default_value[comp];
192  }
193 
194 private:
198  bool _initialized = false;
202  bool _coupled = false;
206  bool _nodal = false;
210  bool _dot = false;
214  bool _old = false;
218  unsigned int _components = 1;
239 };
240 
241 } // namespace Moose::Kokkos
KOKKOS_FUNCTION bool old() const
Get whether the tag is old/older value.
KOKKOS_FUNCTION TagID tag() const
Get the vector tag ID.
The Kokkos array class.
Definition: KokkosArray.h:64
KOKKOS_FUNCTION unsigned int sys(unsigned int comp=0) const
Get the system number of a component.
::Moose::PassKey<::Coupleable > CoupleableKey
unsigned int TagID
Definition: MooseTypes.h:238
bool _initialized
Whether the variable is initialized.
bool _nodal
Whether the variable is nodal.
Variable(const std::vector< MooseVariableFieldBase *> &variables, const TagID tag)
KOKKOS_FUNCTION bool initialized() const
Get whether the variable is initialized.
This class provides an interface for common operations on field variables of both FE and FV types wit...
Variable(const MooseVariableFieldBase &variable, const TagName &tag_name=Moose::SOLUTION_TAG)
Constructor Initialize the variable with a MOOSE variable and vector tag name.
KOKKOS_FUNCTION bool dot() const
Get whether the tag is time derivative.
Array< Real > _default_value
Default value of each component when the variable is not coupled.
KOKKOS_FUNCTION bool coupled() const
Get whether the variable is coupled.
bool _old
Whether the tag is old/older value.
Variable()=default
Default constructor.
KOKKOS_FUNCTION unsigned int components()
Get the number of components.
KOKKOS_FUNCTION index_type size() const
Get the total array size.
Definition: KokkosArray.h:205
void init(const MooseVariableFieldBase &variable, const TagID tag)
Initialize the variable with a MOOSE variable and vector tag ID.
Variable(const MooseVariableFieldBase &variable, const TagID tag)
Constructor Initialize the variable with a MOOSE variable and vector tag ID.
KOKKOS_FUNCTION bool nodal() const
Get whether the variable is nodal.
Array< unsigned int > _sys
System number of each component.
Interface for objects that needs coupling capabilities.
Definition: Coupleable.h:52
bool _dot
Whether the tag is time derivative.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool _coupled
Whether the variable is coupled.
TagID _tag
Vector tag ID.
const TagID INVALID_TAG_ID
Definition: MooseTypes.C:23
KOKKOS_FUNCTION Real value(unsigned int comp=0) const
Get the default value of a component.
The Kokkos variable object that carries the coupled variable and tag information. ...
const MooseVariableFieldBase * mooseVar(unsigned int comp=0)
Get the MOOSE variable of a component.
const TagName SOLUTION_TAG
Definition: MooseTypes.C:25
KOKKOS_FUNCTION unsigned int var(unsigned int comp=0) const
Get the variable number of a component.
unsigned int _components
Number of components.
Array< unsigned int > _var
Variable number of each component.
Array< const MooseVariableFieldBase * > _moose_var
MOOSE variable of each component.
Variable(const std::vector< MooseVariableFieldBase *> &variables, const TagName &tag_name=Moose::SOLUTION_TAG)