Tpetra Matrix/Vector Services Version of the Day
Tpetra_RowMatrixTransposer_def.hpp
00001 //@HEADER
00002 // ************************************************************************
00003 // 
00004 //               Tpetra: Linear Algebra Services Package 
00005 //                 Copyright (2001) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ************************************************************************
00027 //@HEADER
00028 
00029 #ifndef TPETRA_ROWMATRIXTRANSPOSER_DEF_HPP
00030 #define TPETRA_ROWMATRIXTRANSPOSER_DEF_HPP
00031 
00032 #include "Tpetra_Map.hpp"
00033 #include "Teuchos_DefaultSerialComm.hpp"
00034 #ifdef DOXYGEN_USE_ONLY
00035   // #include "Tpetra_RowMatrixtransposer_decl.hpp"
00036 #endif
00037 
00038 namespace Tpetra {
00039 
00040 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class SpMatOps>
00041 RowMatrixTransposer<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps>::RowMatrixTransposer(const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& origMatrix)
00042   : origMatrix_(origMatrix), comm_(origMatrix.getComm()), indexBase_(origMatrix_.getIndexBase()) {}
00043 
00044 template<class Scalar, 
00045   class LocalOrdinal, 
00046   class GlobalOrdinal, 
00047   class Node, 
00048   class SpMatOps>
00049 RowMatrixTransposer<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps>::~RowMatrixTransposer() {}
00050 
00051 template<class Scalar, 
00052   class LocalOrdinal,
00053   class GlobalOrdinal, 
00054   class Node, 
00055   class SpMatOps>
00056 RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps> >
00057 RowMatrixTransposer<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps>::createTranspose (
00058   const OptimizeOption optimizeTranspose,
00059   Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > transposeRowMap)
00060 {
00061   optimizeTranspose_ = optimizeTranspose;
00062   transposeMatrix_ = rcp(new CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, SpMatOps>(
00063     transposeRowMap == null? origMatrix_.getDomainMap() : transposeRowMap, 0));
00064   ArrayView<const LocalOrdinal> localIndicies;
00065   ArrayView<const Scalar> localValues;
00066   ArrayView<const GlobalOrdinal> myGlobalRows = origMatrix_.getRowMap()->getNodeElementList();
00067   size_t numEntriesInRow;
00068   Array<GlobalOrdinal> rowNum(1);
00069   RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > origColMap = origMatrix_.getColMap();
00070   for(
00071     size_t i = Teuchos::OrdinalTraits<size_t>::zero();
00072     i < origMatrix_.getNodeNumRows();
00073     ++i
00074   )
00075   {
00076     rowNum[0] = origMatrix_.getRowMap()->getGlobalElement(i);
00077     numEntriesInRow = origMatrix_.getNumEntriesInLocalRow(i);
00078     origMatrix_.getLocalRowView(i, localIndicies, localValues);
00079     for(size_t j=0; j<numEntriesInRow; ++j){
00080       transposeMatrix_->insertGlobalValues(origColMap->getGlobalElement(localIndicies[j]), rowNum(0,1), localValues(j,1));
00081     }
00082   }
00083 
00084   transposeMatrix_->fillComplete(origMatrix_.getRangeMap(), origMatrix_.getDomainMap(), optimizeTranspose_);
00085 
00086   return transposeMatrix_;
00087 }
00088 
00089 //
00090 // Explicit instantiation macro
00091 //
00092 // Must be expanded from within the Tpetra namespace!
00093 //
00094 
00095 #define TPETRA_ROWMATRIXTRANSPOSE_INSTANT(SCALAR,LO,GO,NODE) \
00096   \
00097   template class RowMatrixTransposer< SCALAR, LO , GO , NODE >;
00098 
00099 
00100 }
00101 
00102 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines