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_Reindex_CrsMatrix.h>
00030
00031 #include <vector>
00032
00033 #include <Epetra_CrsMatrix.h>
00034 #include <Epetra_Map.h>
00035 #include <Epetra_IntVector.h>
00036
00037 #include <Epetra_Export.h>
00038 #include <Epetra_Import.h>
00039
00040 namespace EpetraExt {
00041
00042 CrsMatrix_Reindex::
00043 ~CrsMatrix_Reindex()
00044 {
00045 if( newObj_ ) delete newObj_;
00046 if( NewColMap_ ) delete NewColMap_;
00047 }
00048
00049 CrsMatrix_Reindex::NewTypeRef
00050 CrsMatrix_Reindex::
00051 operator()( OriginalTypeRef orig )
00052 {
00053 origObj_ = &orig;
00054
00055
00056 Epetra_Map & OldRowMap = const_cast<Epetra_Map&>(orig.RowMap());
00057 Epetra_Map & OldColMap = const_cast<Epetra_Map&>(orig.ColMap());
00058 int NumMyElements = OldRowMap.NumMyElements();
00059 assert( OldRowMap.NumMyElements() == NewRowMap_.NumMyElements() );
00060
00061
00062 Epetra_IntVector Cols( OldRowMap );
00063 Epetra_IntVector NewCols( OldColMap );
00064 Epetra_Import Importer( OldColMap, OldRowMap );
00065
00066 for( int i = 0; i < NumMyElements; ++i )
00067 Cols[i] = NewRowMap_.GID(i);
00068
00069 NewCols.Import( Cols, Importer, Insert );
00070
00071 std::vector<int*> NewColIndices(1);
00072 NewCols.ExtractView( &NewColIndices[0] );
00073
00074 int NumMyColElements = OldColMap.NumMyElements();
00075 int NumGlobalColElements = OldColMap.NumGlobalElements();
00076
00077 NewColMap_ = new Epetra_Map( NumGlobalColElements, NumMyColElements, NewColIndices[0], OldColMap.IndexBase(), OldColMap.Comm() );
00078
00079
00080 Epetra_CrsMatrix * NewMatrix = new Epetra_CrsMatrix( View, NewRowMap_, *NewColMap_, 0 );
00081
00082
00083 int * myIndices;
00084 double * myValues;
00085 int indicesCnt;
00086 int numMyRows = NewMatrix->NumMyRows();
00087 for( int i = 0; i < numMyRows; ++i )
00088 {
00089 orig.ExtractMyRowView( i, indicesCnt, myValues, myIndices );
00090 NewMatrix->InsertMyValues( i, indicesCnt, myValues, myIndices );
00091 }
00092
00093 NewMatrix->FillComplete();
00094
00095 newObj_ = NewMatrix;
00096
00097 return *NewMatrix;
00098 }
00099
00100 }
00101