On Tue, May 4, 2010 at 4:44 PM, Li, Zhisong (lizs) <span dir="ltr"><<a href="mailto:lizs@mail.uc.edu">lizs@mail.uc.edu</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>
<div style="direction:ltr;font-family:Tahoma;color:rgb(0, 0, 0);font-size:13px">
<div> <br>
Hi,<br>
<br>
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
<br>
<br>
typedef struct {<br>
PetscScalar u, v, p;<br>
<a name="1286546f55f601f7_lnkB" href="http://?ae=Item&a=New&t=IPM.Note&cc=MTQuMC42NTAuMzAsZW4tVVMsNDI5NDk2NzI5NSxIVE1MLDAsMA==&pspid=_1273007678982_331279185#" target="_blank">
<span></span></a> } Field;<br>
<br>
I first followed the advised method to collect all values from a parallel vector into a vector on the 0th processor:<br>
<br>
VecScatterCreateToZero(x, &scatter, &y);<br>
VecScatterBegin(scatter,x,y,INSERT_VALUES,SCATTER_FORWARD);<br>
VecScatterEnd(scatter,x,y,INSERT_VALUES,SCATTER_FORWARD);<br>
VecScatterDestroy(scatter); <br>
<br>
and then use<br>
Field **z;<br>
DAVecGetArray(da, y, &z); <br>
<br>
and<br>
PetscViewerASCIIOpen(comm,"./result.txt",&viewer); <br>
PetscViewerASCIIPrintf(viewer, "%G ", &z[j][i].u );<br>
<br>
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?<br>
</div></div></div></blockquote><div><br></div><div>What error? This is correct way to do it, if you do not just use VecView().</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div style="direction:ltr;font-family:Tahoma;color:rgb(0, 0, 0);font-size:13px"><div>
I also wonder if "DAGetGlobalVector( )" will do an equal job to collect parallel values?<br>
<br>
<br>
Thank you.<br>
<br>
<br>
Best Regards,<br>
<br>
<br>
Zhisong Li<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
</div>
</div>
</blockquote></div><br><br clear="all"><br>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener<br>