Ejemplo n.º 1
0
 def plottraj(self):
 	print("Plotting 2D trajectory...")
 	n = 0
     trajectory = np.ndarray((self.nsteps,3))
     for fname in self.fname_list:
         wholedata = fits.open(fname)
         for i in xrange(1,len(wholedata)):
             data = wholedata[i].data
             trajectory[n,0] = data['X']
             trajectory[n,1] = data['Y']
             trajectory[n,2] = data['Z']
             n += 1
     #fig = 
     plt.figure()
     #ax = fig.add_subplot(111,projection='3d')
     plt.scatter(trajectory[:,0],trajectory[:,1])#,trajectory[:,2])
     plt.scatter(0,0,marker='x',color='black')
     circle1 = plt.Circle((0,0), radius = 2, color = 'r', fill = False)
     fig = plt.gcf()
     fig.gca().add_artist(circle1)
     fig.gca().axes.get_xaxis().set_visible(False)
     fig.gca().axes.get_yaxis().set_visible(False)
     plt.xlim(-10,10)
     plt.ylim(-10,10)
     plt.axes().set_aspect('equal')
     plt.show()
Ejemplo n.º 2
0
 def plot_n(self):
     ns = np.ndarray(len(self.nsteps))
     i=0
     for fname in self.fname_list:
         data = fits.open(fname)
         ns[i] = len(data[1].data)-1
         i+=1
     ns = ns/self.init_particles
     plt.plot(ns)
     plt.set_xlabel('Timestep')
     plt.set_ylabel('\r$n_step/N$')
Ejemplo n.º 3
0
    def plot_rd(self):

    	r_arr = np.ndarray(self.nsteps)
    	rd_arr = np.ndarray(self.nsteps)
    	n=1
    	for fname in self.fname_list:
    		wholedata = fits.open(fname)
    		for i in xrange(1,len(wholedata)):
    			data = wholedata[i].data
    			r = np.mean(np.sqrt(data['X']**2+data['Y']**2))
    			r_arr[n] = r
    			rd = (1/r)*(data['X']*data['Xd']+data['Y']*data['Yd'])
    			rd_arr[n] = np.mean(rd)
    			n+=1
    		print(fname)
    	r_arr = r_arr/r_arr[0]
    	plt.plot(r_arr,linewidth=2,color='black')
    	plt.xlabel(r'Timestep')
    	plt.ylabel(r'$\frac{<r>}{<r_0>}$',fontsize=16)
    	plt.show()
    	plt.plot(rd_arr,linewidth=2,color='black')
    	plt.xlabel(r'Timestep')
    	plt.ylabel(r'$<\dot{r}>$',fontsize=16)
    	plt.show()
Ejemplo n.º 4
0
 def plottraj3d(self):
     from mpl_toolkits.mplot3d import Axes3D
     print("Plotting 3D trajectory...")
     n = 0
     trajectory = np.ndarray((self.nsteps,3))
     for fname in self.fname_list:
         wholedata = fits.open(fname)
         for i in xrange(1,len(wholedata)):
             data = wholedata[i].data
             trajectory[n,0] = data['X']
             trajectory[n,1] = data['Y']
             trajectory[n,2] = data['Z']
             n += 1
     fig = plt.figure()
     ax = fig.add_subplot(111,projection='3d')
     plt.xlim(-8,8)
     plt.ylim(-8,8)
     plt.scatter(trajectory[:,0],trajectory[:,1],trajectory[:,2])
     plt.show()
Ejemplo n.º 5
0
 def UpdateStateVectorRK4(self,t):
     self.event_horizon = self.get_event_horizon(t)
     new_state = np.ndarray((self.Nparticles,2,2))
     
     for particle in xrange(self.Nparticles):
         kstate = np.copy(self.state)
         #do RK4 shit
         k1 = self.dt * self.SingleParticleDerivativeVector(kstate,particle, t+self.dt)
         kstate[particle] = np.copy(self.state[particle]) + k1/2
         k2 = self.dt * self.SingleParticleDerivativeVector(kstate,particle,t+(self.dt/2))
         kstate[particle] = np.copy(self.state[particle]) + k2/2
         k3 = self.dt * self.SingleParticleDerivativeVector(kstate,particle,t+(self.dt/2))
         kstate[particle] = np.copy(self.state[particle]) + k3
         k4 = self.dt * self.SingleParticleDerivativeVector(kstate,particle,t+self.dt)
         new_state[particle] = np.copy(self.state[particle]) + (1/3)*(k1/2 + k2 + k3 + k4/2)
         
     
     #Get rid of gobbled or ejected particles 
     if self.cleanup != []:
         for particle in self.cleanup:
             print("\n***particle {} shit the bed at step {}***".format(particle,int(t/self.dt)))
             self.remove_particle(particle)
             new_state = np.delete(new_state,particle,axis=0)
             print("***particle {} removed***".format(particle))
             self.cleanup.remove(particle)
             if self.cleanup == []:
                 print("***cleanup completed***")
     self.cleanup = []
     
     #Cleanup collided particles
     if self.collisions != {}:
         print("*****")
         for key in self.collisions:
             p1 = self.collisions[key][1][0]
             p2 = self.collisions[key][1][1]
             new_particle = self.combine_particles()
             print("***{} and {} collided at step{}***".format(p1,p2,int(t/self.dt)))
             new_state = np.delete(new_state,[self.collisions[key][0],self.collisions[1]],axis=0)
             new_state = np.append(new_state,new_particle,axis = 0)
         self.collisions = {}
     return(new_state)
Ejemplo n.º 6
0
    def UpdateStateVectorRK4(self,t):
        self.event_horizon = self.get_event_horizon(t)
        new_state = np.ndarray((self.Nparticles,2,3))
        
        for particle in xrange(self.Nparticles):

            kstate = np.copy(self.state)

            k1 = self.dt * self.SingleParticleDerivativeVector(kstate,particle, t)
            kstate[particle] = np.copy(self.state[particle]) + k1/2
            k2 = self.dt * self.SingleParticleDerivativeVector(kstate,particle,t+(self.dt/2))
            kstate[particle] = np.copy(self.state[particle]) + k2/2
            k3 = self.dt * self.SingleParticleDerivativeVector(kstate,particle,t+(self.dt/2))
            kstate[particle] = np.copy(self.state[particle]) + k3
            k4 = self.dt * self.SingleParticleDerivativeVector(kstate,particle,t+self.dt)
            new_state[particle] = np.copy(self.state[particle]) + (1/3)*(k1/2 + k2 + k3 + k4/2)
            
        
        #Get rid of gobbled or ejected particles 
        if self.cleanup != []:
            new_state = np.delete(new_state,self.cleanup,axis=0)
            self.remove_particle(particle)
            for particle in self.cleanup:
                print("\n***particle {} shit the bed at step {}***".format(particle,int(t/self.dt)))
                print("***particle {} removed***".format(particle))
                self.cleanup.remove(particle)
                if self.cleanup == []:
                	print("***cleanup completed***")
        self.cleanup = []
        
        
        big_particle_list = []
        big_vector_list = []
        new_masses_list = []
        
        

        #Cleanup collided particles
        if self.collisions == "inelastic":
            if self.collision_dict != {}:       
                for key in self.collision_dict:
                	particles = self.collision_dict[key][1]
                	m = 0
                	x = self.collision_dict[key][0][0]
                	y = self.collision_dict[key][0][1]
                	mvx = 0
                	mvy = 0
                	for particle in particles:
                	    m += self.masses[particle]
                	for particle in particles:
                	    mvx += (self.state[particle][1][0]*self.masses[particle])
                	    mvy += (self.state[particle][1][1]*self.masses[particle])
                	    big_particle_list.append(particle)
                	new_masses_list.append(m)
                new_particle = [[x,y],[mvx/m,mvy/m]]
                big_vector_list.append(new_particle)

                self.masses = np.delete(self.masses,big_particle_list,axis=0)
                self.masses = np.append(self.masses,np.array(new_masses_list),axis = 0)
                new_state = np.delete(new_state,big_particle_list,axis=0)
                new_state = np.append(new_state,np.array(big_vector_list),axis = 0)
                self.Nparticles = len(new_state)
                self.collision_dict = {}
                self.collided_particles = np.array([])
        
        elif self.collisions == 'elastic':
            
            distances = squareform(pdist(self.state[:,0,:]))
            ind1, ind2 = np.where(distances < 2 * self.collision_radius)
            unique = (ind1 < ind2)
            ind1 = ind1[unique]
            ind2 = ind2[unique]
            new_collisions = zip(ind1,ind2)
            for i in new_collisions:
            	if i not in self.old_collisions:
            		i1 = i[0]
            		i2 = i[1]
            		
                	m1 = self.masses[i1]
                	m2 = self.masses[i2]
                	
                	x1 = new_state[i1,0,0]
                	y1 = new_state[i1,0,1]
                	z1 = new_state[i2,0,3]
                	x2 = new_state[i2,0,0]
                	y2 = new_state[i2,0,1]
                	z2 = new_state[i2,0,2]
                	
                	x1d = new_state[i1,1,0]
                	y1d = new_state[i1,1,1]
                	z1d = new_state[i1,1,2]
                	x2d = new_state[i2,1,0]
                	y2d = new_state[i2,1,1]
                	z2d = new_state[i2,1,2]
                	
                	new_state[i1, 1] = [(x1d*(m1-m2) + 2*m2*x2d)/(m1+m2),
                	                    (y1d*(m1-m2) + 2*m2*y2d)/(m1+m2),
                	                    (z1d*(m1-m2) + 2*m2*z2d)/(m1+m2)]
                	new_state[i2, 1] = [(x2d*(m2-m1) + 2*m1*x1d)/(m1+m2),
                	                    (y2d*(m2-m1) + 2*m1*y1d)/(m1+m2),
                	                    (z2d*(m2-m1) + 2*m1*z1d)/(m1+m2)]
            self.old_collisions = new_collisions
        return(new_state)