479 | | |
480 | | |
| 479 | This example constructs the topdl describing a simple start topology with 11 nodes, one center and 10 satellites. |
| 480 | |
| 481 | [[Image(ten_smaller.png)]] |
| 482 | |
| 483 | A python program to create that looks like this: |
| 484 | |
| 485 | {{{ |
| 486 | #!/usr/bin/env python |
| 487 | |
| 488 | from deter import topdl |
| 489 | |
| 490 | elems = [] # elements in the topology |
| 491 | subs = [] # substrates in the topology |
| 492 | |
| 493 | # Create the center node and put it in the element list. (Name is set |
| 494 | # explicitly) |
| 495 | center = topdl.Computer(name='center') |
| 496 | elems.append(center) |
| 497 | |
| 498 | # Connect 10 satellites |
| 499 | for i in range(0,10): |
| 500 | # Create a substrate to join the new element to center |
| 501 | link = topdl.Substrate('link%d' % i) |
| 502 | # Create the new element (n-i) and connect it to the new substrate with an |
| 503 | # Interface object |
| 504 | node = topdl.Computer(name='n-%d' % i, interface=[ |
| 505 | topdl.Interface(substrate=['link%d' %i])]) |
| 506 | # Add an interface to center linking it to the new substrate |
| 507 | center.interface.append(topdl.Interface(substrate=['link%d' %i])) |
| 508 | |
| 509 | # Add the new link and node to the lists |
| 510 | subs.append(link) |
| 511 | elems.append(node) |
| 512 | |
| 513 | # Create the topology from the lists. This names the unnamed interfaces and |
| 514 | # makes connections. |
| 515 | top = topdl.Topology(elements=elems, substrates=subs) |
| 516 | |
| 517 | # Print the XML |
| 518 | print topdl.topology_to_xml(top, top='experiment') |
| 519 | }}} |
| 520 | |
| 521 | The program builds the topology by creating a [TopdlLibrary#ComputerClass computer object] that is the center of the star, then creates other computers that are connected to the center. The connection is accomplished by creating a [TopdlLibrary#SubstrateClass Substrate object] that represents the connection and adding [TopdlLibrary#InterfaceClass Interface objects] to the center computer and the satellite that bind them to the substrate. |
| 522 | |
| 523 | |