def __init__(self, structured_node_regions, cell2ordnodes): num_cells = len(cell2ordnodes) node2ordcells = _invert_cell2ordnodes(cell2ordnodes) structured_cell_regions = [] for node_region in structured_node_regions: # Preview of node region _print_partial_region('Structured node region:', node_region) # Extract cell structured region topleft_quad, compass = _find_topleftmost_structured_quad(node_region, node2ordcells) cell_region = _find_remaining_structure(topleft_quad, compass, node_region, node2ordcells) structured_cell_regions.append(cell_region) # Renumber cells oldcell2newcell, newcell2oldcell, num_structured_cells, unstructured_cells_offset = _renumber_cells(structured_cell_regions, num_cells) # Determine number of unstructured cells assert num_structured_cells == unstructured_cells_offset num_unstructured_cells = num_cells - num_structured_cells # Unstructured cell region metadata unstructured_cell_regions = UnstructuredCellRegion() unstructured_cell_regions.unstructured_cells_offset = unstructured_cells_offset unstructured_cell_regions.num_unstructured_cells = num_unstructured_cells # Apply cell reordering to original map new_cell2ordnodes = renumber_keys(cell2ordnodes, newcell2oldcell) # Save self.new_cell2ordnodes = new_cell2ordnodes self.structured_cell_regions = structured_cell_regions self.unstructured_cell_regions = unstructured_cell_regions self.oldcell2newcell = oldcell2newcell
def __init__(self, structured_node_regions, structured_cell_regions, inedge2ordnodes, inedge2ordcells): self._inedge2ordnodes = inedge2ordnodes self._inedge2ordcells = inedge2ordcells # Get numbers assert len(self._inedge2ordnodes) == len(inedge2ordcells), "Number of edges must match!" assert len(structured_node_regions) == len(structured_cell_regions), "Number of edges must match!" num_edges = len(self._inedge2ordnodes) # Invert map self.node2ordinedges = _build_node2ordinedges(self._inedge2ordnodes) # Detect structure self.detect_edge_structure_and_renumber_edges(structured_node_regions, structured_cell_regions, num_edges) # Applying edge renumbering self.new_inedge2ordnodes = renumber_keys(self._inedge2ordnodes, self.newedge2oldedge) self.new_inedge2ordcells = renumber_keys(inedge2ordcells, self.newedge2oldedge)
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)