[petsc-dev] Best Way to Assign Cell Number to VTK Plot in DMPlex

Faibussowitsch, Jacob jfaibussowitsch at anl.gov
Fri Oct 4 18:46:23 CDT 2019


If you are requesting a Vec from a Plex, then the discretization in its DS determines its size.
What if I have multiple fields on a single DM with varying numComponents per field (although each one has the same quadrature number and dimension I believe)? Does it just make the vec based on field 0? I have made a PetscFE,  and used it to set each field, then called DMCreateDS on the dm afterwards.

Best,

Jacob

On Oct 4, 2019, at 4:59 PM, Matthew Knepley <knepley at gmail.com<mailto:knepley at gmail.com>> wrote:

On Fri, Oct 4, 2019 at 3:09 PM Faibussowitsch, Jacob <jfaibussowitsch at anl.gov<mailto:jfaibussowitsch at anl.gov>> wrote:
Note that Paraview already knows the cell number and can display it
Now that would have been useful to know months ago.

Here is me making a similar field containing the rank instead of the cell number:
Yes I ended up cannibalizing that function and this worked well enough. One thing I noticed however is that it the global vector this creates is of the size of number of cells, but when I create a global vector it is the size of num vertices.

If you are requesting a Vec from a Plex, then the discretization in its DS determines its size. You need to

  make a clone (DMClone) and set a P0 discretization

This is what I do there.

   Matt

I omitted the PETSc__rank_ options prefix part when creating the default fe, is that responsible for setting the vec size here?

Best,

Jacob

On Oct 4, 2019, at 9:42 AM, Matthew Knepley <knepley at gmail.com<mailto:knepley at gmail.com>> wrote:

On Thu, Oct 3, 2019 at 11:42 AM Matthew Knepley <knepley at gmail.com<mailto:knepley at gmail.com>> wrote:
On Tue, Oct 1, 2019 at 11:57 AM Faibussowitsch, Jacob via petsc-dev <petsc-dev at mcs.anl.gov<mailto:petsc-dev at mcs.anl.gov>> wrote:
Hello All,

I am plotting an output value from a vecview, and want to show in a separate plot which cells correspond to which values in the vec. I plan to do this by making a field on the cells whose value is the global number of that cell. I have 2 issues with this:

1. How do I guarantee that the ordering of the Vec I made corresponds to the DMPlex cell ordering such that Vec(0) corresponds to Cells(0) etc. (I make the Vec separately from the DM since using DMCreateLocalVector makes a vector on the vertices)

2. I am trying to use DMPlexVTKWriteAll to make my output, so I am adding my field to the DMPlexVTK using PetscViewerVTKAddField, but I can’t seem to get PetscViewerVTKWriteFunction to work properly, and the man pages don’t link to an example. Here is my code for this section:

PetscErrorCode        (*PetscViewerVTKWriteFunction) (PetscObject, PetscViewer);

ierr = PetscViewerCreate(comm=PETSC_COMM_WORLD, &vtkviewer);CHKERRQ(ierr);
ierr = PetscViewerVTKOpen(comm=PETSC_COMM_WORLD, "mesh.vtk", FILE_MODE_WRITE, &vtkviewer);CHKERRQ(ierr);
ierr = PetscViewerSetUp(vtkviewer);CHKERRQ(ierr);

PetscViewerVTKWriteFunction = (CellNum vtkviewer);
ierr = PetscViewerVTKAddField(vtkviewer, (PetscObject) dm, PetscViewerVTKWriteFunction, PETSC_VTK_CELL_FIELD, PETSC_TRUE, CellNum);CHKERRQ(ierr);
ierr = DMPlexVTKWriteAll((PetscObject) dm, vtkviewer);CHKERRQ(ierr);

Any help would be greatly appreciated!

I think what you want is to make a Section over cells with 1 dof, fill it with the cell number (from a global numbering), and then view that Vec.

Here is me making a similar field containing the rank instead of the cell number:

  https://www.mcs.anl.gov/petsc/petsc-master/docs/manualpages/DMPLEX/DMPlexCreateRankField.html

Note that Paraview already knows the cell number and can display it

  Thanks,

     Matt

   Matt

Best,

Jacob



--
What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/<http://www.cse.buffalo.edu/~knepley/>


--
What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/<http://www.cse.buffalo.edu/~knepley/>



--
What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/<http://www.cse.buffalo.edu/~knepley/>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20191004/3668d2af/attachment-0001.html>


More information about the petsc-dev mailing list