Exemple #1
0
 def SingleParticleNewtonianForce(self, i, soi_radius, collision_radius):
     
     forces = np.zeros([self.Nparticles,2])
 
     if self.collisions == {}:
         keynum = 0
     else:
         keynum = max(self.collisions)
 
     x1 = self.state[i,0,0]
     y1 = self.state[i,0,1]
     newkey = (x1,y1)
     m1 = self.masses[i]
     for particle_num in xrange(self.Nparticles):
         if particle_num != i:
             m2 = self.masses[particle_num]
             x2 = self.state[particle_num,0,0]
             y2 = self.state[particle_num,0,1]
             distance2 = ((x2-x1)**2+(y2-y1)**2)
             if distance2 < soi_radius:
                 jforce = m2/distance2
                 jforcedir = [x2-x1,y2-y1]/np.sqrt(distance2)
                 forces[particle_num] = jforce*jforcedir
             if distance2 < collision_radius:
                 for key in self.collisions:
                     if i not in self.collisions[key][1] or particle_num not in self.collisions[key][1]:
                         self.collisions[keynum] = [(x1,y1),[i,particle_num]]
         
     return(np.sum(forces,axis=0))
Exemple #2
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()
Exemple #3
0
 def get_event_horizon(self,t):
     return(self.M + np.sqrt(self.M**2 - self.a(t)**2))
Exemple #4
0
    def SingleParticleNewtonianForce(self, i, soi_radius, collision_radius):        
        forces = np.zeros([self.Nparticles,2])
        
        x1 = self.state[i,0,0]
        y1 = self.state[i,0,1]
        
        m1 = self.masses[i]
        collided1 = 0
        
        if self.interaction=='ClassicalNBody':

            xmin = x1-soi_radius
            xmax = x1+soi_radius
            ymin = y1-soi_radius
            ymax = y1+soi_radius
            sliced_indices_x = np.where(np.logical_and(self.state[:,0,0]>xmin,self.state[:,0,0]<xmax))
            sliced_indices_y = np.where(np.logical_and(self.state[:,0,1]>ymin,self.state[:,0,1]<ymax))
            sliced_indices = np.intersect1d(sliced_indices_x,sliced_indices_y)
            sliced_arr = self.state[sliced_indices]
        
            no_i_indices = np.where(np.logical_and(sliced_arr[:,0,0] == x1,sliced_arr[:,0,1]==y1))
            sliced_arr = np.delete(sliced_arr,no_i_indices,axis=0)
            sliced_masses = self.masses[sliced_indices]
            sliced_masses = np.delete(sliced_masses,no_i_indices,axis=0)
            
            distances2 = np.array(np.transpose(np.matrix((sliced_arr[:,0,0]-x1)**2+(sliced_arr[:,0,1]-y1)**2)))
        
            jforce = np.array(np.transpose(np.matrix(sliced_masses)))/distances2
            jforcedir = np.array(np.transpose(np.matrix([sliced_arr[:,0,0]-x1,sliced_arr[:,0,1]-y1])))/np.sqrt(distances2)
            forces = jforce*jforcedir
        

            for particle_num in xrange(self.Nparticles):
                if particle_num != i:
                	collided2 = 0
                	m2 = self.masses[particle_num]
                	x2 = self.state[particle_num,0,0]
                	y2 = self.state[particle_num,0,1]
                	distance2 = ((x2-x1)**2+(y2-y1)**2)
                	
                	"""
                	if the collision dict is empty, put in the two particles being evaluated.
                
                	if it's not empty, first search to see if the main particle is in there
                	if the main particle is in there, move on to the secondary
                	if the secondary particle is not in there, put it in the entry with the main particle
                	"""
                	if self.Nparticles == 2:
                	    if distance2>500000:
                	        print('\n',distance2)
                	        print(self.state)
                	        raise ValueError("it f****d the duck")
                	elif self.Nparticles == 1:
                	    raise ValueError("it shit the bed")
                	
                	if self.collisions != False and i not in self.cleanup and particle_num not in self.cleanup:
                	    if distance2 < collision_radius:
                	        if self.collision_dict == {}:
                	            self.collision_dict[0] = [(x1,y1),[i,particle_num]]
                	        else:
                	            i_val = farts.dict_check(self.collision_dict, i)
                	            keynum = max(self.collision_dict)+1
                	            if i_val == -1:
                	                self.collision_dict[keynum] = [(x1,y1),[i]]
                	                i_val = keynum
                	            elif farts.dict_check(self.collision_dict, particle_num) == -1:
                	                self.collision_dict[i_val][1].append(particle_num)

            return(np.sum(forces,axis=0))