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 "FFTSemiImplicit.h" 10 : #include "TensorProblem.h" 11 : #include "DomainAction.h" 12 : 13 : registerMooseObject("SwiftApp", FFTSemiImplicit); 14 : 15 : InputParameters 16 0 : FFTSemiImplicit::validParams() 17 : { 18 0 : InputParameters params = TensorTimeIntegrator::validParams(); 19 0 : params.addClassDescription("Semi-implicit time integrator."); 20 0 : params.addRequiredParam<TensorInputBufferName>( 21 : "reciprocal_buffer", "Buffer with the reciprocal of the integrated buffer"); 22 0 : params.addRequiredParam<TensorInputBufferName>( 23 : "linear_reciprocal", "Buffer with the reciprocal of the linear prefactor (e.g. kappa*k^2)"); 24 0 : params.addRequiredParam<TensorInputBufferName>( 25 : "nonlinear_reciprocal", "Buffer with the reciprocal of the non-linear contribution"); 26 0 : params.addParam<unsigned int>( 27 0 : "history_size", 1, "How many old states to use (determines time integration order)."); 28 0 : return params; 29 0 : } 30 : 31 0 : FFTSemiImplicit::FFTSemiImplicit(const InputParameters & parameters) 32 : : TensorTimeIntegrator<>(parameters), 33 0 : _history_size(getParam<unsigned int>("history_size")), 34 0 : _reciprocal_buffer(getInputBuffer("reciprocal_buffer")), 35 0 : _linear_reciprocal(getInputBuffer("linear_reciprocal")), 36 0 : _non_linear_reciprocal(getInputBuffer("nonlinear_reciprocal")), 37 0 : _old_reciprocal_buffer(getBufferOld("reciprocal_buffer", _history_size)), 38 0 : _old_non_linear_reciprocal(getBufferOld("nonlinear_reciprocal", _history_size)) 39 : { 40 0 : } 41 : 42 : void 43 0 : FFTSemiImplicit::computeBuffer() 44 : { 45 0 : const auto n_old = std::min(_old_reciprocal_buffer.size(), _old_non_linear_reciprocal.size()); 46 : 47 : torch::Tensor ubar; 48 0 : if (n_old == 0) 49 : // compute FFT time update (1st order) 50 0 : ubar = (_reciprocal_buffer + _sub_dt * _non_linear_reciprocal) / (1.0 - _sub_dt * _linear_reciprocal); 51 : 52 : if (n_old >= 1) 53 : // compute FFT time update (2nd order) - this probably breaks for adaptive dt! 54 : // ubar = (4.0 * _reciprocal_buffer - _old_reciprocal_buffer[0] + 55 : // (2.0 * _sub_dt) * (2.0 * _non_linear_reciprocal - _old_non_linear_reciprocal[0])) / 56 : // (3.0 - (2.0 * _sub_dt) * _linear_reciprocal); 57 0 : ubar = (_reciprocal_buffer + 58 0 : _sub_dt / 2.0 * (3.0 * _non_linear_reciprocal - _old_non_linear_reciprocal[0])) / 59 0 : (1.0 - _sub_dt * _linear_reciprocal); 60 : 61 0 : _u = _domain.ifft(ubar); 62 0 : }