Exemple #1
0
    def rope_particles(self, screen: pygame.Surface, camera: pygame.Vector3,
                       rx: int, ry: int, k_rx, x1: int, x2: int):
        left = projection(self.polygons[1].points[0], camera, rx, ry, True,
                          k_rx)
        right = projection(self.polygons[0].points[2], camera, rx, ry, True,
                           k_rx)
        pygame.draw.line(screen, "grey", (x1, SCREEN_DIMENSION[1]), left.xy, 2)
        pygame.draw.line(screen, "grey", (x2, SCREEN_DIMENSION[1]), right.xy,
                         2)
        body_left = projection(self.polygons[0].points[0], camera, rx, ry,
                               True, k_rx)
        body_right = projection(self.polygons[1].points[2], camera, rx, ry,
                                True, k_rx)
        self.particles.append(
            Particle((body_left.x -
                      random.randint(0, abs(int(body_right.x - body_left.x))),
                      body_left.y + 10), (0, 10), random.randint(10, 30)))
        self.particles.append(
            Particle((body_right.x +
                      random.randint(0, abs(int(body_right.x - body_left.x))),
                      body_right.y + 10), (0, 10), random.randint(10, 30)))

        for particle in self.particles:
            particle.update()
            particle.draw(screen)
Exemple #2
0
def main():
    """
    This test illustrates the setting a ParticleContainer with pre-existing IDs
    """
    print "************************************************************************************"
    print " This test illustrates the setting a ParticleContainer with pre-existing IDs "
    print "************************************************************************************ \n"

    p1 = Particle([0.2, 1.3, 33.0], "Si", 2.0, 1.23)
    p2 = Particle([5.0, 2.3, -22.1], "C", 1.0, 2.34)
    p3 = Particle([5.0, 2.3, -20.1], "C", 1.0, 2.34)
    p4 = Particle([0.0, 2.3, -20.1], "C", 1.0, 2.34)
    p5 = Particle([90.0, -0.0, -80.1], "Zr", 1.0, 4.0)

    idList = [2, 3, 6, 10]
    print "Using idList = ", idList, " to initialize particle container"
    atoms1 = ParticleContainer(idList)
    print "Initial atoms1 state from a pre-set ID list ", atoms1, "\n"

    atoms1[2] = p1
    atoms1[3] = p2
    atoms1[6] = p3
    atoms1[10] = p4
    print "atoms1 state from a pre-set ID list populated atoms1[..] = ... ", atoms1, "\n"

    atoms1.put(p5)
    print "atoms1 state after a put(p5) call ", atoms1, "\n"
Exemple #3
0
def main():

    """
    This test illustrates the different ways Particle constructors can be used
    by using default values etc
    """
    print "************************************************************************************"
    print " This test illustrates the different ways Particle constructors can be used  "
    print " by using default values etc "
    print "************************************************************************************ \n"

    p1 = Particle( [0.2, 1.3,  33.0], "Si", 2.0, 1.23)
    p2 = Particle( [5.0, 2.3, -22.1], "C",  1.0, 2.34)
    p3 = Particle( [5.0, 2.3, -20.1], "C",  1.0, 2.34)
    p4 = Particle( [0.0, 2.3, -20.1], "C",  1.0, 2.34)

    p5 = Particle( type="Si", charge=2.0, pos=[0.2, 1.3, 54.0], mass=100.0)
    p6 = Particle( pos=[0.2, 1.3, 54.0], mass=100.0)
    p7 = Particle()
    p8 = Particle( [0.01, 2.4, 10.2], "Co", mass=134.0, charge=0.001 )
    p9 = Particle( [0.2, 1.3, 54.0], mass=100.0)
    p10 = Particle( [0.2, 1.3, 54.0] )

    # The following fail with argument checking native python functionality
    # p9  = Particle( [0.01, 2.4, 10.2], "Co", mass=134.0, 0.001 )
    # p10 = Particle( [0.01, 2.4, 10.2], mass=134.0, "Co" )

    print "p5  = ", p5.__dict__
    print "p6  = ", p6.__dict__
    print "p7  = ", p7.__dict__
    print "p8  = ", p8.__dict__
    print "p9  = ", p9.__dict__
    print "p10 = ", p10.__dict__
def test_visualize():
    particles = [
        Particle(0.3, 0.5, +1),
        Particle(0.0, -0.5, -1),
        Particle(-0.1, -0.4, +3)
    ]
    sim = ParticleSimulator(particles)
    sim.visualize()
def main():
    """
    This test shows how to add StructureContainer objects together
    A special test to double-check re-labeling ... add a big container to a 'small' one
    """
    print "***************************************************************************************"
    print " This test shows how to add StructureContainer objects together "
    print " A special test to double-check re-labeling ... add a big container to a 'small' one "
    print "*************************************************************************************** \n"

    p1 = Particle([1.1, 1.1, 1.1], "Si", 2.0, 1.23)
    p2 = Particle([2.2, 2.2, 2.2], "C", 1.0, 2.34)
    p3 = Particle([3.3, 3.3, 3.3], "C", 1.0, 2.34)

    b1 = Bond(1, 2, 1.111, "hooke")
    b2 = Bond(2, 3, 2.222, "hooke")

    atoms1 = ParticleContainer()
    atoms1.put(p1)
    atoms1.put(p2)
    atoms1.put(p3)

    bonds1 = BondContainer()
    bonds1.put(b1)
    bonds1.put(b2)

    polymer1 = StructureContainer(atoms1,
                                  bonds1)  # Complete structure 1 completely

    p1other = Particle([1.11, 1.11, 1.11], "C", 1.0, 2.34)
    p2other = Particle([2.22, 2.22, 2.22], "Ar", 2.0, 2.34)

    b1other = Bond(1, 2, 1.1,
                   "hooke-2")  # Correct ptclIDs for second structure

    atoms2 = ParticleContainer()
    atoms2.put(p1other)
    atoms2.put(p2other)

    bonds2 = BondContainer()
    bonds2.put(b1other)

    polymer2 = StructureContainer(atoms2,
                                  bonds2)  # Complete structure 1 completely

    del p1, p2, p3, p1other, p2other, b1, b2, b1other, atoms1, atoms2, bonds1, bonds2
    print "\n Cleaning memory for initial objects \n"

    print "-------------------- Before adding --------------------"
    print "polymer1 = ", polymer1
    print "polymer2 = ", polymer2
    print " "

    print "-------------------- After adding --------------------"
    # polymer1 += polymer2
    polymer2 += polymer1
    print "polymer2 = ", polymer2
Exemple #6
0
def three_particle_free_non_equilibrium_test(params):
    eps = 1e-14

    photon = Particle(**SMP.photon)
    neutrino_e = Particle(**SMP.leptons.neutrino_e)
    neutrino_mu = Particle(**SMP.leptons.neutrino_mu)
    sterile = Particle(**NuP.dirac_sterile_neutrino(mass=140 * UNITS.MeV))
    neutral_pion = Particle(**SMP.hadrons.neutral_pion)

    theta = 1e-3
    thetas = defaultdict(float, {
        'electron': theta,
    })

    interaction = NuI.sterile_hadrons_interactions(
        thetas = thetas, sterile=sterile,
        neutrinos = [neutrino_e],
        leptons = [],
        mesons = [neutral_pion]
    )

    universe = Universe(params=params)
    universe.add_particles([photon, neutrino_e, neutrino_mu, sterile, neutral_pion])
    universe.interactions += interaction

    params.update(universe.total_energy_density(), universe.total_entropy())

    universe.update_particles()
    universe.init_interactions()

    photon_distribution = photon._distribution
    neutrino_e_distribution = neutrino_e._distribution
    neutrino_mu_distribution = neutrino_mu._distribution
    sterile_distribution = sterile._distribution
    neutral_pion_distribution = neutral_pion._distribution

    universe.calculate_collisions()

    assert all(photon.collision_integral == 0), "Equilibrium particle integral is non-zero"
    assert all(numpy.abs(neutrino_e.collision_integral * params.h) < eps), "Integrals do not cancel"
    assert all(numpy.abs(sterile.collision_integral * params.h) < eps), "Integrals do not cancel"
    assert all(numpy.abs(neutral_pion.collision_integral * params.h) < eps), "Integrals do not cancel"
    assert all(neutrino_mu.collision_integral == 0), "Free particle integral is non-zero"

    universe.update_distributions()

    assert all(photon._distribution == photon_distribution),\
        "Equilibrium particle distribution changed"
    assert all(neutrino_e._distribution - neutrino_e_distribution < eps),\
        "Interacting particle distribution changed"
    assert all(sterile._distribution - sterile_distribution < eps),\
        "Interacting particle distribution changed"
    assert all(neutral_pion._distribution - neutral_pion_distribution < eps),\
        "Interacting particle distribution changed"
    assert all(neutrino_mu._distribution == neutrino_mu_distribution),\
        "Free particle distribution changed"
Exemple #7
0
def runStrucAdd(numPtcls1, numPtcls2):
    """
    Creates structures with ptcls and bonds between consecutive IDs
    Adds and reports timing

    Args:
        numPtcls1 (int): # of ptcls in first  struc
        numPtcls2 (int): # of ptcls in second struc
    Returns:
           (initTime, addTime, compressTime)
    """

    atoms1 = ParticleContainer()
    bonds1 = BondContainer()
    atoms2 = ParticleContainer()
    bonds2 = BondContainer()

    start_time = time.time()
    for n in range(numPtcls1):
        pobj1 = Particle([1.1, 1.1, 1.1], "Si", 2.0, float(n + 1))
        atoms1.put(pobj1)

    for n in range(1, numPtcls1):
        bobj1 = Bond(n, n + 1, 1.233, "hooke-1")
        bonds1.put(bobj1)

    for n in range(numPtcls2):
        pobj2 = Particle([2.2, 2.2, 2.2], "C", 1.0, float(n + 1))
        atoms2.put(pobj2)

    for n in range(1, numPtcls2):
        bobj2 = Bond(n, n + 1, 1.233, "hooke-2")
        bonds2.put(bobj2)
    end_time = time.time()

    initTime = end_time - start_time

    polymer1 = StructureContainer(atoms1, bonds1)  # Complete structure 1
    polymer2 = StructureContainer(atoms2, bonds2)  # Complete structure 2
    del atoms1, atoms2
    print "\n Cleaning memory for initial objects \n"

    start_time = time.time()
    polymer1 += polymer2
    end_time = time.time()
    addTime = end_time - start_time

    start_time = time.time()
    polymer1.compressPtclIDs()
    end_time = time.time()
    compressTime = end_time - start_time

    return (numPtcls1, numPtcls2, initTime, addTime, compressTime)
Exemple #8
0
def main():
    """
    This test shows various operators within Particle and ParticleContainer classes.
    Shows memory management structure and access methods.
    """
    p1 = Particle([0.2, 1.3, 33.0], "Si", 2.0, 1.23)
    p2 = Particle([5.0, 2.3, -22.1], "C", 1.0, 2.34)
    p3 = Particle([5.0, 2.3, -20.1], "C", 1.0, 2.34)
    p4 = Particle([0.0, 2.3, -20.1], "C", 1.0, 2.34)

    atoms1 = ParticleContainer()
    atoms2 = ParticleContainer()

    atoms1.put(p1)
    atoms1.put(p2)
    #
    atoms2.put(p3)
    atoms2.put(p4)

    del p1, p2, p3, p4
    print "\n Cleaning memory for initial objects \n"

    print "x = atoms1[1] returns x as an effective 'reference' \n"
    x = atoms1[1]
    print "x = ", x.__dict__, "\n"
    x.position = [1.0, 1.0, 1.0]
    print "after changing with x.position = [1.0, 1.0, 1.0]"
    print "x = ", x.__dict__, "\n"

    # This value has been changed by code above
    print "atoms1 has been changed"
    print atoms1

    print "before, atoms1--> ", atoms1, "\n"
    del atoms1[2]
    print "after 'del atoms1[2]' atoms1 --> ", atoms1, "\n"

    print "Testing 'in' operator (1 in atoms1)"
    if (1 in atoms1):
        print "atoms1 contains gid 1"
    else:
        print "key not found in atoms1"

    print "Testing 'in' operator (5 in atoms1)"
    if (5 in atoms1):
        print "atoms1 contains gid 5"
    else:
        print "key not found in atoms1"

    print " "
    atoms1 += atoms2
    print "Will print the new atoms1 after adding atoms1 += atoms2"
    print atoms1
def init_distribution_test(params):

    photon = Particle(params=params, **SMP.photon)
    neutrino = Particle(params=params, **SMP.leptons.neutrino_e)

    neutrino.update()

    assert numpy.allclose(
        photon._distribution,
        numpy.vectorize(photon.distribution)(photon.grid.TEMPLATE))
    assert numpy.allclose(
        neutrino._distribution,
        numpy.vectorize(neutrino.distribution)(neutrino.grid.TEMPLATE))
Exemple #10
0
def main():
    """
    This test shows how the setPtclPos method works to externally set all particle
    positions from a list
    """
    print "************************************************************************************"
    print " This test shows how the setPtclPos method works to externally set all particle "
    print " positions from a list"
    print "************************************************************************************ \n"

    p1 = Particle([0.2, 1.3, 33.0], "Si", 2.0, 1.23)
    p2 = Particle([5.0, 2.3, -22.1], "C", 1.0, 2.34)
    p3 = Particle([5.0, 2.3, -20.1], "C", 1.0, 2.34)
    p4 = Particle([0.0, 2.3, -20.1], "C", 1.0, 2.34)

    b1 = Bond(1, 2, 1.233, "hooke")
    b2 = Bond(2, 3, 0.500, "hooke")
    b3 = Bond(3, 4, 2.301, "hooke")
    b4 = Bond(1, 3, 0.828, "hooke")

    atoms1 = ParticleContainer()
    atoms1.put(p1)
    atoms1.put(p2)
    atoms1.put(p3)
    atoms1.put(p4)

    bonds = BondContainer()
    bonds.put(b1)
    bonds.put(b2)
    bonds.put(b3)
    bonds.put(b4)

    del p1, p2, p3, p4, b1, b2, b3, b4
    polymer1 = StructureContainer(atoms1, bonds)
    del atoms1, bonds
    polymer1.setBoxLengths([[-3.0, 100], [-5, 23.0], [34.3, 100.1]])

    print "Initial state of structure before reset ", polymer1

    newPtclPos = [[1, 0.111, 0.222, 0.333], [2, 0.222, 0.333, 0.444],
                  [4, 0.444, 0.555, 0.666]]

    print "new positions = ", newPtclPos

    polymer1.setPtclPositions(newPtclPos)

    ptclPosList = polymer1.getPtclPositions()

    print "new positions from structure = ", ptclPosList
    print " "
    print "After position reset/get ", polymer1
Exemple #11
0
def non_equilibium_setup():
    args, _ = setup()
    params = args[0]

    photon = Particle(**SMP.photon)
    neutrino_e = Particle(**SMP.leptons.neutrino_e)
    neutrino_mu = Particle(**SMP.leptons.neutrino_mu)
    neutrino_self_scattering = SMI.neutrino_scattering(neutrino_e, neutrino_e)

    universe = Universe(params=params)
    universe.add_particles([photon, neutrino_e, neutrino_mu])
    universe.interactions += [neutrino_self_scattering]

    return [params, universe], {}
 def __init__(self,
              init_state = [[1, 0, 0, -1],
                            [-0.5, 0.5, 0.5, 0.5],
                            [-0.5, -0.5, -0.5, 0.5]],
              bounds = [-2, 2, -2, 2],
              size = 0.04,
              M = 0.05,
              G = 0.0, 
              interaction = None,):
     self.init_state = np.asarray(init_state, dtype=float)
     self.M = M * np.ones(self.init_state.shape[0])
     self.size = size
     self.state = self.init_state.copy()
     self.particles = []
     for idx, elem in enumerate(init_state):
         self.particles.append(Particle(particle_id = idx, 
                             position = elem[:2], 
                             velocity = elem[2:4], 
                             properties = {'mass' : M, 
                                           'size' : size,}))
     self.time_elapsed = 0
     self.bounds = bounds
     self.G = G
     self.pressure_record = []
     self.interaction = interaction
Exemple #13
0
 def kill(self, sprite):
     for _ in range(10):
         Particle((self.sprite_groups[PARTICLES], self.sprite_groups[ALL]),
                  sprite.get_pos(), sprite.particle_color, 10, 10, 10, 10)
     sprite.kill()
     if is_sounds():
         choice(self.death_sounds).play()
def benchmark():
    particles = [
        Particle(random.uniform(-1.0, 1.0), random.uniform(-1.0, 1.0),
                 random.uniform(-1.0, 1.0)) for i in range(1000)
    ]
    sim = ParticleSimulator(particles)
    sim.evolve(0.1)
Exemple #15
0
 def _add_particles(self, k, r, c, v):
     self.particles = []
     init_pos = (self.size // 2, self.size // 2)
     for i in range(k):
         p = Particle(radius=r, color=c, velocity=v)
         self.particles.append(p)
     i = 0
     for p in self.particles:
         r = random()
         x = 0
         if i <= k // 4:
             p.set_initial_pos((init_pos[0] + i * 30 + r * x,
                                init_pos[1] + i * 30 + r * x))
         elif i <= k // 2:
             p.set_initial_pos((init_pos[0] - (i - k // 4) * 30 - r * x,
                                init_pos[1] - (i - k // 4) * 30 - r * x))
         elif i <= 3 * k // 4:
             p.set_initial_pos((init_pos[0] + (i - k // 2) * 30 + r * x,
                                init_pos[1] - (i - k // 2) * 30 - r * x))
         else:
             p.set_initial_pos(
                 (init_pos[0] - (i - 3 * k // 4) * 30 - r * x,
                  init_pos[1] + (i - 3 * k // 4) * 30 + r * x))
         i += 1
         p.draw()
 def addParticle(self):
     # self.particles.append(Particle(self.location))
     ch = random(10)
     if ch <= 5:
         self.particles.append(Particle(self.location))
     else:
         self.particles.append(RectParticle(self.location))
Exemple #17
0
def positron_track(positronSource, mat, Estep):

    positron = Particle('Positron', 511, 1)
    xpath, ypath, zpath = [0], [0], [0]
    x, y, z = 0, 0, 0
    positron.eKin = samplingEnergy(positronSource)

    r = np.random.uniform(-1, 1)
    theta = np.arccos(r)
    phi = np.random.uniform(0, 2 * np.pi)
    alpha, beta, gamma = np.sin(phi) * np.sin(theta), np.cos(phi) * np.sin(
        theta), np.cos(theta)
    n = np.array([alpha, beta, gamma])

    while positron.eKin > 25e-6:

        let = bethe_bloch(positron, mat)  #+ bremsstrahlung(positron, mat)
        r = Estep / let
        theta_sc = samplingTheta(positron, mat, r)
        phi_sc = np.random.uniform(0, 2 * np.pi)

        x += (r * n[0])
        y += (r * n[1])
        z += (r * n[2])

        n = ms3d(*n, theta_sc, phi_sc)

        xpath.append(x)
        ypath.append(y)
        zpath.append(z)

        #de = enStraggling(positron, mat, Estep/r, r)
        positron.eKin = positron.eKin - Estep

    return xpath, ypath, zpath
Exemple #18
0
    def update(self):
        # particle fireworks VFX
        # create new bunch of sparks
        if randint(0, glb.FPS) == 5:
            x = randint(self.rect.left + 30, self.rect.right - 30)
            y = randint(self.rect.top + 150, self.rect.bottom - 10)
            color = [randint(150, 255), randint(150, 255), randint(150, 255)]
            color[randint(0, 2)] -= 150
            gravity = 0.1
            bounding_rect = self.rect.inflate(-10, -10)
            for i in range(randint(80, 200)):
                vx = gauss(0, 3)
                vy = -uniform(6, 2)
                radius = randint(2, 5)
                glow_size = radius*2
                glow_value = 25
                lifetime = randint(3*glb.FPS, 5*glb.FPS)
                particle = Particle(x, y, vx, vy, color, radius, lifetime, gravity,
                              vx_func=lambda vx: vx - 0.02,
                              size_func=lambda size: size - 0.03,
                              rect=bounding_rect,
                              glow_size=glow_size, glow_value=glow_value,
                              glow_size_func=lambda gsz: gsz - 0.02,
                              glow_value_func=lambda gval: gval - 0.3)
                self.particles.append(particle)

        self.particles = [p for p in self.particles if p.alive]
        
        super().update()
Exemple #19
0
def create_particles(x, y, color):
    count = random.randrange(20, 30, 1)
    numbers = range(-5, -1) + range(1, 5)
    for i in range(0, count):
        particle_group.add(
            Particle(x + 40, y + 40, random.choice(numbers),
                     random.choice(numbers), random.randint(3, 8), color))
def main():
    """
    This test shows how to save/dump/restore state of structureContainers using pickle
    """
    print "************************************************************************************"
    print " This test shows how to save/dump/restore state of structureContainers using pickle"
    print "************************************************************************************ \n"

    p1 = Particle([0.2, 1.3, 33.0], "Si", 2.0, 1.23)
    p2 = Particle([5.0, 2.3, -22.1], "C", 1.0, 2.34)
    p3 = Particle([5.0, 2.3, -20.1], "C", 1.0, 2.34)
    p4 = Particle([0.0, 2.3, -20.1], "C", 1.0, 2.34)

    b1 = Bond(1, 2, 1.233, "hooke")
    b2 = Bond(2, 3, 0.500, "hooke")
    b3 = Bond(3, 4, 2.301, "hooke")
    b4 = Bond(1, 3, 0.828, "hooke")

    atoms1 = ParticleContainer()
    atoms1.put(p1)
    atoms1.put(p2)
    atoms1.put(p3)
    atoms1.put(p4)

    bonds = BondContainer()
    bonds.put(b1)
    bonds.put(b2)
    bonds.put(b3)
    bonds.put(b4)

    del p1, p2, p3, p4, b1, b2, b3, b4
    polymer1 = StructureContainer(atoms1, bonds)
    del atoms1, bonds
    polymer1.setBoxLengths([[-3.0, 100], [-5, 23.0], [34.3, 100.1]])

    print "Initial state of structure before dump ", polymer1

    print "-------------------------------------------------------------------------------- \n"

    polymer1.dump('polymer1')

    polymerNew = StructureContainer()
    polymerNew.restore('polymer1.pkl')

    print "After load from pickle \n"
    print polymerNew
    print "-------------------------------------------------------------------------------- \n"
def main():
    """
    This test shows basics of the Simulation classes
    Highlights differences between setting reference to the structure
    container and a deepcopy
    """
    print "************************************************************************************"
    print " This test shows basics of the Simulation classes"
    print " Highlights differences between setting reference to the structure"
    print "  container and a deepcopy"
    print "************************************************************************************ \n"

    p1 = Particle([0.2, 1.3, 33.0], "Si", 2.0, 1.23)
    p2 = Particle([5.0, 2.3, -22.1], "C", 1.0, 2.34)
    p3 = Particle([5.0, 2.3, -20.1], "C", 1.0, 2.34)

    atoms1 = ParticleContainer()
    atoms1.put(p1)
    atoms1.put(p2)
    atoms1.put(p3)

    polymer1 = StructureContainer(
        atoms1, verbose=False)  # Complete structure 1 completely
    polymer2 = StructureContainer(verbose=False)
    polymer2 += polymer1

    del p1, p2, p3, atoms1
    print "\n Cleaning memory for initial objects \n"

    print "-------------------- Before adding --------------------"
    print "polymer1 = ", polymer1
    print "polymer2 = ", polymer2
    print " "

    simObj1 = Simulation("GaussianJuly2014")
    simObj2 = Simulation("Lammps012038")

    simObj1.setStructureContainer(polymer1)
    simObj2.copyStructureContainerInto(polymer1)

    del polymer1.ptclC[1]

    print "-------------------- After changing polymer1 struc --------------------"
    print "polymer1 = ", polymer1
    simObj1.printStruc()
    simObj2.printStruc()
Exemple #22
0
def mass_regime_switching_test(params):

    electron = Particle(params=params, **SMP.leptons.electron)
    assert electron.regime == REGIMES.INTERMEDIATE

    electron.mass = 0
    assert electron.regime == REGIMES.RADIATION

    electron.mass = 1e5 * UNITS.MeV
    assert electron.regime == REGIMES.DUST
Exemple #23
0
def three_particle_decay_test(params):
    os.environ['SPLIT_COLLISION_INTEGRAL'] = ''

    photon = Particle(**SMP.photon)
    neutrino_e = Particle(**SMP.leptons.neutrino_e)
    sterile = Particle(**NuP.dirac_sterile_neutrino(mass=200 * UNITS.MeV))
    neutral_pion = Particle(**SMP.hadrons.neutral_pion)

    theta = 1e-2
    thetas = defaultdict(float, {
        'electron': theta,
    })

    interaction = NuI.sterile_hadrons_interactions(
        thetas = thetas, sterile=sterile,
        neutrinos = [neutrino_e],
        leptons = [],
        mesons = [neutral_pion],
        kind = CollisionIntegralKind.F_f_vacuum_decay
    )

    universe = Universe(params=params)
    universe.add_particles([photon, neutrino_e, sterile, neutral_pion])
    universe.interactions += interaction

    params.update(universe.total_energy_density(), universe.total_entropy())

    universe.update_particles()
    universe.init_interactions()

    collision_integral = sterile.collision_integrals[0].integrate(sterile.grid.TEMPLATE)

    theo_value = (CONST.G_F * theta * neutral_pion.decay_constant)**2 \
                * sterile.mass**3 * (1 - (neutral_pion.mass / sterile.mass)**2)**2 \
                / (16 * numpy.pi) / UNITS.MeV

    decay_rate = -(collision_integral * sterile.params.H \
                * sterile.conformal_energy(sterile.grid.TEMPLATE) / sterile.conformal_mass \
                / sterile._distribution) / UNITS.MeV

    ratio = decay_rate / theo_value

    assert any(numpy.abs(val) - 1 < 1e-2 for val in ratio), "Three-particle decay test failed"
Exemple #24
0
def four_particle_decay_test(params):
    os.environ['SPLIT_COLLISION_INTEGRAL'] = ''

    photon = Particle(**SMP.photon)
    neutrino_e = Particle(**SMP.leptons.neutrino_e)
    sterile = Particle(**NuP.dirac_sterile_neutrino(mass=200 * UNITS.MeV))

    theta = 1e-4
    thetas = defaultdict(float, {
        'electron': theta,
    })

    interaction = NuI.sterile_leptons_interactions(
        thetas=thetas, sterile=sterile,
        neutrinos=[neutrino_e],
        leptons=[],
        kind = CollisionIntegralKind.F_f_vacuum_decay
    )

    for inter in interaction:
        inter.integrals = [integral for integral in inter.integrals
                            if sum(reactant.side for reactant in integral.reaction) in [2]]

    universe = Universe(params=params)
    universe.add_particles([photon, neutrino_e, sterile])
    universe.interactions += interaction

    params.update(universe.total_energy_density(), universe.total_entropy())

    universe.update_particles()
    universe.init_interactions()

    collision_integral = sterile.collision_integrals[0].integrate(sterile.grid.TEMPLATE)

    theo_value = (CONST.G_F * theta)**2 * sterile.mass**5 / (192 * numpy.pi**3) / UNITS.MeV

    decay_rate = -(collision_integral * sterile.params.H \
                * sterile.conformal_energy(sterile.grid.TEMPLATE) / sterile.conformal_mass \
                / sterile._distribution) / UNITS.MeV

    ratio = decay_rate / theo_value

    assert any(numpy.abs(val) - 1 < 1e-2 for val in ratio), "Four-particle decay test failed"
Exemple #25
0
def dust_regime_test(params):

    proton = Particle(params=params, **SMP.hadrons.proton)
    assert proton.in_equilibrium, "Proton must always stay in equilibrium"
    assert not proton.decoupling_temperature, "Proton can't decouple"
    assert proton.mass != 0, "Proton is massive"
    assert proton.eta == 1, "Proton is a fermion, it's eta must be equal to 1"
    assert proton.numerator(
    ) != 0, "Massive particles contribute to the numerator"
    assert proton.denominator(
    ) != 0, "Massive particles contribute to the denominator"
Exemple #26
0
def radiation_regime_test(params):

    photon = Particle(params=params, **SMP.photon)
    assert photon.in_equilibrium, "Photon must always stay in equilibrium"
    assert not photon.decoupling_temperature, "Photon can't decouple"
    assert photon.regime == REGIMES.RADIATION, "Photon is a relativistic particle"
    assert photon.mass == 0, "Photon is massless"
    assert photon.eta == -1, "Photon is a boson, it's eta must be equal to -1"
    assert photon.numerator(
    ) == 0, "Photon does not contribute to the numerator"
    assert photon.denominator(
    ) != 0, "Photon does contribute to the denominator"
def main():
    """
    This test illustrates the different ways ParticleContainer can set Particle
    object data (eg the [] operator on ParticleContainer)
    """
    p1 = Particle([0.2, 1.3, 33.0], "Si", 2.0, 1.23)
    p2 = Particle([5.0, 2.3, -22.1], "C", 1.0, 2.34)
    p3 = Particle([5.0, 2.3, -20.1], "C", 1.0, 2.34)
    p4 = Particle([0.0, 2.3, -20.1], "C", 1.0, 2.34)

    p5 = Particle([9.0, -8.0, -80.1], "Ar", 1.0, 4.0)
    p6 = Particle([90.0, -0.0, -80.1], "Zr", 1.0, 4.0)

    atoms1 = ParticleContainer()
    atoms1.put(p1)
    atoms1.put(p2)
    atoms1.put(p3)
    atoms1.put(p4)

    print "Initial atoms1 state from an empty container, populated with put()", atoms1, "\n"

    tag = 4
    print "Replacing ID tag", tag, "with p5 particle data \n"
    atoms1[4] = p5
    print "atoms1 state", atoms1, "\n"

    tag = 5
    print "Setting ID tag that does not exist", tag, "with p6 particle data ---> atoms1[5]=p6 \n"
    atoms1[5] = p6
    print "atoms1 state", atoms1, "\n"
Exemple #28
0
def test_evolve(benchmark):  # pytest-benchmark
    particles = [
        Particle(0.3, 0.5, +1),
        Particle(0.0, -0.5, -1),
        Particle(-0.1, -0.4, +3)
    ]
    sim = ParticleSimulator(particles)
    sim.evolve(0.1)

    p0, p1, p2 = particles

    def fequal(a, b, eps=1e-5):
        return abs(a - b) < eps

    assert fequal(p0.x, 0.210269)
    assert fequal(p0.y, 0.543863)
    assert fequal(p1.x, -0.099334)
    assert fequal(p1.y, -0.490034)
    assert fequal(p2.x, 0.191358)
    assert fequal(p2.y, -0.365227)

    benchmark(sim.evolve, 0.1)  # pytest-benchmark
Exemple #29
0
def draw():
    if len(particles) < max_particles:
        particles.append(Particle())

    to_remove = []
    for p in particles:
        if p.out_of_boundaries():
            to_remove.append(p)
        p.move()
        p.display()

    for p in to_remove:
        particles.remove(p)
Exemple #30
0
def samplingEnergy(beta_sourge):

    p = Particle('Positron', 511, 1)
    i = 0

    while i != 1:
        p.eKin = np.random.uniform(0, beta_sourge.Emax)
        y = np.random.uniform(0, 0.8)

        if y < beta_sourge.beta_spectrum(p):
            i = 1

    return p.eKin