Hi Stefano,

> 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?

TSTrajectory is mainly used by TSAdjoint, but not limited to it. For example, 
it can also be used for visualization purposes. 

> 
> 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)

This is not the expected behavior. Can you provide more details on how you used 
TSTrajectoryGet()? How did you know it is the last step recorded from the 
previous TSSolve?

> 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.

total_steps is automatically incremented in TSSolve(), which serves as a unique 
identifier for a time step. TSTrajectory is marked as 'developer level'. The 
implementation is quite tricky. I am willing to help if you have some specific 
needs. 

Thanks,
Hong (Mr.)

> 
> 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. 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