This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to use auto time step?

+7 votes

Dear all,
Is it possible to use auto time step for the time dependent problem in FEniCS?
I'm using the NonlinearVariationalSolver, for example, if I defined the problem as follow:

a=derivative(L,u,du)# L is the weak form
problem=NonlinearVariationalProblem(L,u,bcs=bc,J=a)
solver=NonlinearVariationalSolver(problem)


while norm(du)>tolerence:
    solver.solve()
    while solver_is_reach_the_maximun_iters:
        dt=dt*0.5
        solver.solve()
    if solve_is_failed:
        print error
        stop

    du=u-u0
    u0.assign(u)
    if solver.iteraters>5:
         dt=dt*0.5
    else:
         dt=2.0*dt

The problem is, how can I get the information of the solver in each time step, for example, the iterations of each time step, the maxium iterations and relative errors and so on....
I print solver.parameters, but don't find it.

By the way, is it possible to use the auto time step like this way? Or any other helpful suggestion?

Thank your!

asked Jan 6, 2017 by walkandthink FEniCS Novice (320 points)

1 Answer

0 votes

The call to solver.solve() method gives two values in return, 1. no of iterations (integer) and 2. converged (True or False.)

The adaptive time step can be achieved with something like :

(no_of_iterations,converged) = solver.solve()
if no_of_iterations < 5:
    dt = 2*dt
else:
    dt = 0.5*dt
answered Jul 7, 2017 by omknadgir FEniCS Novice (260 points)
...