Exemplo n.º 1
0
def main():
	"""Script to clean a given case."""
	args = read_inputs()
	Case(args.path)

	print 'case path: %s' % Case.path

	print '[info]: cleaning mesh and force coefficients'
	os.system('rm -f '+Case.path+'/*.dat')

	print '[info]: cleaning solution folders'
	for i in xrange(10):
		os.system('rm -rf '+Case.path+'/'+str(i)+'*')

	print '[info]: cleaning images'
	os.system('rm -rf '+Case.images)
Exemplo n.º 2
0
def main():
	"""Solves the Navier-Stokes equations in a two-dimensional domain
	with an immersed boundary method."""

	# parse the command-line
	args = read_inputs()

	# create the case
	Case(args.path)

	# create the computational domain
	Domain(is_show=args.mesh)
	
	# create the solver
	solver = Solver()

	# solve the Navier-Stokes equations
	solver.solve(body=Domain.body)
Exemplo n.º 3
0
def main():
    """Solves the Navier-Stokes equations in a two-dimensional domain
	with an immersed boundary method."""

    # parse the command-line
    args = read_inputs()

    # create the case
    Case(args.path)

    # create the computational domain
    Domain(is_show=args.mesh)

    # create the solver
    solver = Solver()

    # solve the Navier-Stokes equations
    solver.solve(body=Domain.body)
Exemplo n.º 4
0
def main():
	"""Script to plot velocity at center lines
	and to compare with Ghia et al. (1982) experimental data.
	"""
	# parse the command-line
	args = read_inputs()

	# create the case
	Case(args.path)

	# generate the mesh
	mesh = Mesh()

	# initialize the solver
	Solver(skip_assemble=True, skip_poisson=True)

	# read variables field at last iteration saved
	print '{Post-processing}: Comparison with Ghia et al. (1982)'
	Parameters.ite = Parameters.start + Parameters.nt
	Solver.u.read()
	Solver.v.read()
	Solver.p.read()
	
	# read velocity on the centered vertical line of the cavity
	file_path = os.getcwd()+'/resources/ghia_et_al_1982/u_vertical_line.dat'
	with open(file_path, 'r') as file_name:
		data = np.genfromtxt(file_name, 
							 dtype=float, names=True, unpack=True)
		y_vl_ghia = data['y']
		u_vl_ghia = data[str(Parameters.Re)]
	
	# read velocity on the centered horizontal line of the cavity
	file_path = os.getcwd()+'/resources/ghia_et_al_1982/v_horizontal_line.dat'
	with open(file_path, 'r') as file_name:
		data = np.genfromtxt(file_name, 
							 dtype=float, names=True, unpack=True)
		x_hl_ghia = data['x']
		v_hl_ghia = data[str(Parameters.Re)]
	
	# create arrays to store the solution
	y_vl = np.empty(Mesh.Ny, dtype=float)
	u_vl = np.empty(Mesh.Ny, dtype=float)
	x_hl = np.empty(Mesh.Nx, dtype=float)
	v_hl = np.empty(Mesh.Nx, dtype=float)
	I, J = 0, 0
	for i in xrange(Mesh.Nx*Mesh.Ny):
		if Mesh.x[i%Mesh.Nx] == Mesh.x[Mesh.Nx/2]:
			y_vl[I] = Mesh.y[i/Mesh.Nx]
			u_vl[I] = Solver.u.field[i]
			I += 1
		if Mesh.y[i/Mesh.Nx] == Mesh.y[Mesh.Ny/2]:
			x_hl[J] = Mesh.x[i%Mesh.Nx]
			v_hl[J] = Solver.v.field[i]
			J += 1

	# plot velcoity on the vertical line
	plt.figure(num=None)
	plt.grid(True)
	plt.xlabel(r'$y$', fontsize=18)
	plt.ylabel(r'$u$', fontsize=18)
	plt.plot(y_vl, u_vl, color='b', ls='-', lw=2.0)
	plt.scatter(y_vl_ghia, u_vl_ghia, color='r', marker='o', s=6)
	plt.legend(['pyIBM', 'Ghia et al. (1982)'], loc='best', prop={'size':16})
	plt.savefig(Case.images+'/velocity_vertical_line_%d.png' % (Parameters.start+Parameters.nt))
	plt.clf()
	plt.close()

	# plot velocity on the horizontal line
	plt.figure(num=None)
	plt.grid(True)
	plt.xlabel(r'$x$', fontsize=18)
	plt.ylabel(r'$v$', fontsize=18)
	plt.plot(x_hl, v_hl, color='b', ls='-', lw=2.0)
	plt.scatter(x_hl_ghia, v_hl_ghia, color='r', marker='o', s=6)
	plt.legend(['pyIBM', 'Ghia et al. (1982)'], loc='best', prop={'size':16})
	plt.savefig(Case.images+'/velocity_horizontal_line_%d.png' % (Parameters.start+Parameters.nt))
	plt.clf()
	plt.close()
Exemplo n.º 5
0
def main():
    """Script to plot velocity at center lines
	and to compare with Ghia et al. (1982) experimental data.
	"""
    # parse the command-line
    args = read_inputs()

    # create the case
    Case(args.path)

    # generate the mesh
    mesh = Mesh()

    # initialize the solver
    Solver(skip_assemble=True, skip_poisson=True)

    # read variables field at last iteration saved
    print '{Post-processing}: Comparison with Ghia et al. (1982)'
    Parameters.ite = Parameters.start + Parameters.nt
    Solver.u.read()
    Solver.v.read()
    Solver.p.read()

    # read velocity on the centered vertical line of the cavity
    file_path = os.getcwd() + '/resources/ghia_et_al_1982/u_vertical_line.dat'
    with open(file_path, 'r') as file_name:
        data = np.genfromtxt(file_name, dtype=float, names=True, unpack=True)
        y_vl_ghia = data['y']
        u_vl_ghia = data[str(Parameters.Re)]

    # read velocity on the centered horizontal line of the cavity
    file_path = os.getcwd(
    ) + '/resources/ghia_et_al_1982/v_horizontal_line.dat'
    with open(file_path, 'r') as file_name:
        data = np.genfromtxt(file_name, dtype=float, names=True, unpack=True)
        x_hl_ghia = data['x']
        v_hl_ghia = data[str(Parameters.Re)]

    # create arrays to store the solution
    y_vl = np.empty(Mesh.Ny, dtype=float)
    u_vl = np.empty(Mesh.Ny, dtype=float)
    x_hl = np.empty(Mesh.Nx, dtype=float)
    v_hl = np.empty(Mesh.Nx, dtype=float)
    I, J = 0, 0
    for i in xrange(Mesh.Nx * Mesh.Ny):
        if Mesh.x[i % Mesh.Nx] == Mesh.x[Mesh.Nx / 2]:
            y_vl[I] = Mesh.y[i / Mesh.Nx]
            u_vl[I] = Solver.u.field[i]
            I += 1
        if Mesh.y[i / Mesh.Nx] == Mesh.y[Mesh.Ny / 2]:
            x_hl[J] = Mesh.x[i % Mesh.Nx]
            v_hl[J] = Solver.v.field[i]
            J += 1

    # plot velcoity on the vertical line
    plt.figure(num=None)
    plt.grid(True)
    plt.xlabel(r'$y$', fontsize=18)
    plt.ylabel(r'$u$', fontsize=18)
    plt.plot(y_vl, u_vl, color='b', ls='-', lw=2.0)
    plt.scatter(y_vl_ghia, u_vl_ghia, color='r', marker='o', s=6)
    plt.legend(['pyIBM', 'Ghia et al. (1982)'], loc='best', prop={'size': 16})
    plt.savefig(Case.images + '/velocity_vertical_line_%d.png' %
                (Parameters.start + Parameters.nt))
    plt.clf()
    plt.close()

    # plot velocity on the horizontal line
    plt.figure(num=None)
    plt.grid(True)
    plt.xlabel(r'$x$', fontsize=18)
    plt.ylabel(r'$v$', fontsize=18)
    plt.plot(x_hl, v_hl, color='b', ls='-', lw=2.0)
    plt.scatter(x_hl_ghia, v_hl_ghia, color='r', marker='o', s=6)
    plt.legend(['pyIBM', 'Ghia et al. (1982)'], loc='best', prop={'size': 16})
    plt.savefig(Case.images + '/velocity_horizontal_line_%d.png' %
                (Parameters.start + Parameters.nt))
    plt.clf()
    plt.close()
Exemplo n.º 6
0
def main():
    """Script to plot pressure, velocity and/or vorticity."""
    # parse the command-line
    args = read_inputs()

    # create the case
    Case(args.path)

    # generates the computational domain
    Domain()

    # zoom on a given window
    if args.zoom != None:
        limits = args.zoom
    else:
        limits = [Mesh.xmin, Mesh.xmax, Mesh.ymin, Mesh.ymax]

    # initializes the solver
    Solver(skip_assemble=True, skip_poisson=True)

    # changes timesteps to plot if argument specified
    if args.time != None:
        if len(args.time) == 1:
            Parameters.start, Parameters.nt = args.time[0], 0
        else:
            Parameters.start = args.time[0]
            Parameters.write_every = args.time[2]
            Parameters.nt = args.time[
                1] - Parameters.start + Parameters.write_every
            Parameters.ite = Parameters.start - Parameters.write_every

    # chooses variables to plot if argument specified
    if args.variable != None:
        variables = args.variable
    else:
        variables = ['pressure', 'velocity', 'vorticity']

    print variables

    # assemble matrices to compute vorticity
    if 'vorticity' in variables:
        Solver.u.assemble_matrix({
            'type': 'gradient',
            'scheme': 'central',
            'direction': 'y'
        })
        Solver.v.assemble_matrix({
            'type': 'gradient',
            'scheme': 'central',
            'direction': 'x'
        })

    # create an 'images' folder in case folder if necessary
    if not os.path.isdir(Case.path + '/images'):
        os.system('mkdir ' + Case.path + '/images')

    # loops over time
    for ite in xrange(Parameters.start, Parameters.start + Parameters.nt,
                      Parameters.write_every):

        Parameters.ite += Parameters.write_every

        print 'Iteration ', Parameters.ite

        # plots different variables
        if 'pressure' in variables:
            plot_pressure(Solver.p, Domain.body, limits)
        if 'velocity' in variables:
            plot_velocity(Solver.u, Solver.v, Domain.body, limits)
        if 'vorticity' in variables:
            plot_vorticity(Solver.u, Solver.v, Domain.body, limits)
Exemplo n.º 7
0
def main():
	"""Script to plot pressure, velocity and/or vorticity."""
	# parse the command-line
	args = read_inputs()

	# create the case
	Case(args.path)

	# generates the computational domain
	Domain()
	
	# zoom on a given window
	if args.zoom != None:
		limits = args.zoom
	else:
		limits = [Mesh.xmin, Mesh.xmax, Mesh.ymin, Mesh.ymax]

	# initializes the solver
	Solver(skip_assemble=True, skip_poisson=True)
	
	# changes timesteps to plot if argument specified
	if args.time != None:
		if len(args.time) == 1:
			Parameters.start, Parameters.nt = args.time[0], 0
		else:
			Parameters.start = args.time[0]
			Parameters.write_every = args.time[2]
			Parameters.nt = args.time[1] - Parameters.start + Parameters.write_every
			Parameters.ite = Parameters.start - Parameters.write_every

	# chooses variables to plot if argument specified
	if args.variable != None:
		variables = args.variable
	else:
		variables = ['pressure', 'velocity', 'vorticity']

	print variables	

	# assemble matrices to compute vorticity
	if 'vorticity' in variables:
			Solver.u.assemble_matrix({'type': 'gradient', 'scheme': 'central', 'direction': 'y'})
			Solver.v.assemble_matrix({'type': 'gradient', 'scheme': 'central', 'direction': 'x'})

	# create an 'images' folder in case folder if necessary
	if not os.path.isdir(Case.path+'/images'):
		os.system('mkdir '+Case.path+'/images')

	# loops over time
	for ite in xrange(Parameters.start, Parameters.start+Parameters.nt, Parameters.write_every):
		
		Parameters.ite += Parameters.write_every

		print 'Iteration ', Parameters.ite

		# plots different variables
		if 'pressure' in variables:
			plot_pressure(Solver.p, Domain.body, limits)
		if 'velocity' in variables:
			plot_velocity(Solver.u, Solver.v, Domain.body, limits)
		if 'vorticity' in variables:
			plot_vorticity(Solver.u, Solver.v, Domain.body, limits)