<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr; font-family: Tahoma; color: rgb(0, 0, 0); font-size: 13px;">
<div style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <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>
&nbsp;&nbsp; PetscScalar u, v, p;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a _tbb="1" class="tba" id="send" name="lnkB" href="?ae=Item&amp;a=New&amp;t=IPM.Note&amp;cc=MTQuMC42NTAuMzAsZW4tVVMsNDI5NDk2NzI5NSxIVE1MLDAsMA==&amp;pspid=_1273007678982_331279185#">
<span class="tbLh tbBtwn tbAfter"></span></a>&nbsp; &nbsp;&nbsp; } 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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VecScatterCreateToZero(x, &amp;scatter, &amp;y);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VecScatterBegin(scatter,x,y,INSERT_VALUES,SCATTER_FORWARD);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VecScatterEnd(scatter,x,y,INSERT_VALUES,SCATTER_FORWARD);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VecScatterDestroy(scatter);&nbsp; <br>
<br>
and then use<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Field&nbsp; **z;<br>
&nbsp; &nbsp; &nbsp;&nbsp; DAVecGetArray(da, y, &amp;z); <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
and<br>
&nbsp;&nbsp;&nbsp;&nbsp; PetscViewerASCIIOpen(comm,&quot;./result.txt&quot;,&amp;viewer);&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp; PetscViewerASCIIPrintf(viewer, &quot;%G &quot;, &amp;z[j][i].u );<br>
<br>
to finish. But I always either meet error for the line &quot;DAVecGetArray(da, y, &amp;z);&quot; 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>
<br>
I also wonder if &quot;DAGetGlobalVector( )&quot; 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>
</body>
</html>