Exemple #1
0
void writetxtfile_mat(const char *filename, CompCol_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 columns
    for (int j = 0; j < N ; j++)
       for (int i=A.col_ptr(j);i<A.col_ptr(j+1);i++)
       {
          rowp1 = A.row_ind(i)+1;
          colp1 = j + 1;
          if ( rowp1 == M && colp1 == N ) flag = 1;
          fprintf(out_file,"%14d%4s%14d%4s% 20.16E\n", rowp1, "    ",
                                                       colp1,"    ", A.val(i));
       }
 
    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 CompCol_Mat_double &A)
  : val_(0), pntr_(A.dim(1)+1), indx_(0), nz_(0)
{
  dim_[0] = A.dim(0);
  dim_[1] = A.dim(1);

  int i, j, k;

  for (k = 0; k < dim_[1]; k++)
    for (j = A.col_ptr(k); j < A.col_ptr(k+1); j++)
      if (A.row_ind(j) >= k)
    nz_++;

  val_.newsize(nz_);
  indx_.newsize(nz_);

  // Copy just triangular part
  pntr_(0) = 0;
  for (k = 0; k < dim_[1]; k++) {
    pntr_(k+1) = pntr_(k);
    for (j = A.col_ptr(k); j < A.col_ptr(k+1); j++) {
      if (A.row_ind(j) >= k) {
    i = pntr_(k+1)++;
    val_(i) = A.val(j);
    indx_(i) = A.row_ind(j);
      }
    }
  }

  for (i = 0; i < dim_[1]; i++)
    QSort(indx_, val_, pntr_[i], pntr_[i+1] - pntr_[i]);

  for (i = 0; i < dim_[1]; i++)
    if (indx_[pntr_(i)] != i) {
      std::cerr << "IC Preconditioner: diagonal not found!" << i << "\n";
      exit(1);
    }
  
  ICFactor(pntr_, indx_, val_);
}