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_Transpose_CrsGraph.h>
00030
00031 #include <Epetra_Export.h>
00032 #include <Epetra_CrsGraph.h>
00033 #include <Epetra_Map.h>
00034
00035 #include <vector>
00036
00037 namespace EpetraExt {
00038
00039 CrsGraph_Transpose::
00040 ~CrsGraph_Transpose()
00041 {
00042 delete newObj_;
00043 }
00044
00045 CrsGraph_Transpose::NewTypeRef
00046 CrsGraph_Transpose::
00047 operator()( OriginalTypeRef orig )
00048 {
00049 origObj_ = &orig;
00050
00051 int nRows = orig.NumMyRows();
00052 int nCols = orig.NumMyCols();
00053
00054 const Epetra_BlockMap & RowMap = orig.RowMap();
00055
00056 int numIndices;
00057 int * Indices;
00058
00059 Epetra_CrsGraph * TransposeGraph = 0;
00060
00061 if( !ignoreNonLocalCols_ && orig.DistributedGlobal() )
00062 {
00063 std::vector<int> TransNumNZ( nCols, 0 );
00064 for( int i = 0; i < nRows; ++i )
00065 {
00066 orig.ExtractMyRowView( i, numIndices, Indices );
00067 for( int j = 0; j < numIndices; ++j ) ++TransNumNZ[ Indices[j] ];
00068 }
00069
00070 std::vector< std::vector<int> > TransIndices( nCols );
00071 for( int i = 0; i < nCols; ++i )
00072 if( TransNumNZ[i] )
00073 {
00074 TransIndices[i].resize( TransNumNZ[i] );
00075 TransNumNZ[i] = 0;
00076 }
00077
00078 for( int i = 0; i < nRows; ++i )
00079 {
00080 orig.ExtractMyRowView( i, numIndices, Indices );
00081 for( int j = 0; j < numIndices; ++j )
00082 TransIndices[ Indices[j] ][ TransNumNZ[ Indices[j] ]++ ] = i;
00083 }
00084
00085 Epetra_CrsGraph SharedTransGraph( View, orig.ImportMap(), RowMap, &TransNumNZ[0] );
00086 for( int i = 0; i < nCols; ++i )
00087 if( TransNumNZ[i] ) SharedTransGraph.InsertMyIndices( i, TransNumNZ[i], &TransIndices[i][0] );
00088 SharedTransGraph.FillComplete();
00089
00090 TransposeGraph = new Epetra_CrsGraph( Copy, RowMap, 0 );
00091 Epetra_Export Exporter( orig.ImportMap(), RowMap );
00092 TransposeGraph->Export( SharedTransGraph, Exporter, Add );
00093 TransposeGraph->FillComplete();
00094 }
00095 else
00096 {
00097 std::vector<int> TransNumNZ( nRows, 0 );
00098 for( int i = 0; i < nRows; ++i )
00099 {
00100 orig.ExtractMyRowView( i, numIndices, Indices );
00101 for( int j = 0; j < numIndices; ++j )
00102 if( Indices[j] < nRows ) ++TransNumNZ[ Indices[j] ];
00103 }
00104
00105 std::vector< std::vector<int> > TransIndices( nRows );
00106 for( int i = 0; i < nRows; ++i )
00107 if( TransNumNZ[i] )
00108 {
00109 TransIndices[i].resize( TransNumNZ[i] );
00110 TransNumNZ[i] = 0;
00111 }
00112
00113 for( int i = 0; i < nRows; ++i )
00114 {
00115 orig.ExtractMyRowView( i, numIndices, Indices );
00116 for( int j = 0; j < numIndices; ++j )
00117 if( Indices[j] < nRows ) TransIndices[ Indices[j] ][ TransNumNZ[ Indices[j] ]++ ] = i;
00118 }
00119
00120 TransposeGraph = new Epetra_CrsGraph( Copy, RowMap, RowMap, &TransNumNZ[0] );
00121
00122 for( int i = 0; i < nRows; ++i )
00123 if( TransNumNZ[i] ) TransposeGraph->InsertMyIndices( i, TransNumNZ[i], &TransIndices[i][0] );
00124
00125 TransposeGraph->FillComplete();
00126 }
00127
00128 newObj_ = TransposeGraph;
00129
00130 return *TransposeGraph;
00131 }
00132
00133 }
00134