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 "TensorInterfaceVelocityPostprocessor.h" 10 : #include "DomainAction.h" 11 : #include "TensorProblem.h" 12 : 13 : registerMooseObject("SwiftApp", TensorInterfaceVelocityPostprocessor); 14 : 15 : InputParameters 16 8 : TensorInterfaceVelocityPostprocessor::validParams() 17 : { 18 8 : InputParameters params = TensorPostprocessor::validParams(); 19 8 : params.addClassDescription("Compute the integral over a buffer"); 20 16 : params.addParam<Real>("gradient_threshold", 21 16 : 1e-3, 22 : "Ignore cells with a gradient component magnitude below this threshold."); 23 8 : return params; 24 0 : } 25 : 26 4 : TensorInterfaceVelocityPostprocessor::TensorInterfaceVelocityPostprocessor( 27 4 : const InputParameters & parameters) 28 : : TensorPostprocessor(parameters), 29 4 : _u_old(_tensor_problem.getBufferOld(getParam<TensorInputBufferName>("buffer"), 1)), 30 4 : _dim(_domain.getDim()), 31 4 : _i(torch::tensor(c10::complex<double>(0.0, 1.0), MooseTensor::complexFloatTensorOptions())), 32 12 : _gradient_threshold(getParam<Real>("gradient_threshold")) 33 : { 34 4 : } 35 : 36 : void 37 40 : TensorInterfaceVelocityPostprocessor::execute() 38 : { 39 40 : if (_u_old.empty()) 40 : { 41 4 : _velocity = 0.0; 42 4 : return; 43 : } 44 : 45 72 : const auto du = (_u - _u_old[0]) / _dt; // TODO: _dt_old? 46 : torch::Tensor vsquare; 47 108 : for (const auto i : make_range(_dim)) 48 : { 49 216 : const auto grad = _domain.ifft(_domain.fft(_u) * _domain.getReciprocalAxis(i) * _i); 50 72 : const auto v = torch::where(torch::abs(grad) > 1e-3, du / grad, 0.0); 51 72 : if (i == 0) 52 36 : vsquare = v * v; 53 : else 54 72 : vsquare += v * v; 55 : } 56 : 57 36 : _velocity = std::sqrt(torch::max(vsquare).item<double>()); 58 : } 59 : 60 : PostprocessorValue 61 40 : TensorInterfaceVelocityPostprocessor::getValue() const 62 : { 63 40 : return _velocity; 64 : }