[petsc-dev] What's the easiest route (for a beginner) to visualize a solution from a PETSc example?

Stefano Zampini stefano.zampini at gmail.com
Fri Jul 26 06:39:48 CDT 2019


When using a DM, we can also visualize meshes (DMDA, DMPLEX) and vectors defined on them with GLVIS https://glvis.org/ <https://glvis.org/>, which I find quite useful for quick debugging.

It popups an X window and uses OpenGL for interactive visualization. It needs the GLVis server up and running. Users of PETSc can configure with --download-glvis

Once configure, in a separate terminal, run
$ $PETSC_DIR/$PETSC_ARCH/bin/glvis # GLVIS server

In a simulation, one can then do (provided vectors have been obtained from a DM)

$ ./mytsapp -vec_view glvis # visualize time evolution of the solution

$./mysnesapp -snes_monitor_residual # visualize residual at each nonlinear iteration on a grid

$ ./mydmapp -dm_view glvis # visualize the mesh


Data can also be dumped (ASCII only, this is a limitation of GLVis) and visualized later with either GLVis itself or VisIt.

Attached the screenshot of the popup window for

$ cd src/dm/impls/plex/examples/tests
$ ./ex1 -filename ${PETSC_DIR}/share/petsc/datafiles/meshes/surfacesphere_bin.msh -dm_plex_gmsh_spacedim 3 -dm_view glvis




> On Jul 26, 2019, at 4:05 AM, Smith, Barry F. via petsc-dev <petsc-dev at mcs.anl.gov> wrote:
> 
> 
>   The PETSc paradigm for this is 
> 
>    DMView(dm, viewer);   /* save mesh info 
>    VecView(vec,viewer);   
> 
>    Which has basic variants
> 
>   DMView(dm, viewer);   /* save mesh info 
>   VecView(vec,viewer);   
>   VecView(vec,viewer);   
>   ...
> 
>   and
> 
>    VecView(vec,viewer);   
>    ...
> 
>   User simply changes the viewer to select a large variety of viewers (from X to Visit: in theory). Of course in the introductory tutorial it will be a "simple" viewer but it is important to still have the flexible usage because the user must learn the correct paradigm and how trivial it is to switch viewers (in theory but not neccessarily in practice yet). 
> 
>   Since the vec knows about the associated DM, passing the DM separately should be optional
> 
> 1)    We don't support this paradigm completely consistently/properly for all viewers/dm combinations (we should)
> 
> 2)    For some combinations we have additional functionality to make it easier to manage the relationship between the mesh and the vector
>       a) For example with the Matlab binary viewer and and DA it 
>             i) saves  the DA object (dof, dimensions, periodicity information, ...) as a Matlab struct so it can be easily be manipulated in 
>               Matlab. But there is no such saving for loading into Python. 
>            ii) saves a .info file that users can use with PetscBinaryBinaryReadMatlab.m that automatically reshapes the vector as a Matlab 
>                multi-dimensional array of the appropriate shape. Nothing similar for Python
>        b) for DA vectors and binary and ASCII viewers it automatically calls DAGlobalToNatural() so the user is given the vector in the "right ordering"
>        c) In theory much of this could could be used for viewing from Matlab with the Matlab engine, regular binary files, HDF matlab format files and 
>             sockets, but the plumbing is not set up. Also python
> 
>  3)   What to do once the data is "in the visualizer", for example sample python scripts, Matlab scripts, Visit directions, .... We totally lack the 
>         directions and the scripts.
> 
>  So maybe there are at least two tasks (issues?) that come with this question 
> 
> I) make the paradigm more uniform and add the functionality needed to the viewers for for more combinations.
> 
> II) add scripts and documentation for the usage.
> 
>  For the beginner example I would use DMDA with 
>     a) binary viewer for Python (plus needed utilities for reshaping automatically like Matlab) and displaying and 
>     b) matlab binary viewer for Matlab with script to show plotting
> 
>  For DMPLEX we need something similar (same paradigm) but with some mesh loader and etc. I would only do this for Python (and just have docs saying it is possible for Matlab but the mesh loaders/displayers have to be written.)
> 
> 
>  Barry
> 
> A related note. For users not using a DM, the viewer defaults to a simple 1d output of the vectors. For users of their own mesh data structure (DMSHELL) they would be provide a viewer with DMShellSetView() (doesn't exist yet, but should) and if they need to also manipulate the vector in the viewer they would use VecSetOperation(VECOP_VIEW = 33, VECOP_LOAD = 41). This is an more advanced topic.
> 
> 
> 
> 
> 
> 
> 
> 
>> On Jul 25, 2019, at 11:48 AM, Jed Brown via petsc-dev <petsc-dev at mcs.anl.gov> wrote:
>> 
>> Dave May via petsc-dev <petsc-dev at mcs.anl.gov> writes:
>> 
>>> I'd describe how to use the binary dump and how to generate vtk files.
>>> 
>>> The first is the most universal as it's completely generic and does not
>>> depend on a dm, thus users with their own mesh data structure and or don't
>>> have a mesh at all can use it. Would be worth while also providing a
>>> minimal python+mathplotlib script which loads the data and spits out a PDF
>>> so folks don't have to depend on matlab.
>> 
>> If you have a parallel example that doesn't use DM, you're gonna have a
>> lot of bookkeeping to plot the data after loading the vector.  Seems
>> like a distraction that will trap a lot of people in the minutia instead
>> of the big picture.
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20190726/8b9a7cca/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2019-07-26 at 2.36.30 PM.png
Type: image/png
Size: 124319 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20190726/8b9a7cca/attachment-0001.png>


More information about the petsc-dev mailing list