4 import matplotlib.pyplot
as plt
5 from mpl_toolkits.mplot3d
import Axes3D
8 colors = [
'b',
'r', 'y', 'c', 'm']
13 return math.sqrt(np.power(d, 2).sum())
17 def __init__(self, build_dir, nsteps, niter, nparticles):
119 return np.asarray([self.
x[p][step], self.
y[p][step], self.
z[p][step]])
125 with open(data_file)
as csvfile:
126 csv_file = csv.reader(csvfile, delimiter=
',')
131 if iter == 0
and step == 1:
132 self.
_x[part][0] = row[3]
133 self.
_y[part][0] = row[4]
134 self.
_z[part][0] = row[5]
139 self.
_x_c[0] = row[3]
140 self.
_y_c[0] = row[4]
141 self.
_z_c[0] = row[5]
142 if iter == self.
niter - 1:
144 self.
_drift[step] = row[10]
147 self.
_x_c[step] = row[3]
148 self.
_y_c[step] = row[4]
149 self.
_z_c[step] = row[5]
151 self.
_x[part][step] = row[3]
152 self.
_y[part][step] = row[4]
153 self.
_z[part][step] = row[5]
155 with open(ref_file)
as csvfile:
156 csv_file = csv.reader(csvfile, delimiter=
',')
160 if iter == self.
niter - 1:
161 self.
_x_ref[step] = row[3]
162 self.
_y_ref[step] = row[4]
163 self.
_z_ref[step] = row[5]
164 if iter == 0
and step == 1:
169 for step
in range(self.
_nsteps + 1):
170 center = np.asarray([self.
x_c[step], self.
y_c[step], self.
z_c[step]])
173 self.
_dist_min = self._distances.min(axis=0)
174 self.
_dist_max = self._distances.max(axis=0)
175 self.
_dist_mean = self._distances.mean(axis=0)
179 _dist = data.dist_max - data.dist_min
180 return np.where(_dist[after:] == _dist[after:].min())[0][0] + after
188 print(
"Initial Center of Mass: % 10.4f\t% 10.4f\t% 10.4f" % (data.x_c[:1][0], data.y_c[:1][0], data.z_c[:1][0]))
189 print(
"Last Center of Mass: % 10.4f\t% 10.4f\t% 10.4f" % (data.x_c[until:ndisplay][0], data.y_c[until:ndisplay][0], data.z_c[until:ndisplay][0]))
190 print(
"Initial Energy: %16.4f" % data.energy[0])
191 print(
"Final Energy: %16.4f" % data.energy[-1])
192 print(
"Final Drift: %16.4f" % data.drift[-1])
193 print(
"Final Residual: %16.4e (max: %.4e)" % (data.residual[-1], data.residual.max()))
195 plt.figure(figsize=(15, 15), dpi=1200)
196 ax = plt.axes(projection=
'3d')
197 plt.title(
"Trajectory of Particles\ndashed: single; black solid: reference; green solid: center of mass; dot: initial point; cross: end point")
198 ax.plot(data.x_ref[:ndisplay], data.y_ref[:ndisplay], data.z_ref[:ndisplay],
'--k')
199 if data.nparticles <= 5:
200 for p
in range(data.nparticles):
201 ax.plot(data.x[p][:ndisplay], data.y[p][:ndisplay], data.z[p][:ndisplay],
'--%s' % colors[p])
202 ax.plot(data.x_c[:ndisplay], data.y_c[:ndisplay], data.z_c[:ndisplay],
'-g')
203 ax.plot(data.x_c[:1], data.y_c[:1], data.z_c[:1],
'ok')
204 ax.plot(data.x_c[until:ndisplay], data.y_c[until:ndisplay], data.z_c[until:ndisplay],
'xk', markeredgewidth=2, markersize=5)
212 maxfig = 4
if wo_drift
else 5
213 figheight = 10
if wo_drift
else 15
214 steprange = range(start, ndisplay)
216 plt.figure(figsize=(15, figheight), dpi=1200)
217 plt.subplots_adjust(wspace=0.1)
219 plt.subplot(maxfig, 1, figid)
220 plt.plot(steprange, data.energy[start:ndisplay])
222 plt.xlim(start, until)
226 if wo_drift ==
False:
227 plt.subplot(maxfig, 1, figid)
228 plt.plot(steprange, data.drift[start:ndisplay] / data.energy[start:ndisplay])
230 plt.xlim(start, until)
231 plt.ylabel(
"Relative Drift\n(regarding total energy)")
234 plt.subplot(maxfig, 1, figid)
235 plt.plot(steprange, data.residual[start:ndisplay])
237 plt.xlim(start, until)
239 plt.ylabel(
"Residual")
243 plt.subplot(maxfig, 1, figid)
244 plt.plot(steprange, data.distances.transpose()[start:ndisplay])
246 plt.xlim(start, until)
247 plt.ylabel(
"Distance of Particles\nfrom Center of Mass")
250 plt.subplot(maxfig, 1, figid)
251 plt.plot(steprange, data.dist_min.transpose()[start:ndisplay],
'-r')
252 plt.plot(steprange, data.dist_max.transpose()[start:ndisplay],
'-b')
253 plt.plot(steprange, data.dist_mean.transpose()[start:ndisplay],
'-g')
255 plt.xlim(start, until)
256 plt.ylabel(
"Stats of Distance of Particles\nfrom Center of Mass")
262 stop = step + width + 1
264 plt.figure(figsize=(15, 15), dpi=1200)
265 ax = plt.axes(projection=
'3d')
266 plt.title(
"Particle Meetup at step %d\ndot: start; square: end" % step)
267 if data.nparticles <= 5:
268 for p
in range(data.nparticles):
269 ax.plot(data.x[p][start:stop], data.y[p][start:stop], data.z[p][start:stop],
'--%s' % colors[p])
270 ax.plot(data.x_c[start:stop], data.y_c[start:stop], data.z_c[start:stop],
'-g')
271 ax.plot(data.x_c[step:step+1], data.y_c[step:step+1], data.z_c[step:step+1],
'xk', markeredgewidth=3, markersize=10)
272 ax.plot(data.x_c[start:start+1], data.y_c[start:start+1], data.z_c[start:start+1],
'ok')
273 ax.plot(data.x_c[stop-1:stop], data.y_c[stop-1:stop], data.z_c[stop-1:stop],
'sk')
def _get_coords(self, step, p)
def __init__(self, build_dir, nsteps, niter, nparticles)