test/OverlappingRowMatrix/cxx_main.cpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //                IFPACK
00005 //                 Copyright (2004) 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 #include "Ifpack_ConfigDefs.h"
00030 
00031 #ifdef HAVE_MPI
00032 #include "Epetra_MpiComm.h"
00033 #else
00034 #include "Epetra_SerialComm.h"
00035 #endif
00036 #include "Epetra_CrsMatrix.h"
00037 #include "Epetra_Vector.h"
00038 #include "Epetra_LinearProblem.h"
00039 #include "Epetra_Map.h"
00040 #include "Epetra_Import.h"
00041 #include "Epetra_Time.h"
00042 #include "Galeri_Maps.h"
00043 #include "Galeri_CrsMatrices.h"
00044 #include "Teuchos_ParameterList.hpp"
00045 #include "Teuchos_RefCountPtr.hpp"
00046 #include "Ifpack_OverlappingRowMatrix.h"
00047 #include "Ifpack_LocalFilter.h"
00048 #include "Ifpack_Utils.h"
00049 
00050 int main(int argc, char *argv[])
00051 {
00052 #ifdef HAVE_MPI
00053   MPI_Init(&argc,&argv);
00054   Epetra_MpiComm Comm( MPI_COMM_WORLD );
00055 #else
00056   Epetra_SerialComm Comm;
00057 #endif
00058 
00059   if (Comm.NumProc() == 1)
00060   {
00061 #ifdef HAVE_MPI
00062     MPI_Finalize();
00063 #endif
00064     cout << "Test `TestOverlappingRowMatrix.exe' passed!" << endl;
00065     exit(EXIT_SUCCESS);
00066   }
00067 
00068   Teuchos::ParameterList GaleriList;
00069   int nx = 100; 
00070   GaleriList.set("n", nx * nx);
00071   GaleriList.set("nx", nx);
00072   GaleriList.set("ny", nx);
00073   Teuchos::RefCountPtr<Epetra_Map> Map = Teuchos::rcp( Galeri::CreateMap("Linear", Comm, GaleriList) );
00074   Teuchos::RefCountPtr<Epetra_CrsMatrix> A = Teuchos::rcp( Galeri::CreateCrsMatrix("Laplace2D", &*Map, GaleriList) );
00075 
00076   int OverlapLevel = 5;
00077   Epetra_Time Time(Comm);
00078 
00079   // ======================================== //
00080   // Build the overlapping matrix using class //
00081   // Ifpack_OverlappingRowMatrix.             //
00082   // ======================================== //
00083  
00084   Time.ResetStartTime();
00085   Ifpack_OverlappingRowMatrix B(A,OverlapLevel);
00086   if (Comm.MyPID() == 0)
00087     cout << "Time to create B = " << Time.ElapsedTime() << endl;
00088 
00089   int NumGlobalRowsB = B.NumGlobalRows();
00090   int NumGlobalNonzerosB = B.NumGlobalNonzeros();
00091 
00092   Epetra_Vector X(A->RowMatrixRowMap());
00093   Epetra_Vector Y(A->RowMatrixRowMap());
00094   for (int i = 0 ; i < A->NumMyRows() ; ++i) 
00095     X[i] = 1.0* A->RowMatrixRowMap().GID(i);
00096   Y.PutScalar(0.0);
00097 
00098   Epetra_Vector ExtX_B(B.RowMatrixRowMap());
00099   Epetra_Vector ExtY_B(B.RowMatrixRowMap());
00100   ExtY_B.PutScalar(0.0);
00101 
00102   IFPACK_CHK_ERR(B.ImportMultiVector(X,ExtX_B));
00103   IFPACK_CHK_ERR(B.Multiply(false,ExtX_B,ExtY_B));
00104   IFPACK_CHK_ERR(B.ExportMultiVector(ExtY_B,Y,Add));
00105 
00106   double Norm_B;
00107   Y.Norm2(&Norm_B);
00108   if (Comm.MyPID() == 0)
00109     cout << "Norm of Y using B = " << Norm_B << endl;
00110   
00111   // ================================================== //
00112   //Build the overlapping matrix as an Epetra_CrsMatrix //
00113   // ================================================== //
00114 
00115   Time.ResetStartTime();
00116   Epetra_CrsMatrix& C = 
00117     *(Ifpack_CreateOverlappingCrsMatrix(&*A,OverlapLevel));
00118   if (Comm.MyPID() == 0)
00119     cout << "Time to create C = " << Time.ElapsedTime() << endl;
00120 
00121   // simple checks on global quantities
00122   int NumGlobalRowsC = C.NumGlobalRows();
00123   int NumGlobalNonzerosC = C.NumGlobalNonzeros();
00124   assert (NumGlobalRowsB == NumGlobalRowsC);
00125   assert (NumGlobalNonzerosB == NumGlobalNonzerosC);
00126 
00127   Epetra_Vector ExtX_C(C.RowMatrixRowMap());
00128   Epetra_Vector ExtY_C(C.RowMatrixRowMap());
00129   ExtY_C.PutScalar(0.0);
00130   Y.PutScalar(0.0);
00131 
00132   IFPACK_CHK_ERR(C.Multiply(false,X,Y));
00133 
00134   double Norm_C;
00135   Y.Norm2(&Norm_C);
00136   if (Comm.MyPID() == 0)
00137     cout << "Norm of Y using C = " << Norm_C << endl;
00138 
00139   if (IFPACK_ABS(Norm_B - Norm_C) > 1e-5)
00140     IFPACK_CHK_ERR(-1);
00141 
00142   // ======================= //
00143   // now localize the matrix //
00144   // ======================= //
00145 
00146   Ifpack_LocalFilter D(Teuchos::rcp(&B, false));
00147 
00148 #ifdef HAVE_MPI
00149   MPI_Finalize() ; 
00150 #endif
00151 
00152   if (Comm.MyPID() == 0)
00153     cout << "Test `TestOverlappingRowMatrix.exe' passed!" << endl;
00154 
00155   return(EXIT_SUCCESS);
00156 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:05:33 2011 for Ifpack Package Browser (Single Doxygen Collection) by  doxygen 1.6.3