[petsc-users] Creating a 2d geometry by using vector
Barry Smith
bsmith at mcs.anl.gov
Fri Aug 19 15:51:37 CDT 2011
On Aug 19, 2011, at 2:55 PM, Alan Wei wrote:
> Dear Barry,
> 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?
Not really. If you pass a local (nonparallel) vector to the VecGetArray() the resulting array covers all the entries in the vector. If you pass a global (parallel) vector then the resulting array only gives you access to the values that are on that one process.
Barry
>
> best,
> Alan
>
> On Thu, Aug 18, 2011 at 10:12 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>
> On Aug 18, 2011, at 9:40 PM, Alan Wei wrote:
>
> > Dear Barry,
> > 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'.
>
> 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.
>
> Barry
>
>
> >
> > thanks,
> >
> > Alan
> >
> > On Thu, Aug 18, 2011 at 9:09 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
> >
> > Alan,
> >
> > I'm not sure what you are getting at but we commonly use tricks like (see src/snes/examples/tutorials/ex19.c)
> >
> > typedef struct {
> > PetscScalar u,v,omega,temp;
> > } Field;
> >
> > Then in this case use a DMDAVecGetArray() to get f and x and then have nice notation like
> >
> > f[j][i].u = x[j][i].u;
> > f[j][i].v = x[j][i].v;
> > f[j][i].omega = x[j][i].omega - (x[j][i+1].v - x[j][i].v)*dhx;
> > f[j][i].temp = x[j][i].temp;
> >
> > note that this means the values are stored interlaced in the vector.
> >
> > Barry
> >
> > On Aug 18, 2011, at 9:03 PM, Alan Wei wrote:
> >
> > > Dear All,
> > > 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[ ].
> > >
> > > thanks in advance,
> > > Alan
> >
> >
>
>
More information about the petsc-users
mailing list