[vtkusers] Help with vtkOpenFOAMReader and extraction

Takuya OSHIMA oshima at eng.niigata-u.ac.jp
Mon Feb 7 20:30:43 EST 2011


Hi Sandro,

Could you be a bit more specific about "What I get for output has
nothing to do with reality"? I tried your code and at least got a
correct display of the geometry (hence I don't think there is anything
fundamentally wrong with your code).

In the meantime, I attached a simple code that picks up a field
specified in the command line, colors geometry by the field and loops
over time. It's simple because I am not much of a Python guy but
hopefully it may be of some help to what your are trying to do.

Takuya

Takuya OSHIMA, Ph.D.
Faculty of Engineering, Niigata University
8050 Ikarashi-Ninocho, Nishi-ku, Niigata, 950-2181, JAPAN

From: Sandro Grm <sandro at c3m.si>
Subject: [vtkusers] Help with vtkOpenFOAMReader and extraction
Date: Fri, 04 Feb 2011 08:34:02 +0100

> Dear,
>         
>         I started to use vtk (python interface) last week. I was not
>         able to
>         find any example how work with vtkOpenFOAMReader. I'm able to
>         obtain
>         vtkMultiBlockDataSet, next I extract a block which is of
>         vtkUnstructuredGrid type, but from there I was not able to
>         extract
>         single data set, for example scalar (pressure "p"), or vector
>         (velocity
>         "U")  to render or anyhow other manipulate those data.
>         
>         Please can someone give me a hint how to do it.
>         
>         Thanks + Best, Sandro. 
>         
>         My python code is:
>         
>         # -*- coding: utf-8 -*-
>         import os
>         import vtk as vtk
>         import numpy as np
>         import scipy as sp
>         import math
>         
>         rootDir = "thermoViscoPlasticFoam"
>         fileName = rootDir + "/system/controlDict"
>         
>         reader = vtk.vtkOpenFOAMReader()
>         reader.SetFileName(fileName)
>         reader.CreateCellToPointOn()
>         reader.DecomposePolyhedraOn()
>         reader.Update()
>         
>         # this print is listed at the bottom
>         print str(reader.GetOutput())
>         
>         # extract first time interval data set
>         ug = reader.GetOutput().GetBlock(0)
>         
>         # saw in same examples, but do not understand the point
>         compositeFilter = vtk.vtkCompositeDataGeometryFilter()
>         compositeFilter.SetInputConnection(reader.GetOutputPort())
>         compositeFilter.Update()
>         
>         # here is my question, how to see which data set is inside and 
>         # how to extract them for further use (render, cut plain, ...)
>         
>         # mapper
>         mapper = vtk.vtkPolyDataMapper()
>         mapper.SetInputConnection(compositeFilter.GetOutputPort())
>         
>         # plot to screen
>         actor = vtk.vtkActor()
>         actor.SetMapper(mapper)
>         
>         renderer = vtk.vtkRenderer()
>         renderer.AddActor(actor)
>         
>         renWin = vtk.vtkRenderWindow()
>         renWin.AddRenderer(renderer)
>         
>         iren = vtk.vtkRenderWindowInteractor();
>         iren.SetRenderWindow(renWin);
>         
>         renWin.SetSize(850, 850)
>         renWin.Render()
>         iren.Start();
>         
>         
>         What I get for output has nothing to do with reality. 
>         
>         
>         
>         And the reader.GetOutput print:
>         
>         vtkMultiBlockDataSet (0x18f5310)
>           Debug: Off
>           Modified Time: 396
>           Reference Count: 2
>           Registered Events: (none)
>           Source: (none)
>           Information: 0x18ec270
>           Data Released: False
>           Global Release Data: Off
>           UpdateTime: 403
>           Release Data: Off
>           UpdateExtent: Not Initialized
>           Update Number Of Pieces: 1
>           Update Piece: 0
>           Update Ghost Level: 0
>           MaximumNumberOfPieces: -1
>           RequestExactExtent: Off
>            Field Data:
>             Debug: Off
>             Modified Time: 152
>             Reference Count: 1
>             Registered Events: (none)
>             Number Of Arrays: 1
>             Array 0 name = CasePath
>             Number Of Components: 1
>             Number Of Tuples: 24
>           Number Of Children: 1
>           Child 0: vtkUnstructuredGrid
>             Debug: Off
>             Modified Time: 390
>             Reference Count: 2
>             Registered Events: (none)
>             Source: (none)
>             Information: 0x1a330a0
>             Data Released: False
>             Global Release Data: Off
>             UpdateTime: 0
>             Field Data:
>               Debug: Off
>               Modified Time: 174
>               Reference Count: 1
>               Registered Events: (none)
>               Number Of Arrays: 0
>               Number Of Components: 0
>               Number Of Tuples: 0
>             Number Of Points: 25586
>             Number Of Cells: 24800
>             Cell Data:
>               Debug: Off
>               Modified Time: 374
>               Reference Count: 1
>               Registered Events: (none)
>               Number Of Arrays: 6
>               Array 0 name = Sr
>               Array 1 name = T
>               Array 2 name = U
>               Array 3 name = magGradU
>               Array 4 name = nu
>               Array 5 name = p
>               Number Of Components: 8
>               Number Of Tuples: 24800
>               Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
>               Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
>               Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
>               Scalars: 
>                 Debug: Off
>                 Modified Time: 371
>                 Reference Count: 1
>                 Registered Events: (none)
>                 Name: p
>                 Data type: float
>                 Size: 24800
>                 MaxId: 24799
>                 NumberOfComponents: 1
>                 Information: 0
>                 Name: p
>                 Number Of Components: 1
>                 Number Of Tuples: 24800
>                 Size: 24800
>                 MaxId: 24799
>                 LookupTable: (none)
>                 Array: 0x1eb0c40
>               Vectors: 
>                 Debug: Off
>                 Modified Time: 296
>                 Reference Count: 1
>                 Registered Events: (none)
>                 Name: U
>                 Data type: float
>                 Size: 74400
>                 MaxId: 74399
>                 NumberOfComponents: 3
>                 Information: 0
>                 Name: U
>                 Number Of Components: 3
>                 Number Of Tuples: 24800
>                 Size: 74400
>                 MaxId: 74399
>                 LookupTable: (none)
>                 Array: 0x1debef0
>               Normals: (none)
>               TCoords: (none)
>               Tensors: (none)
>               GlobalIds: (none)
>               PedigreeIds: (none)
>               EdgeFlag: (none)
>             Point Data:
>               Debug: Off
>               Modified Time: 390
>               Reference Count: 1
>               Registered Events: (none)
>               Number Of Arrays: 6
>               Array 0 name = Sr
>               Array 1 name = T
>               Array 2 name = U
>               Array 3 name = magGradU
>               Array 4 name = nu
>               Array 5 name = p
>               Number Of Components: 8
>               Number Of Tuples: 25586
>               Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
>               Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
>               Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
>               Scalars: 
>                 Debug: Off
>                 Modified Time: 387
>                 Reference Count: 1
>                 Registered Events: (none)
>                 Name: p
>                 Data type: float
>                 Size: 25586
>                 MaxId: 25585
>                 NumberOfComponents: 1
>                 Information: 0
>                 Name: p
>                 Number Of Components: 1
>                 Number Of Tuples: 25586
>                 Size: 25586
>                 MaxId: 25585
>                 LookupTable: (none)
>                 Array: 0x1ec8fd0
>               Vectors: 
>                 Debug: Off
>                 Modified Time: 322
>                 Reference Count: 1
>                 Registered Events: (none)
>                 Name: U
>                 Data type: float
>                 Size: 76758
>                 MaxId: 76757
>                 NumberOfComponents: 3
>                 Information: 0
>                 Name: U
>                 Number Of Components: 3
>                 Number Of Tuples: 25586
>                 Size: 76758
>                 MaxId: 76757
>                 LookupTable: (none)
>                 Array: 0x1e34980
>               Normals: (none)
>               TCoords: (none)
>               Tensors: (none)
>               GlobalIds: (none)
>               PedigreeIds: (none)
>               EdgeFlag: (none)
>             Bounds: 
>               Xmin,Xmax: (0, 0.61)
>               Ymin,Ymax: (0, 0.29)
>               Zmin,Zmax: (-0.0101496, 0.0151496)
>             Compute Time: 421
>             Number Of Points: 25586
>             Point Coordinates: 0x17cae20
>             Locator: 0
>             Number Of Pieces: 1
>             Piece: -1
>             Ghost Level: 0
>         
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkPythonExample1.py
Type: application/octet-stream
Size: 4423 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110208/20c0253f/attachment.obj>


More information about the vtkusers mailing list