Changes between Version 15 and Version 16 of TopdlLibrary


Ignore:
Timestamp:
Oct 8, 2012 10:48:11 AM (7 years ago)
Author:
faber
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TopdlLibrary

    v15 v16  
    477477== Making a Topology ==
    478478
    479 
    480 
     479This example constructs the topdl describing a simple start topology with 11 nodes, one center and 10 satellites.
     480
     481[[Image(ten_smaller.png)]]
     482
     483A python program to create that looks like this:
     484
     485{{{
     486#!/usr/bin/env python
     487
     488from deter import topdl
     489
     490elems = []      # elements in the topology
     491subs = []       # substrates in the topology
     492
     493# Create the center node and put it in the element list.  (Name is set
     494# explicitly)
     495center = topdl.Computer(name='center')
     496elems.append(center)
     497
     498# Connect 10 satellites
     499for 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.
     515top = topdl.Topology(elements=elems, substrates=subs)
     516
     517# Print the XML
     518print topdl.topology_to_xml(top, top='experiment')
     519}}}
     520
     521The 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