吾生有涯 学海无涯
析模有界 知识无界

Julia CFD|12 二维泊松方程

内容纲要

Poisson方程的表达式为:

与Laplace方程不同,Poisson方程带有源项。

1 方程离散

Poisson的离散方式与Laplace方程类似:

改成迭代式形式为:

2 初始值与边界值

假设计算区域初始条件下。四个边界上

对于源项,其值为:

3 计算代码

using PyPlot
matplotlib.use("TkAgg")

nx = 50
ny = 50
nt = 100
xmin = 0
xmax = 2
ymin = 0
ymax = 1

dx = (xmax - xmin) / (nx - 1)
dy = (ymax - ymin) / (ny - 1)


# 初始化
p = zeros((ny, nx));
b = zeros((ny, nx));
x = range(xmin, xmax, length = nx);
y = range(xmin, xmax, length = ny);

# 源项
b[floor(Int, ny / 4), floor(Int, nx / 4)] = 100;
b[floor(Int, 3 * ny / 4), floor(Int, 3 * nx / 4)] = -100;

function plot2D(x, y, p)
fig = PyPlot.figure(figsize=(11,7), dpi=100)
ss = PyPlot.surf(x,y,p, rstride=1, cstride=1, cmap=ColorMap("coolwarm"),
linewidth=0)
xlim(0,2)
ylim(0,1)
PyPlot.show()
end

查看初始值分布。

plot2D(x,y,p)

初始分布如下图所示。

迭代计算代码如下。

for it in 1:nt
pd = copy(p)
p[2:end-1,2:end-1] = ((pd[2:end-1,3:end] + pd[2:end-1,1:end-2])*dy^2 +
(pd[3:end,2:end-1]+pd[1:end-2,2:end-1])*dx^2 -b[2:end-1,2:end-1]*dx^2*dy^2)/(2*(dx^2+dy^2))

p[1,:] .= 0
p[ny,:] .= 0
p[:,1] .= 0
p[:,nx] .= 0
end

计算结果如下图所示。


完整代码如下。

using PyPlot
matplotlib.use("TkAgg")

nx = 50
ny = 50
nt = 100
xmin = 0
xmax = 2
ymin = 0
ymax = 1

dx = (xmax - xmin) / (nx - 1)
dy = (ymax - ymin) / (ny - 1)

# 初始化
p = zeros((ny, nx));
b = zeros((ny, nx));
x = range(xmin, xmax, length = nx);
y = range(xmin, xmax, length = ny);

# 源项
b[floor(Int, ny / 4), floor(Int, nx / 4)] = 100;
b[floor(Int, 3 * ny / 4), floor(Int, 3 * nx / 4)] = -100;
plot2D(x, y, p)

for it in 1:nt
pd = copy(p)
p[2:end-1,2:end-1] = ((pd[2:end-1,3:end] + pd[2:end-1,1:end-2])*dy^2 +
(pd[3:end,2:end-1]+pd[1:end-2,2:end-1])*dx^2 -b[2:end-1,2:end-1]*dx^2*dy^2)/(2*(dx^2+dy^2))

p[1,:] .= 0
p[ny,:] .= 0
p[:,1] .= 0
p[:,nx] .= 0
end

function plot2D(x, y, p)
fig = PyPlot.figure(figsize=(11,7), dpi=100)
ss = PyPlot.surf(x,y,p, rstride=1, cstride=1, cmap=ColorMap("coolwarm"),
linewidth=0)
xlim(0,2)
ylim(0,1)
PyPlot.show()
end

plot2D(x, y, p)

本篇文章来源于微信公众号: CFD之道

赞(0) 打赏
版权声明:未经允许,请勿随意用于商业用途。
文章名称:《Julia CFD|12 二维泊松方程》
文章链接:https://www.topcfd.cn/12745/
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。
分享到

说两句 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者吧

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

登录

找回密码

注册