added calculation for tree and grid topology; choose topology using sys.argv