Ejemplo n.º 1
0
 def solve_poisson(self):
     """Solves the Poisson equation for the pressure field."""
     b = 1. / Parameters.dt * (grad(Solver.u, 'x') + grad(Solver.v, 'y'))
     Solver.p.field = Solver.poisson.solve(Solver.p.laplacian.mat,
                                           b - Solver.p.laplacian.bc_vect,
                                           Solver.p.field)
     print '{Poisson} Number of iterations: %d' \
        % Solver.poisson.ite
Ejemplo n.º 2
0
def plot_vorticity(u, v, body=None, limits=None):
    """Plots vorticity field on the mesh.
	
	Arguments
	---------
	u, v -- instances Variable for the velocity components.
	body -- immersed body (default None).
	limits -- plot limits (default None).
	"""
    u.read()
    v.read()

    # computes vorticity
    w = grad(v, 'x') - grad(u, 'y')

    # initializes figure
    plt.figure(num=None)
    plt.grid(False)
    plt.xlabel(r'$x$', fontsize=20)
    plt.xlabel(r'$y$', fontsize=20)

    # creates contour of vorticity
    nc = 100
    wmin, wmax = w.min(), w.max()
    wmin, wmax = -1.0, 1.0
    if wmin == wmax:
        wmin, wmax = -1.0, 1.0
    levels = np.linspace(wmin, wmax, nc)

    cont = plt.contourf(Mesh.x,
                        Mesh.y,
                        w.reshape(Mesh.Ny, Mesh.Nx),
                        levels,
                        extend='both',
                        cmap=cm.jet)
    cbar = plt.colorbar(cont)
    cbar.set_label('vorticity')

    # plots body of there is one
    if Mesh.is_body:
        plt.plot(np.append(body.x, body.x[0]),
                 np.append(body.y, body.y[0]),
                 'k',
                 ls='-',
                 lw=1)

    # sets axis limits
    plt.xlim(limits[0], limits[1])
    plt.ylim(limits[2], limits[3])

    # inserts title and saves figure
    plt.title('vorticity - ' + str(Parameters.ite))
    plt.savefig(Case.path + '/images/' + 'vorticity' +
                str('%04d' % (Parameters.ite, )) + '.png')

    plt.clf()
    plt.close()
Ejemplo n.º 3
0
    def intermediate_velocity(self):
        """Computes the intermediate velocity field.
		
		Solves the Navier-Stokes equations,
		without the pressure gradient and boundardy forces,
		using Euler's method.
		"""
        Solver.u.field += Parameters.dt * (
            1. / Parameters.Re * lap(Solver.u) - Solver.u.field *
            grad(Solver.u, 'x') - Solver.v.field * grad(Solver.u, 'y'))
        Solver.v.field += Parameters.dt * (
            1. / Parameters.Re * lap(Solver.v) - Solver.u.field *
            grad(Solver.v, 'x') - Solver.v.field * grad(Solver.v, 'y'))
Ejemplo n.º 4
0
	def intermediate_velocity(self):
		"""Computes the intermediate velocity field.
		
		Solves the Navier-Stokes equations,
		without the pressure gradient and boundardy forces,
		using Euler's method.
		"""
		Solver.u.field += Parameters.dt * (
							1./Parameters.Re*lap(Solver.u)
							- Solver.u.field*grad(Solver.u, 'x')
							- Solver.v.field*grad(Solver.u, 'y'))
		Solver.v.field += Parameters.dt * (
							1./Parameters.Re*lap(Solver.v)
							- Solver.u.field*grad(Solver.v, 'x')
							- Solver.v.field*grad(Solver.v, 'y'))
Ejemplo n.º 5
0
def plot_vorticity(u, v, body=None, limits=None):
	"""Plots vorticity field on the mesh.
	
	Arguments
	---------
	u, v -- instances Variable for the velocity components.
	body -- immersed body (default None).
	limits -- plot limits (default None).
	"""
	u.read()
	v.read()

	# computes vorticity
	w = grad(v,'x') - grad(u,'y')

	# initializes figure
	plt.figure(num=None)
	plt.grid(False)
	plt.xlabel(r'$x$', fontsize=20)
	plt.xlabel(r'$y$', fontsize=20)

	# creates contour of vorticity
	nc = 100
	wmin, wmax = w.min(), w.max()
	wmin, wmax = -1.0, 1.0
	if wmin == wmax:
		wmin, wmax = -1.0, 1.0
	levels = np.linspace(wmin, wmax, nc)
	
	cont = plt.contourf(Mesh.x, Mesh.y, w.reshape(Mesh.Ny, Mesh.Nx),
						levels, extend='both', cmap=cm.jet)
	cbar = plt.colorbar(cont)
	cbar.set_label('vorticity')

	# plots body of there is one
	if Mesh.is_body:
		plt.plot(np.append(body.x,body.x[0]), np.append(body.y, body.y[0]), 'k', ls='-', lw=1)

	# sets axis limits
	plt.xlim(limits[0], limits[1])
	plt.ylim(limits[2], limits[3])

	# inserts title and saves figure
	plt.title('vorticity - '+str(Parameters.ite))
	plt.savefig(Case.path+'/images/'+'vorticity'+str('%04d'%(Parameters.ite,))+'.png')
	
	plt.clf()
	plt.close()
Ejemplo n.º 6
0
	def update_velocity(self):
		"""Updates the velocity field with pressure correction
		to make the field divergence-free.
		"""
		Solver.u.field -= Parameters.dt * grad(Solver.p, 'x')
		Solver.v.field -= Parameters.dt * grad(Solver.p, 'y')
Ejemplo n.º 7
0
	def solve_poisson(self):
		"""Solves the Poisson equation for the pressure field."""
		b = 1./Parameters.dt * (grad(Solver.u, 'x') + grad(Solver.v, 'y'))
		Solver.p.field = Solver.poisson.solve(Solver.p.laplacian.mat, b-Solver.p.laplacian.bc_vect, Solver.p.field)
		print '{Poisson} Number of iterations: %d' \
			  % Solver.poisson.ite
Ejemplo n.º 8
0
    def update_velocity(self):
        """Updates the velocity field with pressure correction
		to make the field divergence-free.
		"""
        Solver.u.field -= Parameters.dt * grad(Solver.p, 'x')
        Solver.v.field -= Parameters.dt * grad(Solver.p, 'y')