<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Feb 28, 2018 at 12:39 AM, Smith, Barry F. <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
  Matt,<br>
<br>
  I have confirmed this is reproducible and a bug. The problem arises because<br>
<br>
frame #0: 0x000000010140625a libpetsc.3.8.dylib`<wbr>PetscViewerVTKAddField_VTK(<wbr>viewer=0x00007fe66760c750, dm=0x00007fe668810820, PetscViewerVTKWriteFunction=(<wbr>libpetsc.3.8.dylib`<wbr>DMPlexVTKWriteAll at plexvtk.c:633), fieldtype=PETSC_VTK_POINT_<wbr>FIELD, vec=0x00007fe66880ee20) at vtkv.c:140<br>
    frame #1: 0x0000000101404e6e libpetsc.3.8.dylib`<wbr>PetscViewerVTKAddField(viewer=<wbr>0x00007fe66760c750, dm=0x00007fe668810820, PetscViewerVTKWriteFunction=(<wbr>libpetsc.3.8.dylib`<wbr>DMPlexVTKWriteAll at plexvtk.c:633), fieldtype=PETSC_VTK_POINT_<wbr>FIELD, vec=0x00007fe66880ee20) at vtkv.c:46<br>
    frame #2: 0x0000000101e0b7c3 libpetsc.3.8.dylib`VecView_<wbr>Plex_Local(v=<wbr>0x00007fe66880ee20, viewer=0x00007fe66760c750) at plex.c:301<br>
    frame #3: 0x0000000101e0ead7 libpetsc.3.8.dylib`VecView_<wbr>Plex(v=0x00007fe66880e820, viewer=0x00007fe66760c750) at plex.c:348<br>
<br>
keeps a linked list of vectors that are to be viewed and the vectors are the same Vec because they are obtained with DMGetLocalVector().<br>
<br>
The safest fix is to have PetscViewerVTKAddField_VTK() do a VecDuplicate() on the vector passed in and store that in the linked list instead of just storing a pointer to the passed in vector (which might and can be overwritten before all the linked vectors are actually stored).<br></blockquote><div><br></div><div>Danyang,</div><div><br></div><div>Barry is right, and the bug can be fixed the way he says. However, this points out why VTK is bad format. I think a better choice is</div><div>to use HDF5 and XDMF. For example, in my code now I always use</div><div><br></div><div>  DMVIewFromOptions(dm, NULL, "-dm_view");</div><div><br></div><div>and then later (perhaps several times)</div><div><br></div><div>  VecViewFromOptions(u, NULL, "-u_vec_view")</div><div>  VecViewFromOptions(v, NULL, "-v_vec_view")</div><div><br></div><div>and then on the command line</div><div><br></div><div>  -dm_view hdf5:test.h5 -u_vec_view hdf5:test.h5::append -v_vec_view hdf5:test.h5::append</div><div><br></div><div>which produces a file</div><div><br></div><div>  test.h5</div><div><br></div><div>Then I run</div><div><br></div><div>  $PETSC_DIR/bin/petsc_gen_xdmf.py test.h5</div><div><br></div><div>which produces another file</div><div><br></div><div>  test.xmf</div><div><br></div><div>This can be loaded by Paraview for visualization.</div><div><br></div><div>  Thanks,</div><div><br></div><div>     Matt</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
  Barry<br>
<div><div class="h5"><br>
<br>
<br>
> On Feb 27, 2018, at 10:44 PM, Danyang Su <<a href="mailto:danyang.su@gmail.com">danyang.su@gmail.com</a>> wrote:<br>
><br>
> Hi All,<br>
><br>
> How to set different object names when using multiple VecView? I try to use PetscObjectSetName with multiple output, but the object name is overwritten by the last one.<br>
><br>
> As shown below, as well as the enclosed files as example, the vector name in sol.vtk is vec_v for both vector u and v.<br>
><br>
>      call PetscViewerCreate(PETSC_COMM_<wbr>WORLD, viewer, ierr);CHKERRA(ierr)<br>
>      call PetscViewerSetType(viewer, PETSCVIEWERVTK, ierr);CHKERRA(ierr)<br>
>      call PetscViewerPushFormat(viewer, PETSC_VIEWER_ASCII_VTK, ierr);CHKERRA(ierr)<br>
>      call PetscViewerFileSetName(viewer, 'sol.vtk', ierr);CHKERRA(ierr)<br>
><br>
>      call PetscObjectSetName(u, 'vec_u', ierr);CHKERRA(ierr)<br>
>      call VecView(u, viewer, ierr);CHKERRA(ierr)<br>
><br>
>      call PetscObjectSetName(v, 'vec_v', ierr);CHKERRA(ierr)<br>
>      call VecView(v, viewer, ierr);CHKERRA(ierr)<br>
><br>
>      call PetscViewerDestroy(viewer, ierr);CHKERRA(ierr)<br>
><br>
>      call DMRestoreGlobalVector(dm, u, ierr);CHKERRA(ierr)<br>
>      call DMRestoreGlobalVector(dm, v, ierr);CHKERRA(ierr)<br>
><br>
> Thanks,<br>
><br>
> Danyang<br>
><br>
</div></div>> <ex1f90.F90><makefile.txt><<wbr>sol.vtk><br>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>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</div><div><br></div><div><a href="http://www.caam.rice.edu/~mk51/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div>
</div></div>