打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Julia CFD|12 二维泊松方程
userphoto

2023.10.23 四川

关注

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)
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
基于Python的CFD编程入门(8)二维伯格斯方程(2-D Burgers’ Equation)
基于Python的CFD编程入门(5)二维线性对流问题
隐函数求二阶偏导数例子
一款html5 canvas实现的图片玻璃碎片特效
图形中投影矩阵的推导
如何从零学习PostgreSQL Page结构
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服