TSComputeRHSFunction() and TSComputeIFunction() should lock read only vectors to prevent user bugs
petsc-users: Re: [petsc-users] ts behavior question Reported-by: Gideon Simpson gideon.simpson@gmail.com
PetscErrorCode TSComputeRHSFunction(TS ts,PetscReal t,Vec U,Vec y)
{
PetscErrorCode ierr;
TSRHSFunction rhsfunction;
TSIFunction ifunction;
void *ctx;
DM dm;
PetscFunctionBegin;
PetscValidHeaderSpecific(ts,TS_CLASSID,1);
PetscValidHeaderSpecific(U,VEC_CLASSID,3);
PetscValidHeaderSpecific(y,VEC_CLASSID,4);
ierr = TSGetDM(ts,&dm);CHKERRQ(ierr);
ierr = DMTSGetRHSFunction(dm,&rhsfunction,&ctx);CHKERRQ(ierr);
ierr = DMTSGetIFunction(dm,&ifunction,NULL);CHKERRQ(ierr);
if (!rhsfunction && !ifunction) SETERRQ(PetscObjectComm((PetscObject)ts),PETSC_ERR_USER,"Must call TSSetRHSFunction() and / or TSSetIFunction()");
ierr = PetscLogEventBegin(TS_FunctionEval,ts,U,y,0);CHKERRQ(ierr);
if (rhsfunction) {
** ierr = VecLockReadPush(U);CHKERRQ(ierr);**
PetscStackPush("TS user right-hand-side function");
ierr = (*rhsfunction)(ts,t,U,y,ctx);CHKERRQ(ierr);
PetscStackPop;
** ierr = VecLockReadPop(U);CHKERRQ(ierr);**
} else {
ierr = VecZeroEntries(y);CHKERRQ(ierr);
}
Edited by Barry Smith