范学良的科学网博客分享 http://blog.sciencenet.cn/u/fanxueliang

博文

2维瞬态导热

已有 1927 次阅读 2016-2-15 14:13 |个人分类:science|系统分类:科研笔记| Python

import numpy as np

import pylab as pl

dx = 0.01 # Step size in x-direction

dy = 0.01 # Step size in y-direction

nx = int(1/dx) # Number of bins over the x-axis

ny = int(1/dy) # Number of bins over the y-axis

a=1 # diffusion coefficient

dt=(dx*dy)**2/(dx**2+dy**2)/2/a/2

total_time=200000


# Compute the distance of (x, y) from (0.5, 0.5)

def dist(x,y): return np.sqrt((x-0.5)**2 + (y-0.5)**2)


# Initialize unow and u as zero matrices

un = np.zeros([nx,ny])

u = np.zeros([nx,ny])


# Store the initial condition in unow

for i in range(nx):

 for j in range(ny):

    if dist(i*dx,j*dy)<=0.1:

       un[i,j] = 1


for k in range(total_time):

 u[1:-1,1:-1]=un[1:-1,1:-1]+dt*a*(

 (un[2:,1:-1]-2*un[1:-1,1:-1]+un[:-2,1:-1])/dx/dx+

 (un[1:-1,2:]-2*un[1:-1,1:-1]+un[1:-1,:-2])/dy/dy)


 un=u


pl.imshow(un,cmap='hot')

pl.colorbar()

pl.axis('off')

pl.title(str(total_time)+'steps'+'='+str(total_time*dt)+'s')





https://blog.sciencenet.cn/blog-373659-956294.html

上一篇:NO TITLE
下一篇:今天天气不错的,很有些秋高气爽的味道了。
收藏 IP: 117.83.15.*| 热度|

1 王安良

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-20 09:50

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部