# Compare integration time-stepping schemes for KS equation. # Conclusions: 'ETD-RK4' is superior to 'SI-RK3', # - Superiority deteriorates when adding noise to ICs. # - Superiority fairly independent of N. # - The naive methods (rk4, rk1) are quite terrible. import time import numpy as np from matplotlib import pyplot as plt from dapper.mods.KS import Model model = Model() print("THERE WILL BE WARNINGS GENERATED.") print("This is normal, because some schemes cause NaNs for some dt's.") # Experiment range minexpo = -8 # use -11 to observe saturation due to num. prec. hh = 2.0**np.arange(minexpo, 0) # list of dt # Params T = 30 N = 4 # IC -- NB: integration accuracy depends on noise level E0 = model.x0_Kassam + 1e-3*np.random.randn(N, model.Nx) # Allocate stats mref = 'step_ETD_RK4'
def test_KS(): from dapper.mods.KS import Model KS = Model() assert _allclose(KS.dxdt, KS.d2x_dtdx, KS.x0)
import numpy as np import dapper as dpr from dapper.mods.KS import Model, Tplot from dapper.mods.Lorenz96 import LPs from dapper.tools.localization import nd_Id_localization from dapper.tools.math import Id_Obs KS = Model(dt=0.5) Nx = KS.Nx # nRepeat=10 t = dpr.Chronology(KS.dt, dkObs=2, KObs=2 * 10**4, BurnIn=2 * 10**3, Tplot=Tplot) Dyn = {'M': Nx, 'model': KS.step, 'linear': KS.dstep_dx, 'noise': 0} X0 = dpr.GaussRV(mu=KS.x0, C=0.001) Obs = Id_Obs(Nx) Obs['noise'] = 1 Obs['localizer'] = nd_Id_localization((Nx, ), (4, )) HMM = dpr.HiddenMarkovModel(Dyn, Obs, t, X0) HMM.liveplotters = LPs(np.arange(Nx)) ####################
if mod == "LUV": from dapper.mods.LorenzUV.lorenz96 import LUV ii = np.arange(LUV.nU) step = with_rk4(LUV.dxdt, autonom=True) Nx = LUV.M T = 1e2 dt = 0.005 LUV.F = 10 x0 = 0.01 * randn(LUV.M) eps = 0.001 N = 66 # Don't need all Nx for a good approximation of upper spectrum. # Lyapunov exponents: [ 0.08 0.07 0.06 ... -37.9 -39.09 -41.55] if mod == "KS": from dapper.mods.KS import Model KS = Model() step = KS.step x0 = KS.x0 dt = KS.dt N = KS.Nx Nx = len(x0) T = 1e3 eps = 0.0002 # n0 ≈ 140 if mod == "QG": from dapper.mods.QG import model_config, sample_filename, shape # NB: There may arise an ipython/multiprocessing bug/issue. # Ref https://stackoverflow.com/a/45720872 . If so, set mp=False, # or run outside of ipython. However, I did not encounter lately.