Пример #1
0
def main():
    mesh_filename = 'meshes/mini-airfoil.p.part'

    cell2nodes = read_mesh_from_file(mesh_filename, 'cell_to_ord_nodes', int, frozenset)
    node2node = read_mesh_from_file(mesh_filename, 'node_to_node', int, frozenset)
    # DEBUGGING
    global nodes2cell
    nodes2cell = invert_list(cell2nodes)
    ## END DEBUGGING

    # Setup conditions
    seed(7)
    start_node = randint(0, len(node2node) - 1)
    start_node = 58

    # Go
    cell2ord = dict()
    quad_search = QuadSearch(node2node)
    for count, c in enumerate(quad_search.visit(start_node, BestFirstSearchCandidates)):
        # print c
        cell2ord[c.get_cell_id()] = count

    def cell_labeller(old_cell, new_cell):
        if old_cell in cell2ord:
            return '*%d*' % cell2ord[old_cell]
        else:
            return old_cell

    draw(label_cells=cell_labeller)
Пример #2
0
def draw(label_cells=None):
    if label_cells: LABEL_CELLS = label_cells

    print 'graph {'

    printer = GraphPrinter()

    # Read edge2node
    printer.node2inedges, num_inedges = read_inverted_enumerated_map(FILENAME, 'inedge_to_nodes', 0)
    printer.node2borderedges, num_borderedges = read_inverted_enumerated_map(FILENAME, 'borderedge_to_nodes', num_inedges)

    # Read maps
    printer.oldnode2newnode = read_one_to_one('oldnode_to_newnode')
    printer.oldcell2newcell = read_one_to_one('oldcell_to_newcell')
    printer.oldedge2newedge = invert_map(read_one_to_one('newedge_to_oldedge'))
    # Append border edges
    for edge_id in xrange(num_inedges, num_inedges + num_borderedges):
        assert edge_id not in printer.oldedge2newedge
        printer.oldedge2newedge[edge_id] = edge_id

    # Build inverse maps
    newnode2oldnode = invert_map(printer.oldnode2newnode)
    newcell2oldcell = invert_map(printer.oldcell2newcell)


    # Color structured nodes
    for old_node, new_node in printer.oldnode2newnode.iteritems():
        attributes = ['fontsize=%d' % NODEFONTSIZE]
        if COLOR_STRUCTURED_NODES and new_node in new_structured_nodes:
            attributes += ['fillcolor=red', 'style=filled']
        print '"%s" [%s];' % (printer.get_node_name(old_node), ','.join(attributes))


    # Draw edges
    for source, targets in enumerate(read_mesh_from_file(FILENAME, 'node_to_node', int, list)):
        for t in targets:
            # Only one instance of each edge
            if source >= t:
                attribs = printer.get_edge_attribs(source, t)
                print printer.edge_a_to_b(source, t, attribs)


    # Draw cells
    for new_cell, new_nodes in enumerate(read_mesh_from_file(FILENAME, 'new_cell_to_ord_nodes', int, list)):
        n1, n2, n3, n4 = [ newnode2oldnode[new] for new in new_nodes ]
        old_cell = newcell2oldcell[new_cell]

        attribs = ['color=white', 'fontsize=%d' % CELLFONTSIZE]
        attribs += printer.get_elem_label_attribute(LABEL_CELLS, old_cell, new_cell)

        if COLOR_STRUCTURED_CELLS and new_cell in new_structured_cells:
            attribs += ['fontcolor=brown']
        else:
            attribs += ['fontcolor=blue']

        print printer.edge_a_to_b(n1, n3, attribs)

    print '}'
Пример #3
0
def read_inverted_enumerated_map(filename, field, offset):
    b2as = defaultdict(set)
    a_count = 0
    for a, bs in enumerate(read_mesh_from_file(FILENAME, field, int, list), offset):
        a_count += 1
        for b in bs:
            b2as[b].add(a)

    return b2as, a_count
Пример #4
0
def main(in_filename, out_filename, random_seed, start_node):
    # Copy file
    copyfile(in_filename, out_filename)

    # Read adjacency list
    log('Reading node2node map')
    node2node = read_mesh_from_file(out_filename, 'node_to_node', int, frozenset)


    # Set random seed, and choose a start node
    if random_seed:
        seed(random_seed)

    if start_node is None:
        start_node = randint(0, len(node2node) - 1)

    log('Out of %d nodes, we chose %d' % (len(node2node), start_node))


    # Detect node structure
    log('Detecting structure')
    node_structure = DetectNodeStructure(node2node, start_node)

    # Write out structured node data
    log('Writing out structured node to ' + out_filename)
    write_structured_node_info(node_structure, out_filename)


    log('Writing oldnode2newnode')
    write_text_map('oldnode_to_newnode', node_structure.oldnode2newnode, out_filename)

    # Renumber nodes
    node_structure.structured_node_regions = [ renumber_value_lists(region, node_structure.oldnode2newnode)
    for region in node_structure.structured_node_regions ]


    # Reorder coordinates
    log('Reordering coordinates')
    coord_data = read_mesh_from_file(out_filename, 'coord_data', float, list)
    new_coord_data = renumber_keys(coord_data, node_structure.newnode2oldnode)
    write_new_coord_data(new_coord_data, out_filename)


    # Figure out cell2nodes stuff
    log('Figuring out cell2nodes')
    cell2ordnodes = read_mesh_from_file(out_filename, 'cell_to_ord_nodes', int, list)

    # Apply node renumbering to cell map
    cell2ordnodes = renumber_value_lists(cell2ordnodes, node_structure.oldnode2newnode)

    cell_structure = CellStructureFromNodeStructure(node_structure.structured_node_regions, cell2ordnodes)
    log('Writing out structured cells to ' + out_filename)
    write_structured_cell_info(cell_structure, out_filename)


    # Figure out inedge2nodes
    log('Figuring out inedge2nodes and inedge2cells')
    inedge2nodes = read_mesh_from_file(out_filename, 'inedge_to_nodes', int, list)
    inedge2cells = read_mesh_from_file(out_filename, 'inedge_to_cells', int, list)

    # Apply node and cell renumbering to inedge maps
    inedge2nodes = renumber_value_lists(inedge2nodes, node_structure.oldnode2newnode)
    inedge2cells = renumber_value_lists(inedge2cells, cell_structure.oldcell2newcell)

    # Renumber cells
    for cell_region in cell_structure.structured_cell_regions:
        cell_region.structured_cells = renumber_value_lists(cell_region.structured_cells, cell_structure.oldcell2newcell)

    edge_structure = EdgeStructureFromNodeStructure(node_structure.structured_node_regions, cell_structure.structured_cell_regions, inedge2nodes, inedge2cells)

    log('Writing out structured inedges to ' + out_filename)
    write_structured_inedge_info(edge_structure, out_filename)



    # Read border edges
    borderedge2nodes = read_mesh_from_file(out_filename, 'borderedge_to_nodes', int, list)
    borderedge2cell = read_mesh_from_file(out_filename, 'borderedge_to_cell', int, list)

    # Apply node and cell renumbering to borderedge maps
    new_borderedge2nodes = renumber_value_lists(borderedge2nodes, node_structure.oldnode2newnode)
    new_borderedge2cell = renumber_value_lists(borderedge2cell, cell_structure.oldcell2newcell)

    log('Writing renumbered borderedges to ' + out_filename)
    write_renumbered_border_edges(new_borderedge2nodes, new_borderedge2cell, out_filename)

    log('Writing oldcell2newcell')
    write_text_map('oldcell_to_newcell', cell_structure.oldcell2newcell, out_filename)

    log('Writing oldedge2newedge')
    write_text_map('newedge_to_oldedge', edge_structure.newedge2oldedge, out_filename)