Using Python To Solve The Navier-Stokes Equations - Applications
Using Python To Solve The Navier-Stokes Equations - Applications
2015
Lina Wu
CUNY Borough of Manhattan Community College
Xingang Fang
University of West Florida
This work is made publicly available by the City University of New York (CUNY).
Contact: [email protected]
Journal of Scientific Research & Reports
7(3): 207-217, 2015, Article no.JSRR.2015.202
ISSN: 2320-0227
SCIENCEDOMAIN international
www.sciencedomain.org
USA.
2 Department of Mathematics, Borough of Manhattan Community College, The City University of
Article Information
DOI: 10.9734/JSRR/2015/17346
Editor(s):
(1) Narcisa C. Apreutesei, Technical University of Iasi, Romania.
Reviewers:
(1) Anonymous, China.
(2)Ette Harrison Etuk, Department of Mathematics Computer Science, Rivers State University of
Science and Technology, Nigeria.
Complete Peer review History:
http://www.sciencedomain.org/review-history.php?iid=1127&id=22&aid=9129
Abstract
This article describes a new numerical solver for the Navier-Stokes equations. The proposed solver
is written in Python which is a newly developed language. The Python packages are built to solve
the Navier-Stokes equations with existing libraries. We have created discretized coefficient matrices
from systems of the Navier-Stokes equations by the finite difference method. In addition we focus on
the preconditioned Krylov subspace iterative methods in the linearized systems. Numerical results
of performances for the Preconditioned iterative methods are demonstrated. The comparison
between Python and Matlab is discussed at the end of the paper.
208
Liu et al.; JSRR, 7(3), 207-217, 2015; Article no.JSRR.2015.202
scientific computing including the scientific are more interested in the applications of
notebook iPython, the statistic package the preconditioned Krylov subspace iterative
panda, the cross-platform GUI toolkits methods. We will compare the performances
pyQt, wxPython and GTK, the all-in-one between Python and Matlab.
scientific Python distribution Pythonxy and
canopy express (former EPD Python), the
test framework unittest and nose. 1.2 The Naviver-Stokes Equations
• Cost: Matlab is very expensive for The Navier-Stokes equations, which are
the researchers while Python and named after Claude-Louis Navier and George
corresponding packages are totally free. It Gabriel Stokes, come from the motion of fluid
is more favorable for students who would substances. The equations are important with
like to learn the numerical analysis with no both academic and economic interests. The
cost. Navier-Stokes equations model the movement
of the fluid from various types, such as the
With the advanced features of Python, we are weather, ocean currents, water flows in a pipe
able to develop some efficient and easy-to- and air flows around a wing. They are also
use softwares to solve PDEs. In this paper, used as the models to study the blood flow, the
we focus on using Python to solve the PDEs design of power stations, the analysis of pollution.
arising from the incompressible flow problems, The incompressible Navier-Stokes equations are
especially the Navier-Stokes equations. We given by the following PDEs:
∂u
− ν∆u + (u · ∇) u + ∇p = f in Ω × (0, T ] (1.1)
∂t
∇·u=0 in Ω × [0, T ] (1.2)
Bu = g on Ω × [0, T ] (1.3)
u(x, 0) = u0 in Ω (1.4)
Assume Ω ⊂ R2 . Denoting u = (u, v), and f = (f1 , f2 ), we can write the equations (1.1)–(1.2) in
scalar form as follows:
∂u ∂u ∂u ∂p
− ν∆u + u +v + = f1 ,
∂t ∂x ∂y ∂x
∂v ∂v ∂v ∂p
− ν∆v + u +v + = f2 ,
∂t ∂x ∂y ∂y
∂u ∂v
+ = 0.
∂x ∂y
209
Liu et al.; JSRR, 7(3), 207-217, 2015; Article no.JSRR.2015.202
Here α is O(δt), where δt is the time step. And uk is the solution which is obtained from the previous
step. The initial guess u0 can be the solution from the Stokes equations which are
αu − ν∆u + ∇p = f in Ω × (0, T ]
∇·u=0 in Ω × [0, T ]
The following finite difference expressions are utilized (for the two dimensional case) when we
discretize the equations with respect to the space:
210
Liu et al.; JSRR, 7(3), 207-217, 2015; Article no.JSRR.2015.202
With the above scheme, we obtain the Notice here the linear system Ax = b is
following linear system Ax = b , where the linear system we need to solve at each
Picard’s iteration. Therefore, at each k-iteration
A1 0 BT1 in the Picard’s iteration, we have the solution x.
A = 0 A 2 B2 , T
(2.1) Under certain conditions, the sequence xinfk=1 will
B1 B2 0 converge to the solution of the nonlinear problem
where A1 , A2 are discrete reaction-convection- (1.1) to (1.4).
diffusion operators. A1 is the approximation
of αu − ν∆u + u ∂u + v ∂u , and A2 is the
∂x ∂y 2.2 Numerical Solvers
approximation of αv − ν∆v + v ∂x ∂v ∂v
+ v ∂y . Here
B1 ≈ ∂x and B2 ≈ ∂y . We denote the matrix A
∂ ∂ Currently, our most important application is to
in the block form: play with the different numerical solvers for the
[ ] Saddle point system Ax = b with the coefficient
A BT matrix 2.1. We focus on Krylov subspace iterative
A= , (2.2)
B 0 methods: such as the General Minimum Residual
where Method (GMRES) [4] and the Biconjugate
[ ] gradient stabilized method (BICGSTAB) [5]. For
A1 0 both methods, the preconditioning techniques are
A= , (2.3)
0 A2 important for the Navier-Stokes equations. The
and B = [B1 B2 ]. preconditioner P is a matrix which approximates
A in some yet-undefined sense. It is obvious that
The right hand side b = [f1 , f2 , 0]T . The the linear system
discretized linear system Ax = b is the major
system we focus on. Notice here the matrix A is P −1 Ax = P −1 b (2.4)
a large sparse matrix. Therefore the computation has the same solution as
involving the matrix A should always consider the
sparsity and use sparse operations. Ax = b . (2.5)
211
Liu et al.; JSRR, 7(3), 207-217, 2015; Article no.JSRR.2015.202
212
Liu et al.; JSRR, 7(3), 207-217, 2015; Article no.JSRR.2015.202
213
Liu et al.; JSRR, 7(3), 207-217, 2015; Article no.JSRR.2015.202
Figure 5 shows the convergence curves for 1. The length of the codes are similar. Both
those three preconditioned GMRES methods. Matlab and Python are script languages.
They are easy to use and easy to
We did a few numerical experiments using Matlab implement.
and Python. The performance of both languages
2. Both Matlab and Python can obtain
are quite close.
the images of the solutions, plot the
214
Liu et al.; JSRR, 7(3), 207-217, 2015; Article no.JSRR.2015.202
Figure 5: Sample Output: GMRES iteration convergence for the Driven Cavity
Problem
eigenvalues, velocity streamlines etc. cpu time for both languages. The CPU
3. The speed are also similar. Here is time for Python is higher than the CPU
the comparison. We run the 2D Oseen time in Matlab. The reason is due to
problem with constant wind using Matlab the optimization of the sparsity operations
and Python on the same computer. We in Matlab. We currently are working
used HSS preconditioning technique with on improving the sparsity operations in
GMRES iterations. Table 2 shows the Python too.
215
Liu et al.; JSRR, 7(3), 207-217, 2015; Article no.JSRR.2015.202
Table 2: CPU time for the 2D Oseen problem with constant wind
Matrix Size Matlab CPU time Python CPU time
40 × 40 0.029 0.05
176 × 176 0.13 0.45
736 × 736 2.69 36.8
3008 × 3008 83 119
216
Liu et al.; JSRR, 7(3), 207-217, 2015; Article no.JSRR.2015.202
———————————————————————————————————————————————-
⃝2015
c Liu et al.; This is an Open Access article distributed under the terms of the Creative Commons Attribution
License http://creativecommons.org/licenses/by/4.0, which permits unrestricted use, distribution, and reproduction
in any medium, provided the original work is properly cited.
Peer-review history:
The peer review history for this paper can be accessed here (Please copy paste the total link in your browser
address bar)
www.sciencedomain.org/review-history.php?iid=1127&id=22&aid=9129
217