EpetraExt Package Browser (Single Doxygen Collection) Development
test/Composite/cxx_main.cpp
Go to the documentation of this file.
00001 //@HEADER
00002 // ***********************************************************************
00003 // 
00004 //     EpetraExt: Epetra Extended - Linear Algebra Services Package
00005 //                 Copyright (2001) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 //@HEADER
00028 
00029 // Transform_Composite Test routine
00030 
00031 #include <EpetraExt_ConfigDefs.h>
00032 #include "EpetraExt_Version.h"
00033 
00034 #include "Epetra_SerialComm.h"
00035 #include "Epetra_Time.h"
00036 
00037 #ifdef EPETRA_MPI
00038 #include "Epetra_MpiComm.h"
00039 #include <mpi.h>
00040 #endif
00041 
00042 #include "Epetra_Map.h"
00043 #include "Epetra_CrsGraph.h"
00044 #include "Epetra_CrsMatrix.h"
00045 #include "Epetra_Vector.h"
00046 #include "Epetra_LinearProblem.h"
00047 
00048 #include "EpetraExt_Transform_Composite.h"
00049 #include "EpetraExt_LPTrans_From_GraphTrans.h"
00050 #include "EpetraExt_SymmRCM_CrsGraph.h"
00051 #include "EpetraExt_Reindex_LinearProblem.h"
00052 //#include "EpetraExt_CrsSingletonFilter_LinearProblem.h"
00053 
00054 #ifdef EPETRA_MPI
00055 #include "EpetraExt_Overlap_CrsGraph.h"
00056 #endif
00057 
00058 #include "../epetra_test_err.h"
00059 
00060 int main(int argc, char *argv[]) {
00061 
00062   int i, ierr=0, returnierr=0;
00063 
00064 #ifdef EPETRA_MPI
00065 
00066   // Initialize MPI
00067 
00068   MPI_Init(&argc,&argv);
00069   int size, rank; // Number of MPI processes, My process ID
00070 
00071   MPI_Comm_size(MPI_COMM_WORLD, &size);
00072   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00073 
00074 #else
00075 
00076   int size = 1; // Serial case (not using MPI)
00077   int rank = 0;
00078 
00079 #endif
00080 
00081   bool verbose = false;
00082 
00083   // Check if we should print results to standard out
00084   if (argc>1) if (argv[1][0]=='-' && argv[1][1]=='v') verbose = true;
00085 
00086 
00087 #ifdef EPETRA_MPI
00088   Epetra_MpiComm Comm(MPI_COMM_WORLD);
00089 #else
00090   Epetra_SerialComm Comm;
00091 #endif
00092   if (!verbose) Comm.SetTracebackMode(0); // This should shut down any error traceback reporting
00093 
00094   int MyPID = Comm.MyPID();
00095   int NumProc = Comm.NumProc();
00096 
00097   bool verbose1 = verbose;
00098   if( verbose ) verbose = (MyPID==0);
00099 
00100   if ( verbose )
00101     cout << EpetraExt::EpetraExt_Version() << endl << endl;
00102 
00103   Comm.Barrier();
00104 
00105   if( verbose1 ) cout << Comm << endl << flush;
00106 
00107   int NumMyElements = 3;
00108   int NumGlobalElements = NumProc*NumMyElements;
00109   int IndexBase = 0;
00110   
00111   Epetra_Map Map( NumGlobalElements, NumMyElements, 0, Comm );
00112   if( verbose1 ) cout << Map << endl << flush;
00113 
00114   Epetra_CrsGraph Graph( Copy, Map, 1 );
00115 
00116   int PIDFac = 10*MyPID;
00117   int index = PIDFac+2;
00118   Graph.InsertGlobalIndices( PIDFac+0, 1, &index );
00119   index = PIDFac+0;
00120   Graph.InsertGlobalIndices( PIDFac+1, 1, &index );
00121   index = PIDFac+1;
00122   Graph.InsertGlobalIndices( PIDFac+2, 1, &index );
00123 
00124   Graph.FillComplete();
00125   if( verbose1 ) cout << Graph << endl << flush;
00126 
00127   EpetraExt::Transform_Composite<Epetra_LinearProblem> CompTrans;
00128 
00129 //  EpetraExt::LinearProblem_CrsSingletonFilter CSF_LPTrans;
00130 //  EpetraExt::SameTypeTransform<Epetra_LinearProblem> * CSF_LPTransPtr = &CSF_LPTrans;
00131 //  CompTrans.addTransform( CSF_LPTransPtr );
00132 
00133   EpetraExt::LinearProblem_Reindex * RI_Trans = new EpetraExt::LinearProblem_Reindex(0);
00134   EpetraExt::SameTypeTransform<Epetra_LinearProblem> * RI_LPTrans = RI_Trans;
00135   CompTrans.addTransform( RI_LPTrans );
00136 
00137   EpetraExt::CrsGraph_SymmRCM RCM_Trans;
00138   EpetraExt::SameTypeTransform<Epetra_LinearProblem> *
00139         RCM_LPTrans = new EpetraExt::LinearProblem_GraphTrans( RCM_Trans );
00140   CompTrans.addTransform( RCM_LPTrans );
00141 
00142 #ifdef EPETRA_MPI
00143   EpetraExt::CrsGraph_Overlap Overlap_Trans(1);
00144   EpetraExt::SameTypeTransform<Epetra_LinearProblem> *
00145         Overlap_LPTrans = new EpetraExt::LinearProblem_GraphTrans( Overlap_Trans );
00146   CompTrans.addTransform( Overlap_LPTrans );
00147 #endif
00148 
00149   Epetra_CrsMatrix Matrix( Copy, Graph );
00150   index = 2;
00151   double val = 2;
00152   Matrix.ReplaceMyValues( 0, 1, &val, &index );
00153   index = 0;
00154   val = 0;
00155   Matrix.ReplaceMyValues( 1, 1, &val, &index );
00156   index = 1;
00157   val = 1;
00158   Matrix.ReplaceMyValues( 2, 1, &val, &index);
00159 
00160   vector<double> valA(3);
00161   valA[0]=0; valA[1]=1; valA[2]=2;
00162   Epetra_BlockMap & MapRef = Map;
00163   Epetra_Vector LHS( Copy, MapRef, &valA[0] );
00164   Epetra_Vector RHS( Copy, MapRef, &valA[0] );
00165 
00166   Epetra_LinearProblem Prob( &Matrix, &LHS, &RHS );
00167 
00168   Epetra_LinearProblem & NewProb = CompTrans( Prob );
00169 
00170   CompTrans.fwd();
00171   CompTrans.rvs();
00172 
00173 #ifdef EPETRA_MPI
00174   MPI_Finalize();
00175 #endif
00176 
00177   return ierr;
00178 }
00179 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines