def main(): """Plots the contour of vorticity at every time saved.""" # parse the command-line args = read_inputs() # get the time-steps to plot if any(args.time_steps): # if provided by command-line arguments time_steps = range(args.time_steps[0], args.time_steps[1]+1, args.time_steps[2]) else: # if not, list solution folders time_steps = sorted(int(folder) for folder in os.listdir(args.folder_path) if folder[0]=='0') # create images folder if does not exit to store PNG files images_path = '%s/images' % args.folder_path if not os.path.isdir(images_path): os.makedirs(images_path) # calculate the mesh characteristics nx, ny, dx, dy, _, yu, xv, _ = read_grid(args.folder_path) # calculate appropriate array boundaries i_start = numpy.where(xv >= args.bottom_left[0])[0][0] i_end = numpy.where(xv <= args.top_right[0])[0][-1] j_start = numpy.where(yu >= args.bottom_left[1])[0][0] j_end = numpy.where(yu <= args.top_right[1])[0][-1] # create a mesh-grid x = xv[i_start:i_end] y = yu[j_start:j_end] X, Y = numpy.meshgrid(x, y) for time_step in time_steps: # read the velocity data at the given time-step pressure = read_pressure(args.folder_path, time_step, nx, ny) pressure = pressure.reshape((ny, nx))[j_start:j_end, i_start:i_end] # plot the contour of pressure print 'Generating PNG file at time-step %d...' % time_step pyplot.figure() pyplot.xlabel(r'$x$', fontsize=18) pyplot.ylabel(r'$y$', fontsize=18) pyplot.xlim(args.bottom_left[0], args.top_right[0]) pyplot.ylim(args.bottom_left[1], args.top_right[1]) pyplot.axis('equal') levels = numpy.linspace(args.pressure_limits[0], args.pressure_limits[1], args.levels) cont = pyplot.contour(X, Y, pressure, levels) cont_bar = pyplot.colorbar(cont) cont_bar.set_label('pressure') pyplot.savefig('{}/p{:0>7}.png'.format(images_path, time_step)) pyplot.clf() pyplot.close() print '\nPressure contours: DONE!\n'
def main(): """Plots the contour of vorticity at every time saved.""" # parse the command-line args = read_inputs() # get the time-steps to plot if any(args.time_steps): # if provided by command-line arguments time_steps = range(args.time_steps[0], args.time_steps[1] + 1, args.time_steps[2]) else: # if not, list solution folders time_steps = sorted( int(folder) for folder in os.listdir(args.folder_path) if folder[0] == '0') # create images folder if does not exit to store PNG files images_path = '%s/images' % args.folder_path if not os.path.isdir(images_path): os.makedirs(images_path) # calculate the mesh characteristics nx, ny, dx, dy, _, yu, xv, _ = read_grid(args.folder_path) # calculate appropriate array boundaries i_start = numpy.where(xv >= args.bottom_left[0])[0][0] i_end = numpy.where(xv <= args.top_right[0])[0][-1] j_start = numpy.where(yu >= args.bottom_left[1])[0][0] j_end = numpy.where(yu <= args.top_right[1])[0][-1] # create a mesh-grid x = xv[i_start:i_end] y = yu[j_start:j_end] X, Y = numpy.meshgrid(x, y) for time_step in time_steps: # read the velocity data at the given time-step pressure = read_pressure(args.folder_path, time_step, nx, ny) pressure = pressure.reshape((ny, nx))[j_start:j_end, i_start:i_end] # plot the contour of pressure print 'Generating PNG file at time-step %d...' % time_step pyplot.figure() pyplot.xlabel(r'$x$', fontsize=18) pyplot.ylabel(r'$y$', fontsize=18) pyplot.xlim(args.bottom_left[0], args.top_right[0]) pyplot.ylim(args.bottom_left[1], args.top_right[1]) pyplot.axis('equal') levels = numpy.linspace(args.pressure_limits[0], args.pressure_limits[1], args.levels) cont = pyplot.contour(X, Y, pressure, levels) cont_bar = pyplot.colorbar(cont) cont_bar.set_label('pressure') pyplot.savefig('{}/p{:0>7}.png'.format(images_path, time_step)) pyplot.clf() pyplot.close() print '\nPressure contours: DONE!\n'
def main(): """Plots the calculated and theoretical circulations at saved time-steps.""" # parse the command-line args = read_inputs() # get the time-steps if any(args.time_steps): # if provided by command-line arguments time_steps = range(args.time_steps[0], args.time_steps[1]+1, args.time_steps[2]) else: # if not, list solution folders time_steps = sorted(int(folder) for folder in os.listdir(args.folder_path) if folder[0]=='0') # read and generate the computational mesh nx, ny, dx, dy, _, yu, xv, _ = read_grid(args.folder_path) # grid-spacing h = dx[0] # grid-spacing (grid should be uniformly spaced) # total number of iterations nt = time_steps[-1] - time_steps[0] # initialization times = args.dt * numpy.array(time_steps) total_vorticity = numpy.empty_like(times, dtype=float) circulation = numpy.empty_like(times, dtype=float) # loop over the saved time-steps for index, time_step in enumerate(time_steps): # read the vorticity file vorticity_file = '%s/%07d/vorticity' % (args.folder_path, time_step) with open(vorticity_file, 'r') as infile: vorticity = numpy.loadtxt(infile, dtype=float, usecols=(2,)) # calculate the total vorticity total_vorticity[index] = h**2 * vorticity.sum() # calculate the theoretical circulation circulation[index] = -math.sin(math.pi*time_step/nt) # plot the total vorticity and theoretical circulation pyplot.figure() pyplot.grid(True) pyplot.xlabel('Time', fontsize=16) pyplot.ylabel('Total circulation', fontsize=16) pyplot.plot(times, total_vorticity, label='Total vorticity', color='r', ls='.', marker='o', markersize=10) pyplot.plot(times, circulation, label='Theoretical circulation', color='b', ls='-', lw=2) pyplot.xlim(args.limits[0], args.limits[1]) pyplot.ylim(args.limits[2], args.limits[3]) pyplot.title('Comparison of Total Vorticity and Theoretical Circulation ' 'at Re=10,000') pyplot.legend(loc='best', prop={'size': 16}) # save the figure if args.save: images_path = '%s/images' % args.folder_path if not os.path.isdir(images_path): os.makedirs(images_path) pyplot.savefig('%s/total_vorticity.png' % images_path) # display the figure if args.show: pyplot.show()
def main(): """Plots the contour of vorticity at saved time-steps.""" # parse the command-line args = read_inputs() # get the time-steps to plot if any(args.time_steps): # if provided by command-line arguments time_steps = range(args.time_steps[0], args.time_steps[1] + 1, args.time_steps[2]) else: # if not, list solution folders time_steps = sorted( int(folder) for folder in os.listdir(args.folder_path) if folder[0] == '0') # create images folder if does not exist to store PNG files images_path = '%s/images' % args.folder_path if not os.path.isdir(images_path): os.makedirs(images_path) # calculate the mesh characteristics nx, ny, dx, dy, _, yu, xv, _ = read_grid(args.folder_path) # calculate appropriate array boundaries i_start = numpy.where(xv >= args.bottom_left[0])[0][0] i_end = numpy.where(xv <= args.top_right[0])[0][-1] j_start = numpy.where(yu >= args.bottom_left[1])[0][0] j_end = numpy.where(yu <= args.top_right[1])[0][-1] # create a mesh-grid x = 0.5 * (xv[i_start:i_end] + xv[i_start + 1:i_end + 1]) y = 0.5 * (yu[j_start:j_end] + yu[j_start + 1:j_end + 1]) X, Y = numpy.meshgrid(x, y) # initialize vorticity vorticity = numpy.empty((y.size, x.size)) for time_step in time_steps: # read the velocity data at the given time-step u, v = read_velocity(args.folder_path, time_step, nx, ny, dx, dy) # calculate the vorticity for j in xrange(j_start, j_end): Dy = 0.5 * (dy[j] + dy[j + 1]) for i in xrange(i_start, i_end): Dx = 0.5 * (dx[i] + dx[i + 1]) vorticity[j-j_start, i-i_start] = (v[j*nx+i+1]-v[j*nx+i])/Dx \ - (u[(j+1)*(nx-1)+i]-u[j*(nx-1)+i])/Dy if args.save: # save the vorticity data in the time-step folder print 'Saving vorticity data at time-step %d...' % time_step vorticity_file = '{}/{:0>7}/vorticity'.format( args.folder_path, time_step) with open(vorticity_file, 'w') as outfile: for j in xrange(y.size): for i in xrange(x.size): outfile.write('%f\t%f\t%f\n' % (x[i], y[j], vorticity[j, i])) outfile.write('\n') if not args.using_gnuplot: # plot the contour of vorticity using pyplot print('Generating PNG file with Pyplot at time-step %d...' % time_step) pyplot.figure() pyplot.xlabel(r'$x$', fontsize=18) pyplot.ylabel(r'$y$', fontsize=18) pyplot.xlim(args.bottom_left[0], args.top_right[0]) pyplot.ylim(args.bottom_left[1], args.top_right[1]) pyplot.axis('equal') levels = numpy.linspace(-args.vorticity_limit, args.vorticity_limit, args.levels) cont = pyplot.contour(X, Y, vorticity, levels) cont_bar = pyplot.colorbar(cont) cont_bar.set_label('vorticity') pyplot.savefig('{}/o{:0>7}.png'.format(images_path, time_step)) pyplot.clf() pyplot.close() if args.using_gnuplot: # create the gnuplot script file print 'Creating Gnuplot vorticity script...' gnuplot_file = '{}/vorticity_script.plt'.format(args.folder_path) with open(gnuplot_file, 'w') as outfile: outfile.write('reset;\n') outfile.write('set terminal pngcairo enhanced ' 'font "Times, 15" size 900,600;\n') for time_step in time_steps: outfile.write('\nset output "%s/o%07d.png"\n' % (images_path, time_step)) outfile.write('set multiplot;\n') outfile.write('reset;\n') outfile.write('set view map; set size ratio -1; unset key;\n') outfile.write('set pm3d map;\n') outfile.write('set palette defined ' '(-2 "dark-blue", -1 "light-blue", 0 "white", ' '1 "light-red", 2 "dark-red");\n') outfile.write('set cbrange [%f:%f];\n' % (-args.vorticity_limit, args.vorticity_limit)) outfile.write('splot [%f:%f] [%f:%f] "%s/%07d/vorticity";\n' % (args.bottom_left[0], args.top_right[0], args.bottom_left[1], args.top_right[1], args.folder_path, time_step)) outfile.write('unset multiplot;\n') print 'Generating PNG files with Gnuplot...' os.system('gnuplot %s' % gnuplot_file) print '\nVorticity contours: DONE!\n'
def main(): #view available fonts #for font in font_manager.findSystemFonts(): # print font try: fontpath = '/usr/share/fonts/truetype/msttcorefonts/Georgia.ttf' prop = font_manager.FontProperties(fname=fontpath) matplotlib.rcParams['font.family'] = prop.get_name() except: pass """Plots the contour of velocity (u and v) at every time saved.""" # parse the command-line args = read_inputs() # get the time-steps to plot if any(args.time_steps): # if provided by command-line arguments time_steps = range(args.time_steps[0], args.time_steps[1] + 1, args.time_steps[2]) else: # if not, list solution folders time_steps = sorted( int(folder) for folder in os.listdir(args.folder_path) if folder[0] == '0') # create image folder if does not exist to store PNG files images_path = '%s/images' % args.folder_path if not os.path.isdir(images_path): os.makedirs(images_path) # calculate the mesh characteristics nx, ny, dx, dy, xu, yu, xv, yv = read_grid(args.folder_path) # generate a mesh grid for u- and v- velocities Xu, Yu = numpy.meshgrid(xu, yu) Xv, Yv = numpy.meshgrid(xv, yv) for time_step in time_steps: # read the velocity data at the given time-step u, v = read_velocity(args.folder_path, time_step, nx, ny, dx, dy) print 'Generating PNG file at time-step %d...' % time_step # plot u-velocity contour print '\tu-velocity...' pyplot.figure() pyplot.xlabel(r'$x$', fontsize=18) pyplot.ylabel(r'$y$', fontsize=18) levels = numpy.linspace(args.velocity_limits[0], args.velocity_limits[1], args.levels[0]) cont = pyplot.contour(Xu, Yu, u.reshape((ny, nx - 1)), levels) cont_bar = pyplot.colorbar(cont) cont_bar.set_label('u-velocity') pyplot.xlim(args.bottom_left[0], args.top_right[0]) pyplot.ylim(args.bottom_left[1], args.top_right[1]) pyplot.savefig('{}/u{:0>7}.png'.format(images_path, time_step)) pyplot.clf() pyplot.close() # plot v-velocity contour print '\tv-velocity...' pyplot.figure() pyplot.xlabel(r'$x$', fontsize=18) pyplot.ylabel(r'$y$', fontsize=18) levels = numpy.linspace(args.velocity_limits[2], args.velocity_limits[3], args.levels[1]) cont = pyplot.contour(Xv, Yv, v.reshape((ny - 1, nx)), levels) cont_bar = pyplot.colorbar(cont) cont_bar.set_label('v-velocity') pyplot.xlim(args.bottom_left[0], args.top_right[0]) pyplot.ylim(args.bottom_left[1], args.top_right[1]) pyplot.savefig('{}/v{:0>7}.png'.format(images_path, time_step)) pyplot.clf() pyplot.close() print '\nVelocity contours: DONE!\n'
def main(): """Plots the calculated and theoretical circulations at saved time-steps.""" # parse the command-line args = read_inputs() # get the time-steps if any(args.time_steps): # if provided by command-line arguments time_steps = range(args.time_steps[0], args.time_steps[1] + 1, args.time_steps[2]) else: # if not, list solution folders time_steps = sorted( int(folder) for folder in os.listdir(args.folder_path) if folder[0] == '0') # read and generate the computational mesh nx, ny, dx, dy, _, yu, xv, _ = read_grid(args.folder_path) # grid-spacing h = dx[0] # grid-spacing (grid should be uniformly spaced) # total number of iterations nt = time_steps[-1] - time_steps[0] # initialization times = args.dt * numpy.array(time_steps) total_vorticity = numpy.empty_like(times, dtype=float) circulation = numpy.empty_like(times, dtype=float) # loop over the saved time-steps for index, time_step in enumerate(time_steps): # read the vorticity file vorticity_file = '%s/%07d/vorticity' % (args.folder_path, time_step) with open(vorticity_file, 'r') as infile: vorticity = numpy.loadtxt(infile, dtype=float, usecols=(2, )) # calculate the total vorticity total_vorticity[index] = h**2 * vorticity.sum() # calculate the theoretical circulation circulation[index] = -math.sin(math.pi * time_step / nt) # plot the total vorticity and theoretical circulation pyplot.figure() pyplot.grid(True) pyplot.xlabel('Time', fontsize=16) pyplot.ylabel('Total circulation', fontsize=16) pyplot.plot(times, total_vorticity, label='Total vorticity', color='r', ls='.', marker='o', markersize=10) pyplot.plot(times, circulation, label='Theoretical circulation', color='b', ls='-', lw=2) pyplot.xlim(args.limits[0], args.limits[1]) pyplot.ylim(args.limits[2], args.limits[3]) pyplot.title('Comparison of Total Vorticity and Theoretical Circulation ' 'at Re=10,000') pyplot.legend(loc='best', prop={'size': 16}) # save the figure if args.save: images_path = '%s/images' % args.folder_path if not os.path.isdir(images_path): os.makedirs(images_path) pyplot.savefig('%s/total_vorticity.png' % images_path) # display the figure if args.show: pyplot.show()
def main(): """Plots the contour of vorticity at saved time-steps.""" # parse the command-line args = read_inputs() # get the time-steps to plot if any(args.time_steps): # if provided by command-line arguments time_steps = range(args.time_steps[0], args.time_steps[1]+1, args.time_steps[2]) else: # if not, list solution folders time_steps = sorted(int(folder) for folder in os.listdir(args.folder_path) if folder[0]=='0') # create images folder if does not exist to store PNG files images_path = '%s/images' % args.folder_path if not os.path.isdir(images_path): os.makedirs(images_path) # calculate the mesh characteristics nx, ny, dx, dy, _, yu, xv, _ = read_grid(args.folder_path) # calculate appropriate array boundaries i_start = numpy.where(xv >= args.bottom_left[0])[0][0] i_end = numpy.where(xv <= args.top_right[0])[0][-1] j_start = numpy.where(yu >= args.bottom_left[1])[0][0] j_end = numpy.where(yu <= args.top_right[1])[0][-1] # create a mesh-grid x = 0.5*(xv[i_start:i_end] + xv[i_start+1:i_end+1]) y = 0.5*(yu[j_start:j_end] + yu[j_start+1:j_end+1]) X, Y = numpy.meshgrid(x, y) # initialize vorticity vorticity = numpy.empty((y.size, x.size)) for time_step in time_steps: # read the velocity data at the given time-step u, v = read_velocity(args.folder_path, time_step, nx, ny, dx, dy) # calculate the vorticity for j in xrange(j_start, j_end): Dy = 0.5 * (dy[j] + dy[j+1]) for i in xrange(i_start, i_end): Dx = 0.5 * (dx[i] + dx[i+1]) vorticity[j-j_start, i-i_start] = (v[j*nx+i+1]-v[j*nx+i])/Dx \ - (u[(j+1)*(nx-1)+i]-u[j*(nx-1)+i])/Dy if args.save: # save the vorticity data in the time-step folder print 'Saving vorticity data at time-step %d...' % time_step vorticity_file = '{}/{:0>7}/vorticity'.format(args.folder_path, time_step) with open(vorticity_file, 'w') as outfile: for j in xrange(y.size): for i in xrange(x.size): outfile.write('%f\t%f\t%f\n' % (x[i], y[j], vorticity[j, i])) outfile.write('\n') if not args.using_gnuplot: # plot the contour of vorticity using pyplot print ('Generating PNG file with Pyplot at time-step %d...' % time_step) pyplot.figure() pyplot.xlabel(r'$x$', fontsize=18) pyplot.ylabel(r'$y$', fontsize=18) pyplot.xlim(args.bottom_left[0], args.top_right[0]) pyplot.ylim(args.bottom_left[1], args.top_right[1]) pyplot.axis('equal') levels = numpy.linspace(-args.vorticity_limit, args.vorticity_limit, args.levels) cont = pyplot.contour(X, Y, vorticity, levels) cont_bar = pyplot.colorbar(cont) cont_bar.set_label('vorticity') pyplot.savefig('{}/o{:0>7}.png'.format(images_path, time_step)) pyplot.clf() pyplot.close() if args.using_gnuplot: # create the gnuplot script file print 'Creating Gnuplot vorticity script...' gnuplot_file = '{}/vorticity_script.plt'.format(args.folder_path) with open(gnuplot_file, 'w') as outfile: outfile.write('reset;\n') outfile.write('set terminal pngcairo enhanced ' 'font "Times, 15" size 900,600;\n') for time_step in time_steps: outfile.write('\nset output "%s/o%07d.png"\n' % (images_path, time_step)) outfile.write('set multiplot;\n') outfile.write('reset;\n') outfile.write('set view map; set size ratio -1; unset key;\n') outfile.write('set pm3d map;\n') outfile.write('set palette defined ' '(-2 "dark-blue", -1 "light-blue", 0 "white", ' '1 "light-red", 2 "dark-red");\n') outfile.write('set cbrange [%f:%f];\n' % (-args.vorticity_limit, args.vorticity_limit)) outfile.write('splot [%f:%f] [%f:%f] "%s/%07d/vorticity";\n' % (args.bottom_left[0], args.top_right[0], args.bottom_left[1], args.top_right[1], args.folder_path, time_step)) outfile.write('unset multiplot;\n') print 'Generating PNG files with Gnuplot...' os.system('gnuplot %s' % gnuplot_file) print '\nVorticity contours: DONE!\n'
def main(): #view available fonts #for font in font_manager.findSystemFonts(): # print font try: fontpath = '/usr/share/fonts/truetype/msttcorefonts/Georgia.ttf' prop = font_manager.FontProperties(fname=fontpath) matplotlib.rcParams['font.family'] = prop.get_name() except: pass """Plots the contour of velocity (u and v) at every time saved.""" # parse the command-line args = read_inputs() # get the time-steps to plot if any(args.time_steps): # if provided by command-line arguments time_steps = range(args.time_steps[0], args.time_steps[1]+1, args.time_steps[2]) else: # if not, list solution folders time_steps = sorted(int(folder) for folder in os.listdir(args.folder_path) if folder[0]=='0') # create image folder if does not exist to store PNG files images_path = '%s/images' % args.folder_path if not os.path.isdir(images_path): os.makedirs(images_path) # calculate the mesh characteristics nx, ny, dx, dy, xu, yu, xv, yv = read_grid(args.folder_path) # generate a mesh grid for u- and v- velocities Xu, Yu = numpy.meshgrid(xu, yu) Xv, Yv = numpy.meshgrid(xv, yv) for time_step in time_steps: # read the velocity data at the given time-step u, v = read_velocity(args.folder_path, time_step, nx, ny, dx, dy) print 'Generating PNG file at time-step %d...' % time_step # plot u-velocity contour print '\tu-velocity...' pyplot.figure() pyplot.xlabel(r'$x$', fontsize=18) pyplot.ylabel(r'$y$', fontsize=18) levels = numpy.linspace(args.velocity_limits[0], args.velocity_limits[1], args.levels[0]) cont = pyplot.contour(Xu, Yu, u.reshape((ny, nx-1)), levels) cont_bar = pyplot.colorbar(cont) cont_bar.set_label('u-velocity') pyplot.xlim(args.bottom_left[0], args.top_right[0]) pyplot.ylim(args.bottom_left[1], args.top_right[1]) pyplot.savefig('{}/u{:0>7}.png'.format(images_path, time_step)) pyplot.clf() pyplot.close() # plot v-velocity contour print '\tv-velocity...' pyplot.figure() pyplot.xlabel(r'$x$', fontsize=18) pyplot.ylabel(r'$y$', fontsize=18) levels = numpy.linspace(args.velocity_limits[2], args.velocity_limits[3], args.levels[1]) cont = pyplot.contour(Xv, Yv, v.reshape((ny-1, nx)), levels) cont_bar = pyplot.colorbar(cont) cont_bar.set_label('v-velocity') pyplot.xlim(args.bottom_left[0], args.top_right[0]) pyplot.ylim(args.bottom_left[1], args.top_right[1]) pyplot.savefig('{}/v{:0>7}.png'.format(images_path, time_step)) pyplot.clf() pyplot.close() print '\nVelocity contours: DONE!\n'