Example #1
0
def createParticle(x = None, y = None, size = None, density = None):
    if size == None:
        size = random.randint(particleSize[0], particleSize[1])
    if density == None:
        density = random.randint(1, 20)
    if x == None or y == None:
        x = random.randint(size, width-size)
        y = random.randint(size, height-size)
    particle = Particle((x, y), size, density, mass_of_air)
    particle.speed = random.random()
    particle.angle = random.uniform(0, math.pi*2)

    my_particles.append(particle)
Example #2
0
 def fastFunc(compactDict):
     particle = Particle()
     for key, val in compactDict.items():
         setattr(particle, key, val)
     particle = trace_Particle(particle)
     compactDictTraced = {}
     for key, val in vars(particle).items():
         if val is not None:
             compactDictTraced[key] = val
     return compactDictTraced
 def errorFunc(outputOffsetFact):
     h=5e-6
     PTL_Ring.elList[1].update_rOffset_Fact(outputOffsetFact)
     PTL_Ring.build_Lattice()
     particle=Particle()
     particleTracer=ParticleTracer(PTL_Ring)
     particle=particleTracer.trace(particle,h,1.0,fastMode=False)
     qoArr=particle.qoArr
     particleAngEl=np.arctan2(qoArr[-1][1],qoArr[-1][0]) #very close to zero, or negative, if particle made it to
     #end
     if particleAngEl<.01:
         error=np.std(1e6*particle.qoArr[:,1])
         return error
     else: return np.nan
Example #4
0
    def trace(self,particle,h,T0,fastMode=False,accelerated=False,energyCorrection=False,stepsBetweenLogging=1,
              tau_Collision=None):
        #trace the particle through the lattice. This is done in lab coordinates. Elements affect a particle by having
        #the particle's position transformed into the element frame and then the force is transformed out. This is obviously
        # not very efficient.
        #qi: initial position coordinates
        #vi: initial velocity coordinates
        #h: timestep
        #T0: total tracing time
        #fastMode: wether to use the performance optimized versoin that doesn't track paramters
        assert 0<h<1e-4 and T0>0.0# reasonable ranges
        if tau_Collision is not None and tau_Collision<=0.0:
            raise Exception('Collision time must be None or nonzero positive number')
        self.tau_Collision=tau_Collision if tau_Collision is not None else np.inf
        self.energyCorrection=energyCorrection
        self.stepsBetweenLogging=stepsBetweenLogging
        if particle is None:
            particle=Particle()
        if particle.traced==True:
            raise Exception('Particle has previously been traced. Tracing a second time is not supported')
        self.particle = particle
        if self.particle.clipped==True: #some particles may come in clipped so ignore them
            self.particle.finished(self.currentEl,self.qEl,self.pEl,totalLatticeLength=0)
            return self.particle
        self.fastMode=fastMode
        self.h=h
        self.T0=float(T0)
        self.initialize()
        self.accelerated=accelerated
        if self.particle.clipped==True: #some a particles may be clipped after initializing them because they were about
            # to become clipped
            self.particle.finished(self.currentEl,self.qEl,self.pEl,totalLatticeLength=0)
            return particle
        self.time_Step_Loop()
        self.forceLast=None #reset last force to zero
        self.particle._q = self.currentEl.transform_Element_Coords_Into_Lab_Frame(self.qEl)
        self.particle.p = self.currentEl.transform_Element_Frame_Vector_Into_Lab_Frame(self.pEl)
        self.particle.currentEl=self.currentEl

        self.particle.finished(self.currentEl,self.qEl,self.pEl,totalLatticeLength=self.totalLatticeLength)
        return self.particle
#Librerias importadas
import matplotlib.pyplot as plt
import numpy as np
#Clase importada
from ParticleClass import Particle as Particle

P1 = Particle(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.00,
              1.0)  #Particula1 (x,y,z,vx,vy,vz,m,carga)
P2 = Particle(1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.00,
              -1.0)  #Particula2 (x,y,z,vx,vy,vz,m,carga)

i = 0
x1 = []
y1 = []
z1 = []
vx1 = []
vy1 = []
x2 = []
y2 = []
z2 = []
vx2 = []
vy2 = []

k = 9e9  #Constante de Coulomb (N*m**2/C**2)
Bz = 10.0  #Valor del campo magnetico constante en direccion z

while (i < 10000):
    x1.append(P1.X)
    y1.append(P1.Y)
    z1.append(P1.Z)
    vx1.append(P1.VX)
Example #6
0
# Andrés Santiago Duque Escobar
#


from ParticleClass import Particle, Vector, LorentzForce
from matplotlib.pyplot import plot, show


x1 = []
y1 = []
x2 = []
y2 = []
t = []

#Partículas
p1 = Particle(0.,0.,0.,0.,0.,0.,10.,0.001)
p2 = Particle(1.,0.,0.,0.,0.,0.,10.,-0.001)

#Campo magnético
B = Vector(0.,0.,10.)

x1.append(p1.X)
y1.append(p1.Y)
x2.append(p2.X)
y2.append(p2.Y)
t.append(0.)
step = 0.0001
for i in range(263):
    #Campo electrico    
    E1 = p2.Electric_Field(p1.Pos) #Sobre p1 debido a p2
    E2 = p1.Electric_Field(p2.Pos) #Sobre p2 debido a p1
import matplotlib.pyplot as plt
from ParticleClass import Particle as Particle

P2 = Particle(0.0, 0.0, 0.0, 1.00, 0.0, 0.0, 10.00, 1.0)

i = 0
x = []
y = []
z = []
vx = []
vy = []
Bz = 10.000

while i < 100000:
    x.append(P2.X)
    y.append(P2.Y)
    z.append(P2.Z)
    vx.append(P2.VX)
    vy.append(P2.VY)
    fx = P2.Carga * P2.VY * Bz
    fy = -1.0 * P2.Carga * P2.VX * Bz
    P2.time_evol(fx, fy, 0.0, 0.0001)
    P2.time_slice_print()
    i += 1

plt.plot(x, y)
plt.show()
Example #8
0
def main():

    # grid is 20x20 - positions range from (0,0) to (20,20)
    # 1 unit away - repulse 4 unit/sec
    # 2 unit away - keep going, no change
    # 3 unit away - attract slightly - 1unit/sec
    # 4-7 unit away - continue, no change

    # jerry_pos = input("Please enter a position: ") # prompt input for positions and velocities
    # they must be placed on the 20 x 20 grid and not occupy the same position

    ben = Particle(0, 0, 1,
                   1)  # sets ben's position at [0, 0] and velocity at [1, 1]
    jerry = Particle(1, 1, 0, 0)

    old_x_dist = x_dist(ben, jerry)
    old_y_dist = y_dist(ben, jerry)
    old_jerryPos = jerry.getPos()
    old_jerryVel = jerry.getVel()
    old_benPos = ben.getPos()
    old_benVel = ben.getVel()

    for i in range(1, numberOfRuns):
        print("run {}".format(i))
        update(ben, jerry)

    print("x distance {0} to {1}".format(old_x_dist, x_dist(ben, jerry)))
    print("y distance {0} to {1}".format(old_y_dist, y_dist(ben, jerry)))
    print("jerry pos {0} to {1}".format(old_jerryPos, jerry.getPos()))
    print("jerry vel {0} to {1}".format(old_jerryVel, jerry.getVel()))
    print("ben pos {0} to {1}".format(old_benPos, ben.getPos()))
    print("ben vel {0} to {1}".format(old_benVel, jerry.getVel()))
Example #9
0
import matplotlib.pyplot as plt
import numpy as np
from ParticleClass import Particle as Particle

P1 = Particle(0, 0, 0, 0, 0, 0, 10, 1.)
P2 = Particle(1, 0, 0, 0, 0, 0, 10, -1)

e0 = 8.85e-12
k = 1 / (4 * np.pi * e0)
i = 0
x1 = []
y1 = []
z1 = []
x2 = []
y2 = []
z2 = []
vx1 = []
vy1 = []
vx2 = []
vy2 = []

Bz = 10.000

while i < 10000:

    x1.append(P1.X)
    y1.append(P1.Y)
    z1.append(P1.Z)
    vx1.append(P1.VX)
    vy1.append(P1.VY)