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 "FFTGradientSquare.h" 10 : #include "SwiftUtils.h" 11 : 12 : registerMooseObject("SwiftApp", FFTGradientSquare); 13 : 14 : InputParameters 15 8 : FFTGradientSquare::validParams() 16 : { 17 8 : InputParameters params = TensorOperator<>::validParams(); 18 8 : params.addClassDescription("Tensor gradient."); 19 16 : params.addRequiredParam<TensorInputBufferName>("input", "Input buffer name"); 20 16 : params.addParam<bool>( 21 16 : "input_is_reciprocal", false, "Input buffer is already in reciprocal space"); 22 16 : params.addParam<Real>("factor", 1.0, "Prefactor to the gradient square"); 23 8 : return params; 24 0 : } 25 : 26 4 : FFTGradientSquare::FFTGradientSquare(const InputParameters & parameters) 27 : : TensorOperator<>(parameters), 28 4 : _input(getInputBuffer("input")), 29 8 : _input_is_reciprocal(getParam<bool>("input_is_reciprocal")), 30 8 : _factor(getParam<Real>("factor")), 31 4 : _dim(_domain.getDim()), 32 8 : _i(torch::tensor(c10::complex<double>(0.0, 1.0), MooseTensor::complexFloatTensorOptions())) 33 : { 34 4 : } 35 : 36 : void 37 4 : FFTGradientSquare::computeBuffer() 38 : { 39 12 : auto sqr = [](const auto & a) { return a * a; }; 40 : 41 4 : const auto r = _input_is_reciprocal ? _input : _domain.fft(_input); 42 : 43 12 : _u = sqr(_domain.ifft(r * _domain.getReciprocalAxis(0) * _i)); 44 12 : for (const auto d : make_range(1u, _dim)) 45 32 : _u += sqr(_domain.ifft(r * _domain.getReciprocalAxis(d) * _i)); 46 : 47 4 : if (_factor != 1.0) 48 0 : _u *= _factor; 49 4 : }