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::Kokkos 21 : { 22 : 23 : /** 24 : * The Kokkos variable object that carries the coupled variable and tag information 25 : */ 26 : class Variable 27 : { 28 : public: 29 : using CoupleableKey = ::Moose::PassKey<::Coupleable>; 30 : 31 : /** 32 : * Default constructor 33 : */ 34 22351 : Variable() = default; 35 : /** 36 : * Constructor 37 : * Initialize the variable with a MOOSE variable and vector tag ID 38 : * @param variable The MOOSE variable 39 : * @param tag The vector tag ID 40 : */ 41 : Variable(const MooseVariableFieldBase & variable, const TagID tag) { init(variable, tag); } 42 : /** 43 : * Constructor 44 : * Initialize the variable with a MOOSE variable and vector tag name 45 : * @param variable The MOOSE variable 46 : * @param tag_name The vector tag name 47 : */ 48 14051 : Variable(const MooseVariableFieldBase & variable, const TagName & tag_name = Moose::SOLUTION_TAG) 49 14051 : { 50 14051 : init(variable, tag_name); 51 14051 : } 52 : /** 53 : * Constructor 54 : * Initialize the variable with multiple MOOSE variables and vector tag ID 55 : * @param variables The MOOSE variables 56 : * @param tag The vector tag ID 57 : */ 58 : ///@{ 59 : 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 : } 67 : ///@} 68 : /** 69 : * Constructor 70 : * Initialize the variable with multiple MOOSE variables and vector tag name 71 : * @param variables The MOOSE variables 72 : * @param tag The vector tag ID 73 : */ 74 : ///@{ 75 : 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 : } 85 : ///@} 86 : /** 87 : * Initialize the variable with a MOOSE variable and vector tag ID 88 : * @param variable The MOOSE variable 89 : * @param tag The vector tag ID 90 : */ 91 : void init(const MooseVariableFieldBase & variable, const TagID tag); 92 : /** 93 : * Initialize the variable with a MOOSE variable and vector tag name 94 : * @param variable The MOOSE variable 95 : * @param tag_name The vector tag name 96 : */ 97 : void init(const MooseVariableFieldBase & variable, 98 : const TagName & tag_name = Moose::SOLUTION_TAG); 99 : /** 100 : * Initialize the variable with multiple MOOSE variables and vector tag ID 101 : * @param variables The MOOSE variables 102 : * @param tag The vector tag ID 103 : */ 104 : ///@{ 105 : void init(const std::vector<const MooseVariableFieldBase *> & variables, const TagID tag); 106 : void init(const std::vector<MooseVariableFieldBase *> & variables, const TagID tag); 107 : ///@} 108 : /** 109 : * Initialize the variable with multiple MOOSE variables and vector tag name 110 : * @param variables The MOOSE variables 111 : * @param tag_name The vector tag name 112 : */ 113 : ///@{ 114 : 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); 118 : ///@} 119 : /** 120 : * Initialize the variable with default coupled values 121 : * @param values The default coupled values 122 : */ 123 : void init(const std::vector<Real> & values, CoupleableKey); 124 : /** 125 : * Initialize the variable with default coupled vector values 126 : * @param values The default coupled vector values 127 : */ 128 : void init(const std::vector<Real3> & values, CoupleableKey); 129 : 130 : /** 131 : * Get the MOOSE variable of a component 132 : * @param comp The variable component 133 : * @returns The MOOSE variable 134 : */ 135 8006 : const MooseVariableFieldBase * mooseVar(unsigned int comp = 0) 136 : { 137 8006 : return _moose_var.size() ? _moose_var[comp] : nullptr; 138 : } 139 : 140 : /** 141 : * Get whether the variable is initialized 142 : * @returns Whether the variable is initialized 143 : */ 144 17750 : KOKKOS_FUNCTION bool initialized() const { return _initialized; } 145 : /** 146 : * Get whether the variable is coupled 147 : * @returns Whether the variable is coupled 148 : */ 149 70440309 : KOKKOS_FUNCTION bool coupled() const { return _coupled; } 150 : /** 151 : * Get whether the variable is nodal 152 : * @returns Whether the variable is nodal 153 : */ 154 153796 : KOKKOS_FUNCTION bool nodal() const { return _nodal; } 155 : /** 156 : * Get whether the tag is time derivative 157 : * @returns Whether the tag is time derivative 158 : */ 159 75384 : KOKKOS_FUNCTION bool dot() const { return _dot; } 160 : /** 161 : * Get whether the tag is old/older value 162 : * @returns Whether the tag is old/older value 163 : */ 164 68175 : KOKKOS_FUNCTION bool old() const { return _old; } 165 : /** 166 : * Get whether the variable is vector variable 167 : * @returns Whether the variable is vector variable 168 : */ 169 17750 : KOKKOS_FUNCTION bool vector() const { return _vector; } 170 : /** 171 : * Get the number of components 172 : * @returns The number of components 173 : */ 174 226152 : KOKKOS_FUNCTION unsigned int components() const { return _components; } 175 : /** 176 : * Get the vector tag ID 177 : * @returns The vector tag ID 178 : */ 179 76458967 : KOKKOS_FUNCTION TagID tag() const { return _tag; } 180 : /** 181 : * Get the variable number of a component 182 : * @param comp The variable component 183 : * @returns The variable number 184 : */ 185 129040066 : KOKKOS_FUNCTION unsigned int var(unsigned int comp = 0) const { return _var[comp]; } 186 : /** 187 : * Get the system number of a component 188 : * @param comp The variable component 189 : * @returns The system number 190 : */ 191 142672832 : KOKKOS_FUNCTION unsigned int sys(unsigned int comp = 0) const { return _sys[comp]; } 192 : /** 193 : * Get the default value of a component 194 : * @param comp The variable component 195 : * @returns The default value 196 : */ 197 19202 : KOKKOS_FUNCTION Real value(unsigned int comp = 0) const 198 : { 199 : KOKKOS_ASSERT(!_coupled && !_vector); 200 : 201 19202 : return _default_value[comp]; 202 : } 203 : /** 204 : * Get the default vector value of a component 205 : * @param comp The variable component 206 : * @returns The default vector value 207 : */ 208 109824 : KOKKOS_FUNCTION Real3 vectorValue(unsigned int comp = 0) const 209 : { 210 : KOKKOS_ASSERT(!_coupled && _vector); 211 : 212 109824 : return _default_vector_value[comp]; 213 : } 214 : 215 : private: 216 : /** 217 : * Whether the variable is initialized 218 : */ 219 : bool _initialized = false; 220 : /** 221 : * Whether the variable is coupled 222 : */ 223 : bool _coupled = false; 224 : /** 225 : * Whether the variable is nodal 226 : */ 227 : bool _nodal = false; 228 : /** 229 : * Whether the tag is time derivative 230 : */ 231 : bool _dot = false; 232 : /** 233 : * Whether the tag is old/older value 234 : */ 235 : bool _old = false; 236 : /** 237 : * Whether the variable is vector variable 238 : */ 239 : bool _vector = false; 240 : /** 241 : * Number of components 242 : */ 243 : unsigned int _components = 1; 244 : /** 245 : * Vector tag ID 246 : */ 247 : TagID _tag = Moose::INVALID_TAG_ID; 248 : /** 249 : * MOOSE variable of each component 250 : */ 251 : Array<const MooseVariableFieldBase *> _moose_var; 252 : /** 253 : * Variable number of each component 254 : */ 255 : Array<unsigned int> _var; 256 : /** 257 : * System number of each component 258 : */ 259 : Array<unsigned int> _sys; 260 : /** 261 : * Default value of each component when the variable is not coupled 262 : */ 263 : Array<Real> _default_value; 264 : /** 265 : * Default vector value of each component when the variable is not coupled 266 : */ 267 : Array<Real3> _default_vector_value; 268 : }; 269 : 270 : } // namespace Moose::Kokkos