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_SubCopy_CrsMatrix.h"
00030
00031 #include <Epetra_CrsMatrix.h>
00032 #include <Epetra_Map.h>
00033 #include <Epetra_Import.h>
00034 #include <Epetra_IntSerialDenseVector.h>
00035
00036 #include <vector>
00037
00038 namespace EpetraExt {
00039
00040 CrsMatrix_SubCopy::
00041 ~CrsMatrix_SubCopy()
00042 {
00043 if( newObj_ ) delete newObj_;
00044 }
00045
00046 CrsMatrix_SubCopy::NewTypeRef
00047 CrsMatrix_SubCopy::
00048 operator()( OriginalTypeRef orig )
00049 {
00050 origObj_ = &orig;
00051
00052
00053 assert( orig.Filled() );
00054
00055
00056 const Epetra_Map & oRowMap = orig.RowMap();
00057 const Epetra_Map & oColMap = orig.ColMap();
00058
00059 int oNumRows = oRowMap.NumMyElements();
00060 int oNumCols = oColMap.NumMyElements();
00061 int nNumRows = newRowMap_.NumMyElements();
00062 int nNumDomain = newDomainMap_.NumMyElements();
00063
00064 bool matched = true;
00065
00066
00067 for( int i = 0; i < nNumRows; ++i )
00068 matched = matched && ( oRowMap.MyGID(newRowMap_.GID(i)) );
00069 if( !matched ) cerr << "EDT_CrsMatrix_SubCopy: Bad new_row_Map. GIDs of new row map must be GIDs of the original row map on the same processor.\n";
00070
00071
00072 if( !newRangeMap_.SameAs(newDomainMap_) ) {
00073 Epetra_IntSerialDenseVector pidList(nNumDomain);
00074 oColMap.RemoteIDList(newDomainMap_.NumMyElements(), newDomainMap_.MyGlobalElements(), pidList.Values(), 0);
00075 for( int i = 0; i < nNumDomain; ++i )
00076 matched = matched && ( pidList[i]>=0 );
00077 }
00078
00079 if( !matched ) cout << "EDT_CrsMatrix_SubCopy: Bad newDomainMap. One or more GIDs in new domain map are not part of original domain map.\n";
00080 assert( matched );
00081
00082
00083
00084 Epetra_IntSerialDenseVector pidList(oNumCols);
00085 Epetra_IntSerialDenseVector lidList(oNumCols);
00086 Epetra_IntSerialDenseVector sizeList(oNumCols);
00087 newDomainMap_.RemoteIDList(oColMap.NumMyElements(), oColMap.MyGlobalElements(), pidList.Values(), 0);
00088 int numNewCols = 0;
00089 Epetra_IntSerialDenseVector newColMapGidList(oNumCols);
00090 int * origColGidList = oColMap.MyGlobalElements();
00091 for( int i = 0; i < oNumCols; ++i )
00092 if (pidList[i] >=0)
00093 newColMapGidList[numNewCols++]= origColGidList[i];
00094 newColMap_ = Epetra_Map(-1, numNewCols, newColMapGidList.Values(), 0, oColMap.Comm());
00095
00096 importer_ = new Epetra_Import(newRowMap_, oRowMap);
00097
00098 Epetra_CrsMatrix * newMatrix = new Epetra_CrsMatrix(Copy, newRowMap_, newColMap_, 0);
00099
00100 newObj_ = newMatrix;
00101
00102 newObj_->Import(*origObj_, *importer_, Add);
00103
00104 newObj_->FillComplete();
00105
00106 return *newObj_;
00107 }
00108
00109
00110 bool CrsMatrix_SubCopy::fwd()
00111 {
00112
00113 if (newObj_->Filled()) newObj_->PutScalar(0.0);
00114
00115 newObj_->Import(*origObj_, *importer_, Add);
00116
00117 newObj_->FillComplete();
00118
00119
00120 return (true);
00121 }
00122
00123
00124 bool CrsMatrix_SubCopy::rvs()
00125 {
00126 if (!newObj_->Filled()) return(false);
00127
00128 origObj_->Export(*newObj_, *importer_, Add);
00129
00130 origObj_->FillComplete();
00131
00132 return (true);
00133 }
00134
00135 }
00136