def main(): # Set Defaults iout = 1 npsample = ['128', '128', '64'] # Parse Arguments if len(sys.argv) == 3: npsample = re.split(',', sys.argv[2]) if len(sys.argv) >= 2: iout = int(sys.argv[1]) # Compute Requested Outputs if iout < 0: iouts = range(1, abs(iout) + 1) else: iouts = range(iout, iout + 1) # Define Region of Interest (Box Units) center = 0.5 radius = 0.4 thickness = 0.2 # Sample Points nx = int(npsample[0]) ny = int(npsample[1]) nz = int(npsample[2]) # Generate Sampling Points x, y, z = mkpoints_xyz(center, radius, thickness, nx, ny, nz) # Some Reshaping zz, yy, xx = mkvec(z, y, x) points = np.zeros((xx.shape[0], 3)) for ii in range(xx.shape[0]): points[ii,:] = np.array([xx[ii], yy[ii], zz[ii]]) # Loop Over Outputs for iiout in iouts: # Open Ramses Output output = RamsesOutput(".", iiout) source = output.amr_source(["P"]) # Fetch Ramses Data points_dset = sample_points(source, points) # Allocate Memory for Output Array PXY = np.zeros((nx, ny)) # Integrate Along Z (Simpson's Rule) print "(%s UTC) Integrating..." % strftime("%H:%M:%S", gmtime()) idx_lo = 0 for ix in range(nx): for iy in range(ny): idx_hi = idx_lo + nz PXY[ix,iy] = simps(points_dset["P"][idx_lo:idx_hi], z) idx_lo = idx_hi print "(%s UTC) Done Integrating." % strftime("%H:%M:%S", gmtime()) # Compute Limits, Centre, Rescale ext = np.array([x.min(), x.max(), y.min(), y.max()]) ext = ( ext - 0.5 ) * output.info["boxlen"] # Save 2D Pressure Map np.savez('PXY_%i.npz' % iiout, \ PXY=PXY,\ x=x, y=y, z=z,\ boxlen=output.info["boxlen"],\ ext=ext,\ tout=output.info["time"])
def main(): # Set Defaults iout = 1 npsample = ['128', '128', '64'] # Parse Arguments if len(sys.argv) == 3: npsample = re.split(',', sys.argv[2]) if len(sys.argv) >= 2: iout = int(sys.argv[1]) # Compute Requested Outputs if iout < 0: iouts = range(1, abs(iout) + 1) else: iouts = range(iout, iout + 1) # Define Region of Interest (Box Units) center = 0.5 radius = 0.4 thickness = 0.2 # Sample Points nx = int(npsample[0]) ny = int(npsample[1]) nz = int(npsample[2]) # Generate Sampling Points x, y, z = mkpoints_xyz(center, radius, thickness, nx, ny, nz) # Some Reshaping zz, yy, xx = mkvec(z, y, x) points = np.zeros((xx.shape[0], 3)) for ii in range(xx.shape[0]): points[ii,:] = np.array([xx[ii], yy[ii], zz[ii]]) # Loop Over Outputs for iiout in iouts: # Open Ramses Output output = RamsesOutput(".", iiout) source = output.amr_source(["rho", "vel"]) # Fetch Ramses Data points_dset = sample_points(source, points) # Allocate Memory for Output Array OmegaXY = np.zeros((nx, ny)) # Average Along Z print "(%s UTC) Z-Averaging XY Velocity Field..." % strftime("%H:%M:%S", gmtime()) idx_lo = 0 for ix in range(nx): for iy in range(ny): idx_hi = idx_lo + nz v_x = points_dset["vel"][idx_lo:idx_hi,0] v_y = points_dset["vel"][idx_lo:idx_hi,1] v_xy = np.sqrt(v_x**2. + v_y**2.) rho_tot = np.sum(points_dset["rho"][idx_lo:idx_hi]) weight = points_dset["rho"][idx_lo:idx_hi] / rho_tot v_xy_avg = np.sum(v_xy * weight) / nz r = np.sqrt((x[ix] - 0.5)**2. + (y[iy]-0.5)**2.) * output.info["boxlen"] OmegaXY[ix,iy] = v_xy_avg / r idx_lo = idx_hi print "(%s UTC) Done Averaging." % strftime("%H:%M:%S", gmtime()) # Compute Limits, Centre, Rescale ext = np.array([x.min(), x.max(), y.min(), y.max()]) ext = ( ext - 0.5 ) * output.info["boxlen"] # Save Z-Averaged Planar Angular Velocity Map np.savez('OmegaXY_%i.npz' % iiout, \ OmegaXY=OmegaXY,\ x=x, y=y, z=z,\ boxlen=output.info["boxlen"],\ ext=ext,\ tout=output.info["time"])