I don’t have the time to go through your code, but you could try and hunt down singularities in your formulation. For example, make sure you don’t have operators like \mathrm{det}( \cdot ), (\nabla \cdot)^{-1}, \sqrt{\cdot}, etc, with a zero or constant initial guess of your solution varaible.
See also, Default absolute tolerance and relative tolerance - #4 by nate.