From: John P. <jwp...@gm...> - 2017-11-13 15:01:24
|
On Sat, Nov 11, 2017 at 2:14 PM, Salazar De Troya, Miguel < sal...@ll...> wrote: > Hello > > > I have an optimization problem for which at a certain iteration, PETSc > fails to build the preconditioner. I would like to catch that error and > print my EquationSystem to disk so I can rerun the PETSc solve at that > optimization iteration from the start. I cannot just rerun my optimization > and write to disk at the iteration I know it is going to fail. The reason > is that in parallel the optimization slightly differs every time I run it > so the iteration it is going to fail at keeps changing. Maybe something > along this lines: > > > try{ > > system.solve() > > } > > catch(...){ > > EquationSystem & es = system.get_equation_systems(); > > es.write("eq_output.xdr") > > } > I'm pretty sure we don't throw an exception when a solve fails, so there's not going to be anything for you to catch here... For a LinearImplicitSystem, the usual approach is to inspect the value of system.get_linear_solver()->get_converged_reason(); and then decide what to do (retry the last time step, etc.) from there. When you say "optimization problem" are you actually using the TAO-based OptimizationSystem class that is in libmesh? -- John |