A level set method for determining critical curvatures for drainage and imbibition.