[petsc-users] Push Back in Vector

Pedro Torres torres.pedrozpk at gmail.com
Thu Feb 25 19:50:30 CST 2010


2010/2/25 Jed Brown <jed at 59a2.org>

> On Thu, 25 Feb 2010 13:37:21 -0300, Pedro Torres <
> torres.pedrozpk at gmail.com> wrote:
> > Well, in my case I have a sequential vector and I'm trying to append one
> > element at the end of the array, without the need of destroy this.
>
> PETSc Vec doesn't work this way.  Use whatever data structure you like
> to put this thing together, then give it to PETSc once you know what you
> have.
>
> > - Create a new vector with size+1
> > - copy old array in the new array and append the element,
>
> This is what dynamically sized array containers (e.g. std::vector) do
> internally, but they guess at how much extra will be needed (usually
> increasing the allocated size by a geometric factor).
>
> (When I asked what you are trying to do, I was looking for a higher
> level description of what you wanted to achieve, and why you thought
> appending to a Vec was a desirable thing.)
>

The things is that I don't have the final dimension of the vector, because
it depends of mesh size, boundary conditions,etc. But I think that I can do
the following,

- use std::vector
- when I get final size, I create a Vec with VecCreateSeqWithArray and Petsc
will use the array in std::vector.

Is that right?

Thanks a lot!

Pedro


>
> Jed
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20100225/6b89f925/attachment.htm>


More information about the petsc-users mailing list