Line data Source code
1 : /**********************************************************************/ 2 : /* DO NOT MODIFY THIS HEADER */ 3 : /* Swift, a Fourier spectral solver for MOOSE */ 4 : /* */ 5 : /* Copyright 2024 Battelle Energy Alliance, LLC */ 6 : /* ALL RIGHTS RESERVED */ 7 : /**********************************************************************/ 8 : 9 : #include "LBMConstantTensor.h" 10 : 11 : registerMooseObject("SwiftApp", LBMConstantTensor); 12 : 13 : InputParameters 14 0 : LBMConstantTensor::validParams() 15 : { 16 0 : InputParameters params = LatticeBoltzmannOperator::validParams(); 17 0 : params.addRequiredParam<std::vector<std::string>>("constants", "The scalar constant names."); 18 0 : params.addClassDescription("LBMConstantTensor object."); 19 0 : return params; 20 0 : } 21 : 22 0 : LBMConstantTensor::LBMConstantTensor(const InputParameters & parameters) 23 0 : : LatticeBoltzmannOperator(parameters) 24 : { 25 0 : } 26 : 27 : void 28 0 : LBMConstantTensor::init() 29 : { 30 0 : auto names = getParam<std::vector<std::string>>("constants"); 31 : 32 0 : for (auto name : names) 33 : { 34 0 : auto value = (_lb_problem.getConstant<Real>(name)); 35 0 : _values.push_back(value); 36 : } 37 : 38 : // check number of constants 39 0 : if (_u.dim() > 3 && size_t(_u.size(3)) != size_t(_values.size())) 40 0 : mooseError("The number of constants must match the number of components in the buffer."); 41 0 : else if (_u.dim() <= 3 && _values.size() != 1) 42 0 : mooseError("For scalar buffers only one constant can be passed."); 43 0 : } 44 : 45 : void 46 0 : LBMConstantTensor::computeBuffer() 47 : { 48 0 : if (_u.dim() > 3) 49 0 : for (const auto i : index_range(_values)) 50 0 : _u.index({torch::indexing::Slice(), 51 0 : torch::indexing::Slice(), 52 0 : torch::indexing::Slice(), 53 : static_cast<int64_t>(i)}) 54 0 : .fill_(_values[i]); 55 : else 56 0 : _u.fill_(_values[0]); 57 0 : }