[petsc-users] DMDACoor3d and VecView
Roc Wang
pengxwang at hotmail.com
Thu May 23 11:19:00 CDT 2013
> From: jedbrown at mcs.anl.gov
> To: pengxwang at hotmail.com; petsc-users at mcs.anl.gov
> Subject: Re: [petsc-users] DMDACoor3d and VecView
> Date: Thu, 23 May 2013 10:10:19 -0500
>
> Roc Wang <pengxwang at hotmail.com> writes:
>
> > The coordinates of nodes are needed to plot the 3-D distributions of
> > the solution. The matrix and the vector are managed with DMDA, so the
> > array for the coordinates can be obtained by
> > DMDAGetCoordinateDA(da,&cda) and DMDAVecGetArray(cda,gc,&coors).
> > Here, coors is defined as DMDACoor3d ***coors. Since the function
> > VecVeiw can only output one vector, Vec sol, to a binary file , the
> > array of coordinates must be output to another file and thus must be
> > read separately.
>
> Not true, just read them in the same order you wrote them.
Does this mean I can save the vectors in the same binary file? If yes, whether the following procedure is correct?
/* writing vectors in solver program */
DM cda;
Vec gc;
ierr = DMDAGetCoordinateDA(da,&cda);CHKERRQ(ierr);
ierr = DMDAGetCoordinates(cda, &gc);CHKERRQ(ierr);
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"vector.bin",FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
ierr = VecView(sol,viewer);CHKERRQ(ierr); //write solution vector
ierr = VecView(gc,viewer);CHKERRQ(ierr); //write coordinate vector
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
/* reading vectors in a stand-along program */
ierr = VecCreate(PETSC_COMM_WORLD,&sol);CHKERRQ(ierr);
ierr = VecCreate(PETSC_COMM_WORLD,&gc);CHKERRQ(ierr);
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"vector.bin",FILE_MODE_READ,&viewer);CHKERRQ(ierr);
ierr = VecLoad(sol,viewer);CHKERRQ(ierr); //read solution vector
ierr = VecLoad(gc,viewer);CHKERRQ(ierr); //read coordinate vector
ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
>
> > The problem is that the array of coordinates is local array and the
> > number of processes in the post-processing program must be same as
> > that in the solver.
>
> DMGetCoordinates() returns a global Vec. Store that, not the local Vec.
>
> From the names, you must have an older version of PETSc. Please upgrade
> to petsc-3.4.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20130523/caffc27a/attachment-0001.html>
More information about the petsc-users
mailing list