Hello,

I was wondering whether I can use vector SetValues inside the Function routine 
or not. i.e. in the following example, can I use SetValues(f, ...) to fill 
vector f? If so, what are the drawbacks? The benefit would be, I can use global 
IDs to fill the vector f but when I use VeecGetArray(f,&ff) I should use local 
IDs (ff[Local ID] = ...).

PetscErrorCode FormFunction(SNES snes,Vec x,Vec f,void *ctx)
{

        ierr = VecGetArray(x,&xx);CHKERRQ(ierr);
        ierr = VeecGetArray(f,&ff);CHKERRQ(ierr);

  for (i=xs; i<xs+xm; i++) {
    ff[i] = d*(xx[i-1] - 2.0*xx[i] + xx[i+1]) + xx[i]*xx[i] - FF[i];
  }
        /* Restore vectors */
        ierr = VecRestoreArray(x,&xx);CHKERRQ(ierr);
        ierr = VecRestoreArray(f,&ff);CHKERRQ(ierr); ;
}

Thanks,
Hesam

Reply via email to