def finalize_turn_on_master(self, pieces_treated):
		
		# re-merge bunch
		bunch = sum(pieces_treated)

		#finalize present turn (with non parallel part, e.g. synchrotron motion)
		for ele in self.non_parallel_part:
			ele.track(bunch)

		# id and momenta after track
		id_after = bunch.id[bunch.id<=self.n_part_per_turn]
		xp_after = bunch.xp[bunch.id<=self.n_part_per_turn]
		z_after = bunch.z[bunch.id<=self.n_part_per_turn]
		yp_after = bunch.yp[bunch.id<=self.n_part_per_turn]

		# sort id and momenta after track
		indsort = np.argsort(id_after)
		id_after = np.take(id_after, indsort)
		xp_after = np.take(xp_after, indsort)
		yp_after = np.take(yp_after, indsort)
		z_after = np.take(z_after, indsort)

		# save results
		import myfilemanager as mfm
		mfm.save_dict_to_h5('particles_at_turn_%d.h5'%self.ring_of_CPUs.i_turn,{\
		'id_after': id_after,
		'xp_after': xp_after,
		'yp_after': yp_after,
		'z_after': z_after,
		'id_before':self.id_before,
		'xp_before':self.xp_before,
		'yp_before':self.yp_before})


		# prepare next turn (re-slice)
		new_pieces_to_be_treated = bunch.extract_slices(self.slicer)
		orders_to_pass = ['reset_clouds']

		return orders_to_pass, new_pieces_to_be_treated
예제 #2
0
    def finalize_simulation(self):

        # save results
        import myfilemanager as mfm
        mfm.save_dict_to_h5('beam_coord.h5',{\
         'beam_x':self.beam_x,
         'beam_y':self.beam_y,
         'beam_z':self.beam_z,
         'sx':self.sx,
         'sy':self.sy,
         'sz':self.sz,
         'epsx':self.epsx,
         'epsy':self.epsy,
         'epsz':self.epsz})

        # output plots
        if False:
            beam_x = self.beam_x
            beam_y = self.beam_y
            beam_z = self.beam_z
            sx = self.sx
            sy = self.sy
            sz = self.sz
            epsx = self.epsx
            epsy = self.epsy
            epsz = self.epsz

            import pylab as plt

            plt.figure(2, figsize=(16, 8), tight_layout=True)
            plt.subplot(2, 3, 1)
            plt.plot(beam_x)
            plt.ylabel('x [m]')
            plt.xlabel('Turn')
            plt.gca().ticklabel_format(style='sci', scilimits=(0, 0), axis='y')
            plt.subplot(2, 3, 2)
            plt.plot(beam_y)
            plt.ylabel('y [m]')
            plt.xlabel('Turn')
            plt.gca().ticklabel_format(style='sci', scilimits=(0, 0), axis='y')
            plt.subplot(2, 3, 3)
            plt.plot(beam_z)
            plt.ylabel('z [m]')
            plt.xlabel('Turn')
            plt.gca().ticklabel_format(style='sci', scilimits=(0, 0), axis='y')
            plt.subplot(2, 3, 4)
            plt.plot(np.fft.rfftfreq(len(beam_x), d=1.),
                     np.abs(np.fft.rfft(beam_x)))
            plt.ylabel('Amplitude')
            plt.xlabel('Qx')
            plt.subplot(2, 3, 5)
            plt.plot(np.fft.rfftfreq(len(beam_y), d=1.),
                     np.abs(np.fft.rfft(beam_y)))
            plt.ylabel('Amplitude')
            plt.xlabel('Qy')
            plt.subplot(2, 3, 6)
            plt.plot(np.fft.rfftfreq(len(beam_z), d=1.),
                     np.abs(np.fft.rfft(beam_z)))
            plt.xlim(0, 0.1)
            plt.ylabel('Amplitude')
            plt.xlabel('Qz')

            fig, axes = plt.subplots(3, figsize=(16, 8), tight_layout=True)
            twax = [plt.twinx(ax) for ax in axes]
            axes[0].plot(sx)
            twax[0].plot(epsx, '-g')
            axes[0].set_xlabel('Turns')
            axes[0].set_ylabel(r'$\sigma_x$')
            twax[0].set_ylabel(r'$\varepsilon_y$')
            axes[1].plot(sy)
            twax[1].plot(epsy, '-g')
            axes[1].set_xlabel('Turns')
            axes[1].set_ylabel(r'$\sigma_x$')
            twax[1].set_ylabel(r'$\varepsilon_y$')
            axes[2].plot(sz)
            twax[2].plot(epsz, '-g')
            axes[2].set_xlabel('Turns')
            axes[2].set_ylabel(r'$\sigma_x$')
            twax[2].set_ylabel(r'$\varepsilon_y$')
            axes[0].grid()
            axes[1].grid()
            axes[2].grid()
            for ax in list(axes) + list(twax):
                ax.ticklabel_format(useOffset=False,
                                    style='sci',
                                    scilimits=(0, 0),
                                    axis='y')
            plt.show()
	def finalize_simulation(self):
		
		# save results
		import myfilemanager as mfm
		mfm.save_dict_to_h5('beam_coord.h5',{\
			'beam_x':self.beam_x,
			'beam_y':self.beam_y,
			'beam_z':self.beam_z,
			'sx':self.sx,
			'sy':self.sy,
			'sz':self.sz,
			'epsx':self.epsx,
			'epsy':self.epsy,
			'epsz':self.epsz})
		
		# output plots
		if False:
			beam_x = self.beam_x
			beam_y = self.beam_y
			beam_z = self.beam_z
			sx = self.sx
			sy = self.sy 
			sz = self.sz
			epsx = self.epsx
			epsy =	self.epsy
			epsz =	self.epsz
			
			import pylab as plt
			
			plt.figure(2, figsize=(16, 8), tight_layout=True)
			plt.subplot(2,3,1)
			plt.plot(beam_x)
			plt.ylabel('x [m]');plt.xlabel('Turn')
			plt.gca().ticklabel_format(style='sci', scilimits=(0,0),axis='y')
			plt.subplot(2,3,2)
			plt.plot(beam_y)
			plt.ylabel('y [m]');plt.xlabel('Turn')
			plt.gca().ticklabel_format(style='sci', scilimits=(0,0),axis='y')
			plt.subplot(2,3,3)
			plt.plot(beam_z)
			plt.ylabel('z [m]');plt.xlabel('Turn')
			plt.gca().ticklabel_format(style='sci', scilimits=(0,0),axis='y')
			plt.subplot(2,3,4)
			plt.plot(np.fft.rfftfreq(len(beam_x), d=1.), np.abs(np.fft.rfft(beam_x)))
			plt.ylabel('Amplitude');plt.xlabel('Qx')
			plt.subplot(2,3,5)
			plt.plot(np.fft.rfftfreq(len(beam_y), d=1.), np.abs(np.fft.rfft(beam_y)))
			plt.ylabel('Amplitude');plt.xlabel('Qy')
			plt.subplot(2,3,6)
			plt.plot(np.fft.rfftfreq(len(beam_z), d=1.), np.abs(np.fft.rfft(beam_z)))
			plt.xlim(0, 0.1)
			plt.ylabel('Amplitude');plt.xlabel('Qz')
			
			fig, axes = plt.subplots(3, figsize=(16, 8), tight_layout=True)
			twax = [plt.twinx(ax) for ax in axes]
			axes[0].plot(sx)
			twax[0].plot(epsx, '-g')
			axes[0].set_xlabel('Turns')
			axes[0].set_ylabel(r'$\sigma_x$')
			twax[0].set_ylabel(r'$\varepsilon_y$')
			axes[1].plot(sy)
			twax[1].plot(epsy, '-g')
			axes[1].set_xlabel('Turns')
			axes[1].set_ylabel(r'$\sigma_x$')
			twax[1].set_ylabel(r'$\varepsilon_y$')
			axes[2].plot(sz)
			twax[2].plot(epsz, '-g')
			axes[2].set_xlabel('Turns')
			axes[2].set_ylabel(r'$\sigma_x$')
			twax[2].set_ylabel(r'$\varepsilon_y$')
			axes[0].grid()
			axes[1].grid()
			axes[2].grid()
			for ax in list(axes)+list(twax): 
				ax.ticklabel_format(useOffset=False, style='sci', scilimits=(0,0),axis='y')
			plt.show()