[petsc-users] How to save a vector value of multiple DOF to a file?

Li, Zhisong (lizs) lizs at mail.uc.edu
Tue May 4 16:44:23 CDT 2010


Hi,

I want to setup a function in the main function to save the data to a file. For example suppose the vector x in ts/tutorials/ex7 consists of 3 DOF as

typedef struct {
   PetscScalar u, v, p;
                     } Field;

I first followed the advised method to collect all values from a parallel vector into a vector on the 0th processor:

       VecScatterCreateToZero(x, &scatter, &y);
       VecScatterBegin(scatter,x,y,INSERT_VALUES,SCATTER_FORWARD);
       VecScatterEnd(scatter,x,y,INSERT_VALUES,SCATTER_FORWARD);
       VecScatterDestroy(scatter);

and then use
       Field  **z;
       DAVecGetArray(da, y, &z);

and
     PetscViewerASCIIOpen(comm,"./result.txt",&viewer);
     PetscViewerASCIIPrintf(viewer, "%G ", &z[j][i].u );

to finish. But I always either meet error for the line "DAVecGetArray(da, y, &z);" or save a file of all extremely small values(e.g. 8.652e-317), which is obviously wrong. So what is the correct way to do this? Where can I find a similar example to follow?

I also wonder if "DAGetGlobalVector( )" will do an equal job to collect parallel values?


Thank you.


Best Regards,


Zhisong Li






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20100504/dea7a1c0/attachment.htm>


More information about the petsc-users mailing list