Skip to content

How to define your simulation (multibunch)

giadarol edited this page Dec 9, 2018 · 11 revisions

To define a multi-bunch simulation to be run with the PyPARIS ring of CPUs, the user needs to write a simulation class. Each CPU will instantiate a separate instance of the class, and use it to preform the simulation according to the paradigm defined here.

PyPARIS will add to the object a member called ring_of_CPUs, which carries the information about the multiprocess structure and allows each process to identify itself.

A prototype simulation class is defined in the following, and examples can be found in the PyPARIS test folders.

class Simulation(object):
    def __init__(self):
        self.N_turns = 5000
        self.N_buffer_float_size = 10000000
        self.N_buffer_int_size = 100
        self.N_parellel_rings = 10
        
        self.n_slices_per_bunch = 200
        self.z_cut_slicing = 3*sigma_z_bunch
        self.N_pieces_per_transfer = 300
        

    def init_all(self): 
        # Executed on all cores at the beginning of the simulation
        #  - Generate the portion of the machine to be 
        #    simulated by the specific core.
        #  - Insert and initialize the e-cloud elements
        #  - At end-ring: prepare for global bunch operations
        if self.ring_of_CPUs.I_am_at_end_ring:    
            self.non_parallel_part=\
                 self.machine.one_turn_map[-n_non_sliceable:]

            
    def init_master(self):
        # ...arbitrary code...
        return list_bunches

    def init_start_ring(self):
        # ...arbitrary code...
        pass

    def perform_bunch_operations_at_start_ring(self, bunch):
        # ...arbitrary code...
        pass 

    def slice_bunch_at_start_ring(self, bunch):
        # ...arbitrary code...
        return list_slices

    def treat_piece(self, piece):
        # ...arbitrary code...
        pass
        
    def merge_slices_at_end_ring(self, list_slices):
        # ...arbitrary code...
        return bunch

    def perform_bunch_operations_at_end_ring(self, bunch):
        # ...arbitrary code...

    def piece_to_buffer(self, piece):
        # ...arbitrary code...

    def buffer_to_piece(self, buf):
        # ...arbitrary code...

Clone this wiki locally