Smoothed particle hydrodynamics: Theory and application to non-spherical stars