1cb512458SBarry Smith #ifndef lint 2*35aab85fSBarry Smith static char vcid[] = "$Id: ij.c,v 1.15 1995/11/23 04:28:18 bsmith Exp bsmith $"; 3cb512458SBarry Smith #endif 4d6dfbf8fSBarry Smith 52d9e4a2aSBarry Smith #include "aij.h" 62d9e4a2aSBarry Smith 72d9e4a2aSBarry Smith /* 8ec8511deSBarry Smith MatToSymmetricIJ_SeqAIJ - Convert a sparse AIJ matrix to IJ format 9d5d45c9bSBarry Smith (ignore the "A" part) Allocates the space needed. Uses only 10d5d45c9bSBarry Smith the lower triangular part of the matrix. 112d9e4a2aSBarry Smith 122d9e4a2aSBarry Smith Description: 132d9e4a2aSBarry Smith Take the data in the row-oriented sparse storage and build the 142d9e4a2aSBarry Smith IJ data for the Matrix. Return 0 on success, row + 1 on failure 152d9e4a2aSBarry Smith at that row. Produces the ij for a symmetric matrix by only using 162d9e4a2aSBarry Smith the lower triangular part of the matrix. 172d9e4a2aSBarry Smith 182d9e4a2aSBarry Smith Input Parameters: 192d9e4a2aSBarry Smith . Matrix - matrix to convert 202d9e4a2aSBarry Smith 212d9e4a2aSBarry Smith Output Parameters: 222d9e4a2aSBarry Smith . ia - ia part of IJ representation (row information) 232d9e4a2aSBarry Smith . ja - ja part (column indices) 242d9e4a2aSBarry Smith 252d9e4a2aSBarry Smith Notes: 260452661fSBarry Smith $ Both ia and ja may be freed with PetscFree(); 27464493b3SBarry Smith $ This routine is provided for ordering routines that require a 28464493b3SBarry Smith $ symmetric structure. It is used in SpOrder (and derivatives) since 29464493b3SBarry Smith $ those routines call SparsePak routines that expect a symmetric 30464493b3SBarry Smith $ matrix. 312d9e4a2aSBarry Smith */ 32*35aab85fSBarry Smith int MatToSymmetricIJ_SeqAIJ(int n,int *ai,int *aj,int shift, int **iia, int **jja ) 332d9e4a2aSBarry Smith { 34*35aab85fSBarry Smith int *work,*ia,*ja,*j,i, nz, row, col; 352d9e4a2aSBarry Smith 362d9e4a2aSBarry Smith /* allocate space for row pointers */ 370452661fSBarry Smith *iia = ia = (int *) PetscMalloc( (n+1)*sizeof(int) ); CHKPTRQ(ia); 38cddf8d76SBarry Smith PetscMemzero(ia,(n+1)*sizeof(int)); 390452661fSBarry Smith work = (int *) PetscMalloc( (n+1)*sizeof(int) ); CHKPTRQ(work); 402d9e4a2aSBarry Smith 412d9e4a2aSBarry Smith /* determine the number of columns in each row */ 422d9e4a2aSBarry Smith ia[0] = 1; 432d9e4a2aSBarry Smith for (row = 0; row < n; row++) { 443439631bSBarry Smith nz = ai[row+1] - ai[row]; 453439631bSBarry Smith j = aj + ai[row]; 462d9e4a2aSBarry Smith while (nz--) { 47dbb450caSBarry Smith col = *j++ + shift; 48416022c9SBarry Smith if (col > row) { break;} 492d9e4a2aSBarry Smith if (col != row) ia[row+1]++; 502d9e4a2aSBarry Smith ia[col+1]++; 512d9e4a2aSBarry Smith } 522d9e4a2aSBarry Smith } 532d9e4a2aSBarry Smith 542d9e4a2aSBarry Smith /* shift ia[i] to point to next row */ 552d9e4a2aSBarry Smith for ( i=1; i<n+1; i++ ) { 562d9e4a2aSBarry Smith row = ia[i-1]; 572d9e4a2aSBarry Smith ia[i] += row; 582d9e4a2aSBarry Smith work[i-1] = row - 1; 592d9e4a2aSBarry Smith } 602d9e4a2aSBarry Smith 612d9e4a2aSBarry Smith /* allocate space for column pointers */ 62dbb450caSBarry Smith nz = ia[n] + (!shift); 630452661fSBarry Smith *jja = ja = (int *) PetscMalloc( nz*sizeof(int) ); CHKPTRQ(ja); 642d9e4a2aSBarry Smith 652d9e4a2aSBarry Smith /* loop over lower triangular part putting into ja */ 662d9e4a2aSBarry Smith for (row = 0; row < n; row++) { 673439631bSBarry Smith nz = ai[row+1] - ai[row]; 683439631bSBarry Smith j = aj + ai[row]; 692d9e4a2aSBarry Smith while (nz--) { 70dbb450caSBarry Smith col = *j++ + shift; 71416022c9SBarry Smith if (col > row) { break;} 723439631bSBarry Smith if (col != row) {ja[work[col]++] = row + 1; } 733439631bSBarry Smith ja[work[row]++] = col + 1; 742d9e4a2aSBarry Smith } 752d9e4a2aSBarry Smith } 760452661fSBarry Smith PetscFree(work); 772d9e4a2aSBarry Smith return 0; 782d9e4a2aSBarry Smith } 792d9e4a2aSBarry Smith 80d5d45c9bSBarry Smith 81d5d45c9bSBarry Smith 82