Florian Lindner <[email protected]> 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
pgpeukPNc7lPO.pgp
Description: PGP signature
