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 "ConstantTensor.h" 10 : #include "SwiftUtils.h" 11 : #include "DomainAction.h" 12 : 13 : registerMooseObject("SwiftApp", ConstantTensor); 14 : registerMooseObject("SwiftApp", ConstantReciprocalTensor); 15 : 16 : template <bool reciprocal> 17 : InputParameters 18 332 : ConstantTensorTempl<reciprocal>::validParams() 19 : { 20 332 : InputParameters params = TensorOperator<>::validParams(); 21 664 : params.addParam<SwiftConstantName>("imaginary", "0.0", "Imaginary part of the constant value."); 22 : if constexpr (reciprocal) 23 92 : params.addClassDescription("Constant tensor in reciprocal space."); 24 : else 25 : { 26 240 : params.addClassDescription("Constant tensor in real space."); 27 240 : params.suppressParameter<SwiftConstantName>("imaginary"); 28 : } 29 664 : params.addParam<SwiftConstantName>("real", "0.0", "Real part of the constant value."); 30 664 : params.addParam<bool>("reciprocal", false, "Construct a reciprocal buffer"); 31 664 : params.addParam<bool>("full", false, "Construct a full tensor will all entries"); 32 332 : return params; 33 0 : } 34 : 35 : template <bool reciprocal> 36 166 : ConstantTensorTempl<reciprocal>::ConstantTensorTempl(const InputParameters & parameters) 37 : : TensorOperator(parameters), 38 166 : _dim(_domain.getDim()), 39 166 : _real(this->getConstant<Real>("real")), 40 332 : _imaginary(this->getConstant<Real>("imaginary")) 41 : { 42 166 : } 43 : 44 : template <bool reciprocal> 45 : void 46 156 : ConstantTensorTempl<reciprocal>::computeBuffer() 47 : { 48 : if constexpr (reciprocal) 49 168 : _u = torch::complex( 50 42 : torch::full(_domain.getReciprocalShape(), _real, MooseTensor::floatTensorOptions()), 51 42 : torch::full(_domain.getReciprocalShape(), _imaginary, MooseTensor::floatTensorOptions())); 52 : else 53 114 : _u = torch::full(_domain.getShape(), _real, MooseTensor::floatTensorOptions()); 54 156 : } 55 : 56 : template class ConstantTensorTempl<true>; 57 : template class ConstantTensorTempl<false>;