12步解N-S方程之第一步

12 steps to Navier-Stokes

12步解N-S方程

本系列教程是美国Prof. Lorena教授的网络教程。学习的前提是你有偏微分方程、计算流体力学以及Python的基础知识。

先看一个完成学习后所编程序执行后Cavity flow的数值解 :

214422_yQCM_2001999.png

Cavity flow solution at Reynolds number of 200 with a 41x41 mesh.

214637_7RA9_2001999.jpg

     Python源代码:

    

# -*- coding: utf-8 -*-
#This is step 1 of python cfd courses.
#Text and code provided under a Creative Commons Attribution license, CC-BY
#. (c) Lorena A. Barba, 2013. Thanks: Gilbert Forsyth for help writing the
#notebooks. NSF for support via CAREER award #1149784.
#
# date         author              description
# 2014/08/31   wubin               1-d linear convection
#
#    pu/pt+c*pu/px=0
#  a little equation can teach us so much!!!!
#
import numpy as np
import matplotlib.pyplot as plt
import time,sys                         #load some system utilities
from IPython.core.display import clear_output  #used for inline animation
#
#gridgen part
nx=41
dx=2.0/(nx-1)
nt=25          #total timesteps,like iterations
dt=0.025      #
c=1.0          #assume wavespeed is 1.0
#
#initialize part
#give every nx vertex a initial value
u=np.ones(nx)
u[0.5/dx:1.0/dx+1]=2  #slice only 1.0/dx,but not 1.0/dx+1
#print u
#
#plt.figure()
#plt.plot(np.linspace(0,2,nx),u)
#plt.show()
u0=np.empty_like(u)
u0=u.copy()
#
#iteration part
un=np.ones(nx)  #un is a temporary array
#python's array begins from 0,but why not slice the first element?because in
#iteration ,there is a Ui-1,0-1 is -1,will out of a array bounds.
for n in range(nt):
un=u.copy()   #copy the intial values from u to un
for i in range(1,nx):
u[i]=un[i]-c*dt/dx*(un[i]-un[i-1])
plt.figure()
xc=np.linspace(0,2,nx)
plt.plot(xc,u,linewidth=2.0,label="converged")
plt.plot(xc,u0,linewidth=2.0,label="initial")
plt.legend(loc='upper right')
plt.savefig("F:\PYTHON\python_cfd\comparision.png",dpi=150)
plt.show()

运行结果如下图所示。

214423_RCpV_2001999.png


转载于:https://my.oschina.net/cfdvalidation/blog/308374

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值