You are right that TSEvent is not suitable for this case.  To stop the 
timestepper, I would call TSSetConvergedReason(ts,TS_CONVERGED_USER) in a 
PostStep function.

Hong (Mr.)

> On May 28, 2019, at 4:36 AM, Patrick Sanan via petsc-users 
> <petsc-users@mcs.anl.gov> wrote:
> 
> I'm working with/on a code which uses TSSUNDIALS, and I'd like to be able to 
> stop the timestepper based on the value of the solution. In particular, I 
> wish to enforce that a given concentration has not changed by more than a 
> specified amount before stopping. Note that this is simpler than general 
> event detection, as I'm happy stopping before the condition is satisfied and 
> don't care about finding the point in time when the condition is satisfied 
> exactly.
> 
> As far as I know, PETSc's event handling interface isn't supported with the 
> SUNDIALS implementation. (As an aside, I'd be happier using TSARKIMEX or 
> another native timestepper, but so far haven't been able to avoid tiny 
> timesteps).
> 
> My question is whether the following approach has any obvious fatal flaw, and 
> if any TS gurus have other/better/simpler ideas.
> 
> The idea is to add my own logic, say with TSSetPreStep(), to:
> 
> 1. Maintain the previous step's state (this is a 1d problem, so I'm not too 
> concerned about the overhead of this)
> 2. Check my condition, and if it's satisfied, dump the previous step's data, 
> and use TSSetMaxTime() with the previous step's time, thus ending the solve.
> 

Reply via email to