Package: rkstiff
rkstiffRunge-Kutta integrating factor (IF) and exponential time-differencing (ETD) methods
for solving nonlinear-PDE's of the formut= Lu + NL(u).
Some examples of non-linear PDES that can be numerically solved using these methods are:Nonlinear Schrodinger equation (NLS)Kuramoto-Sivashinsky (KS)Korteweg-de Vries (KdV)BurgersAllen-CahnSine-GordonThe adaptive step solver
options provided in this package areETD35  (5thorder ETD with 3rdorderembedding)ETD34 (4thorder ETD with 3rdorder embedding)IF34 (4thorder IF with 3rdorder embedding)IF45DP (5thorder IF with 4thorder embedding)The constant step solver options provided areETD4 (4thorder ETD - Krogstad method)ETD5 (5thorder ETD - same as the 5th order method in ETD35)IF4 (4thorder IF - same as the 4th order method in IF34)In general, one should
prefer ETD35 as it often has the best speed and stability for diagonal systems or diagonalized
non-diagonal systems. Because the RK coefficients can be costly
to compute, IF34 or constant step methods may be preferable in certain settings.
A detailed discussion of these solvers is provided in the journal articleExponential time-differencing with embedded Runge–Kutta adaptive step control.DependenciesPackage requiresnumpyscipyTested with versionsnumpy = 1.19.2scipy = 1.6.0UsageEach of the solvers is a python class (UPPERCASE) stored in a module of the same name (lowercase). Initializing each class requires two arguments, a linear operatorLin the form of a numpy array, and a nonlinear functionNL(u). The solvers can then be proagated either by using the solver.step function (user steps through time) or using the solver.evolve function (stepping handled internally). For examplefromrkstiffimportetd35L=# some linear operatordefNL(u):#  nonlinear function defined heresolver=etd35.ETD35(linop=L,NLfunc=NL)u0=# initial field to be propagatedt0=# initial timetf=# final timeuf=solver.evolve(u0,t0=t0,tf=tf)By default, when using the function evolve, the field is stored at each step in a python list: u0,u1,...,uf are stored in solver.u. The corresponding times t0,t1,...,tf are stored in solver.t.ExampleConsider the Kuramoto-Sivashinsky (KS) equation:ut= -uxx- uxxxx- uux.Converting to spectral space using a Fourier transform (F) we havevt= kx2(1- kx2)v - F { F-1{v} F-1{ i kxv} }where v = F{u}. We can then plug L = kx2(1- kx2), and NL(u) =  - F { F-1{v} F-1{ i kxv} } into an rkstiff solver and propagate the field u in spectral space, converting back to real space when desired. For exampe, the python code may look something like thisimportnumpyasnpfromrkstiffimportgridsfromrkstiffimportif34# uniform grid spacing, real-valued u -> construct_x_kx_rfftN=8192a,b=0,32*np.pix,kx=grids.construct_x_kx_rfft(N,a,b)L=kx**2*(1-kx**2)defNL(uFFT):u=np.fft.irfft(uFFT)ux=np.fft.irfft(1j*kx*uFFT)return-np.fft.rfft(u*ux)u0=np.cos(x/16)*(1.+np.sin(x/16))u0FFT=np.fft.rfft(u0)solver=if34.IF34(linop=L,NLfunc=NL)ufFFT=solver.evolve(u0FFT,t0=0,tf=50,store_freq=20)# store every 20th step in solver.u and solver.tU=[]foruFFTinsolver.u:U.append(np.fft.irfft(uFFT))U=np.array(U)t=np.array(solver.t)The grid module in rkstiff has several useful helper functions for setting up spatial and spectral grids. Here we used it to construct grids for a real-valueduutilizing the real-valued numpy Fourier transform (rfft). The results of the KS 'chaotic' propagation are shown below.InstallationFrom the github sourcegitclonehttps://github.com/whalenpt/rkstiff.gitcdrkstiff
python3-mpipinstall.PyPI install with a virtualenv (see thePython Packaging Authorityguide)python3-mvenvenvsourceenv/bin/activate
python3-mpipinstallrkstiffFor use with Anaconda using the conda-forge channel (see theGetting started with conda guide), from the terminalcondacreate--namerkstiff-env
condaactivaterkstiff-env
condainstallrkstiff-cconda-forgeThe demos require installation of the pythonmatplotlibandjupyterpackages in addition tonumpyandscipy. The tests require installation of the python packagepytest. These may be installed seperately or by usingpython3-mpipinstall'.[demo]'python3-mpipinstall'.[test]'when installing from the rkstiff source directoryLicenseThis project is licensed under the MIT License - see theLICENSEfile for details.Citation@article{WHALEN2015579,
title = {Exponential time-differencing with embedded Runge–Kutta adaptive step control},
journal = {Journal of Computational Physics},
volume = {280},
pages = {579-601},
year = {2015},
author = {P. Whalen and M. Brio and J.V. Moloney}
}ContactPatrick Whalen -whalenpt@gmail.com