[petsc-users] save a vector value of multiple DOF to a file
Jed Brown
jed at 59A2.org
Thu May 6 12:14:27 CDT 2010
On Thu, 6 May 2010 16:47:07 +0000, "Li, Zhisong (lizs)" <lizs at mail.uc.edu> wrote:
>
> Hi, Matt,
>
> First let me state the problem again:
>
> I use the following code to write a global solution vector x to a file, which is in 2D domain with multiple DOF (u, v, p) as in a typical CFD problem (like snes/ex19.c):
>
> VecScatterCreateToZero(x, &scatter, &y);
> VecScatterBegin(scatter, x, y, INSERT_VALUES,SCATTER_FORWARD);
> VecScatterEnd(scatter, x, y, INSERT_VALUES,SCATTER_FORWARD);
> VecScatterDestroy(scatter);
vout - output SEQVEC that is large enough to scatter into on processor 0 and of length zero on all other processors
http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-current/docs/manualpages/Vec/VecScatterCreateToZero.html
> DAVecGetArray(da,y,&ww);
The DA is still global, the vector is serial and only on one process, it
is not compatible with the DA. It is also in the "PETSc ordering", see
the user's manual.
> I also tried the following code as you suggested:
>
> DAGetGlobalVector(da, &x);
> DAVecGetArray(da, x, &ww);
>
> It gives no error for sequential or parallel running, but the value are all 0 (wrong).
The values are correct, you never put anything in this vector x.
> I think writing data to a file should be a common utility for PETSc, can you just find me a sample code that I can follow?
See the manual page:
http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-current/docs/manualpages/Vec/VecView.html
PetscViewerASCIIOpen(PETSC_COMM_WORLD,"./result.txt",&viewer);
VecView(x,viewer);
or similar with a binary viewer
Jed
More information about the petsc-users
mailing list