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 "DeAliasingTensor.h" 10 : #include "MooseEnum.h" 11 : #include "SwiftUtils.h" 12 : #include "wasplsp/LSP.h" 13 : 14 : registerMooseObject("SwiftApp", DeAliasingTensor); 15 : 16 : InputParameters 17 16 : DeAliasingTensor::validParams() 18 : { 19 16 : InputParameters params = TensorOperator<>::validParams(); 20 16 : params.addClassDescription("Create a de-aliasing filter."); 21 32 : MooseEnum deAliasingMethod("SHARP HOULI"); 22 32 : params.addRequiredParam<MooseEnum>("method", deAliasingMethod, "Prefactor"); 23 32 : params.addParam<Real>("p", 16, "Hou-Li filter exponent"); 24 32 : params.addParam<Real>("alpha", 36, "Hou-Li filter pre-factor"); 25 : 26 16 : return params; 27 16 : } 28 : 29 8 : DeAliasingTensor::DeAliasingTensor(const InputParameters & parameters) 30 : : TensorOperator<>(parameters), 31 8 : _method(getParam<MooseEnum>("method").getEnum<DeAliasingMethod>()), 32 16 : _p(getParam<Real>("p")), 33 24 : _alpha(getParam<Real>("alpha")) 34 : { 35 8 : } 36 : 37 : void 38 8 : DeAliasingTensor::computeBuffer() 39 : { 40 : // maximum frequency in each direction 41 16 : auto imax = torch::max(torch::abs(_i)).item<double>(); 42 16 : auto jmax = torch::max(torch::abs(_j)).item<double>(); 43 16 : auto kmax = torch::max(torch::abs(_k)).item<double>(); 44 : 45 8 : switch (_method) 46 : { 47 : case DeAliasingMethod::SHARP: 48 24 : _u = torch::where((torch::abs(_i) > 2 * imax / 3) | (torch::abs(_j) > 2 * jmax / 3) | 49 8 : (torch::abs(_k) > 2 * kmax / 3), 50 : 0.0, 51 : 1.0); 52 4 : break; 53 : 54 4 : case DeAliasingMethod::HOULI: 55 8 : auto px = torch::pow(torch::abs(_i) / (imax ? imax : 1.0), _p); 56 8 : auto py = torch::pow(torch::abs(_j) / (jmax ? jmax : 1.0), _p); 57 12 : auto pz = torch::pow(torch::abs(_k) / (kmax ? kmax : 1.0), _p); 58 : 59 16 : _u = torch::exp(-_alpha * (px + py + pz)); 60 : break; 61 : } 62 8 : }