test/UseTranspose/cxx_main.cpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //            Trilinos: An Object-Oriented Solver Framework
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 #include "Ifpack_ConfigDefs.h"
00030 #ifdef HAVE_MPI
00031 #include "mpi.h"
00032 #include "Epetra_MpiComm.h"
00033 #else
00034 #include "Epetra_SerialComm.h"
00035 #endif
00036 #include "Epetra_Comm.h"
00037 #include "Epetra_Map.h"
00038 #include "Epetra_MultiVector.h"
00039 #include "Epetra_CrsMatrix.h"
00040 #include "Ifpack_ILU.h"
00041 #include "Ifpack_ILUT.h"
00042 #include "Ifpack_AdditiveSchwarz.h"
00043 
00044 template<class T>
00045 void Test(const string what, Epetra_RowMatrix& A)
00046 {
00047   T Prec(&A);
00048 
00049   bool UseTranspose = true;
00050 
00051   IFPACK_CHK_ERRV(Prec.Initialize());
00052   IFPACK_CHK_ERRV(Prec.Compute());
00053   IFPACK_CHK_ERRV(Prec.SetUseTranspose(UseTranspose));
00054 
00055   Epetra_MultiVector LHS_exact(A.OperatorDomainMap(), 2);
00056   Epetra_MultiVector LHS(A.OperatorDomainMap(), 2);
00057   Epetra_MultiVector RHS(A.OperatorRangeMap(), 2);
00058 
00059   LHS_exact.Random(); LHS.PutScalar(0.0);
00060 
00061   A.Multiply(UseTranspose, LHS_exact, RHS);
00062 
00063   Prec.ApplyInverse(RHS, LHS);
00064 
00065   LHS.Update(1.0, LHS_exact, -1.0);
00066   double norm[2];
00067 
00068   LHS.Norm2(norm);
00069   norm[0] += norm[1];
00070 
00071   if (norm[0] > 1e-5)
00072   {
00073     cout << what << ": Test failed: norm = " << norm[0] << endl;
00074     exit(EXIT_FAILURE);
00075   }
00076 
00077   cout << what << ": Test passed: norm = " << norm[0] << endl;
00078 }
00079 
00080 // =========== //
00081 // main driver //
00082 // =========== //
00083 
00084 int main(int argc, char *argv[]) 
00085 {
00086 #ifdef HAVE_MPI
00087   MPI_Init(&argc,&argv);
00088   Epetra_MpiComm Comm (MPI_COMM_WORLD);
00089 #else
00090   Epetra_SerialComm Comm;
00091 #endif
00092 
00093   if (Comm.NumProc() != 1)
00094   {
00095     cerr << "To be run with one processor only" << endl;
00096 #ifdef HAVE_MPI
00097     MPI_Finalize();
00098 #endif
00099     exit(EXIT_SUCCESS);
00100   }
00101 
00102   Epetra_Map Map(8, 0, Comm);
00103 
00104   Epetra_CrsMatrix A(Copy, Map, 0);
00105 
00106   // for this matrix the incomplete factorization
00107   // is the exact one, so ILU and ILUT must be exact solvers.
00108   for (int row = 0; row < 8; ++row)
00109   {
00110     double value = 2.0 + row;
00111     A.InsertGlobalValues(row, 1, &value, &row);
00112     if (row)
00113     {
00114       int col = row - 1;
00115       value = 1.0 + row;
00116       A.InsertGlobalValues(row, 1, &value, &col);
00117     }
00118 #if 0
00119     if (row != Map.NumGlobalElements() - 1)
00120     {
00121       int col = row + 1;
00122       value = 0.0;
00123       A.InsertGlobalValues(row, 1, &value, &col);
00124     }
00125 #endif
00126   }
00127 
00128   A.FillComplete();
00129 
00130   Test<Ifpack_ILU>("Ifpack_ILU", A);
00131   Test<Ifpack_ILUT>("Ifpack_ILUT", A);
00132   Test<Ifpack_AdditiveSchwarz<Ifpack_ILU> >("AS, Ifpack_ILU", A);
00133   Test<Ifpack_AdditiveSchwarz<Ifpack_ILUT> >("AS, Ifpack_ILUT", A);
00134 
00135 #ifdef HAVE_MPI
00136   MPI_Finalize() ;
00137 #endif
00138 
00139   return(EXIT_SUCCESS);
00140 }

Generated on Thu Sep 18 12:37:21 2008 for Ifpack Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1