Refactored partition creation code.

Removed a lot of duplicate code and broke up some large functions. There
are still a number of things that are unclear as to how they work,
particularly with regard to the automatic creation of partitions.
Furthermore, the performance of a simulation with automatically
generated partitions is fairly bad when compared to manually assigned
partitions (assuming the user picks semi-optimal values). As such, it
would likely be worthwhile to look further into replacing this section
of the code with a simpler more effective heuristic.