timestepAnalysis.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """Basic testing to ensure the chosen timestep is sensible and to probe
  2. the symplectic character of the integrator."""
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. from scipy.signal import savgol_filter
  6. from analysis import utils
  7. f, ax = plt.subplots(1, 1)
  8. for name, label, factor, color in zip(['dt1E-2', 'dt1E-3'],
  9. [r'$dt=10^{-2}$', r'$dt=10^{-3}$'],
  10. [1, 10],
  11. ['cornflowerblue', 'darkorange']):
  12. time = []
  13. median = []
  14. areas = []
  15. for n in np.linspace(10, 1000, 100):
  16. truth = utils.loadData('dt1E-4', int(n*100))
  17. # Load the data
  18. data = utils.loadData(name, int(n*factor))
  19. # Find the deviation
  20. time.append(truth['t'])
  21. deviations = np.linalg.norm(data['r_vec'] - truth['r_vec'], axis=-1)
  22. median.append(np.median(deviations))
  23. areas.append(np.percentile(deviations, [6, 16, 31, 100-31, 100-16, 100-6]))
  24. # Plot
  25. areas = np.array(areas)
  26. areas = savgol_filter(areas, 11, 3, axis=0) #Smoothing
  27. median = savgol_filter(median, 11, 3)
  28. ax.fill_between(time, areas[:,0], areas[:,-1], alpha=.25, color=color)
  29. ax.fill_between(time, areas[:,1], areas[:,-2], alpha=.25, color=color)
  30. ax.fill_between(time, areas[:,2], areas[:,-3], alpha=.25, color=color)
  31. ax.plot(time, median, color=color, label=label)
  32. utils.stylizePlot([ax])
  33. utils.setAxes(ax, x='Time', y='Displacement',
  34. xcoords=(.85,-0.08), ycoords=(-0.1,.75))
  35. ax.set_yscale('log')
  36. ax.set_xlim(0, time[-1])
  37. ax.axvline(x=3.55, linestyle='--', linewidth=1, color='black')
  38. plt.legend(loc='upper left')
  39. plt.show()