EpetraExt_View_CrsGraph.cpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //     EpetraExt: Epetra Extended - 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 #include <EpetraExt_View_CrsGraph.h>
00030 
00031 #include <Epetra_CrsGraph.h>
00032 #include <Epetra_BlockMap.h>
00033 
00034 #include <vector>
00035 
00036 namespace EpetraExt {
00037 
00038 CrsGraph_View::
00039 ~CrsGraph_View()
00040 {
00041   if( newObj_ ) delete newObj_;
00042 }
00043 
00044 CrsGraph_View::NewTypeRef
00045 CrsGraph_View::
00046 operator()( OriginalTypeRef orig )
00047 {
00048   origObj_ = &orig;
00049 
00050   //Error, must be local indices
00051   assert( !orig.IndicesAreGlobal() );
00052 
00053   //test maps, new std::map must be left subset of old
00054   const Epetra_BlockMap & oRowMap = orig.RowMap();
00055   const Epetra_BlockMap & oColMap = orig.ColMap();
00056 
00057   int nNumRows = NewRowMap_->NumMyElements();
00058   int nNumCols = 0;
00059   if( NewColMap_ ) nNumCols = NewColMap_->NumMyElements();
00060 
00061   bool matched = true;
00062   for( int i = 0; i < nNumRows; ++i )
00063     matched = matched && ( oRowMap.GID(i) == NewRowMap_->GID(i) );
00064   if( nNumCols )
00065     for( int i = 0; i < nNumCols; ++i )
00066       matched = matched && ( oColMap.GID(i) == NewColMap_->GID(i) );
00067 
00068   if( !matched ) std::cout << "EDT_CrsGraph_View: Bad Row or Col Mapping\n";
00069   assert( matched );
00070 
00071   //intial construction of graph
00072   std::vector<int> numIndices( nNumRows );
00073   std::vector<int*> indices( nNumRows );
00074   for( int i = 0; i < nNumRows; ++i )
00075   {
00076     orig.ExtractMyRowView( i, numIndices[i], indices[i] );
00077     int j = 0;
00078     if( nNumCols )
00079     {
00080       while( j < numIndices[i] && NewColMap_->GID(indices[i][j]) != -1 ) ++j;
00081       numIndices[i] = j;
00082     }
00083   }
00084 
00085   Epetra_CrsGraph * newGraph( new Epetra_CrsGraph( View,
00086                                                    *NewRowMap_,
00087                                                    *NewColMap_,
00088                                                    &numIndices[0] ) );
00089 
00090   //insert views of row indices
00091   for( int i = 0; i < nNumRows; ++i )
00092     newGraph->InsertMyIndices( i, numIndices[i], indices[i] );
00093 
00094   newGraph->FillComplete();
00095 
00096   newObj_ = newGraph;
00097 
00098   return *newGraph;
00099 }
00100 
00101 } // namespace EpetraExt
00102 

Generated on Tue Oct 20 12:45:30 2009 for EpetraExt by doxygen 1.4.7