[petsc-users] save a vector value of multiple DOF to a file
Li, Zhisong (lizs)
lizs at mail.uc.edu
Thu May 6 11:47:07 CDT 2010
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);
DAVecGetArray(da,y,&ww);
PetscViewerASCIIOpen(PETSC_COMM_WORLD,"./result.txt",&viewer);
PetscPrintf(PETSC_COMM_WORLD," %G\n ", ww[15][17].p);
This works correctly for sequential processing. After scattering, I can find both x and y size as 8721 using VecGetSize(). But for parallel processing, DAVecGetArray() produces errors. If I don't use DAVecGetArray(), how can I access the data and write it to a file?
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).
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?
Thank you.
Regards,
Zhisong Li
> >The error message:
>>
> >[1]PETSC ERROR: --------------------- Error Message
> >------------------------------------
> >[1]PETSC ERROR: Arguments are incompatible!
> >[1]PETSC ERROR: Vector local size 0 is not compatible with DA local sizes
> >4284 4437
> >!
>This is your problem. The Vec you pass into DAVecGetArray() does not
>actually come from
>the DA at all, and in fact has size 0. You can get properly sized Vecs using
>DAGetGlobalVector().
>What Vec are you trying to access (since it obviously cannot have valid
>values in it)?
> Matt
More information about the petsc-users
mailing list