FrontISTR  5.7.0
Large-scale structural analysis program with finit element method
matrix2graph.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2019 FrontISTR Commons
3  * This software is released under the MIT License, see LICENSE.txt
4  *****************************************************************************/
5 
6 #include "matrix2graph.h"
7 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "separator.h"
11 
12 void matrix2graph(int num_of_row, int num_of_col, int num_of_nzero, int *irow,
13  int *jcol, graph_type *graph) {
14  int i;
15  int *count, tmp_nodeid;
16 
17  graph->xadj = (int *)calloc(num_of_col + 1, sizeof(int));
18  if (graph->xadj == NULL) separator_memory_exit("matrix2graph: graph");
19  graph->xadj[0] = 0;
20  for (i = 0; i < num_of_nzero; i++) {
21  if (irow[i] != jcol[i]) {
22  graph->xadj[irow[i]]++;
23  graph->xadj[jcol[i]]++;
24  }
25  }
26  for (i = 0; i < num_of_col; i++) graph->xadj[i + 1] += graph->xadj[i];
27  graph->adjncy = (int *)calloc(graph->xadj[num_of_col], sizeof(int));
28  if (graph->adjncy == NULL) separator_memory_exit("matrix2graph: graph");
29  count = (int *)calloc(num_of_row, sizeof(int));
30  if (count == NULL) separator_memory_exit("tmp: count");
31  for (i = 0; i < num_of_row; i++) count[i] = 0;
32  for (i = 0; i < num_of_nzero; i++) {
33  if (irow[i] != jcol[i]) {
34  tmp_nodeid = irow[i] - 1;
35  graph->adjncy[graph->xadj[tmp_nodeid] + count[tmp_nodeid]] = jcol[i] - 1;
36  count[tmp_nodeid]++;
37  tmp_nodeid = jcol[i] - 1;
38  graph->adjncy[graph->xadj[tmp_nodeid] + count[tmp_nodeid]] = irow[i] - 1;
39  count[tmp_nodeid]++;
40  }
41  }
42  free(count);
43  graph->nvtxs = num_of_col;
44  graph->nedges = graph->xadj[num_of_col];
45  graph->ncon = 0;
46 
47  return;
48 }
graph_type::adjncy
int * adjncy
Definition: matrix2graph.h:17
graph_type::ncon
int ncon
Definition: matrix2graph.h:15
graph_type::nedges
int nedges
Definition: matrix2graph.h:14
separator_memory_exit
void separator_memory_exit(char *var)
Definition: mem_util.c:9
graph_type
Definition: matrix2graph.h:9
matrix2graph
void matrix2graph(int num_of_row, int num_of_col, int num_of_nzero, int *irow, int *jcol, graph_type *graph)
Definition: matrix2graph.c:12
matrix2graph.h
graph_type::nvtxs
int nvtxs
Definition: matrix2graph.h:13
graph_type::xadj
int * xadj
Definition: matrix2graph.h:16
separator.h
NULL
#define NULL
Definition: hecmw_io_nastran.c:30