Discussion:
[vtkusers] vtkExodusIIReader/Writer examples in Python
Meehan, Bernard
2013-11-13 22:49:01 UTC
Permalink
Hi – does anyone have Python examples of how to use vtkExodusIIReader/Writer other than the ones in the documentation?
(namely, TestContourGrid.py)

Thanks,
Tim
David Thompson
2013-11-14 14:47:15 UTC
Permalink
Hi Tim,
... does anyone have Python examples of how to use vtkExodusIIReader/Writer other than the ones in the documentation? (namely, TestContourGrid.py)
Not using both together, but attached is a simple reader example that fetches some data and computes order statistics (quantiles) on one array. You'll have to edit the "SetFileName" line to point to a checkout of the ParaViewData directory. Was there some particular feature you are having trouble with?

David
Meehan, Bernard
2013-11-14 16:12:21 UTC
Permalink
Hi David - that is a cool example, a couple of things that I hadn't even
known existed in the toolkit.

The datasets that I have contain two features that I would like to get at
- global information, like total energy input, total kinetic energy, etc.,
that I would like to be able to graph, and then unstructured blocks
hexahedrons with point and cell data that I would like to (for example) be
able to probe with a plane. I have looked at the files with 'ncdump' but
wasn't sure how the various structures end up the vtkExodusIIReader
object. I could have the wrong idea about Exodus II files as well - my
understanding of the format does not go much past "they end in .exo"

I think I have a good-ish idea of what should be in the file, just not so
good of an idea of how to get it and plot it, etc. If I were to have a
wish list of things for examples it might read something like:

Print out the list of global information (like 'EKIN', the kinetic
energy), select one and plot it in 2D.

Print out a list of the node or cell information (like 'DENSITY'), and
plot it in 3D.

Thanks again for the example, I'm going to have to tinker with it a bit
and learn about other uses I could have for vtkTable and
vtkOrderStatistics.

Cheers,
Tim
Post by David Thompson
Hi Tim,
... does anyone have Python examples of how to use
vtkExodusIIReader/Writer other than the ones in the documentation?
(namely, TestContourGrid.py)
Not using both together, but attached is a simple reader example that
fetches some data and computes order statistics (quantiles) on one array.
You'll have to edit the "SetFileName" line to point to a checkout of the
ParaViewData directory. Was there some particular feature you are having
trouble with?
David
A***@csiro.au
2013-11-15 03:35:50 UTC
Permalink
Hi Tim,

See my code below. My code was checking that the exodusIIWriter eliminates all side-set (etc) information if you pass it a multiblock VTK. (If you pass it an exodus it does the correct thing.)

Code snippet:

# Read filename exo_with_ss
r_ss = vtk.vtkExodusIIReader()
r_ss.SetFileName(exo_with_ss)
r_ss.GenerateGlobalNodeIdArrayOn()
r_ss.GenerateGlobalElementIdArrayOn()
r_ss.ExodusModelMetadataOn()
r_ss.UpdateInformation()
# ensure that sidesets are actually loaded, since by default they're not
for ss_id in range(r_ss.GetNumberOfSideSetArrays()):
r_ss.SetSideSetArrayStatus(r_ss.GetSideSetArrayName(ss_id), 1)

# translate the exodus information to multiblock vtk
r_ss.Update()
r_ss = r_ss.GetOutput()

# print some information
for i in range(r_ss.GetNumberOfBlocks()):
blk = r_ss.GetBlock(i)
if blk.GetNumberOfBlocks() > 0:
print " " + r_ss.GetMetaData(i).Get(vtk.vtkCompositeDataSet.NAME())
for j in range(blk.GetNumberOfBlocks()):
print " " + blk.GetMetaData(j).Get(vtk.vtkCompositeDataSet.NAME())

# write an exodus file
writer = vtk.vtkExodusIIWriter()
writer.SetFileName(output_file)
writer.SetInputConnection(r_ss.GetProducerPort())
writer.Write()


Ph: +61 7 3327 4497. Fax: +61 7 3327 4666
Queensland Centre for Advanced Technologies
PO Box 883, Kenmore, Qld, 4069

From: vtkusers-***@vtk.org [mailto:vtkusers-***@vtk.org] On Behalf Of Meehan, Bernard
Sent: Thursday, 14 November 2013 8:49 AM
To: ***@vtk.org
Subject: [vtkusers] vtkExodusIIReader/Writer examples in Python

Hi - does anyone have Python examples of how to use vtkExodusIIReader/Writer other than the ones in the documentation?
(namely, TestContourGrid.py)

Thanks,
Tim
David Thompson
2013-11-15 13:50:46 UTC
Permalink
... The datasets that I have contain two features that I would like to get at
- global information, like total energy input, total kinetic energy, etc.,
that I would like to be able to graph,
Those will be read if you add:

rdr.SetAllArrayStatus(rdr.GLOBAL,1)

to the script.
and then unstructured blocks
hexahedrons with point and cell data that I would like to (for example) be
able to probe with a plane. I have looked at the files with 'ncdump' but
wasn't sure how the various structures end up the vtkExodusIIReader
object. I could have the wrong idea about Exodus II files as well - my
understanding of the format does not go much past "they end in .exo"
There is manual for the Exodus library API that includes some information about storage conventions on the SourceForge page:
http://sourceforge.net/projects/exodusii/files/Documentation/Documentation/
I think I have a good-ish idea of what should be in the file, just not so
good of an idea of how to get it and plot it, etc. If I were to have a
Print out the list of global information (like 'EKIN', the kinetic
energy), select one and plot it in 2D.
You might look at using the vtkExtractArraysOverTime filter to get a time series of global information, but I am not sure how fast that will be. The ExodusIIReader has a mechanism called "FastPath" (you'll see it in the reader's documentation) that will extract one point- or cell-value over time, but I don't think it works for global variables -- so the reader may have to cycle through all the time steps manually to extract it.
Print out a list of the node or cell information (like 'DENSITY'), and
plot it in 3D.
I'm not sure what you mean by "plot it in 3-D" means... do you mean color the mesh with the variable? Or a 3-D scatter plot? There should by python examples on the VTK wiki that deal with the former. The latter is possible but not terribly straightforward.

You can list the node and cell variables for any dataset like so:

ugrid = rdr.GetOutput().GetBlock(0).GetBlock(0)
print 'Point Data:'
fields = ugrid.GetPointData()
for i in range(fields.GetNumberOfArrays()):
print ' ' + fields.GetAbstractArray(i).GetName()
print 'Cell Data:'
fields = ugrid.GetCellData()
for i in range(fields.GetNumberOfArrays()):
print ' ' + fields.GetAbstractArray(i).GetName()

David
Post by David Thompson
Hi Tim,
... does anyone have Python examples of how to use
vtkExodusIIReader/Writer other than the ones in the documentation?
(namely, TestContourGrid.py)
Not using both together, but attached is a simple reader example that
fetches some data and computes order statistics (quantiles) on one array.
You'll have to edit the "SetFileName" line to point to a checkout of the
ParaViewData directory. Was there some particular feature you are having
trouble with?
David
Loading...