5import matplotlib.pyplot
as plt
6from matplotlib
import gridspec
7from matplotlib.colors
import LogNorm
8from matplotlib
import mathtext
10from scipy
import stats
11from tkinter
import Tcl
17plt.rc(
'font', family=
'serif')
18plt.rc(
'text', usetex=
False)
24files = glob.glob(snapshot_dir +
"particles-*.vtu")
26files = Tcl().call(
'lsort',
'-dict', files)
36E_dif_all = np.zeros( len(files) )
37t_all = np.zeros( len(files) )
40for N_snapshot, file
in enumerate(files, start=0):
42 print(
"N_snapshot: ", N_snapshot)
43 time = N_snapshot * snapshot_rate * time_step_sim
44 t_all[N_snapshot] = time
46 print(
'Reading snapshot: ' + file )
47 print(
"time of simulation = ", time)
48 print(
"********************************************")
51 partData = reader.load()
52 partData.show_attribute_list()
54 print(
"********************************************")
62 E_tot = partData.energyTot
64 E_dif = (E_tot - E_ini) / E_ini
65 E_dif_all[N_snapshot] = E_dif
67 print(
"Measure energy conservation:")
68 print(
"Initial E = ", E_ini)
69 print(
"Total E = ", E_tot)
70 print(
"Relative Energy difference = ", E_dif )
71 print(
"********************************************")
73print(
"Done reading all snapshots. Total= ", len(files) )
76fig = plt.figure( figsize=(6, 4) )
78plt.plot(t_all, E_dif_all, c=
'r', lw=0.8, zorder=1)
80plt.ylabel(
r'$\Delta E/E_{\rm ini}$')
82plt.tick_params(direction=
'in', top=
True, right=
True, left=
True, bottom=
True)
83plt.axhline(0, c=
'gray', ls=
':', lw=1.2, zorder=-49 )
84plt.xlim(0, t_all.max())
85plt.ylim(-0.005, 0.005 )
90fig.savefig(
'energy_conservation_profile.pdf')
91fig.savefig(
'energy_conservation_profile.png')
92print(
"saved energy_conservation_profile")
98E_min = E_dif_all.min()
99E_max = E_dif_all.max()
100E_mean= np.mean(E_dif_all)
102assert abs(E_min) < E_tolerance, f
"Energy not conserved. E_min: {E_min}"
103assert abs(E_mean)< E_tolerance, f
"Energy not conserved. E_mean: {E_min}"
104assert abs(E_max) < E_tolerance, f
"Energy not conserved. E_max: {E_max}"
Reads in particle fields from a single .vtu file, or all .vtu at a given snapshot time specified in t...