[petsc-users] Behavior of PetscViewerVTKOpen

Jed Brown jed at jedbrown.org
Mon Feb 24 17:48:06 CST 2020


Emmanuel Ayala <juaneah at gmail.com> writes:

> Hi everyone,
>
> I think VTK is not the best option to save files, but I just want a quick
> way to visualize a structured grid generated with DMDACreate3d. I visualize
> the vts file with ParaView.
>
> The situation is, If I change the number global dimension in each direction
> of the array (*M,N,P *parameters for DMDACreate3d) it is supposed that the
> size of the mesh won't changes, ONLY the number of division in the affected
> direction, but it does NOT happen ( I used DMDASetUniformCoordinates to
> have an uniform grid ). When I save the file, and then check it with
> ParaView, the size changes. (I checked the coordinates with
> DMGetCoordinates everything is OK, size and division), the problem is in
> the visualization using VTK.
>
> I use the next set of functions to save the file.

Normally you view a field defined on your DM (which will be correctly
mapped by your coordinates), not the coordinates (which reside on a
coordinate DM, which does not itself have coordinates).  Try something
like this:

  DMCreateGlobalVector(dm, &U);
  VecView(U, viewer);

> ierr =
> PetscViewerVTKOpen(PETSC_COMM_WORLD,"nodes_coord.vts",FILE_MODE_WRITE,&view);
> CHKERRQ(ierr);
> ierr = DMGetCoordinates(da_nodes,&v1); CHKERRQ(ierr); // borrowed reference
> ierr = VecView(coord,view);CHKERRQ(ierr);
>
> Then, I realize that if I create a vector with DMCreateGlobalVector and
> then copy in it the coordinate from DMGetCoordinates, the size remains
> unchanged (in the visualization) and just the number of elements along the
> direction change (when I modify M,N,P).
>
> ierr =
> PetscViewerVTKOpen(PETSC_COMM_WORLD,"nodes_coord.vts",FILE_MODE_WRITE,&view);
> CHKERRQ(ierr);
> ierr = DMGetCoordinates(da_nodes,&v1); CHKERRQ(ierr); // borrowed reference
> ierr = DMCreateGlobalVector(da_nodes,&coord); CHKERRQ(ierr);
> ierr = VecCopy(v1,coord); CHKERRQ(ierr);
> ierr = VecView(coord,view);CHKERRQ(ierr);
>
> *There is something wrong with PetscViewerVTKOpen or it's just the approach
> that I used?*
>
> Kind regards.


More information about the petsc-users mailing list