paraview 显示动画

From  http://meywang.wordpress.com/

接着徐辉的 帖子。这几天与徐辉、张伟讨论了PalaBos下sparse block的流场数据输出,把目前考虑的东西整理一下。

1. VTK XML格式  
VTK格式参见官方文档( http://www.vtk.org/VTK/img/file-formats.pdf)。

进一步,VTK XML分为结构/非结构,串行/并行等多种数据格式。组合起来大致如下:
•  ImageData (.vti) — Serial vtkImageData (structured).
•  PolyData (.vtp) — Serial vtkPolyData (unstructured).
•  RectilinearGrid (.vtr) — Serial vtkRectilinearGrid (structured).
•  StructuredGrid (.vts) — Serial vtkStructuredGrid (structured).
•  UnstructuredGrid (.vtu) — Serial vtkUnstructuredGrid (unstructured).
•  PImageData (.pvti) — Parallel vtkImageData (structured).
•  PPolyData (.pvtp) — Parallel vtkPolyData (unstructured).
•  PRectilinearGrid (.pvtr) — Parallel vtkRectilinearGrid (structured).
•  PStructuredGrid (.pvts) — Parallel vtkStructuredGrid (structured).
•  PUnstructuredGrid (.pvtu) — Parallel vtkUnstructuredGrid (unstructured).


2. PalaBos输出
因为LB数据结构简单,所以PalaBos默认采用ImageData。好处是文件小,I/O快。但PalaBos默认情况下并没有sparse块的输出。

首先,参考徐辉的 帖子( http://blog.sina.com.cn/s/blog_6a40fba101010hyj.html),获得每一个sparse块的信息。然后,可以采用以下几种思路实现输出,主要是采用不同的VTK XML格式。为了方便,下面以串行为例,并行可以相应处理。

(1). 将每一块输出为一个独立的vti文件,然后在ParaView里面打开,并使用GroupDataset滤镜将这些sparse块组合在一起,进行整个流场的操作。当块数太多时候,可使用Python脚本批处理。

关于ParaView的编译以及脚本使用参见张伟的帖子  http://www.cfluid.com/bbs/viewthread.php?tid=86709&extra=page=3。

(2). 将每一块都写到同一个vti文件中,作为不同的piece区分。但由于vti格式的限制,在文件头要指名wholeextent,因而显示的效果是一个大的block下面包了许多小block。对于vts也是同样情况。

(3). 使用非结构的vtp或vtu,但要描述cell的信息,因而相对麻烦,且输出文件变大不少(要存储point和cell的信息)。

(4). 使用multiBlockDataSet。类似(1),写一些独立的vts、vtp、vtu等文件,然后再写一个vtm文件把这些独立的块文件link起来。vtm格式参加 http://www.cacr.caltech.edu/~slombey/asci/vtk/ 。



另外,既然已经可以获得各个sparse块的信息,那也可以使用Tecplot和Plot3D的格式。我前面有介绍Plot3D格式的帖子。

///////////////////////////////////////////////////////////////////////////////////////////////////////

Generating VTK files with Python

Paraview is an industrial-strength, open-source 3D visualization program designed to visualize large data sets created by computational fluid dynamics (CFD) simulations. Although its native data file format (.vtu) is designed for reading in point- and cell-based data from CFD simulations, I have successfully used it to read in and visualized discrete particle data from a Brownian Dynamics (BD) simulation. Below, you can download a Python class that is useful for visualizing particles in motion. It should be easily adaptable to any type of discrete data set that involves discrete objects, vectors, and/or scalars.  In addition, this class should be useful with any application based on the VTK toolkit because they also read .vtu files.

The Python .vtu Generator

This is the first release of a Python class that writes serial, unstructured VTK files (.vtu) in XML format. Even if your application is very different, I think this class will be useful as an example of how to write valid VTK files in the new XML format. Download the class definition at GitHub.

The class is used as follows. Brownian Dynamics is a method of simulating the motion of colloidal particles in a liquid. I need to visualize the particles–where they are, where they’ve been, and what forces are acting upon them. First, I create an object (let’s call it vtk_writer). Every time I need to see what’s going on in the simulation (perhaps every 5 time steps), I call the method vtk_writer.snapshot(filename, x, y, z, …) to write out a .vtu file. The object keeps track of every .vtu file that has been written. At the end of my simulation, I call vtk_writer.writePVD(filename) which writes out a .pvd file that contains all the filenames of the .vtu files. Using Paraview, open the .pvd file, and all the .vtu files will automatically be loaded.

Reference: VTK file format documentation

Reading XML Data into Paraview

Even if you have completed all the steps correctly so far, you will see nothing in Paraview! In order to visualize something, you use a “filter.” Select your .pvd file in the Pipeline Browser, and choose Glyph from the Filter menu, or the toolbar. In the Object Inspector, chooseSphere for the Glyph Type. Set Radius to 1, Scale Mode to Scalar, and set the Scale Factor to 1. Assuming you put radii into the .vtu files, you should now have scale spheres. However, you may not be able to see them, so click on the Display tab and click the “Zoom to Data” button. Now you should see your spheres! If you have saved forces in the .vtu file, add an Arrow glyph and choose “Forces” from the “Vectors” drop-down. Now you will see the force being exerted on each sphere. Finally, create a box from the “Sources” menu and set the appropriate dimensions for your simulation area.

Creating Movies from Paraview

From the File menu, choose “Save Animation”, choose a directory, and enter a filename. Paraview will generate a .jpg image for every frame of your animation. You then need to use a third-party tool to turn the images into a movie. You can do it with ImageMagick, but I don’t recommend it if you have more than a few hundred frames. Imagemagick loads every image into RAM before creating the movie. A better way is to install mplayer (use the “encode” USE flag on the Gentoo ebuild). Then you can use the command line tool “mencoder” to create the movie much more efficiently. I had some trouble getting Windows Media Player 11 to play the movies created with mencoder. I used the following command line to create Windows-compatible mpeg movies:

 mencoder "mf://*.jpg" -of rawvideo -mpegopts format=mpeg1:tsaf:muxrate=2000 -o output.mpg
 -oac lavc -lavcopts acodec=mp2:abitrate=224 -ovc lavc
 -lavcopts vcodec=mpeg2video:vbitrate=1152:keyint=15:mbd=2:aspect=4/3

Reference: creating movies with Imagemagick


你可能感兴趣的:(paraview 显示动画)