Having the exact same question like Permutation of 2 or more groups while keeping the ordering of the groups, I hope to write a function that could only keep those permutations that stay in order within groups.
However, I wonder if there is any manner to have the permutation on the fly. Currently, I am doing the exclusion in a post-hoc way, i.e. checking each generated permutation if it meets the group ordering criteria. You know, this is not quite scalable since takes so many unnecessary calculations: For two groups (c.f. size n and m), the operation number sums up to (m+n)! instead of (m+n)!/(n!·m!)).