当我知道速度的 u 和 v 分量(numpy 2d 数组)时,如何使用 Python 中的绘图程序绘制流线图? [英] how to plot streamlines , when i know u and v components of velocity(numpy 2d arrays), using a plotting program in python?

查看:39
本文介绍了当我知道速度的 u 和 v 分量(numpy 2d 数组)时,如何使用 Python 中的绘图程序绘制流线图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望标题本身很清楚,我正在使用分数步法、有限差分公式(Navier-Stokes 原始变量形式)解决 2D 盖驱动腔(方域)问题,我有 u 和 v 分量整个域的速度,无需手动计算流线,是否有命令或绘图工具可以帮我完成这项工作?

我希望这个问题与编程足够相关,因为我需要一个工具来绘制流线而不显式计算它们.

我已经以流涡度 NS 形式解决了同样的问题,我只需要获取流函数的等高线图即可获得流线.

我希望该工具或绘图仪是一个 Python 库,而且可以安装在 Fedora 中(我可以妥协并使用 mint)而不必大惊小怪!!

如果有人指出库和相关命令,我将不胜感激(会节省很多时间)

解决方案

看看 .我暂时跳过一个例子,但如果你想探索使用 VTK 来做到这一点,我可以添加一个.

i hope the title itself was quite clear , i am solving 2D lid-driven cavity(square domain) problem using fractional step method , finite difference formulation (Navier-Stokes primitive variable form) , i have got u and v components of velocity over the entire domain , without manually calculating streamlines , is there a command or plotting tool which does the job for me?

i hope this question is relevant enough to programming , as i need a tool for plotting streamlines without explicitly calculating them.

I have solved the same problem in stream-vorticity NS form , i just had to take contour plot of stream function to get the streamlines.

I hope that tool or plotter is a python library, and morevover installable in fedora (i can compromise and use mint)without much fuss!!

i would be grateful if someone points out the library and relevant command (would save a lot of time)

解决方案

Have a look at Tom Flannaghan's streamplot function. The relevant thread on the user's list is here, and there's also another similar code snippet by Ray Speth that does things slightly differently.

If you have problems with speed, it might be more efficient to use some of scipy's integration functionality instead of the pure-numpy integration functions used in both of these examples. I haven't tried it, though, and these deliberately avoid a dependency on scipy. (scipy is a rather heavy dependency compared to numpy)

From it's example plot:

import matplotlib.pyplot as plt
import numpy as np
from streamplot import streamplot

x = np.linspace(-3,3,100)
y = np.linspace(-3,3,100)
u = -1-x**2+y[:,np.newaxis]
v = 1+x-y[:,np.newaxis]**2
speed = np.sqrt(u*u + v*v)

plt.figure()
plt.subplot(121)
streamplot(x, y, u, v, density=1, INTEGRATOR='RK4', color='b')
plt.subplot(122)
streamplot(x, y, u, v, density=(1,1), INTEGRATOR='RK4', color=u,
           linewidth=5*speed/speed.max())
plt.show()

Another option is to use VTK. It's accelerated 3D plotting, so making a 2D plot will require setting the camera properly (which isn't too hard), and you won't be able to get vector output.

Mayavi, tvtk, and mlab provide pythonic wrappers for VTK. It has lots of functionality along these lines.

The easiest way to use VTK to plot streamlines from numpy arrays is to use mayavi.mlab.flow. I'll skip an example for the moment, but if you want to explore using VTK to do this, I can add one.

这篇关于当我知道速度的 u 和 v 分量(numpy 2d 数组)时,如何使用 Python 中的绘图程序绘制流线图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆