> On Jul 25, 2017, at 1:09 PM, Stefano Zampini <[email protected]> 
> wrote:
> 
> Is TSTrajectory and its API (in the public header petscts.h) supposed to be 
> used from outside a TSAdjointSolve?

   Yes most definitely. That is not to say it is usable now except in cases it 
was exactly written for.

> 
> Actually, it is not usable: take for example TSTrajectoryGet() with a given 
> step number: then, if I want to use BASIC it will always return the last step 
> recorded from the previous TSSolve (this behavior is common to all the 
> TSTrajectory implementantions)
> 
> static PetscErrorCode TSTrajectoryGet_Basic(TSTrajectory tj,TS ts,PetscInt 
> stepnum,PetscReal *t)
> {
>   Vec            Sol,*Y;
>   PetscInt       Nr,i;
>   PetscViewer    viewer;
>   PetscReal      timepre;
>   char           filename[PETSC_MAX_PATH_LEN];
>   PetscErrorCode ierr;
> 
>   PetscFunctionBegin;
>   ierr = TSGetTotalSteps(ts,&stepnum);CHKERRQ(ierr);
>   ierr = PetscSNPrintf(filename,sizeof 
> filename,"SA-data/SA-%06d.bin",stepnum);CHKERRQ(ierr);
> 
> Undoubtedly, this code can be very useful inside a TSAdjointSolve (where 
> total_steps is manually decremented...) but not from a user that wants to 
> experiment with the class.
> 
> I would really like to reuse TSTrajectory for a continuous adjoint problem 
> I'm currently working on, and I believe this class should be somewhat 
> refactored.

   Good

> Here are a couple of examples from the public API
> 
> PetscErrorCode TSTrajectoryGet(TSTrajectory tj,TS ts,PetscInt 
> stepnum,PetscReal *time)
> {
>   PetscErrorCode ierr;
> 
>   PetscFunctionBegin;
>   if (!tj) 
> SETERRQ(PetscObjectComm((PetscObject)ts),PETSC_ERR_ARG_WRONGSTATE,"TS solver 
> did not save trajectory");
> 
> ....
> 
> PetscErrorCode TSTrajectorySet(TSTrajectory tj,TS ts,PetscInt 
> stepnum,PetscReal time,Vec X)
> {
>   PetscErrorCode ierr;
>   
>   PetscFunctionBegin;
>   if (!tj) PetscFunctionReturn(0);
> 
> We can use this thread to start a discussion on how it can be refactored, and 
> I'm willing to contribute.
> 
> I personally believe TSTrajectory should not be exposed in the public API (at 
> least put in the private headers) in the upcoming release.
> 
> Thanks,
> -- 
> Stefano

Reply via email to