Esempio n. 1
0
 def SingleParticleDerivativeVector(self,kstate,particle,t):
     if self.interaction_type == "ClassicalNBody":
         rad = farts.xy2rad(kstate[particle],
                            self.SingleParticleNewtonianForce(particle,
                                                              2,
                                                              2))
                                                               
                                                               
     elif self.interaction_type == None:
         rad = farts.xy2rad(self.state[particle],(0,0))
         
     elif self.interaction_type == "ClassicalElastic":
         raise ValueError("ClassicalElastic collisions not implemented yet")
     
     
     r = rad[0,0]   
     phi = rad[0,1]
     
     if(r > 999 or r < self.event_horizon):
             if particle not in self.cleanup:
                 self.cleanup.append(particle)        
     
     f = np.array(([rad[0,0],rad[1,0]],[rad[0,1],rad[1,1]]))
     G=np.array([[f[0,1],
                  -(1/f[0,0]**4)*(self.a(t)**2-2*self.M*f[0,0]+(f[0,0]**2))*((self.M*(f[0,0]**4)*f[0,1]**2)/(self.a(t)**2-2*self.M*f[0,0]+(f[0,0]**2))**2-((f[0,0]**5)*(f[0,1]**2))/((self.a(t)**2)-2*self.M*f[0,0]+(f[0,0]**2))**2+self.M*(-1+self.a(t)*f[1,1])**2+(f[0,0]**3)*((f[0,1]**2)/((self.a(t)**2)-2*self.M*f[0,0]+(f[0,0]**2))-(f[1,1]**2)))+rad[2,0]],
                  [f[1,1],
                  -((2*f[0,1]*(self.a(t)*self.M+(-(self.a(t)**2)*self.M+f[0,0]**3)*f[1,1]))/(f[0,0]*(2*(self.a(t)**2)*self.M+(self.a(t)**2)*f[0,0]+(f[0,0]**3))))+rad[2,1]]])
     
     return(farts.G2xy(G,r,phi))
Esempio n. 2
0
    def SingleParticleDerivativeVector(self, kstate, particle, t):
        #print("\n\n\nInput XY state: ", self.state)
        if self.interaction == False:
            rad = farts.xy2rad(kstate[particle],(0,0))
        elif self.interaction == 'ClassicalNBody':
        	rad = farts.xy2rad(kstate[particle],
                	           self.SingleParticleNewtonianForce(particle, 100, self.cr))
        elif self.interation == True:
        	raise ValueError('Ambiguous interaction specification')

        r = rad[0,0]
        phi = rad[0,1]
        if(r > 999 or r < self.event_horizon-0.2):
            if particle not in self.cleanup:
                self.cleanup.append(particle)
        f = np.array(([rad[0,0],rad[1,0]],
                      [rad[0,1],rad[1,1]]))
       
        #print("\nInput RP state: ", f)
        # The Kerr metric
        G=np.array([[f[0,1],
                    (-(self.M*pow(pow(self.a(t),2) - 2*self.M*f[0,0] + pow(f[0,0],2),2)) + self.a(t)*self.M*pow(pow(self.a(t),2) - 2*self.M*f[0,0] + pow(f[0,0],2),2)*f[1,1] + pow(pow(self.a(t),2) - 2*self.M*f[0,0] + pow(f[0,0],2),2)*f[1,1]*(self.a(t)*self.M + (-(pow(self.a(t),2)*self.M) + pow(f[0,0],3))*f[1,1]) + pow(f[0,0],3)*(-pow(self.a(t),2) + self.M*f[0,0])*pow(f[0,1],2))/(pow(f[0,0],4)*(pow(self.a(t),2) - 2*self.M*f[0,0] + pow(f[0,0],2)))],
                   [f[1,1],
                   (2*(-(self.a(t)*self.M) + (pow(self.a(t),2)*self.M + 2*self.M*pow(f[0,0],2) - pow(f[0,0],3))*f[1,1])*f[0,1])/(pow(f[0,0],2)*(pow(self.a(t),2) - 2*self.M*f[0,0] + pow(f[0,0],2)))]])
        #print("\nRTP G: ",G)
        #G = np.array([[f[0,1],rad[2,0]],
        #              [f[1,1],rad[2,1]]])
        xyG = farts.G2xy(G,r,phi)
        #print("\nXY G: ",xyG)
        return(xyG)
Esempio n. 3
0
 def TimeEvolve(self,nsteps,comments):
     self.cleanup = []
     t=0
     
     ##Get init_state
     if self.use_state == None:
         self.state = np.copy(self.MakeInitialConditions())
         self.init_state = np.copy(self.state)
         self.Nparticles = len(self.state)
     else:
         self.state = np.copy(self.use_state)
     print("Got initial conditions for {} particles".format(self.start_particles))
     
     primary = self.get_header(nsteps,comments)
     frame0 = self.get_hdu()
     
     hdulist = fits.HDUList([primary,frame0])
     total_time = 0
     for step in xrange(1, nsteps):
         stepstart = time.time()
         self.state = self.UpdateStateVectorRK4(t)
         framen = self.get_hdu()
         hdulist.append(framen)
         t += self.dt
         end = time.time()
         steptime = end-stepstart
         total_time += steptime
         avg = total_time/step
         perc = 100*((step+1)/nsteps)
         sys.stdout.write('\rFrame {} of {} completed ({}%).  Step: {}s, Total: {}s, Estimated time remaining: {}s. Nparticles: {}'.format(step+1,
                                                                    nsteps,
                                                                    '%0.1f'%perc,
                                                                    '%0.4f'%steptime,
                                                                    '%0.4f'%total_time,
                                                                    '%i'%(((avg * nsteps)+1)-total_time),
                                                                    '%i'%self.Nparticles))
         sys.stdout.flush()
     print("\nWriting to disk...")
     filenum = farts.get_filenum(self.save_dir)
     self.fname = "{}/nbody_{}_{}.fits".format(self.save_dir,self.start_particles,filenum)
     hdulist.writeto(self.fname,clobber=True)
     print("Data written at {}".format(self.fname))
Esempio n. 4
0
 def TimeEvolve(self,nsteps,comments,write=True):
     self.cleanup = []
     self.nsteps = nsteps
     print("new eom")
     t=0
     
     ##Get init_state
     if self.use_state == None:
         self.cleanup = []
         self.state = np.copy(farts.make_initial_conditions2(self.start_particles,
                                                             self.M,
                                                             self.a(0)))
         self.init_state = np.copy(self.state)
         self.Nparticles = len(self.state)
     else:
         self.state = np.copy(self.init_state)
     print("Got initial conditions for {} particles".format(self.start_particles))
     
     primary = self.get_header(nsteps,comments)
     frame0 = self.get_hdu()
     
     filenum = farts.get_filenum(self.save_dir,self.start_particles)
     self.dirname = "{}/nbody_{}_{}".format(self.save_dir,self.start_particles,filenum)
     os.mkdir(self.dirname)
     os.mkdir("{}/data".format(self.dirname))
     hdulist = fits.HDUList([primary,frame0])
     total_time = 0
     savenums = nsteps/1000
         
     for step in xrange(1, nsteps):
         stepstart = time.time()
         self.state = self.UpdateStateVectorRK4(t)
         framen = self.get_hdu()
         hdulist.append(framen)
         t += self.dt
         end = time.time()
         steptime = end-stepstart
         total_time += steptime
         avg = total_time/step
         perc = 100*((step+1)/nsteps)
         sys.stdout.write('\rFrame {} of {} completed ({}%).  Step: {}s, Total: {}s, Estimated time remaining: {}s. Nparticles: {}'.format(step+1,
             	                	                	           nsteps,
             	                	                	           '%0.1f'%perc,
             	                	                	           '%0.4f'%steptime,
             	                	                	           '%0.4f'%total_time,
             	                	                	           '%i'%(((avg * nsteps)+1)-total_time),
             	                	                	           '%i'%self.Nparticles))
         sys.stdout.flush()
         if step%1000 == 0:
         
             if write == True:
             	print("\nWriting to disk...")
             	fname = "{}/data/{}.fits".format(self.dirname,step)
             	hdulist.writeto(fname,clobber=True)
             	print("Frames {} - {} written at {}".format(step-1000,step,fname))
             	hdulist = fits.HDUList([primary])
             	self.fname_list.append(fname)
         
     if len(hdulist)!=1:
         print("\nWriting to disk...")
         fname = "{}/data/{}.fits".format(self.dirname,step)
         hdulist.writeto(fname,clobber=True)
         print("Frames {} written at {}".format(step+1,fname))
         self.fname_list.append(fname)
     print(self.state)          	    
Esempio n. 5
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))
Esempio n. 6
0
import nbody_kerr as oinks
import ThesisTools as farts
import multiprocessing as mp

nparticles = 15500

init_vecs = farts.make_initial_conditions(nparticles)

def a1(t):
    if t < 15000:
        return 0
    else:
        return .99

a_list = [None,a1]

def a_chooser(inter):
    sim = oinks.OrbitalSystem(nparticles,3,init_state = init_vecs,a=inter,save_dir = "/Volumes/DRIVEYWIVEY/thesis/output")
    sim.TimeEvolve(40000, comments = "")
    sim.movie()
    

def mp_write():
    num_proc = 2
    pool = mp.Pool(num_proc)
    pool.map(a_chooser,a_list)