Line data Source code
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 21 : { 22 : namespace Kokkos 23 : { 24 : 25 : /** 26 : * The Kokkos variable object that carries the coupled variable and tag information 27 : */ 28 : class Variable 29 : { 30 : public: 31 : using CoupleableKey = ::Moose::PassKey<::Coupleable>; 32 : 33 : /** 34 : * Default constructor 35 : */ 36 3658 : Variable() = default; 37 : /** 38 : * Constructor 39 : * Initialize the variable with a MOOSE variable and vector tag ID 40 : * @param variable The MOOSE variable 41 : * @param tag The vector tag ID 42 : */ 43 : Variable(const MooseVariableBase & variable, const TagID tag) { init(variable, tag); } 44 : /** 45 : * Constructor 46 : * Initialize the variable with a MOOSE variable and vector tag name 47 : * @param variable The MOOSE variable 48 : * @param tag_name The vector tag name 49 : */ 50 4781 : Variable(const MooseVariableBase & variable, const TagName & tag_name = Moose::SOLUTION_TAG) 51 4781 : { 52 4781 : init(variable, tag_name); 53 4781 : } 54 : /** 55 : * Initialize the variable with a MOOSE variable and vector tag ID 56 : * @param variable The MOOSE variable 57 : * @param tag The vector tag ID 58 : */ 59 : void init(const MooseVariableBase & variable, const TagID tag); 60 : /** 61 : * Initialize the variable with a MOOSE variable and vector tag name 62 : * @param variable The MOOSE variable 63 : * @param tag_name The vector tag name 64 : */ 65 : void init(const MooseVariableBase & variable, const TagName & tag_name = Moose::SOLUTION_TAG); 66 : /** 67 : * Initialize the variable with coupled MOOSE variables 68 : * @param variables The coupled MOOSE variables 69 : * @param tag The vector tag ID 70 : */ 71 : void 72 : init(const std::vector<const MooseVariableBase *> & variables, const TagID tag, CoupleableKey); 73 : /** 74 : * Initialize the variable with coupled default values 75 : * @param values The default coupled values 76 : */ 77 : void init(const std::vector<Real> & values, CoupleableKey); 78 : 79 : /** 80 : * Get whether the variable is coupled 81 : * @returns Whether the variable is coupled 82 : */ 83 43397395 : KOKKOS_FUNCTION bool coupled() const { return _coupled; } 84 : /** 85 : * Get the number of components 86 : * @returns The number of components 87 : */ 88 : KOKKOS_FUNCTION unsigned int components() { return _components; } 89 : /** 90 : * Get the vector tag ID 91 : * @returns The vector tag ID 92 : */ 93 46284749 : KOKKOS_FUNCTION TagID tag() const { return _tag; } 94 : /** 95 : * Get the variable number of a component 96 : * @param comp The variable component 97 : * @returns The variable number 98 : */ 99 68016653 : KOKKOS_FUNCTION unsigned int var(unsigned int comp = 0) const { return _var[comp]; } 100 : /** 101 : * Get the system number of a component 102 : * @param comp The variable component 103 : * @returns The system number 104 : */ 105 69256828 : KOKKOS_FUNCTION unsigned int sys(unsigned int comp = 0) const { return _sys[comp]; } 106 : /** 107 : * Get the default value of a component 108 : * @param comp The variable component 109 : * @returns The default value 110 : */ 111 15236 : KOKKOS_FUNCTION Real value(unsigned int comp = 0) const 112 : { 113 : KOKKOS_ASSERT(!_coupled); 114 : 115 15236 : return _default_value[comp]; 116 : } 117 : 118 : private: 119 : /** 120 : * Whether the variable is coupled 121 : */ 122 : bool _coupled = false; 123 : /** 124 : * Number of components 125 : */ 126 : unsigned int _components = 1; 127 : /** 128 : * Vector tag ID 129 : */ 130 : TagID _tag = Moose::INVALID_TAG_ID; 131 : /** 132 : * Variable number of each component 133 : */ 134 : Array<unsigned int> _var; 135 : /** 136 : * System number of each component 137 : */ 138 : Array<unsigned int> _sys; 139 : /** 140 : * Default value of each component when the variable is not coupled 141 : */ 142 : Array<Real> _default_value; 143 : }; 144 : 145 : } // namespace Kokkos 146 : } // namespace Moose