[petsc-users] *****SPAM*****Create vector with evenly spaced values
Florian Lindner
mailinglists at xgm.de
Sat Aug 30 03:17:16 CDT 2014
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?
Rgds,
Florian
> >
> >
> > 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
More information about the petsc-users
mailing list