TopdlLibrary: ten.py

File ten.py, 1.0 KB (added by faber, 7 years ago)

Python program to create a start topology

Line 
1#!/usr/bin/env python
2
3from deter import topdl
4
5elems = []      # elements in the topology
6subs = []       # substrates in the topology
7
8# Create the center node and put it in the element list.  (Name is set
9# explicitly)
10center = topdl.Computer(name='center')
11elems.append(center)
12
13# Connect 10 satellites
14for i in range(0,10):
15    # Create a substrate to join the new element to center
16    link = topdl.Substrate('link%d' % i)
17    # Create the new element (n-i) and connect it to the new substrate with an
18    # Interface object
19    node = topdl.Computer(name='n-%d' % i, interface=[
20        topdl.Interface(substrate=['link%d' %i])])
21    # Add an interface to center linking it to the new substrate
22    center.interface.append(topdl.Interface(substrate=['link%d' %i]))
23
24    # Add the new link and node to the lists
25    subs.append(link)
26    elems.append(node)
27
28# Create the topology from the lists.  This names the unnamed interfaces and
29# makes connections.
30top = topdl.Topology(elements=elems, substrates=subs)
31
32# Print the XML
33print topdl.topology_to_xml(top, top='experiment')
34