TSSetEventHandler zero crossing direction issue
Dear PETSc team,
I ran into an issue with the direction
parameter of TSSetEventHandler
.
Is it correct that if for instance direction
of an event is set to 1
, the event is triggered iff the respective fvalue
goes from negative to positive? Suprisingly (for me) this seems to be not true.
Given the bouncing ball ex40,
setting direction
for the ball height u[0]
at
https://gitlab.com/petsc/petsc/-/blob/v3.19.3/src/ts/tutorials/ex40.c#L244 to 1
should never trigger the event as u[0]
only decreases after the initial phase, but TS actually decreases the time step size (similarly to the original code) and diverges then:
PS C:\Users\CI\reps\mfs\build> ."C:/Users/CI/reps/mfs/build/ex40.exe" -ts_monitor -ts_event_monitor
0 TS dt 0.1 time 0.
1 TS dt 0.5 time 0.1
2 TS dt 0.5 time 0.6
3 TS dt 0.5 time 1.1
4 TS dt 0.5 time 1.6
5 TS dt 0.5 time 2.1
6 TS dt 0.5 time 2.6
7 TS dt 0.5 time 3.1
8 TS dt 0.5 time 3.6
TSEvent: iter 0 - Event 0 interval detected due to sign change [3.6 - 4.1]
8 TS dt 0.479188 time 3.6 (r)
8 TS dt 0.0208122 time 3.6 (r)
8 TS dt 0.0208122 time 3.6 (r)
8 TS dt 0. time 3.6 (r)
[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------
[0]PETSC ERROR: TSStep has failed due to DIVERGED_NONLINEAR_SOLVE, increase -ts_max_snes_failures or make negative to attempt recovery
[0]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
[0]PETSC ERROR: Petsc Release Version 3.19.3, Jun 29, 2023
[0]PETSC ERROR: C:\Users\CI\reps\mfs\build\ex40.exe on a dso named DESKTOP-NSELTHR by CI Mon Jul 10 22:46:42 2023
[0]PETSC ERROR: Configure options --PETSC_ARCH=dso --with-single-library=1 --with-shared-libraries=0 --with-windows-graphics=0 --with-x=0 --with-hwloc=1 --with-openblas=1 --with-openblas-dir=/ucrt64 --with-mpi=0 --with-pthread=0 --with-openmp=0 --with-precision=double --with-scalar-type=real --with-debugging=0 CC=gcc CXX=g++ FC=gfortran CFLAGS="-march=nocona -msahf -mtune=generic -O2 -pipe" FFLAGS="-march=nocona -msahf -mtune=generic -O2 -pipe -I/ucrt64/include -fallow-invalid-boz -fallow-argument-mismatch" CXXFLAGS="-march=nocona -msahf -mtune=generic -O2 -pipe"
CPPFLAGS= LDFLAGS=-pipe LIBS=" -lgfortran -lquadmath" MAKEFLAGS=-j33
[0]PETSC ERROR: #1 TSStep() at C:/Users/CI/reps/MINGW-packages/mingw-w64-petsc/src/build-UCRT64/petsc-3.19.3/src/ts/interface/ts.c:3470
[0]PETSC ERROR: #2 TSSolve() at C:/Users/CI/reps/MINGW-packages/mingw-w64-petsc/src/build-UCRT64/petsc-3.19.3/src/ts/interface/ts.c:3845
[0]PETSC ERROR: #3 main() at C:\Users\CI\reps\mfs\ex40.c:255
[0]PETSC ERROR: PETSc Option Table entries:
[0]PETSC ERROR: -ts_event_monitor (source: command line)
[0]PETSC ERROR: -ts_monitor (source: command line)
[0]PETSC ERROR: ----------------End of Error Message -------send entire error message to petsc-maint@mcs.anl.gov----------
I would expect it to kind of run forever. Is that a bug or did I miss something?
Thanks and kind regards, Volker
Edited by Volker Jacht