src/matrixmarket/mtxreader.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           MtxReader.cpp  -  description
00003                              -------------------
00004     begin                : Tue Dec 2 2003
00005     copyright            : (C) 2003 by Roman Geus
00006     email                : roman.geus@psi.ch
00007 ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
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     // Allocate matrix and read matrix data
00048     Epetra_CrsMatrix* mat = new Epetra_CrsMatrix (Copy, _row_map, 0);
00049 
00050     // read matrix entries
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     // finalise Crs matrix
00064     mat->FillComplete(_domain_map, _range_map);
00065 
00066     return mat;
00067 }

Generated on Fri Oct 26 13:35:12 2007 for FEMAXX (Finite Element Maxwell Eigensolver) by  doxygen 1.4.7