from ChemPlugin import * nx, ny = 5, 3 print("Link ChemPlugin instances into a %s by %s grid\n" % (nx, ny)) # Create the ChemPlugin instances cp_left = ChemPlugin() cp_right = ChemPlugin() cp_bottom = ChemPlugin() cp_top = ChemPlugin() cp = [ChemPlugin() for i in range(nx * ny)] # Link the instances into a grid for j in range(ny): for i in range(nx): ij = i + j * nx if i == 0: cp[ij].Link(cp_left) else: cp[ij].Link(cp[ij - 1]) if j == 0: cp[ij].Link(cp_bottom) else: cp[ij].Link(cp[ij - nx]) if j == ny - 1: cp_top.Link(cp[ij]) cp_right.Link(cp[(j + 1) * nx - 1]) # Report the number of links to each instance print("Left boundary is linked to %s instances" % cp_left.nLinks()) print("Bottom boundary is linked to %s instances" % cp_bottom.nLinks()) for i in range(nx * ny): print("Instance %2d is linked to %s instances" % (i, cp[i].nLinks())) print("Top boundary is linked to %s instances" % cp_top.nLinks()) print("Right boundary is linked to %s instances" % cp_right.nLinks()) input("Done!")