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 : #include "KokkosVariable.h" 11 : 12 : #include "SystemBase.h" 13 : #include "FEProblemBase.h" 14 : 15 : namespace Moose::Kokkos 16 : { 17 : 18 : void 19 23200 : Variable::init(const MooseVariableFieldBase & variable, const TagName & tag_name) 20 : { 21 23200 : init(variable, variable.sys().feProblem().getVectorTagID(tag_name)); 22 23200 : } 23 : 24 : void 25 26961 : Variable::init(const MooseVariableFieldBase & variable, const TagID tag) 26 : { 27 26961 : _initialized = true; 28 26961 : _coupled = true; 29 26961 : _nodal = variable.isNodal(); 30 26961 : _components = variable.count(); 31 26961 : _tag = tag; 32 26961 : _vector = variable.isVector(); 33 : 34 26961 : _moose_var.createHost(_components); 35 26961 : _var.create(_components); 36 26961 : _sys.create(_components); 37 : 38 53922 : for (unsigned int comp = 0; comp < _components; ++comp) 39 : { 40 26961 : _moose_var[comp] = &variable; 41 26961 : _var[comp] = variable.number() + comp; 42 26961 : _sys[comp] = variable.sys().number(); 43 : } 44 : 45 26961 : _var.copyToDevice(); 46 26961 : _sys.copyToDevice(); 47 : 48 26961 : const auto & problem = variable.sys().feProblem(); 49 : 50 26961 : if (problem.vectorTagExists(Moose::SOLUTION_DOT_TAG)) 51 12130 : _dot = tag == problem.getVectorTagID(Moose::SOLUTION_DOT_TAG); 52 : 53 26961 : if (problem.vectorTagExists(Moose::OLD_SOLUTION_TAG)) 54 12130 : _old = tag == problem.getVectorTagID(Moose::OLD_SOLUTION_TAG); 55 : 56 26961 : if (problem.vectorTagExists(Moose::OLDER_SOLUTION_TAG)) 57 272 : _old = _old || tag == problem.getVectorTagID(Moose::OLDER_SOLUTION_TAG); 58 26961 : } 59 : 60 : void 61 0 : Variable::init(const std::vector<MooseVariableFieldBase *> & variables, const TagName & tag_name) 62 : { 63 0 : init(std::vector<const MooseVariableFieldBase *>(variables.begin(), variables.end()), 64 0 : variables[0]->sys().feProblem().getVectorTagID(tag_name)); 65 0 : } 66 : 67 : void 68 0 : Variable::init(const std::vector<const MooseVariableFieldBase *> & variables, 69 : const TagName & tag_name) 70 : { 71 0 : init(variables, variables[0]->sys().feProblem().getVectorTagID(tag_name)); 72 0 : } 73 : 74 : void 75 0 : Variable::init(const std::vector<MooseVariableFieldBase *> & variables, const TagID tag) 76 : { 77 0 : init(std::vector<const MooseVariableFieldBase *>(variables.begin(), variables.end()), tag); 78 0 : } 79 : 80 : void 81 135 : Variable::init(const std::vector<const MooseVariableFieldBase *> & variables, const TagID tag) 82 : { 83 135 : if (variables.empty()) 84 0 : mooseError("Cannot initialize a Kokkos variable with zero components."); 85 : 86 135 : _initialized = true; 87 135 : _coupled = true; 88 135 : _nodal = true; 89 135 : _components = variables.size(); 90 135 : _tag = tag; 91 135 : _vector = variables[0]->isVector(); 92 : 93 135 : _moose_var.createHost(_components); 94 135 : _var.create(_components); 95 135 : _sys.create(_components); 96 : 97 353 : for (unsigned int comp = 0; comp < _components; ++comp) 98 : { 99 218 : _nodal = _nodal && variables[comp]->isNodal(); 100 : 101 218 : if (variables[comp]->isVector() != _vector) 102 0 : mooseError("Cannot initialize a Kokkos variable with mixed scalar and vector components."); 103 : 104 218 : _moose_var[comp] = variables[comp]; 105 218 : _var[comp] = variables[comp]->number(); 106 218 : _sys[comp] = variables[comp]->sys().number(); 107 : } 108 : 109 135 : _var.copyToDevice(); 110 135 : _sys.copyToDevice(); 111 : 112 135 : const auto & problem = variables[0]->sys().feProblem(); 113 : 114 135 : if (problem.vectorTagExists(Moose::SOLUTION_DOT_TAG)) 115 0 : _dot = tag == problem.getVectorTagID(Moose::SOLUTION_DOT_TAG); 116 : 117 135 : if (problem.vectorTagExists(Moose::OLD_SOLUTION_TAG)) 118 0 : _old = tag == problem.getVectorTagID(Moose::OLD_SOLUTION_TAG); 119 : 120 135 : if (problem.vectorTagExists(Moose::OLDER_SOLUTION_TAG)) 121 0 : _old = _old || tag == problem.getVectorTagID(Moose::OLDER_SOLUTION_TAG); 122 135 : } 123 : 124 : void 125 398 : Variable::init(const std::vector<Real> & values, CoupleableKey) 126 : { 127 398 : _initialized = true; 128 398 : _coupled = false; 129 398 : _nodal = false; 130 398 : _components = values.size(); 131 : 132 398 : _default_value = values; 133 398 : } 134 : 135 : void 136 41 : Variable::init(const std::vector<Real3> & values, CoupleableKey) 137 : { 138 41 : _initialized = true; 139 41 : _coupled = false; 140 41 : _nodal = false; 141 41 : _components = values.size(); 142 41 : _vector = true; 143 : 144 41 : _default_vector_value = values; 145 41 : } 146 : 147 : } // namespace Moose::Kokkos