A generalization of the theory of the mixing length with applications to atmospheric and oceanic turbulence