def write_snapshot(self,disk,disk_mesh,filename="disk.dat.hdf5",time=0):
        
       
        
        Ngas = self.pos.shape[0]
        f=ws.openfile(filename)
        npart=np.array([Ngas,0,0,0,0,0], dtype="uint32")
        massarr=np.array([0,0,0,0,0,0], dtype="float64")
        header=ws.snapshot_header(npart=npart, nall=npart, massarr=massarr, time=time,
                              boxsize=disk_mesh.BoxSize, double = np.array([1], dtype="int32"))

        
        ws.writeheader(f, header)
        ws.write_block(f, "POS ", 0, self.pos)
        ws.write_block(f, "VEL ", 0, self.vel)
        ws.write_block(f, "MASS", 0, self.dens)
        ws.write_block(f, "U   ", 0, self.utherm)
        ws.write_block(f, "ID  ", 0, self.ids)
        ws.closefile(f)
Exemple #2
0
    def write_snapshot(self,
                       disk,
                       disk_mesh,
                       filename="disk.dat.hdf5",
                       time=0):

        Ngas = self.pos.shape[0]
        f = ws.openfile(filename)
        npart = np.array([Ngas, 0, 0, 0, 0, 0], dtype="uint32")
        massarr = np.array([0, 0, 0, 0, 0, 0], dtype="float64")
        header = ws.snapshot_header(npart=npart,
                                    nall=npart,
                                    massarr=massarr,
                                    time=time,
                                    boxsize=disk_mesh.BoxSize,
                                    double=np.array([1], dtype="int32"))

        ws.writeheader(f, header)
        ws.write_block(f, "POS ", 0, self.pos)
        ws.write_block(f, "VEL ", 0, self.vel)
        ws.write_block(f, "MASS", 0, self.dens)
        ws.write_block(f, "U   ", 0, self.utherm)
        ws.write_block(f, "ID  ", 0, self.ids)
        ws.closefile(f)
  utherm = np.append(utherm,press_background/dens_background/(GAMMA-1))

  UTHERM_BACKGROUND = (press_background/dens_background/(GAMMA-1)).min()
  dens_gas[dens_gas < DENSITY_FLOOR] = DENSITY_FLOOR
  
  N_total = N_gas + N_BACKGROUND
  ids = np.append(ids,np.arange(N_gas+1,N_total+1))

  print "done"
  
  N_gas = N_total

##########################################################
  
print "Writing snapshot..."
f=ws.openfile(ic_filename+".hdf5")

ws.write_block(f, "POS ", 0, np.array([x_gas,y_gas,z_gas]).T)
ws.write_block(f, "VEL ", 0, np.array([vx_gas,vy_gas,vz_gas]).T)
ws.write_block(f, "U   ", 0, utherm)
if (relax_density):
  ws.write_block(f, "MASS", 0, dens_gas)
else:
  ws.write_block(f, "MASS", 0, mass)
ws.write_block(f, "ID  ", 0, ids)

if not (ExternalPotential):
  print "Adding central star..."
  if(add_background):
    ws.write_block(f, "POS ", 4, np.array([BOX_WIDTH * 0.5, BOX_WIDTH * 0.5, BOX_HEIGHT * 0.5]).T)
  else:
accel = 1.0 / radius**2
if (mesh_type == "polar"):
  cellsize = 2.0*np.pi*radius/Ntheta
elif (mesh_type == "rings"):
  cellsize = 2.0*np.pi*inner_rad/N_in

timestep = np.minimum(CourantFac*cellsize/csnd,ErrTolIntAccuracy*np.sqrt(cellsize/accel))
timestep_nbin=np.log10(MaxSizeTimestep/MinSizeTimestep)/np.log10(2.0)
timestep_bins = 2.0**np.linspace(np.log10(MinSizeTimestep)/np.log10(2.0),np.log10(MaxSizeTimestep)/np.log10(2.0),timestep_nbin)
hist=np.histogram(timestep,bins=timestep_bins)
print hist

Ngas = pos.shape[0]
print "shape",pos.shape, vel.shape,dens.shape,ids.shape

f=ws.openfile("disk.dat.hdf5")
npart=np.array([Ngas,0,0,0,0,0], dtype="uint32")
massarr=np.array([0,0,0,0,0,0], dtype="float64")
header=ws.snapshot_header(npart=npart, nall=npart, massarr=massarr,
                          boxsize=BoxX, double = np.array([1], dtype="int32"))

        
ws.writeheader(f, header)
ws.write_block(f, "POS ", 0, pos)
ws.write_block(f, "VEL ", 0, vel)
ws.write_block(f, "MASS", 0, dens)
ws.write_block(f, "U   ", 0, u)
ws.write_block(f, "ID  ", 0, ids)
ws.closefile(f)

R_edge=2.5
#plt.plot(radius,dens,'ro',ms=0.8,mew=0.0)
#plt.plot(radius[np.argsort(radius)],densprofile,color='b',ms=0.8,mew=0.0)
#plt.axis([0,20,0,0.001])

#plt.plot(radius,vphi,'ro',ms=0.8,mew=0.0)
#plt.plot(radius[np.argsort(radius)],np.sqrt(vphiprofilesq),color='b',ms=0.8,mew=0.0)
#plt.axis([0,20,0,1.5])

#plt.show()

#write to disk the "fixed" snapshot
Ngas = pos.shape[0]

filename_fixed = base + "snap_fixed_" + str(num).zfill(3) + ".hdf5"
f = ws.openfile(filename_fixed)
npart = np.array([Ngas, 0, 0, 0, 0, 0], dtype="uint32")
massarr = np.array([0, 0, 0, 0, 0, 0], dtype="float64")
header = ws.snapshot_header(npart=npart,
                            nall=npart,
                            massarr=massarr,
                            time=time,
                            boxsize=BoxX,
                            double=np.array([1], dtype="int32"))

ws.writeheader(f, header)
ws.write_block(f, "POS ", 0, pos)
ws.write_block(f, "VEL ", 0, vel)
ws.write_block(f, "MASS", 0, mass)
ws.write_block(f, "RHO ", 0, dens)
ws.write_block(f, "U   ", 0, u)
#plt.plot(radius,dens,'ro',ms=0.8,mew=0.0)
#plt.plot(radius[np.argsort(radius)],densprofile,color='b',ms=0.8,mew=0.0)
#plt.axis([0,20,0,0.001])

#plt.plot(radius,vphi,'ro',ms=0.8,mew=0.0)
#plt.plot(radius[np.argsort(radius)],np.sqrt(vphiprofilesq),color='b',ms=0.8,mew=0.0)
#plt.axis([0,20,0,1.5])

#plt.show()


#write to disk the "fixed" snapshot 
Ngas = pos.shape[0]

filename_fixed =base+"snap_fixed_"+str(num).zfill(3)+".hdf5"
f=ws.openfile(filename_fixed)
npart=np.array([Ngas,0,0,0,0,0], dtype="uint32")
massarr=np.array([0,0,0,0,0,0], dtype="float64")
header=ws.snapshot_header(npart=npart, nall=npart, massarr=massarr,time=time,
                          boxsize=BoxX, double = np.array([1], dtype="int32"))

        
ws.writeheader(f, header)
ws.write_block(f, "POS ", 0, pos)
ws.write_block(f, "VEL ", 0, vel)
ws.write_block(f, "MASS", 0, mass)
ws.write_block(f, "RHO ", 0, dens)
ws.write_block(f, "U   ", 0, u)
ws.write_block(f, "ID  ", 0, ids)
ws.write_block(f, "VOL ", 0, vol)
ws.closefile(f)