Exemplo n.º 1
0
for x in range(0, n):
    sys.stderr.write(" Devices : Row {} of {}\n".format(x, n))
    for y in range(0, n):
        devProps = {"x": x, "y": y}
        di = DeviceInstance(res, "n_{}_{}".format(x, y), devType, devProps)
        nodes[(x, y)] = di
        res.add_device_instance(di)


def add_channel(x, y, dx, dy, dir):
    edgeProps = {"direction": dir}
    dst = nodes[(x, y)]
    src = nodes[((x + dx + n) % n, (y + dy + n) % n)]
    ei = EdgeInstance(res, dst, "in", src, "out", edgeProps)
    res.add_edge_instance(ei)


for x in range(0, n):
    sys.stderr.write(" Edges : Row {} of {}\n".format(x, n))
    for y in range(0, n):
        centre = nodes[(x, y)]
        add_channel(x, y, 0, -1, 1)
        add_channel(x, y, +1, 0, 2)
        if n > 2:
            add_channel(x, y, 0, +1, 3)
        if n > 2:
            add_channel(x, y, -1, 0, 4)

save_graph(res, sys.stdout)
Exemplo n.º 2
0
        
    for c in cells:
        graph.create_edge_instance(printer,"rms_inc",c,"update")
        graph.create_edge_instance(c,"rms_ack",printer,"rms_ack")
    
    return graph
    

if __name__=="__main__":
    import mock    
    import argparse

    parser = argparse.ArgumentParser(description='Generate graph for airfoil.')
    parser.add_argument('source', type=str, help='Input hdf5 mesh, or take new_grid.h5 by default', nargs="?", default=appBase+"/new_grid.h5")
    parser.add_argument('-o', dest='output', default="-", help='Where to save the file (- for stdout)')
    args = parser.parse_args()
    
    sys.stderr.write(f"src = {args.source}")
    sys.stderr.write(f"exists = {os.path.exists(args.source)}")
    src=h5py.File(args.source,"r")
    model=mock.load(src)
    
    #model=mock.create_square(3)
    
    graph=render_model(model)
    
    dst=sys.stdout
    if args.output!="-":
        dst=args.output
    save_graph(graph,dst)
Exemplo n.º 3
0
#!/usr/bin/env python3

from graph.load_xml import load_graph
from graph.save_xml import save_graph
from lxml import etree

from graph.expand_code import expand_graph_type_source

import sys
import os

if len(sys.argv) != 2:
    raise RuntimeError(
        "This converts exactly one XML file. Please provide one path to an XML file"
    )

sys.stderr.write("Reading graph type from '{}'\n".format(sys.argv[1]))
source = open(sys.argv[1], "rt")
sourcePath = os.path.abspath(sys.argv[1])

dest = sys.stdout
destPath = "[XML-file]"

(gt, gi) = load_graph(source, sourcePath)
assert not gi, "This program only works with graph types (not graph instances)"

expand_graph_type_source(gt, sourcePath)

save_graph(gt, dest)
Exemplo n.º 4
0
#!/usr/bin/env python3

from graph.load_xml import load_graph
from graph.save_xml import save_graph
from lxml import etree

import sys
import os

source=sys.stdin
sourcePath="[XML-file]"

if len(sys.argv) != 2:
    raise RuntimeError("This converts exactly one XML file. Please provide one path to an XML file")

sys.stderr.write("Reading graph type from '{}'\n".format(sys.argv[1]))
source=open(sys.argv[1],"rt")
sourcePath=os.path.abspath(sys.argv[1])

dest=sys.stdout
destPath="[XML-file]"

# LOAD XML
(gt,gi)=load_graph(source, sourcePath)

save_graph(gi if gi else gt, dest)
Exemplo n.º 5
0
    src_port=random.choice(list(src_device.device_type.outputs.values()))

    random.shuffle(device_instances)
    
    dst_device=None
    dst_port=None
    for dst_device in device_instances:
        pp=list(dst_device.device_type.inputs.values())
        random.shuffle(pp)
        for p in pp:
            if p.edge_type == src_port.edge_type:
                dst_port=p
                break
        if dst_port:
            break

    if not dst_port:
        continue

    if ( dst_device.id, dst_port.name, src_device.id, src_port.name) in graphInstance.edge_instances:
        continue

    properties=make_random_instance(dst_port.edge_type.properties)
    ei=EdgeInstance(graphInstance, dst_device, dst_port.name, src_device, src_port.name,properties)
    graphInstance.add_edge_instance(ei)
        
    
    

save_graph(graphInstance,sys.stdout)