Ifpack Package Browser (Single Doxygen Collection) Development
test/HIPS/cxx_main.cpp
Go to the documentation of this file.
00001 
00002 // @HEADER
00003 // ***********************************************************************
00004 // 
00005 //            Trilinos: An Object-Oriented Solver Framework
00006 //                 Copyright (2001) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //  
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00026 // 
00027 // ***********************************************************************
00028 // @HEADER
00029 
00030 #include "Ifpack_ConfigDefs.h"
00031 
00032 #include "Epetra_ConfigDefs.h"
00033 #ifdef HAVE_MPI
00034 #include "mpi.h"
00035 #include "Epetra_MpiComm.h"
00036 #else
00037 #include "Epetra_SerialComm.h"
00038 #endif
00039 #include "Epetra_Comm.h"
00040 #include "Epetra_Map.h"
00041 #include "Epetra_Time.h"
00042 #include "Epetra_BlockMap.h"
00043 #include "Epetra_MultiVector.h"
00044 #include "Epetra_Vector.h"
00045 #include "Epetra_Export.h"
00046 #include "AztecOO.h"
00047 #include "Galeri_Maps.h"
00048 #include "Galeri_CrsMatrices.h"
00049 #include "Ifpack_CrsRiluk.h"
00050 #include "Ifpack.h"
00051 #include "Teuchos_RefCountPtr.hpp"
00052 
00053 #include "Ifpack_HIPS.h"
00054 
00055 extern "C"{
00056 #include "hips.h"
00057 };
00058 
00059 // function for fancy output
00060 
00061 string toString(const int& x) {
00062   char s[100];
00063   sprintf(s, "%d", x);
00064   return string(s);
00065 }
00066 
00067 string toString(const double& x) {
00068   char s[100];
00069   sprintf(s, "%g", x);
00070   return string(s);
00071 }
00072 
00073 // main driver
00074 
00075 int main(int argc, char *argv[]) {
00076 
00077 #ifdef HAVE_MPI
00078   MPI_Init(&argc,&argv);
00079   Epetra_MpiComm Comm (MPI_COMM_WORLD);
00080 #else
00081   Epetra_SerialComm Comm;
00082 #endif
00083 
00084   int ierr=HIPS_Initialize(1);
00085   HIPS_ExitOnError(ierr);
00086 
00087   int MyPID = Comm.MyPID();
00088   bool verbose = false; 
00089   if (MyPID==0) verbose = true;
00090 
00091   Teuchos::ParameterList GaleriList;
00092   int nx = 100; 
00093   GaleriList.set("nx", nx);
00094   GaleriList.set("ny", nx * Comm.NumProc());
00095   //  GaleriList.set("ny", nx);
00096   GaleriList.set("mx", 1);
00097   GaleriList.set("my", Comm.NumProc());
00098                  
00099   Teuchos::RefCountPtr<Epetra_Map> Map = Teuchos::rcp( Galeri::CreateMap("Cartesian2D", Comm, GaleriList) );
00100   Teuchos::RefCountPtr<Epetra_CrsMatrix> A = Teuchos::rcp( Galeri::CreateCrsMatrix("Laplace2D", &*Map, GaleriList) );
00101   Teuchos::RefCountPtr<Epetra_MultiVector> LHS = Teuchos::rcp( new Epetra_MultiVector(*Map, 1) );
00102   Teuchos::RefCountPtr<Epetra_MultiVector> RHS = Teuchos::rcp( new Epetra_MultiVector(*Map, 1) );
00103   LHS->PutScalar(0.0); RHS->Random();
00104 
00105   // ============================ //
00106   // Construct ILU preconditioner //
00107   // ---------------------------- //
00108 
00109   Teuchos::RefCountPtr<Ifpack_HIPS> RILU;
00110 
00111   RILU = Teuchos::rcp( new Ifpack_HIPS(&*A) );
00112 
00113   Teuchos::ParameterList List;
00114   List.set("hips: id",0);
00115   List.set("hips: setup output",2);
00116   List.set("hips: iteration output",0);
00117   List.set("hips: drop tolerance",5e-3);
00118   List.set("hips: graph symmetric",1);
00119   RILU->SetParameters(List);
00120 
00121   
00122   RILU->Initialize();
00123   RILU->Compute();
00124 
00125   // Here we create an AztecOO object
00126   LHS->PutScalar(0.0);
00127 
00128   int Niters = 50;
00129 
00130   AztecOO solver;
00131   solver.SetUserMatrix(&*A);
00132   solver.SetLHS(&*LHS);
00133   solver.SetRHS(&*RHS);
00134   solver.SetAztecOption(AZ_solver,AZ_gmres);
00135   solver.SetPrecOperator(&*RILU);
00136   solver.SetAztecOption(AZ_output, 1); 
00137   solver.Iterate(Niters, 1.0e-8);
00138 
00139   int OldIters = solver.NumIters();
00140 
00141 
00142   HIPS_Finalize();
00143   
00144 #ifdef HAVE_MPI
00145   MPI_Finalize() ;
00146 #endif
00147 
00148   return(EXIT_SUCCESS);
00149 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines