PyCOMPLETE / PyECLOUD

PyECLOUD code for the simulation of electron cloud effects in particle accelerators. More info at: https://github.com/PyCOMPLETE/PyECLOUD/wiki
21 stars 11 forks source link

Video saving multi-cloud #112

Open giadarol opened 5 years ago

giadarol commented 5 years ago

In pyeclsaver.py. This looks quite messy (with lots of duplicated code). Needs to be cleaned up before introducing arbitrary time-step for video:

def _rho_video_save(self, spacech_ele, beamtim, rho_cloud):
        #save rho video
        if self.flag_video and self.flag_last_cloud:
            if not os.path.exists(self.folder_outp + '/rho_video'):
                os.makedirs(self.folder_outp + '/rho_video')
            if self.rho_video is None:
                self.rho_video = []
                self.t_video = []
            if spacech_ele.last_recomputation_check:
                self.rho_video.append(spacech_ele.rho)
                self.t_video.append(beamtim.tt_curr)
            if beamtim.flag_new_bunch_pass:
                self.rho_video = np.array(self.rho_video)
                self.t_video = np.array(self.t_video)
                filename_rho = self.folder_outp + '/rho_video/rho_pass%d.mat'%(beamtim.pass_numb - 1)
                print('Saving %s'%filename_rho)
                sio.savemat(filename_rho, {'xg_sc': spacech_ele.xg, 'yg_sc': spacech_ele.yg, 't_video': self.t_video, 'rho_video': self.rho_video}, oned_as='row')
                print('Done')
                self.rho_video = []
                self.t_video = []

        # save rho video for cloud
        if self.flag_video and self.flag_multiple_clouds:
            if not os.path.exists(self.folder_outp + '/rho_video_%s'%(self.cloud_name)):
                os.makedirs(self.folder_outp + 'rho_video_%s'%(self.cloud_name))
            if self.rho_video_cloud is None:
                    self.rho_video_cloud = []
                    self.t_video_cloud = []
            if spacech_ele.last_recomputation_check:
                if rho_cloud is None:
                    print('Warning! No rho provided for saving.')
                else:
                    self.rho_video_cloud.append(rho_cloud)
                self.t_video_cloud.append(beamtim.tt_curr)
            if beamtim.flag_new_bunch_pass:
                self.rho_video_cloud = np.array(self.rho_video_cloud)
                self.t_video_cloud = np.array(self.t_video_cloud)
                filename_rho = self.folder_outp + 'rho_video_%s/rho_pass%d.mat'%(self.cloud_name, beamtim.pass_numb - 1)
                print('Saving %s'%filename_rho)
                sio.savemat(filename_rho, {'xg_sc': spacech_ele.xg, 'yg_sc': spacech_ele.yg, 't_video': self.t_video_cloud, 'rho_video': self.rho_video_cloud}, oned_as='row')
                print('Done')
                self.rho_video_cloud = []
                self.t_video_cloud = []
giadarol commented 5 years ago

In buildup_simulation.py, probably smarter to pass cloud instead of this:

cloud.impact_man = cloud.pyeclsaver.witness(cloud.MP_e, beamtim, spacech_ele, cloud.impact_man, cloud.dynamics,
                                                            cloud.gas_ion_flag, cloud.resgasion, cloud.t_ion, t_sc_ON,
                                                            cloud.photoem_flag, cloud.phemiss, flag_presence_sec_beams,
                                                            sec_beams_list, cloud_list, buildup_sim=self, rho_cloud=cloud.rho)