void writetxtfile_mat(const char *filename, CompRow_Mat_double &A) { FILE *out_file; out_file = fopen( filename, "w"); int rowp1, colp1; int M = A.dim(0); int N = A.dim(1); int flag = 0; // Loop through rows... for (int i = 0; i < M ; i++) for (int j=A.row_ptr(i);j<A.row_ptr(i+1);j++) { rowp1 = i + 1; colp1 = A.col_ind(j) + 1; if ( rowp1 == M && colp1 == N ) flag = 1; fprintf(out_file,"%14d%4s%14d%4s% 20.16E\n", rowp1, " ", colp1," ", A.val(j)); } if (flag == 0) fprintf(out_file,"%14d%4s%14d%4s% 20.16E\n", M, " ", N," ", A(M-1,N-1)); fclose(out_file); return; }
ICPreconditioner_double::ICPreconditioner_double(const CompRow_Mat_double &A) : val_(0), pntr_(A.dim(0)+1), indx_(0), nz_(0) { dim_[0] = A.dim(0); dim_[1] = A.dim(1); int i, j, k; for (k = 0; k < dim_[0]; k++) for (j = A.row_ptr(k); j < A.row_ptr(k+1); j++) if (A.col_ind(j) >= k) nz_++; val_.newsize(nz_); indx_.newsize(nz_); // Copy just triangular part (including diagonal) pntr_(0) = 0; for (k = 0; k < dim_[0]; k++) { pntr_(k+1) = pntr_(k); for (j = A.row_ptr(k); j < A.row_ptr(k+1); j++) { if (A.col_ind(j) >= k) { i = pntr_(k+1)++; val_(i) = A.val(j); indx_(i) = A.col_ind(j); } } } for (i = 0; i < dim_[0]; i++) QSort(indx_, val_, pntr_[i], pntr_[i+1] - pntr_[i]); for (i = 0; i < dim_[0]; i++) if (indx_[pntr_(i)] != i) { std::cerr << "IC Preconditioner: diagonal not found!" << i << "\n"; exit(1); } ICFactor(pntr_, indx_, val_); }