src/matrixmarket/mtxreader0.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           mtxreader0.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 "mtxreader0.h"
00023 
00024 MtxReader0::~MtxReader0() {}
00025 
00026 Epetra_CrsMatrix* MtxReader0::read() {
00027     MtxDataIterator it(*_istr, true);
00028 
00029     assert(it.get_element_type() != MtxDataIterator::complex);
00030     assert(it.get_storage_scheme() == MtxDataIterator::general ||
00031            it.get_storage_scheme() == MtxDataIterator::symmetric);
00032 
00033     // Allocate map (rows are evenly distributed across processors)
00034     Epetra_Map range_row_map(it.get_rows(), 0, _comm);
00035 
00036     // Allocate matrix and read matrix data
00037     Epetra_CrsMatrix* mat = new Epetra_CrsMatrix (Copy, range_row_map, 0);
00038 
00039     // read matrix entries
00040     while (!it.eof()) {
00041         MtxDataIterator::Triplet tr = *it;
00042         int row = tr.row;
00043         int col = tr.col;
00044         double val = tr.val;
00045 
00046         if (range_row_map.MyGID(row))
00047             mat->InsertGlobalValues(row, 1, &val, &col);
00048 
00049         ++it;
00050     }
00051 
00052     // finalise Crs matrix
00053     if (it.get_rows() == it.get_cols()) {
00054         // if square, make sure that row, domain and range map are identical
00055         mat->FillComplete(range_row_map, range_row_map);
00056     } else {
00057         // if not square, only row and range map are identical
00058         Epetra_Map domain_map(it.get_cols(), 0, _comm);
00059         mat->FillComplete(domain_map, range_row_map);
00060     }
00061 
00062     return mat;
00063 }

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