00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <cassert>
00019 #include "Epetra_Map.h"
00020
00021 #include "mtxdataiterator.h"
00022 #include "mtxreader.h"
00023
00024 MtxReader::MtxReader(string filename, const Epetra_Map& row_map,
00025 const Epetra_Map& domain_map, const Epetra_Map& range_map)
00026 : BaseMtxReader(filename, row_map.Comm()),
00027 _row_map(row_map),
00028 _domain_map(domain_map),
00029 _range_map(range_map) {}
00030
00031 MtxReader::MtxReader(istream& istr, const Epetra_Map& row_map,
00032 const Epetra_Map& domain_map, const Epetra_Map& range_map)
00033 : BaseMtxReader(istr, row_map.Comm()),
00034 _row_map(row_map),
00035 _domain_map(domain_map),
00036 _range_map(range_map) {}
00037
00038 MtxReader::~MtxReader() {}
00039
00040 Epetra_CrsMatrix* MtxReader::read() {
00041 MtxDataIterator it(*_istr, true);
00042
00043 assert(it.get_element_type() != MtxDataIterator::complex);
00044 assert(it.get_storage_scheme() == MtxDataIterator::general ||
00045 it.get_storage_scheme() == MtxDataIterator::symmetric);
00046
00047
00048 Epetra_CrsMatrix* mat = new Epetra_CrsMatrix (Copy, _row_map, 0);
00049
00050
00051 while (!it.eof()) {
00052 MtxDataIterator::Triplet tr = *it;
00053 int row = tr.row;
00054 int col = tr.col;
00055 double val = tr.val;
00056
00057 if (_row_map.MyGID(row))
00058 mat->InsertGlobalValues(row, 1, &val, &col);
00059
00060 ++it;
00061 }
00062
00063
00064 mat->FillComplete(_domain_map, _range_map);
00065
00066 return mat;
00067 }