[petsc-users] *****SPAM*****Create vector with evenly spaced values
Jed Brown
jed at jedbrown.org
Sat Aug 30 07:09:14 CDT 2014
Florian Lindner <mailinglists at xgm.de> writes:
> Am Freitag, 29. August 2014, 09:29:21 schrieben Sie:
>> Florian :
>> >>
>> >> is there a way to create a vector with evenly spaced values in an
>> >> interval, like the numpy.arange function?
>> >> http://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html
>> >> or the linspace function?
>> >
>> >
>> > Ok, I gave it as try. Do I need the VecAssembly the vector?
>>
>> No, but you need VecResetArray() when vector is no longer used.
>
> Why do I need to call that if I have no intention going back to the original values? Of course I do VecDestroy the vector?
Then your use of VecReplaceArray is really weird. Get rid of the malloc
and use VecGetArray, set the values, then VecRestoreArray.
>> > void arange(size_t start, size_t stop)
>> > {
>> > // given a vector of appropriate size
>> > PetscScalar ierr;
>> > PetscScalar *a;
>> > ierr = PetscMalloc(sizeof(PetscScalar) * (stop-start), &a);
>> > CHKERRV(ierr);
>> > size_t pos = 0;
>> > for (size_t i = start; i < stop; i++) {
>> > a[pos] = i;
>> > pos++;
>> > }
>> > cout << "Array filled." << endl;
>> > VecReplaceArray(vector, a);
>> > // VecAssemblyBegin(vector); VecAssemblyEnd(vector); Do I need that?
>> > }
>> >
>> > Any comments?
>> >
>> > Thanks,
>> > Florian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140830/5b1edf62/attachment.pgp>
More information about the petsc-users
mailing list