<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=""> <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 _tbb="1" class="tba" id="send" name="lnkB" href="?ae=Item&a=New&t=IPM.Note&cc=MTQuMC42NTAuMzAsZW4tVVMsNDI5NDk2NzI5NSxIVE1MLDAsMA==&pspid=_1273007678982_331279185#">
<span class="tbLh tbBtwn tbAfter"></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>
<br>
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>
</body>
</html>