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

Matthew Knepley knepley at gmail.com
Tue May 4 17:17:21 CDT 2010


On Tue, May 4, 2010 at 4:44 PM, Li, Zhisong (lizs) <lizs at mail.uc.edu> wrote:

>
> 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;
>                 <http://?ae=Item&a=New&t=IPM.Note&cc=MTQuMC42NTAuMzAsZW4tVVMsNDI5NDk2NzI5NSxIVE1MLDAsMA==&pspid=_1273007678982_331279185#>
>    } 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?
>

What error? This is correct way to do it, if you do not just use VecView().

   Matt


> I also wonder if "DAGetGlobalVector( )" will do an equal job to collect
> parallel values?
>
>
> Thank you.
>
>
> Best Regards,
>
>
> Zhisong Li
>
>
>
>
>
>
>


-- 
What most experimenters take for granted before they begin their experiments
is infinitely more interesting than any results to which their experiments
lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20100504/7c98f076/attachment.htm>


More information about the petsc-users mailing list