Check PETSc error codes inside OpenFOAM
This will stop the simulation as soon as an error is encountered, avoiding a waste of resources. Proper foam shutdown can also be added. For an example on how to do it, see https://github.com/mfem/mfem/blob/master/linalg/petsc.cpp#L43