sym-ildl  1.2
Incomplete LDL' factorizations of indefinite symmetric and skew-symmetric matrices.
block_diag_matrix_save.h
1 //-*-mode:c++-*-
2 #ifndef _BLOCK_DIAG_MATRIX_SAVE_H_
3 #define _BLOCK_DIAG_MATRIX_SAVE_H_
4 
5 template <class el_type>
6 bool block_diag_matrix<el_type> :: save(std::string filename) const
7 {
8  std::ofstream out(filename.c_str(), std::ios::out | std::ios::binary);
9  if(!out)
10  return false;
11 
12  out.flags(std::ios_base::scientific);
13  out.precision(16);
14  std::string header;
15 
16  header= "%%MatrixMarket matrix coordinate ";
17  header += "real symmetric"; //maybe change later to have general/complex/blah as options
18 
19  out << header << std::endl;
20  out << n_rows() << " " << n_cols() << " " << nnz() << "\n";
21 
22  for(int i = 0; i < n_cols(); i++) {
23  out << i+1 << " " << i+1 << " " << main_diag[i] << "\n";
24  if (block_size(i) == 2) {
25  out << i+2 << " " << i+1 << " " << off_diag.find(i)->second << "\n";
26  out << i+2 << " " << i+2 << " " << main_diag[i+1] << "\n";
27  i++;
28  }
29  }
30 
31  out.close();
32  return true;
33 }
34 
35 #endif
bool save(std::string filename) const
Definition: block_diag_matrix_save.h:6