Skip to content

mayaviFoam: A postprocessing script for OpenFOAM

April 21, 2011

mayaviFoam:

Hi, I have created a Postprocessing script called mayaviFoam. It is the a reader module to run with Mayavi2, an open-source, visualization application. It will convert OpenFOAM natural data format into VTK data format and the VTK data is loaded into Mayavi2 using VTKFileReader.

#!/usr/bin/env mayavi2

import os
import glob
from os.path import join, abspath, dirname
from enthought.mayavi.scripts import mayavi2
from enthought.mayavi.sources.vtk_file_reader import VTKFileReader
from enthought.mayavi.modules.surface import Surface

def setup_data(fname):
    """Given a VTK file name `fname`, this creates a mayavi2
    reader for it and adds it to the pipeline.  It returns the reader
    created.
    """
    r = VTKFileReader()
    r.initialize(fname)
    mayavi.add_source(r)
    return r

def surface():
    """Sets up the mayavi pipeline for the visualization.
    """
    # Create an outline for the data.
    s = Surface()
    mayavi.add_module(s)

def load_vtk_file():
    mayavi.new_scene()
    filepath = glob.glob("VTK/*_0.vtk")
    vtk_file_name = os.path.basename(filepath[0])
    data_dir = "VTK"
    fname = join(data_dir, vtk_file_name)
    r = setup_data(fname)
    surface()

@mayavi2.standalone
def main():
    if os.path.exists("VTK"):
        load_vtk_file()

    else:
        os.system('foamToVTK -ascii')
        load_vtk_file()

if __name__ == '__main__':
    main()

Save it as mayaviFoam.py

Procedure:

Open your terminal
1.

cd openfoam_tutorials/multiphase/interFoam/laminar/damBreak

2.

blockMesh

3.

setFields

4. Refere here

python dambreak.py

5.

python mayaviFoam.py

See the output like below

2 Comments leave one →
  1. September 22, 2011 7:43 am

    Very funny pictures Cp Paysite %P

  2. September 25, 2011 1:21 pm

    This is the job description Nn Child Model 0840

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: