A stable finite element method for low inertia undulatory locomotion in three dimensions