static int map_nodes_to_face(int_tuple_int_unordered_map_t* node_face_map, int* nodes, int num_nodes, int_array_t* face_node_offsets, int_array_t* face_nodes) { // Sort the nodes and see if they appear in the node face map. int* sorted_nodes = int_tuple_new(num_nodes); memcpy(sorted_nodes, nodes, sizeof(int) * num_nodes); int_qsort(sorted_nodes, num_nodes); int* entry = int_tuple_int_unordered_map_get(node_face_map, sorted_nodes); int face_index; if (entry == NULL) { // Add a new face! face_index = node_face_map->size; int_tuple_int_unordered_map_insert_with_k_dtor(node_face_map, sorted_nodes, face_index, int_tuple_free); // Record the face->node connectivity. int last_offset = face_node_offsets->data[face_node_offsets->size-1]; int_array_append(face_node_offsets, last_offset + num_nodes); for (int n = 0; n < num_nodes; ++n) int_array_append(face_nodes, nodes[n]); } else { face_index = *entry; int_tuple_free(sorted_nodes); } return face_index; }
static SuperMatrix* supermatrix_new(adj_graph_t* graph) { SuperMatrix* A = polymec_malloc(sizeof(SuperMatrix)); // Fetch sparsity information from the graph. int* edge_offsets = adj_graph_edge_offsets(graph); int num_rows = adj_graph_num_vertices(graph); int num_edges = edge_offsets[num_rows]; int num_nz = num_rows + num_edges; // Translate the sparsity information in the graph to column indices and // row pointers. Since the graph is effectively stored in compressed // row format, we will use SuperLU's compressed row matrix format. int* row_ptrs = intMalloc(num_rows + 1); int* col_indices = intMalloc(num_nz); int* edges = adj_graph_adjacency(graph); int offset = 0; for (int i = 0; i < num_rows; ++i) { row_ptrs[i] = offset; col_indices[offset++] = i; // diagonal column // Off-diagonal columns. for (int j = edge_offsets[i]; j < edge_offsets[i+1]; ++j) col_indices[offset++] = edges[j]; int_qsort(&col_indices[row_ptrs[i]+1], edge_offsets[i+1]-edge_offsets[i]); } row_ptrs[num_rows] = offset; ASSERT(offset == num_nz); // Create zeros for the matrix. real_t* mat_zeros = SUPERLU_MALLOC(sizeof(real_t) * num_nz); memset(mat_zeros, 0, sizeof(real_t) * num_nz); // Hand over these resources to create the Supermatrix. dCreate_CompCol_Matrix(A, num_rows, num_rows, num_nz, mat_zeros, col_indices, row_ptrs, SLU_NC, SLU_D, SLU_GE); return A; }