[petsc-users] *****SPAM*****Create vector with evenly spaced values

Florian Lindner mailinglists at xgm.de
Fri Aug 29 08:55:31 CDT 2014


Am 27.08.2014 14:12, schrieb Florian Lindner:
> Hello,
> 
> 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?


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