I’m using legacy FEniCS and want to make a cutback in a loop, i.e., I want to change the step size in the loop where the problem is being solved.
The code is like this:
...
problem = NonlinearVariationalProblem(weakform, w, BC, J=a)
solver = NonlinearVariationalSolver(problem)
while (t <= t_total):
t += dt
(iteration, converged) = solver.solve()
...
and when the solver cannot solve the problem (error occurs), the loop ends and the simulation is also terminated.
But I want to change the step size (dt) since the error occurs, rather than terminate the loop and the simulation.
I did something like this:
...
while (t <= t_total):
t += dt
(iteration, converged) = solver.solve()
if converged == False:
t -= dt
dt = dt/2
continue
...
Hi Stein,
yes, dt is defined somewhere above the NonlinearProblem,
e.g.,
...
t = 0
t_total = 100
dt = Constant(0.1)
problem = NonlinearVariationalProblem(weakform, w, BC, J=a)
solver = NonlinearVariationalSolver(problem)
while(t <= t_total)
t += dt
(iteration, converged) = solver.solve()
...
and I just want to update dt when the solver couldn’t solve the problem.
But with my code, when the solver can’t solve the problem, the code just terminates and cannot update dt value.