当我知道速度的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?

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

问题描述

我希望标题本身很清楚,我正在使用分数阶跃方法,有限差分公式(Navier-Stokes基本变量形式)解决2D盖驱动腔(方域)问题,我已经获得了u和v分量整个域的速度,而无需手动计算流线,是否有命令或绘图工具对我有用?

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.

我已经解决了流涡NS形式的相同问题,我只需要对流函数进行轮廓绘制就可以得到流线.

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.

我希望工具或绘图仪是python库,并且morevover可安装在fedora中(我可以妥协和使用mint),而不必大惊小怪!

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)

推荐答案

看看汤姆·弗兰纳汉(Tom Flannaghan)的streamplot函数.用户列表上的相关线程在这里,并且还有另一个 Ray Speth的类似代码段,它们的功能略有不同.

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.

如果您对速度有疑问,使用这两个scipy的集成功能可能会更有效,而不是这两个示例中使用的pure- numpy集成功能.不过,我还没有尝试过,这些方法故意避免了对scipy的依赖. (与numpy相比,scipy的依赖性很大)

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)

以示例图为例:

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()

另一个选择是使用VTK.它是加速的3D绘图,因此制作2D绘图将需要正确设置相机(不太难),并且您将无法获得矢量输出.

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和mlab为VTK提供pythonic包装器.这些方面有很多功能.

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

使用VTK从numpy数组绘制流线的最简单方法是使用 mayavi.mlab.flow .现在,我将跳过一个示例,但是如果您想探索使用VTK进行此操作,则可以添加一个示例.

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天全站免登陆