Beispiel #1
0
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'
Beispiel #2
0
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'
Beispiel #3
0
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'
Beispiel #4
0
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'