33import os
44import dill
55import numpy as np
6- import matplotlib .pyplot as plt
7- from matplotlib import animation
86from mpl_toolkits .mplot3d import Axes3D
97
108import pySDC .helpers .plot_helper as plt_helper
@@ -120,7 +118,7 @@ def run_simulation(prob=None):
120118 out = ' Std and var for number of iterations: %4.2f -- %4.2f' % (float (np .std (niters )), float (np .var (niters )))
121119 print (out )
122120
123- # assert np.mean(niters) <= 4.0, 'Mean number of iterations is too high, got %s' % np.mean(niters)
121+ assert np .mean (niters ) <= 4.0 , 'Mean number of iterations is too high, got %s' % np .mean (niters )
124122
125123 fname = 'data/' + prob + '.dat'
126124 f = open (fname , 'wb' )
@@ -144,6 +142,9 @@ def show_results(prob=None, cwd=''):
144142 stats = dill .load (f )
145143 f .close ()
146144
145+ plt_helper .mpl .style .use ('classic' )
146+ plt_helper .setup_mpl ()
147+
147148 # extract error in hamiltonian and prepare for plotting
148149 extract_stats = filter_stats (stats , type = 'err_hamiltonian' )
149150 result = defaultdict (list )
@@ -152,8 +153,6 @@ def show_results(prob=None, cwd=''):
152153 for k , v in result .items ():
153154 result [k ] = sorted (result [k ], key = lambda x : x [0 ])
154155
155- plt_helper .mpl .style .use ('classic' )
156- plt_helper .setup_mpl ()
157156 plt_helper .newfig (textwidth = 238.96 , scale = 0.89 )
158157
159158 # Rearrange data for easy plotting
@@ -163,8 +162,7 @@ def show_results(prob=None, cwd=''):
163162 ham = [item [1 ] for item in v ]
164163 err_ham = ham [- 1 ]
165164 plt_helper .plt .semilogy (time , ham , '-' , lw = 1 , label = 'Iter ' + str (k ))
166- print (err_ham )
167- # assert err_ham < 3.0E-15, 'Error in the Hamiltonian is too large for %s, got %s' % (prob, err_ham)
165+ assert err_ham < 7.5E-15 , 'Error in the Hamiltonian is too large for %s, got %s' % (prob , err_ham )
168166
169167 plt_helper .plt .xlabel ('Time' )
170168 plt_helper .plt .ylabel ('Error in Hamiltonian' )
@@ -177,35 +175,43 @@ def show_results(prob=None, cwd=''):
177175 assert os .path .isfile (fname + '.pgf' ), 'ERROR: plotting did not create PGF file'
178176 assert os .path .isfile (fname + '.png' ), 'ERROR: plotting did not create PNG file'
179177
180- # extract error in hamiltonian and prepare for plotting
178+ # extract positions and prepare for plotting
181179 extract_stats = filter_stats (stats , type = 'position' )
182180 result = sort_stats (extract_stats , sortby = 'time' )
183181
184- plt_helper .mpl .style .use ('classic' )
185- plt_helper .setup_mpl ()
186182 fig = plt_helper .plt .figure ()
187183 ax = fig .add_subplot (111 , projection = '3d' )
188184
189185 # Rearrange data for easy plotting
186+ nparts = len (result [1 ][1 ][0 ])
187+ ndim = len (result [1 ][1 ])
190188 nsteps = len (result )
191- pos = np .zeros ((6 , 3 , nsteps ))
189+ pos = np .zeros ((nparts , ndim , nsteps ))
192190
193191 for idx , item in enumerate (result ):
194- for n in range (6 ):
195- pos [n , 0 , idx ] = item [1 ][0 ][n ]
196- pos [n , 1 , idx ] = item [1 ][1 ][n ]
197- pos [n , 2 , idx ] = item [1 ][2 ][n ]
198-
199- for n in range (6 ):
200- ax .plot (pos [n , 0 , :], pos [n , 1 , :], zs = pos [n , 2 , :])
192+ for n in range (nparts ):
193+ for m in range (ndim ):
194+ pos [n , m , idx ] = item [1 ][m ][n ]
195+
196+ for n in range (nparts ):
197+ if ndim == 2 :
198+ ax .plot (pos [n , 0 , :], pos [n , 1 , :])
199+ elif ndim == 3 :
200+ ax .plot (pos [n , 0 , :], pos [n , 1 , :], pos [n , 2 , :])
201+ else :
202+ raise NotImplemented ('Wrong number of dimensions for plotting, got %s' % ndim )
201203
202204 fname = 'data/' + prob + '_positions'
203- plt_helper .plt .savefig (fname )
205+ plt_helper .savefig (fname )
206+
207+ assert os .path .isfile (fname + '.pdf' ), 'ERROR: plotting did not create PDF file'
208+ assert os .path .isfile (fname + '.pgf' ), 'ERROR: plotting did not create PGF file'
209+ assert os .path .isfile (fname + '.png' ), 'ERROR: plotting did not create PNG file'
204210
205211
206212def main ():
207213 prob = 'outer_solar_system'
208- # run_simulation(prob)
214+ run_simulation (prob )
209215 show_results (prob )
210216
211217
0 commit comments