def BunchFunction(NumberofParticles):
    PList = []
    for i in range(1,NumberofParticles+1):
        theta = 2*math.pi*(i/NumberofParticles) # Used below in asigning velocity vector to each cosmic ray. theta is chosen such that the cosmic ray particles each travel in differnt directions, having started at the same point.
        Proton = CosmicRay([0,8E4,0], [0.4*constants.speed_of_light*np.cos(theta), -(0.43 + (0.48*i)/NumberofParticles)*constants.speed_of_light, 0.4*constants.speed_of_light*np.sin(theta)], [0,0,0],'Proton %s'%(i),constants.proton_mass, constants.proton_mass, 1, 0, 1.0) # 80E4 is the top of the mesosphere, cosmic rays range in speed from 0.43c to 0.996c.
        PList.append(Proton)
    return(PList)
コード例 #2
0
def BunchFunction(NumberofParticles):
    PList = []
    for i in range(NumberofParticles):
        Proton = CosmicRay(
            [7.5E4, 8E4, 7.5E4],
            [(-0.5 + (1 * i) / NumberofParticles) * constants.speed_of_light,
             -(0.43 + (0.556 * i) / NumberofParticles) *
             constants.speed_of_light, 0.5 * constants.speed_of_light],
            [0, 0, 0], 'Proton %s' % (i + 1), 1.67E-27, 1
        )  # 80E4 is top of mesosphere, cosmic ray speed range 0.43c - 0.996c
        PList.append(Proton)
    return (PList)
コード例 #3
0
def BunchFunction(NumberofParticles):
    PList = []
    for i in range(NumberofParticles):
        theta = 2 * math.pi * (i / NumberofParticles)
        # Proton = CosmicRay([6.6E4,8E4,6.6E4], [(-0.5 + (1*i)/NumberofParticles)*constants.speed_of_light,-(0.43 + (0.556*i)/NumberofParticles)*constants.speed_of_light,0.5*constants.speed_of_light], [0,0,0],'Proton %s'%(i+1), 1.67E-27, 1) # 80E4 is top of mesosphere, cosmic ray speed range 0.43c - 0.996c
        Proton = CosmicRay([0, 8E4, 0], [
            0.5 * constants.speed_of_light * np.cos(theta),
            -(0.43 +
              (0.556 * i) / NumberofParticles) * constants.speed_of_light,
            0.5 * constants.speed_of_light * np.sin(theta)
        ], [0, 0, 0], 'Proton %s' % (i + 1), 1.67E-27, 1)
        PList.append(Proton)
    return (PList)
def BunchFunction(NumberofParticles):
    PList = []
    for i in range(1, NumberofParticles + 1):
        theta = 2 * math.pi * (i / NumberofParticles)
        Proton = CosmicRay(
            [0, 8E4, 0], [
                0.4 * constants.speed_of_light * np.cos(theta),
                -(0.43 +
                  (0.48 * i) / NumberofParticles) * constants.speed_of_light,
                0.4 * constants.speed_of_light * np.sin(theta)
            ], [0, 0, 0], 'Proton %s' % (i + 1), constants.proton_mass,
            constants.proton_mass, 1, 0, 1.0
        )  # 80E4 is top of mesosphere, cosmic ray speed range 0.43c - 0.996c
        PList.append(Proton)
    return (PList)
import numpy as np
import pandas as pd
import math
import copy
from scipy import constants
from pytest import approx
from CosmicRayClass import CosmicRay
from AtmosphereSupportFunctions import BunchFunction, Direction, Interacted
from CosmicRaySupportFunctions import StoppingForce, NonRelativisticStoppingForce, ForceDirectionCheck

"""
This file contains test functions for each of the testable functions used in the simulation. Each file is docstringed individually.
To initialise test: open terminal: view -> Terminal, once terminal loads, type in pytest, this runs pytest across all files in the folder.
"""
TestProton = CosmicRay([0,8E4,0], [0,-0.6*constants.speed_of_light,0], [0,0,0],'Proton', constants.proton_mass, constants.proton_mass, 1.0, 0, 1)
StationaryTestProton = CosmicRay([0,8E4,0], [0,0,0], [0,0,0],'Proton', constants.proton_mass, constants.proton_mass, 1.0, 0, 1)



# AtmosphereSupportFunctions Tests:
def test_BunchFunction(): 
    """
    Check that a bunch containing a single particle returns a list of length one and the particle is given the maximum velocity vector 
    """
    ListofOne = BunchFunction(1)
    assert len(ListofOne) == 1
    assert np.all(ListofOne[0].velocity == [0.4*constants.speed_of_light*np.cos(2*math.pi*(0)), -(0.43 + (0.48))*constants.speed_of_light, 0.4*constants.speed_of_light*np.sin(2*math.pi*(0))]) #CosmicRay([0,8E4,0], , [0,0,0],'Proton 1',constants.proton_mass, constants.proton_mass, 1, 0, 1.0) 
    
def test_Direction (): 
    """ 
    Check that particles direction is correctly identified, the test proton has positive X and Z velocity and negative Y velocity.