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_LPTrans_From_MatrixTrans.h>
00030
00031 #include <Epetra_Export.h>
00032 #include <Epetra_Import.h>
00033 #include <Epetra_LinearProblem.h>
00034 #include <Epetra_CrsGraph.h>
00035 #include <Epetra_CrsMatrix.h>
00036 #include <Epetra_MultiVector.h>
00037 #include <Epetra_Vector.h>
00038 #include <Epetra_IntVector.h>
00039 #include <Epetra_Map.h>
00040 #include <Epetra_Comm.h>
00041
00042 namespace EpetraExt {
00043
00044 LinearProblem_MatrixTrans::
00045 ~LinearProblem_MatrixTrans()
00046 {
00047 if( Exporter_ ) delete Exporter_;
00048 if( Importer_ ) delete Importer_;
00049
00050 if( NewProblem_ ) delete NewProblem_;
00051 if( NewRHS_ ) delete NewRHS_;
00052 if( NewLHS_ ) delete NewLHS_;
00053 }
00054
00055 LinearProblem_MatrixTrans::NewTypeRef
00056 LinearProblem_MatrixTrans::
00057 operator()( OriginalTypeRef orig )
00058 {
00059 OldProblem_ = &orig;
00060 OldMatrix_ = dynamic_cast<Epetra_CrsMatrix*>( orig.GetMatrix() );
00061 OldRHS_ = orig.GetRHS();
00062 OldLHS_ = orig.GetLHS();
00063 OldRowMap_ = const_cast<Epetra_Map*>(&OldMatrix_->RowMap());
00064
00065 int ierr = 0;
00066
00067
00068 if( !OldMatrix_ ) ierr = -2;
00069 if( !OldRHS_ ) ierr = -3;
00070 if( !OldLHS_ ) ierr = -4;
00071
00072 NewMatrix_ = &(matrixTrans_( *OldMatrix_ ));
00073
00074 Epetra_BlockMap & NewRowMap = const_cast<Epetra_BlockMap&>(NewMatrix_->Graph().RowMap());
00075
00076 NewRHS_ = new Epetra_MultiVector( NewRowMap, 1 );
00077 NewLHS_ = new Epetra_MultiVector( NewRowMap, 1 );
00078
00079 Exporter_ = new Epetra_Export( *OldRowMap_, NewRowMap );
00080 Importer_ = new Epetra_Import( NewRowMap, *OldRowMap_ );
00081
00082 NewProblem_ = new Epetra_LinearProblem( NewMatrix_, NewLHS_, NewRHS_ );
00083
00084 return *NewProblem_;
00085 }
00086
00087 bool
00088 LinearProblem_MatrixTrans::
00089 fwd()
00090 {
00091 NewLHS_->Export( *OldLHS_, *Exporter_, Insert );
00092 NewRHS_->Export( *OldRHS_, *Exporter_, Insert );
00093 NewMatrix_->Export( *OldMatrix_, *Exporter_, Insert );
00094
00095 return true;
00096 }
00097
00098 bool
00099 LinearProblem_MatrixTrans::
00100 rvs()
00101 {
00102 OldLHS_->Import( *NewLHS_, *Exporter_, Insert );
00103 OldRHS_->Import( *NewRHS_, *Exporter_, Insert );
00104 OldMatrix_->Import( *NewMatrix_, *Exporter_, Insert );
00105
00106 return true;
00107 }
00108
00109 }
00110