[petsc-users] TSSetTimeStep or -ts_dt not working

Zhang, Hong hongzhang at anl.gov
Wed Oct 11 12:49:04 CDT 2017


By default TSRK uses adaptive time stepping. TSSetTimeStep sets the initial time step, and the time step will be adapted automatically during the integration. Since you call TSGetTimeStep after TSSolve, you actually get the step size for the last time step. To view the step size at each step, run with -ts_monitor.

If you want to use a fixed step size, you can do -ts_adapt_type none -ts_dt <value>. 

Hong (Mr.)

> On Oct 11, 2017, at 12:12 PM, Ali Berk Kahraman <aliberkkahraman at yahoo.com> wrote:
> 
> Hello All,
> 
> 
> I am trying to use timesteppers, however I have a problem. Whenever I want to set a dt for the timstepping integration, I cannot succeed. Neither the function TSSetTimeStep nor the command line option seems to work. Using either of them(but not at the same time) and setting it to 1, when I call TSGetTimeStep to learn the value of dt, it gives me the answer 0.002871. Perhaps this is the default value, however I cannot work with this, since the equation I have is slowly evolving.
> 
> 
> Any ideas what might be causing this?
> 
> 
> The part of the code I use,
> 
> 
> PetscReal time=0, timestep=1;
>    int maxsteps=30;
>    float maxtime=300;
> 
> 
>        TS ts;
>        ierr= TSCreate(PETSC_COMM_WORLD,&ts);
>        CHKERRQ(ierr);
>        ierr= TSSetProblemType(ts,TS_LINEAR);
>        CHKERRQ(ierr);
>        ierr= TSSetSolution(ts, dummyvec);
>        CHKERRQ(ierr);
>        ierr= TSSetType(ts,TSRK);
>        CHKERRQ(ierr);
>        ierr= TSSetTime(ts,time);
>        CHKERRQ(ierr);
>        ierr= TSSetTimeStep(ts,timestep);
>        CHKERRQ(ierr);
>        ierr=TSSetExactFinalTime(ts,TS_EXACTFINALTIME_STEPOVER);
>        CHKERRQ(ierr);
>        TSSetMaxSteps(ts,maxsteps);
>        TSSetMaxTime(ts,maxtime);
> 
>        ierr=TSSetFromOptions(ts);CHKERRQ(ierr);
>        TSSetRHSFunction(ts,residual,
>                         FormRHSFunction,&mycontext);
>        ierr= TSSolve(ts,uJi);
>        CHKERRQ(ierr);
>        TSView(ts,PETSC_VIEWER_STDOUT_SELF);
> 
>        TSConvergedReason reason;
>        ierr=TSGetConvergedReason(ts,&reason);CHKERRQ(ierr);
>        printf("Why Converged: %d\n",reason);
>        PetscReal usedtimestep;
>        TSGetTimeStep(ts,&usedtimestep);
>        printf("Used timestep: %f\n",usedtimestep);
> 
> 



More information about the petsc-users mailing list