[petsc-users] Push Back in Vector

Pedro Torres torres.pedrozpk at gmail.com
Thu Feb 25 20:33:06 CST 2010


Ok, I really apreciate your help. Thanks Jed and Barry.

Regards

Pedro

2010/2/25 Barry Smith <bsmith at mcs.anl.gov>

>
> On Feb 25, 2010, at 7:50 PM, Pedro Torres wrote:
>
>
>>
>> 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.
>>
>
>   You could do this. In general what we do is to "process" the mesh,
> boundary conditions etc to determine the needed size, set the vector size,
>  then go back and compute the vector/matrix entries.
>
>   Barry
>
>
>
>> 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/0970561d/attachment.htm>


More information about the petsc-users mailing list