Dear Barry, <div> In ex19, the X is a kinda of global vec, while the x is a local vec. Since DAVecGetArray makes the x and X sharing the same actual vector data, the vec X is, actually, a global copy of the vec x, isnt it?</div>
<div><br></div><div>best,</div><div>Alan<br><br><div class="gmail_quote">On Thu, Aug 18, 2011 at 10:12 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
On Aug 18, 2011, at 9:40 PM, Alan Wei wrote:<br>
<br>
> Dear Barry,<br>
> That is really a great idea, and it is something that I want. I've never noticed that the structure in C is so marvelous. However, I have a further question. In that example, a variable x is defined like Field **x, and DAVecGetArray(da,X,&x). I wonder if there is any relationship between da, X and x after using DAVecGetArray. Or it just a prerequisite for using the nice notation of 'x'.<br>
<br>
</div> The only real relationship is that x looks into the X data structure to allow you to access the data as if it were in simple arrays. In other words the x and X share the same actual vector data.<br>
<font color="#888888"><br>
Barry<br>
</font><div><div></div><div class="h5"><br>
<br>
><br>
> thanks,<br>
><br>
> Alan<br>
><br>
> On Thu, Aug 18, 2011 at 9:09 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
><br>
> Alan,<br>
><br>
> I'm not sure what you are getting at but we commonly use tricks like (see src/snes/examples/tutorials/ex19.c)<br>
><br>
> typedef struct {<br>
> PetscScalar u,v,omega,temp;<br>
> } Field;<br>
><br>
> Then in this case use a DMDAVecGetArray() to get f and x and then have nice notation like<br>
><br>
> f[j][i].u = x[j][i].u;<br>
> f[j][i].v = x[j][i].v;<br>
> f[j][i].omega = x[j][i].omega - (x[j][i+1].v - x[j][i].v)*dhx;<br>
> f[j][i].temp = x[j][i].temp;<br>
><br>
> note that this means the values are stored interlaced in the vector.<br>
><br>
> Barry<br>
><br>
> On Aug 18, 2011, at 9:03 PM, Alan Wei wrote:<br>
><br>
> > Dear All,<br>
> > I'm trying to 'draw' a 2-D cylinder in PETSc. It simply restore the x and y coordinate values in two arrays. I wonder if I can use Vec in PETSc to implement it (i.e. defining a vec circle) so that I can call its x or y coordinate by circle.x or circle.y. Is this possible? also, is this a better way than just defining it as two arrays, i.e. x[ ] and y[ ].<br>
> ><br>
> > thanks in advance,<br>
> > Alan<br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div>