Exemplo n.º 1
0
def draw(name,zshift_tol = 0.25, path = None):
    # Set the work_dir
    if path == None:
        work_dir = os.getcwd()
    if path != None:
        work_dir = os.chdir(path)
        work_dir = os.getcwd()

    grid_file = visual.get("BOUT.inp","grid") # Import grid file

    eigs = collect("t_array") # Import Eigen values
    var = collect(name) # Import variable
    nx,ny,nz = visual.dimd(name) # Set the shape of the variable
    #Import the R,Z values from the grid file
    r = visual.nc_var(grid_file,'Rxy') # R
    z = visual.nc_var(grid_file,'Zxy') # Z
    zshift = visual.nc_var(grid_file, 'zShift') # zShift
    
    z_tol = visual.z_shift_tol(nx,ny,zshift,zshift_tol) # set the z_tolerance value
    
    #Interpolate r, z, zshift values

    r2, ny2 = visual.zshift_interp2d(nx,ny,zshift,z_tol,r)
    z2, ny2 = visual.zshift_interp2d(nx,ny,zshift,z_tol,z)
    zshift2, ny2 = visual.zshift_interp2d(nx,ny,zshift,z_tol,zshift)
    
    pts2 = visual.elm(r2,z2,zshift2,nx,ny2,nz) # Write the vtk points
    
    # Plot eigen values and write the associated vtk file
    plot_eigenvals(eigs, nx, ny, nz ,zshift, z_tol, ny2, name, pts2, var)
Exemplo n.º 2
0
def elm(name ,time ,zShf_int_p = 0.25, path = None):
    #Add error for zShf_int_p > 1

    #Get the working dir
    if path == None:
        work_dir = os.getcwd()
    if path != None:
        work_dir = os.chdir(path)
        work_dir = os.getcwd()
    
    grid_file = visual.get("BOUT.inp","grid")
#    grid_file = str(raw_input('Enter the filename of the gridfile: '))
    grid_dir = work_dir + '/' + grid_file + '.nc'

    # Get the dimensions and initial value of the variable data.    
    max_t, var_0, nx, ny, nz = visual.dim_all(name)
  
    #ELM
    #Import r,z and zshift from grid file
    r = visual.nc_var(grid_dir,'Rxy') # ELM Coordinates
    z = visual.nc_var(grid_dir,'Zxy') # ELM Coordinates
    zshift = visual.nc_var(grid_dir,'zShift') #ELM Coordinates
    
    
    max_z,min_z = visual.z_shift_mm(nx,ny,zshift) #Find the max and minimum zshift values
    z_tol = min_z + (max_z * zShf_int_p) # Set tolerance value ##CHANGE TO IMPORT PERCENT !!##
    
    
    #Interpolate the Rxy and Zxy values
    r2,ny2 = visual.zshift_interp2d(nx,ny,zshift,z_tol,r)
    z2,ny2 = visual.zshift_interp2d(nx,ny,zshift,z_tol,z)
    zshift2,ny2 = visual.zshift_interp2d(nx,ny,zshift,z_tol,zshift)
    
    #Create points for ELM 
    pts2 = visual.elm(r2,z2,zshift2,nx,ny2,nz)
    
    ## Set time
    t = time
    # Set t to max_t, if user desires entire dataset
    if t == -1:
    	t = max_t
    #If t is greater than number of slices then set to max_t
    if t >= max_t:
            t = max_t
    
    ### Make dir for storing vtk files and image files
    #Check if dir for storing vtk files exsists if not make that dir
    if not os.path.exists("batch"):
    	os.makedirs("batch")
    
    #Make dir for storing images
    if not os.path.exists("images"):
    	os.makedirs("images")
    
    #Initial max and min values
    var_x, var_y, var_z = var_0[:,0,0], var_0[0,:,0], var_0[0,0,:]
    max_x, max_y, max_z = np.amax(var_x), np.amax(var_y), np.amax(var_z)
    min_x, min_y, min_z = np.amin(var_x), np.amin(var_y),np.amin(var_z)
    max = np.amax((max_x, max_y, max_z))
    min = np.amin((min_x, min_y, min_z))
    
    #If the variable is pressure, import and add the P0 variable to this
    if name == 'P':
    	p0 = visual.collect("P0") #Import P0
    	add_p = True
    
     
    #For the entire t range import the spacial values, find min max values, interpolate y, coordinate transform, write to vtk
    for q in range(t):
    	var = visual.var3d(name,q) # collect variable
    
    	#Find the min and max values
    	var_x, var_y, var_z = var[:,0,0], var[0,:,0], var[0,0,:]
    	max_x, max_y, max_z = np.amax(var_x), np.amax(var_y), np.amax(var_z)
    	min_x, min_y, min_z = np.amin(var_x), np.amin(var_y), np.amin(var_z)
    	max_i = np.amax(np.array((max_x,max_y,max_z)))
    	min_i = np.amin(np.array((min_x,min_y,min_z)))
    	if max_i >= max:
    		max = max_i
    	if min_i <= min:
    		min = min_i
    
    	#Adding p0
    	if add_p == True:#Adding P0
                    for i in range (nx): # X value
                            for j in range(ny): # Y Value
                                    var[i,j,:] = var[i,j,:] + p0[i,j]
    
    	
    	var2,ny3 = visual.zshift_interp3d(nx,ny,nz,zshift,z_tol,var)
    
    	#Convert coordinate section
    	vrbl = visual.vtk_var(var2,nx,ny2,nz) #vtk variable
    #	vrbl = visual.vtk_var(var,nx,ny,nz) # vtk variable
    	vtk_path = visual.write_vtk(name,pts2,vrbl,q,nx,ny2,nz) # write vtk file
    	print "At t = %d, %d Steps remaining" % (q,t-(q+1)) # Progress indicator
    
    #Write the Max and min values to file
    mm_array = np.array((max,min))
    np.savetxt('max_min_' + name + '.txt',mm_array) 
    return