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

Changing parameter in case of divergence and trying to solve again

+1 vote

Hi!

I would like to try to solve my problem and, if it diverges, change some parameter (for instance, to reduce the timestep) and retry the solution.

Which is the best way of doing this?

Thank you!

asked Nov 29, 2016 by amigoricardo FEniCS Novice (340 points)

1 Answer

0 votes

You need to save the current solution, so you can recall in case of divergence

Ubck = Function(U)
while True:
     try:
         solver.solve()
         break
     except:
         U.assign(Ubck)
         dt.assign(0.5*float(dt))

This assumes that you have defined a solver object, which writes to U and throws an error in case of divergence.

This is a way. Maybe not the best way. At least you should also consider increasing the timestep.

answered Nov 30, 2016 by KristianE FEniCS Expert (12,900 points)
...