|
14 | 14 | class Simulation(object): |
15 | 15 | def __init__(self): |
16 | 16 | self.N_turns = pp.N_turns |
| 17 | + self.pp = pp |
17 | 18 |
|
18 | 19 | def init_all(self): |
19 | 20 |
|
@@ -315,23 +316,31 @@ def init_master(self): |
315 | 316 | n_macroparticles=pp.n_macroparticles_for_footprint_track, intensity=pp.intensity, |
316 | 317 | epsn_x=pp.epsn_x, epsn_y=pp.epsn_y, sigma_z=pp.sigma_z) |
317 | 318 | elif SimSt.first_run: |
318 | | - self.bunch = self.machine.generate_6D_Gaussian_bunch_matched( |
319 | | - n_macroparticles=pp.n_macroparticles, intensity=pp.intensity, |
320 | | - epsn_x=pp.epsn_x, epsn_y=pp.epsn_y, sigma_z=pp.sigma_z) |
321 | | - |
322 | | - # compute initial displacements |
323 | | - inj_opt = self.machine.transverse_map.get_injection_optics() |
324 | | - sigma_x = np.sqrt(inj_opt['beta_x']*pp.epsn_x/self.machine.betagamma) |
325 | | - sigma_y = np.sqrt(inj_opt['beta_y']*pp.epsn_y/self.machine.betagamma) |
326 | | - x_kick = pp.x_kick_in_sigmas*sigma_x |
327 | | - y_kick = pp.y_kick_in_sigmas*sigma_y |
328 | | - |
329 | | - # apply initial displacement |
330 | | - if not pp.footprint_mode: |
331 | | - self.bunch.x += x_kick |
332 | | - self.bunch.y += y_kick |
333 | | - |
334 | | - print 'Bunch initialized.' |
| 319 | + |
| 320 | + if pp.bunch_from_file is not None: |
| 321 | + print 'Loading bunch from file %s ...'%pp.bunch_from_file |
| 322 | + with h5py.File(pp.bunch_from_file, 'r') as fid: |
| 323 | + self.bunch = self.buffer_to_piece(np.array(fid['bunch']).copy()) |
| 324 | + print 'Bunch loaded from file.\n' |
| 325 | + |
| 326 | + else: |
| 327 | + self.bunch = self.machine.generate_6D_Gaussian_bunch_matched( |
| 328 | + n_macroparticles=pp.n_macroparticles, intensity=pp.intensity, |
| 329 | + epsn_x=pp.epsn_x, epsn_y=pp.epsn_y, sigma_z=pp.sigma_z) |
| 330 | + |
| 331 | + # compute initial displacements |
| 332 | + inj_opt = self.machine.transverse_map.get_injection_optics() |
| 333 | + sigma_x = np.sqrt(inj_opt['beta_x']*pp.epsn_x/self.machine.betagamma) |
| 334 | + sigma_y = np.sqrt(inj_opt['beta_y']*pp.epsn_y/self.machine.betagamma) |
| 335 | + x_kick = pp.x_kick_in_sigmas*sigma_x |
| 336 | + y_kick = pp.y_kick_in_sigmas*sigma_y |
| 337 | + |
| 338 | + # apply initial displacement |
| 339 | + if not pp.footprint_mode: |
| 340 | + self.bunch.x += x_kick |
| 341 | + self.bunch.y += y_kick |
| 342 | + |
| 343 | + print 'Bunch initialized.' |
335 | 344 | else: |
336 | 345 | print 'Loading bunch from file...' |
337 | 346 | with h5py.File('bunch_status_part%02d.h5'%(SimSt.present_simulation_part-1), 'r') as fid: |
@@ -482,15 +491,19 @@ def Get_rank(self): |
482 | 491 | def Barrier(self): |
483 | 492 | pass |
484 | 493 |
|
485 | | -def get_sim_instance(N_cores_pretend, id_pretend): |
| 494 | +def get_sim_instance(N_cores_pretend, id_pretend, |
| 495 | + init_sim_objects_auto=True): |
| 496 | + |
486 | 497 | from PyPARIS.ring_of_CPUs import RingOfCPUs |
487 | 498 | myCPUring = RingOfCPUs(Simulation(), |
488 | | - comm=DummyComm(N_cores_pretend, id_pretend)) |
| 499 | + comm=DummyComm(N_cores_pretend, id_pretend), |
| 500 | + init_sim_objects_auto=init_sim_objects_auto) |
489 | 501 | return myCPUring.sim_content |
490 | 502 |
|
491 | | -def get_serial_CPUring(): |
| 503 | +def get_serial_CPUring(init_sim_objects_auto=True): |
492 | 504 | from PyPARIS.ring_of_CPUs import RingOfCPUs |
493 | | - myCPUring = RingOfCPUs(Simulation(), force_serial=True) |
| 505 | + myCPUring = RingOfCPUs(Simulation(), force_serial=True, |
| 506 | + init_sim_objects_auto=init_sim_objects_auto) |
494 | 507 | return myCPUring |
495 | 508 |
|
496 | 509 |
|
|
0 commit comments