00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00051 assert( !orig.IndicesAreGlobal() );
00052
00053
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
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
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 }
00102