예제 #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))
예제 #2
0
 def MakeInitialConditions(self):
     self.cleanup = []
     vecs = np.zeros((self.start_particles,2,2))
     for vec in xrange(self.start_particles):
         r = ((12-5)*np.random.random())+5
         phi = 2*np.pi*np.random.random()
         phid = ((0.1-0.001)*np.random.random())+0.001
         vecs[vec] = [[r*np.cos(phi), r*np.sin(phi)],
                      [-r*np.sin(phi)*phid, r*np.cos(phi)*phid]]
     return(vecs)
예제 #3
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]
        z1 = self.state[i,0,2]
        
        m1 = self.masses[i]
        collided1 = 0
        """
        2D shit
        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
                	""""""
예제 #4
0
 def __init__(self,
              Nparticles,
              M,
              a = farts.a0,
              dt=0.01,
              interaction = "ClassicalNBody",
              masses = None,
              init_state = None,
              save_dir = "/Users/alexdeich/Dropbox/thesis/code/mine/nbody_output"):
     
     self.start_particles = Nparticles
     self.Nparticles = Nparticles
     self.interaction_type = interaction
     self.M = M
     self.dt = dt
     self.a = a
     self.event_horizon = 0
     self.cleanup = []
     if init_state is not None:
         self.use_state = np.copy(init_state)
     else:
         self.use_state = None
     self.save_dir = save_dir
     self.init_state = np.copy(init_state)
     self.state = np.copy(init_state)
     self.collisions = {}
     self.fname = ""
     
     if init_state is not None:
         if init_state.shape == (Nparticles,2,2):
             self.init_state = use_state
         else:
             raise ValueError("Initial state not the right shape: ",init_state.shape,
                              "\nShould be ",(Nparticles,2,2))
 
     if masses == None:
         self.masses = np.zeros(Nparticles)+0.0001
     else:
         if len(masses) == Nparticles:
             self.masses = masses
         else:
             raise ValueError("Mass list must be of length ", Nparticles,
                              "\nGiven length:", len(masses))
예제 #5
0
    def __init__(self,
                 Nparticles,
                 M=1,
                 a = None,
                 dt=0.01,
                 interaction = False,
                 collisions = 'elastic',
                 masses = None,
                 init_state = None,
                 cr = 0.001,
                 save_dir = "./output"):
        
        self.start_particles = Nparticles
        self.Nparticles = Nparticles
        self.interaction = interaction
        self.M = M
        self.dt = dt
        self.a = a
        self.cr = cr
        self.event_horizon = 0
        self.cleanup = []
        if init_state is not None:
            self.use_state = np.copy(init_state)
        else:
            self.use_state = None
        self.save_dir = save_dir
        self.init_state = np.copy(init_state)
        self.state = np.copy(init_state)
        self.collision_dict = {}
        self.collisions=collisions
        self.collided_particles = np.array([])
        self.fname_list = []
        self.dirname = ""
        self.plotdata = 0
        self.skip_mkdir=False
        self.nsteps = 0
        
        self.old_collisions = []

        if self.Nparticles == None and self.init_state is not None:
            self.Nparticles = len(self.init_state)
            
        if self.a == None:
            self.a = farts.a0
        
        if init_state is not None:
            if init_state.shape == (Nparticles,2,3):
                self.init_state = init_state
            else:
                raise ValueError("Initial state not the right shape: ",init_state.shape,
                	             "\nShould be ",(Nparticles,2,3))
    
        if masses == None:
            self.masses = np.zeros(Nparticles)+0.0001
        else:
            if len(masses) == Nparticles:
                self.masses = masses
            else:
                raise ValueError("Mass list must be of length ", Nparticles,
                	             "\nGiven length:", len(masses))
    
        self.collision_radius = .05
예제 #6
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))