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

Smith, Barry F. bsmith at mcs.anl.gov
Thu Jul 25 20:05:31 CDT 2019

   The PETSc paradigm for this is 

    DMView(dm, viewer);   /* save mesh info 

    Which has basic variants

   DMView(dm, viewer);   /* save mesh info 



   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.)


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.

More information about the petsc-dev mailing list