On Thu, Jul 7, 2011 at 5:12 PM, Ethan Coon <span dir="ltr"><<a href="mailto:ecoon@lanl.gov">ecoon@lanl.gov</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hmm, I've been tricked apparently. What I thought was PETSc writing out<br>
VTK was actually PFLOTRAN writing out VTK from PETSc data structures.<br></blockquote><div><br></div><div>PETSc will write out VTK if you</div><div><br></div><div> a) set the PETSC_VIEWER_ASCII_VTK format</div><div><br>
</div><div> b) view the DA first and then Vecs</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
On a day-to-day basis I tend to use HDF5, and I've checked that that<br>
does, in fact, work with only PETSc, and only a few lines of PETSc.<br>
Follow/run example:<br>
<br>
<a href="http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-current/src/dm/da/examples/tutorials/ex9.c.html" target="_blank">http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-current/src/dm/da/examples/tutorials/ex9.c.html</a><br>
<br>
Then load that in python with h5py and view with matplotlib:<br>
<br>
In [1]: import h5py<br>
<br>
In [2]: ex9 = h5py.File('hdf5output')<br>
<br>
In [3]: ex9<br>
Out[3]: <HDF5 file "hdf5output" (mode r+, 142.7k)><br>
<br>
In [4]: ex9.keys()<br>
Out[4]: ['Vec_0x84000000_0']<br>
<br>
In [5]: vec = ex9[ex9.keys()[0]]<br>
<br>
In [6]: vec<br>
Out[6]: <HDF5 dataset "Vec_0x84000000_0": shape (90, 100, 2), type<br>
"<f8"><br>
<br>
In [7]: vec.shape # vec was created from a 2D DA, size (90,100), with 2 dofs<br>
Out[7]: (90, 100, 2)<br>
<br>
In [8]: from matplotlib import pyplot as plt<br>
<br>
In [9]: plt.imshow(vec[:,:,0].transpose(), origin='lower')<br>
Out[9]: <matplotlib.image.AxesImage object at 0x2310850><br>
<br>
In [10]: plt.colorbar()<br>
Out[10]: <matplotlib.colorbar.Colorbar instance at 0x2313320><br>
<br>
In [11]: plt.show()<br>
<br>
<br>
The downside of this option is that, in order for hdf5 files to work in<br>
anything but python (which is smart enough to use introspection on the<br>
file itself) you need a special viewer (the VisIt people call this a<br>
"flavor" of HDF5), see<br>
<br>
<a href="http://visitusers.org/index.php?title=VisIt_and_HDF5" target="_blank">http://visitusers.org/index.php?title=VisIt_and_HDF5</a><br>
<br>
These work on both VisIt and Paraview, but I've never tried to write one<br>
myself, so I don't know how ugly they are. They basically specify the<br>
layout of the hdf5 file.<br>
<br>
Note that if you go with the HDF5 option, you'll likely want to move to<br>
petsc-dev, which includes more HDF5 functionality, such as groups.<br>
<font color="#888888"><br>
Ethan<br>
</font><div><div></div><div class="h5"><br>
<br>
On Thu, 2011-07-07 at 08:21 -0600, Andrew T Barker wrote:<br>
> > Should PETSc ship some Python code to<br>
> > read IS's, Vec's, Mat's in binary format?<br>
><br>
> Yes. Please.<br>
><br>
> I have played with matplotlib some to view Petsc output (vtk), with mixed results. I wonder if Ethan would be willing to share an example or two?<br>
><br>
> Best,<br>
><br>
> Andrew<br>
<br>
</div></div><div><div></div><div class="h5">--<br>
------------------------------------<br>
Ethan Coon<br>
Post-Doctoral Researcher<br>
Applied Mathematics - T-5<br>
Los Alamos National Laboratory<br>
<a href="tel:505-665-8289" value="+15056658289">505-665-8289</a><br>
<br>
<a href="http://www.ldeo.columbia.edu/~ecoon/" target="_blank">http://www.ldeo.columbia.edu/~ecoon/</a><br>
------------------------------------<br>
<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<br>