CFD Online Logo CFD Online URL
Home > Forums > OpenFOAM Post-Processing

Visualizing OpenFOAM VTK-files using mayavi/mlab in Python

Register Blogs Members List Search Today's Posts Mark Forums Read

LinkBack Thread Tools Display Modes
Old   December 16, 2013, 10:39
Default Visualizing OpenFOAM VTK-files using mayavi/mlab in Python
New Member
Bas Nieuwboer
Join Date: Mar 2013
Posts: 6
Rep Power: 4
bjnieuwboer is on a distinguished road
Hi All,

I am trying to visualize my model results from OpenFOAM in python using mayavi/mlab. I am able to plot the surfaces of my model. However, I would like to make a quiverplot of my velocity field and a volume plot of my pressures. I found some documentation this. However, this documentation did not state anything on the combination with loaded VTK-files. The code beneath is the one I use for plotting the surfaces. Could anyone help me extend this to plotting the velocities and pressures using python?

import os
from mayavi.core.api import Engine
from mayavi.sources.vtk_file_reader import VTKFileReader
from mayavi.modules.surface import Surface
from mayavi import mlab
vtkFile_tot = os.path.normpath('D:/Bas/python/VTK/131023cutterBlended08RelVel_0.vtk')
engine = Engine()
scene = engine.new_scene()
reader = VTKFileReader()
surface = Surface()

Last edited by bjnieuwboer; December 16, 2013 at 10:40. Reason: typo in title
bjnieuwboer is offline   Reply With Quote

Old   July 30, 2014, 10:52
Default Working principle
New Member
Bas Nieuwboer
Join Date: Mar 2013
Posts: 6
Rep Power: 4
bjnieuwboer is on a distinguished road
After a while I found a way to visualise my VTK files generated by OpenFOAM using mayavi.

 import os

 # engine imports.
 from mayavi.scripts import mayavi2
 from mayavi.sources.api import VTKFileReader
 from mayavi.modules.glyph import Glyph
 from mayavi.filters.mask_points import MaskPoints
 from mayavi.core.api import Engine
 from mayavi import mlab

 # Create a new VTK scene if none is present yet
 def initializeVTK(filename):
     except NameError:
         global engine
         print 'warning is due to the check if the global variable named engine already exists'
         engine = Engine()
     if len(engine.scenes) == 0:
     r = VTKFileReader()


 # Make a mask for the points
 m = MaskPoints()
 m.filter.set(on_ratio=300, random_mode=False)
 engine.add_filter(m) # this adds the module 'm' the engine
 g = Glyph()
 engine.add_module(g) # this adds the module 'g' the engine

 g.glyph.color_mode = 'color_by_vector'
 g.glyph.scale_mode = 'scale_by_vector'
 # Use arrows to view the scalars.
 gs = g.glyph.glyph_source
 gs.glyph_source = gs.glyph_dict['arrow_source']

 f = mlab.gcf()
 f.scene.background = (1.0, 1.0, 1.0) # set background color   
bjnieuwboer is offline   Reply With Quote


mayavi, mlab, openfoam, vtk

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Superlinear speedup in OpenFOAM 13 msrinath80 OpenFOAM Running, Solving & CFD 18 March 3, 2015 06:36
64bitrhel5 OF installation instructions mirko OpenFOAM Installation 2 August 12, 2008 18:07
Adventure of fisrst openfoam installation on Ubuntu 710 jussi OpenFOAM Installation 0 April 24, 2008 14:25
OpenFOAM Debian packaging current status problems and TODOs oseen OpenFOAM Installation 9 August 26, 2007 13:50
Results saving in CFD hawk Main CFD Forum 16 July 21, 2005 20:51

All times are GMT -4. The time now is 20:31.