Beispiel #1
0
def kagome_polyedge_colouring(kagome):

    polyedges = kagome.polyedge_data

    edge_to_polyedge_index = {vkey: {} for vkey in kagome.vertices()}
    for i, polyedge in enumerate(polyedges):
        for u, v in pairwise(polyedge):
            edge_to_polyedge_index[u][v] = i
            edge_to_polyedge_index[v][u] = i

    vertices = [
        centroid_points([kagome.vertex_coordinates(vkey) for vkey in polyedge])
        for polyedge in polyedges
    ]

    edges = []
    for idx, polyedge in enumerate(polyedges):
        for vkey in polyedge:
            for vkey_2 in kagome.vertex_neighbors(vkey):
                idx_2 = edge_to_polyedge_index[vkey][vkey_2]
                if idx_2 != idx and idx < idx_2 and (idx, idx_2) not in edges:
                    edges.append((idx, idx_2))

    polyedge_network = Network.from_nodes_and_edges(vertices, edges)

    key_to_colour = vertex_coloring(polyedge_network.adjacency)

    return [key_to_colour[key] for key in sorted(key_to_colour.keys())]
# Setup

L0 = 1.0
L  = 1.5
n  = 40
EI = 0.2
pins = [0, 5, 20, n - 5]


# Network

nodes = [[i, i, 0] for i in list(linspace(0, L0, n))]
edges = [[i, i + 1] for i in range(n - 1)]

network = Network.from_nodes_and_edges(nodes=nodes, edges=edges)
network.update_default_node_attributes(
    {'is_fixed': False, 'P': [1, -2, 0], 'EIx': EI, 'EIy': EI, 'B': [1, 1, 1], 'P': [0, 0, 0]})
network.update_default_edge_attributes(
    {'E': 50, 'A': 1, 'l0': L / n})
network.nodes_attribute('B', [0, 0, 0], keys=pins)
network.nodes_attribute('is_fixed', True, keys=pins)
network.attributes['beams'] = {'beam': {'nodes': list(range(n))}}

# Plotter

plotter = NetworkPlotter(network, figsize=(10, 7))


# Initial configuration