def test_particle_momentum(self): P = Particle(1, 'id') self.assertEqual(P.momentum().mom(), (0, 0)) P = Particle(1, 'id', px=1, py=2) self.assertEqual(P.momentum().mom(), (1, 2)) P.set_momentum(4, 5) self.assertEqual(P.momentum().mom(), (4, 5))
def test_particle_position(self): P = Particle(1, 'id') self.assertEqual(P.position().pos(), (0, 0)) P = Particle(1, 'id', x=1, y=2) self.assertEqual(P.position().pos(), (1, 2)) P.set_position(4, 5) self.assertEqual(P.position().pos(), (4, 5))
def event(self, datastore): try: datastore.get('Particles') except NotFoundInDataStore: datastore.put('Particles', ParticleContainer()) if self.particle_x_pos == -1: x_pos = int(random.random() * self.cells) # transformation to integer cell else: x_pos = self.particle_x_pos if self.particle_y_pos == -1: y_pos = int(random.random() * self.layers) # transformation to integer cell else: y_pos = self.particle_y_pos if self.particle_x_mom == -1: x_mom = ( random.random() - 0.5 ) * 2 * self.particle_max_mom # negative x-direction possible else: x_mom = self.particle_x_mom if self.particle_y_mom == -1: y_mom = random.random( ) * self.particle_max_mom # negative y-direction not possible else: y_mom = self.particle_y_mom particle = Particle(self.particle_mass, self.particle_name, x_pos, y_pos, x_mom, y_mom) datastore.get('Particles').add_particle(particle, self.particle_name)
def setUp(self): self.datastore = DataStore() self.module = ParticlePrinter() self.datastore.put('Particles', ParticleContainer(), ObjectLifetime.Application) particle = Particle( 0.1, 'electron', 5, 0, 0.001, 0.005 ) #Create Particle with determined specification for read out with the printer self.datastore.get('Particles').add_particle(particle, 'electron')
def begin(self, datastore): logging.info("Begin of module 'Noise'") configuration = datastore.get(self) self._noise_name = configuration['Particle_name'] self._noise_mass = configuration['Particle_mass'] self._noise_probability = configuration[ 'Particle_probability'] #Probability to have noise per cell self._noise_part = Particle( self._noise_mass, self._noise_name) #Creates a "particle", which is flagged as noise self._detector = datastore.get('Detector')