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_GraphTrans.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_GraphTrans::
00045 ~LinearProblem_GraphTrans()
00046 {
00047 if( MatExporter_ ) delete MatExporter_;
00048 if( VecExporter_ ) delete VecExporter_;
00049 if( Importer_ ) delete Importer_;
00050
00051 if( NewProblem_ ) delete NewProblem_;
00052 if( NewRHS_ ) delete NewRHS_;
00053 if( NewLHS_ ) delete NewLHS_;
00054 if( NewMatrix_ ) delete NewMatrix_;
00055 }
00056
00057 LinearProblem_GraphTrans::NewTypeRef
00058 LinearProblem_GraphTrans::
00059 operator()( OriginalTypeRef orig )
00060 {
00061 OldProblem_ = &orig;
00062 OldMatrix_ = dynamic_cast<Epetra_CrsMatrix*>( orig.GetMatrix() );
00063 OldGraph_ = const_cast<Epetra_CrsGraph*>(&OldMatrix_->Graph());
00064 OldRHS_ = orig.GetRHS();
00065 OldLHS_ = orig.GetLHS();
00066 OldRowMap_ = const_cast<Epetra_Map*>(&OldMatrix_->RowMap());
00067
00068 int ierr = 0;
00069
00070
00071 if( !OldMatrix_ ) ierr = -2;
00072 if( !OldRHS_ ) ierr = -3;
00073 if( !OldLHS_ ) ierr = -4;
00074
00075 Epetra_CrsGraph & NewGraph = graphTrans_( *OldGraph_ );
00076 NewMatrix_ = new Epetra_CrsMatrix( Copy, NewGraph );
00077
00078 Epetra_BlockMap & NewRowMap = const_cast<Epetra_BlockMap&>(NewGraph.RowMap());
00079
00080 NewRHS_ = new Epetra_MultiVector( NewRowMap, 1 );
00081 NewLHS_ = new Epetra_MultiVector( NewRowMap, 1 );
00082
00083 MatExporter_ = new Epetra_Export( *OldRowMap_, NewRowMap );
00084 VecExporter_ = new Epetra_Export( *OldRowMap_, NewRowMap );
00085 Importer_ = new Epetra_Import( *OldRowMap_, NewRowMap );
00086
00087 NewProblem_ = new Epetra_LinearProblem( NewMatrix_, NewLHS_, NewRHS_ );
00088
00089 return *NewProblem_;
00090 }
00091
00092 bool
00093 LinearProblem_GraphTrans::
00094 fwd()
00095 {
00096 NewLHS_->Export( *OldLHS_, *VecExporter_, Insert );
00097 NewRHS_->Export( *OldRHS_, *VecExporter_, Insert );
00098 NewMatrix_->Export( *OldMatrix_, *MatExporter_, Insert );
00099
00100 return true;
00101 }
00102
00103 bool
00104 LinearProblem_GraphTrans::
00105 rvs()
00106 {
00107 OldLHS_->Import( *NewLHS_, *Importer_, Insert );
00108
00109
00110
00111 return true;
00112 }
00113
00114 }
00115