Example: bachelor of science

A compact and fast Matlab code solving the incompressible ...

A compact and fast Matlab code solving the incompressibleNavier-Stokes equations on rectangular SeiboldApplied MathematicsMassachusetts Institute of 31, 20081 IntroductionOn the following pages you find a documentation for the Matlab , as it is used forCourse : Computational Science and En-gineering IIat theMassachusetts Institute of Technology. The code can be downloaded fromtheComputational Science and Engineeringweb Itis also linked on the course web code shall be used for teaching and learning about incompressible , viscous is an example of a simple numerical method for solving the navier -Stokes equations.

A derivation of the Navier-Stokes equations can be found in [2]. The momentum equations (1) and (2) describe the time evolution of the velocity field (u,v) under inertial and viscous forces. The pressure p is a Lagrange multiplier to satisfy the incompressibility condition (3).

Tags:

  Eskto, Navier, The navier stokes

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of A compact and fast Matlab code solving the incompressible ...

1 A compact and fast Matlab code solving the incompressibleNavier-Stokes equations on rectangular SeiboldApplied MathematicsMassachusetts Institute of 31, 20081 IntroductionOn the following pages you find a documentation for the Matlab , as it is used forCourse : Computational Science and En-gineering IIat theMassachusetts Institute of Technology. The code can be downloaded fromtheComputational Science and Engineeringweb Itis also linked on the course web code shall be used for teaching and learning about incompressible , viscous is an example of a simple numerical method for solving the navier -Stokes equations.

2 Itcontains fundamental components, such as discretization on a staggered grid, an implicitviscosity step, a projection step, as well as the visualization of the solution over time. Themain priorities of the code and compactness:The whole code is one single Matlab file of about100 :The code does not use spectral methods, thus can be modified to morecomplex domains, boundary conditions, and flow :The evolution of the flow field is visualized while the simulation speed:Full vectorization and pre- solving the arising linear systemsin an initialization step results in fast time code provides.

3 Variable box sizes, grid resolution, time step, and Reynolds numbers implicit time stepping for the fluid viscosity1 visualization of pressure field, velocity field and streamlines automatic transition from central to donor-cell discretization for the nonlinear advec-tion part fast computation of the time-dependent solution for small to moderate mesh sizesThe code does not provide: 3d unstructured meshes or complex geometries time-dependent geometries adaptivity, such as local mesh refinement, time step control, etc. non-constant viscosity or density higher order time stepping turbulence models time and memory efficiency for large computationsThe code qualifies as a basis for modifications and extensions.

4 The following extensionshave already been applied to the code by MIT students and other users: external forces inflow and outflow boundaries addition of a drag region geometry change to a backwards facing step time dependent geometries coupling with an advection-diffusion equation2 incompressible navier -Stokes EquationsWe consider the incompressible navier -Stokes equations in two space dimensionsut+px= (u2)x (uv)y+1Re(uxx+uyy)(1)vt+py= (uv)x (v2)y+1Re(vxx+vyy)(2)ux+vy= 0(3)2on a rectangular domain = [0, lx] [0, ly]. The four domain boundaries are denotedNorth,South,West, andEast.

5 The domain is fixed in time, and we consider no-slip boundaryconditions on each wall, (x, ly) =uN(x)v(x, ly) = 0(4)u(x,0) =uS(x)v(x,0) = 0(5)u(0, y) = 0v(0, y) =vW(y)(6)u(lx, y) = 0v(lx, y) =vE(y)(7)A derivation of the navier -Stokes equations can be found in [2]. The momentum equations(1) and (2) describe the time evolution of the velocity field (u, v) under inertial and viscousforces. The pressurepis a Lagrange multiplier to satisfy the incompressibility condition(3). Note that the momentum equations are already put into a numerics-friendly form. Thenonlinear terms on the right hand side equal(u2)x+ (uv)y=uux+vuy(8)(uv)x+ (v2)y=uvx+vvy(9)which follows by the chain rule and equation (3).

6 The above right hand side is often writtenin vector form as (u )u. We choose to numerically discretize the form on the left handside, because it is closer to a conservation incompressibility condition is not a time evolution equation, but an algebraic condi-tion. We incorporate this condition by using a projection approach [1]: Evolve the momen-tum equations neglecting the pressure, then project onto the subspace of divergence-freevelocity VisualizationEvery fixed number of time steps the current pressure and velocity field are pressure field is shown as a color plot with some contour lines.

7 On top of this, thenormalized velocity field is shown as a quiver plot, little arrows indicate the direction ofthe flow. Since in a lid driven cavity the flow rate varies significantly over different areas,outputting the normalized velocity field is a common procedure. Additionally, stream linesare shown. Those are paths particles would take in the flow if the velocity field was frozenat the current instant in time. Since the velocity field is divergence-free, the streamlines areclosed. The stream lines are contour lines of the stream functionq. It is a function whoseorthogonal gradient is the velocity field( q) =u qy=uandqx=v(10)Applying the 2d-curl to this equation yields q= ( q) = u q= qyy qxx=uy vx(11)The stream function exists since the compatibility condition u=ux+vy= 0 is Numerical Solution ApproachThe general approach of the code is described in Section in the bookComputationalScience and Engineering[4].

8 Whileu,v,pandqare the solutions to the navier -Stokes equations, we denote thenumerical approximations by capital letters. Assume we have the velocity fieldUnandVnat thenthtime step (timet), and condition (3) is satisfied. We find the solution at the(n+ 1)sttime step (timet+ t) by the following three step nonlinear termsThe nonlinear terms are treated explicitly. This circumvents the solution of a nonlinearsystem, but introduces a CFL condition which limits the time step by a constant timesthe spacial Un t= ((Un)2)x (UnVn)y(12)V Vn t= (UnVn)x ((Vn)2)y(13)In Section 5 we will detail how to discretize the nonlinear viscosityThe viscosity terms are treated implicitly.

9 If they were treated explicitly, we wouldhave a time step restriction proportional to the spacial discretization squared. Wehave no such limitation for the implicit treatment. The price to pay is two linearsystems to be solved in each time U t=1Re(U xx+U yy)(14)V V t=1Re(V xx+V yy)(15) correctionWe correct the intermediate velocity field (U , V ) by the gradient of a pressurePn+1to enforce +1 U t= (Pn+1)x(16)Vn+1 V t= (Pn+1)y(17)The pressure is denotedPn+1, since it is only given implicitly. It is obtained by solvinga linear system. In vector notation the correction equations read as1 tUn+1 1 tUn= Pn+1(18)Applying the divergence to both sides yields the linear system Pn+1= 1 t Un(19)Hence, the pressure correction step is4(a) ComputeFn= Un(b) Solve Poisson equation Pn+1= 1 tFn(c) ComputeGn+1= Pn+1(d) Update velocity fieldUn+1=Un tGn+1 The question, which boundary conditions are appropriate for the Poisson equationfor the pressureP, is complicated.

10 A standard approach is to prescribe homoge-neous Neumann boundary conditions forPwherever no-slip boundary conditions areprescribed for the velocity field. For the lid driven cavity problem this means thathomogeneous Neumann boundary conditions are prescribed everywhere. This impliesin particular that the pressurePis only defined up to a constant, which is fine, sinceonly the gradient ofPenters the momentum addition to the solution steps, we have the visualization step, in which the stream functionQnis computed. Similarly to the pressure is is obtained by the following steps1.


Related search queries