def BunchFunction(NumberofParticles):
    PList = []
    for i in range(NumberofParticles):
        Proton = Charticle(
            [0, 8E4, 0],
            [(0.1 + (0.5 * i) / NumberofParticles) * constants.speed_of_light,
             -(0.43 +
               (0.556 * i) / NumberofParticles) * constants.speed_of_light, 0],
            [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)
import numpy as np
import pandas as pd
import math
import copy
from scipy import constants
from pytest import approx

from Particle import Particle
from Particle import Charticle
from AtmosphereSupportFunctions import StoppingForce, NonRelativisticStoppingForce, Direction, ForceDirectionCheck
from AtmosphereFinal import Atmosphere

# To test: do pytest for each function in AtmosphereFinal, small tests to assert that each gives the expected value. With atmosphere function, calculate/find a database with the values we expect after the first time step of in the data frame, assert that these correct values equal those of the dataframe given by python.
# To initialise test: open terminal: view -> Terminal, once terminal loads, type in pytest, this runs pytest across all files in the folder. Currently not running my test. Fix this.
TestProton = Charticle(
    [0, 8E4, 0],
    [0.6 * constants.speed_of_light, -0.7 * constants.speed_of_light, 0],
    [0, 0, 0], 'Proton', 1.67E-27, 1)
StationaryProton = Charticle([0, 8E4, 0], [0, 0, 0], [0, 0, 0], 'Proton',
                             1.67E-27, 1)


def test_Stoppingforce(
):  # check that relativistic stopping force gives correct value for a given input
    assert StoppingForce(5.3E25, 1, 0.9, 1.36E-17) * 1E15 == approx(
        -5.33,
        rel=0.01)  # Multiply by 1e15 as approx only has accuracy of 1E-12


def test_NonRelativisticStoppingforce(
):  # check that non-relativistic stopping force gives correct value for a given input
    assert NonRelativisticStoppingForce(
import numpy as np
import pandas as pd
import math
import copy
from scipy import constants

from Particle import Particle
from Particle import Charticle

#This file only works at relativistic speeds, at lower speeds, stoppingforce eqn breaks down.
Proton = Charticle([0, 2.5E4, 0], [2.3E7, -2.5E7, 0], [0, 0, 0], 'Proton',
                   1.67E-27, 1)


def StoppingForce(
        eDensity, charge, beta,
        V_excitation):  # Note beta is different for each x, y, z direction
    t1 = (4 * math.pi) / (constants.electron_mass * constants.speed_of_light *
                          constants.speed_of_light)
    t2 = (eDensity * charge * charge) / (beta * beta)
    t3 = (constants.elementary_charge *
          constants.elementary_charge) / (4 * math.pi * constants.epsilon_0)
    ln = np.log((2 * constants.electron_mass * constants.speed_of_light *
                 constants.speed_of_light * beta * beta) / (V_excitation *
                                                            (1 - beta * beta)))
    t4 = ln - beta * beta
    StoppingForce = -t1 * t2 * t3 * t3 * t4
    return (StoppingForce)


def Direction(VelocityVector):
import numpy as np
import pandas as pd
import math
import copy
from scipy import constants
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

from Particle import Particle
from Particle import Charticle



Proton = Charticle([0,0,0], [0,2.5E8,0], [0,0,0],'Proton', 1.67E-27, 1)


def StoppingForce(eDensity,charge,beta,V_excitation): # Note beta is different for each x, y, z direction
    t1 = (4*math.pi)/(constants.electron_mass*constants.speed_of_light*constants.speed_of_light)
    t2 = (eDensity*charge*charge)/(beta*beta)
    t3 = (constants.elementary_charge*constants.elementary_charge)/(4*math.pi*constants.epsilon_0)
    ln = np.log((2*constants.electron_mass*constants.speed_of_light*constants.speed_of_light*beta*beta)/(V_excitation*(1-beta*beta)))
    t4 = ln - beta*beta
    StoppingForce = -t1*t2*t3*t3*t4
    return(StoppingForce)

def Direction(VelocityVector):
    DirectionList = []
    for i in range(len(VelocityVector)):
        if VelocityVector[i] >= 0:
            DirectionList.append(1)
        else:
Exemplo n.º 5
0
import numpy as np
import pandas as pd
import math
import copy
from scipy import constants

from Particle import Particle
from Particle import Charticle
from AtmosphereSupportFunctions import StoppingForce, NonRelativisticStoppingForce, Direction, ForceDirectionCheck

Proton = Charticle(
    [0, 8E4, 0],
    [0.6 * constants.speed_of_light, -0.7 * constants.speed_of_light, 0],
    [0, 0, 0], 'Proton', 1.67E-27,
    1)  # 80E4 is top of mesosphere, cosmic ray speed range 0.43c - 0.996c


def Atmosphere(CosmicRay, RunTime):

    time = 0.0
    deltaT = 0.01 * RunTime
    PositionList = [[], [], []]
    VelocityList = [[], [], []]
    AccerlerationList = [[], [], []]
    TimeList = []
    ListofDirections = Direction(CosmicRay.velocity)

    for _ in np.arange(0, RunTime, deltaT):

        TimeList.append(time)
        beta = CosmicRay.beta()
Exemplo n.º 6
0
import numpy as np
import math
import copy
from scipy import constants
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

from Particle import Particle
from Particle import Charticle



proton = Charticle([0,1E3,0], [20000,20000,20000], [0,0,0],'Proton', 1.67E-27, 1E-19)



def Atmosphere(cray, eDensity, runtime):
    #set initial values
    t = 0.0
    deltaT = 0.01*runtime
    beta = cray.beta()
    cray.gamma()
    Ecray = cray.RelativisticKineticEnergy()
    
    

    pos = [[],[],[]]  
    timelist = []
    yvelocitylist = []

    direction = []
import numpy as np
import math
import copy
from scipy import constants
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

from Particle import Particle
from Particle import Charticle

proton = Charticle([0, 0, 0], [1E6, 1E6, 0], [0, 0, 0], 'Proton', 1.67E-27,
                   1E-19)
EField = np.array([0, 0.0001, 0])
BField = np.array([0, 0.0001, 0])


def zoomer(ChargedObject, runtime, deltaT):
    t = 0
    xpos = []
    ypos = []
    zpos = []
    for _ in np.arange(0, runtime, deltaT):

        ChargedObject.acceleration = (
            ChargedObject.charge * EField + ChargedObject.charge *
            (np.cross(ChargedObject.velocity, BField))) / ChargedObject.mass
        ChargedObject.update(deltaT)
        #print('chime = ',t, 'chosition = ',ChargedObject.position, 'chelocity= ',ChargedObject.velocity, 'chacceleration = ',ChargedObject.acceleration)
        t += deltaT
        xpos.append(ChargedObject.position[0])
        ypos.append(ChargedObject.position[1])
Exemplo n.º 8
0
import numpy as np
import math
import copy
from scipy import constants
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

from Particle import Particle
from Particle import Charticle

proton = Charticle([0, 0, 0], [2.996E8, 0, 0], [0, 0, 0], 'Proton', 1.67E-27,
                   1E-19)
print(proton.gamma())
print(proton.RelativisticKineticEnergy())
beta = (np.linalg.norm(proton.velocity) / constants.speed_of_light)
print(beta)
#stopping power equation -  this is energy loss per metre, need to find how to approximate energy loss per time step by working out distance travelled in each time step.
dEbydx = -(
    ((4 * math.pi) / (constants.electron_mass * constants.speed_of_light *
                      constants.speed_of_light)) *
    ((2.5E25 * proton.charge * constants.speed_of_light) / (beta * beta)) *
    ((constants.elementary_charge * constants.elementary_charge) /
     (4 * math.pi * constants.epsilon_0) *
     (constants.elementary_charge * constants.elementary_charge) /
     (4 * math.pi * constants.epsilon_0)) * (math.log(
         (2 * constants.elementary_charge * constants.speed_of_light *
          constants.speed_of_light * beta * beta) /
         (1.29E-17 *
          (1 - beta * beta))) - beta * beta) * np.linalg.norm(proton.velocity))
print(constants.epsilon_0)
print(constants.electron_mass)