Automatic domain partitioning in three dimensions