hypre_UnitTest.cpp

Go to the documentation of this file.
00001 //@HEADER
00002 // ***********************************************************************
00003 // 
00004 //       Ifpack: Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2009) 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.h"
00030 #include "AztecOO.h"
00031 #include "Galeri_Maps.h"
00032 #include "Galeri_CrsMatrices.h"
00033 #include "Galeri_Utils.h"
00034 #include "Epetra_MultiVector.h"
00035 
00036 #include "Teuchos_UnitTestHarness.hpp"
00037 #include "Teuchos_RCP.hpp"
00038 #include "Epetra_ConfigDefs.h"
00039 #include "Epetra_Vector.h"
00040 #include "Epetra_RowMatrix.h"
00041 #include "Epetra_MultiVector.h"
00042 #include "Epetra_CrsMatrix.h"
00043 #include "Epetra_Map.h"
00044 #ifdef HAVE_MPI
00045 #include "mpi.h"
00046 #include "Epetra_MpiComm.h"
00047 #else
00048 #include "Epetra_SerialComm.h"
00049 #endif
00050 
00051 #include "Teuchos_Array.hpp"
00052 #include <string>
00053 #include <stdio.h>
00054 #include <map>
00055 
00056 using Teuchos::RCP;
00057 using Teuchos::rcp;
00058 
00059 const int N = 10;
00060 const int MatType = 3; //0 -> Unit diagonal, 1 -> Dense, val=col, 2 -> Random Dense, 3 -> Random Sparse
00061 const double tol = 1E-6;
00062 
00063 TEUCHOS_UNIT_TEST( Ifpack_Hypre, Construct ) {
00064 
00065   Epetra_MpiComm comm(MPI_COMM_WORLD);
00066   Epetra_Map RowMap(N, 0, comm);
00067   Epetra_CrsMatrix Matrix(Copy, RowMap, 1);
00068   for(int i = 0; i < N; i++){
00069     int indices[1];
00070     double values[1];
00071     indices[0] = i;
00072     values[0] = 1.0;
00073     Matrix.InsertGlobalValues(i, 1, values, indices);
00074   }
00075   Matrix.FillComplete(); 
00076   //Ifpack_Hypre preconditioner(&Matrix);
00077   //preconditioner.Initialize();
00078 }
00079 
00080 TEUCHOS_UNIT_TEST( Ifpack_Hypre, ParameterList ){
00081   
00082   Epetra_MpiComm Comm(MPI_COMM_WORLD);
00083 
00084   Epetra_Map*            Map;
00085   // pointer to the matrix to be created
00086   Epetra_CrsMatrix*      Matrix;
00087   // container for parameters
00088   Teuchos::ParameterList GaleriList;
00089   // here we specify the global dimension of the problem
00090   int nx = 10 * Comm.NumProc();
00091   int ny = 10 * Comm.NumProc();
00092   GaleriList.set("nx", nx);
00093   GaleriList.set("ny", ny);
00094 
00095   try
00096   {
00097     // Creates a simple linear map; for more details on the map creation
00098     // refer to the documentation
00099     Map = Galeri::CreateMap("Cartesian2D", Comm, GaleriList);
00100 
00101     // Creates a diagonal matrix with 1's on the diagonal
00102     Matrix   = Galeri::CreateCrsMatrix("Biharmonic2D", Map, GaleriList);
00103 
00104     // To created objects must be free'd using delete
00105     Ifpack_Hypre preconditioner(Matrix);
00106   
00107     
00108     int numVec = 2;
00109     Epetra_MultiVector X(Matrix->RowMatrixRowMap(), 2);
00110     Epetra_MultiVector KnownX(Matrix->RowMatrixRowMap(), 2);
00111     KnownX.Random();
00112     Epetra_MultiVector B(Matrix->RowMatrixRowMap(), 2);
00113     Matrix->Multiply(false, KnownX, B);
00114 
00115     //AztecOO problem(&matrix, &X, &B);
00116     //problem.SetPrecOperator(&matrix);
00117     //problem.Iterate(1000, 1e-7);
00118   
00119     Teuchos::ParameterList list("Preconditioner List");
00120   //RCP<FunctionParameter> functs[11];
00121   //functs[0] = rcp(new FunctionParameter(Solver, &HYPRE_PCGSetMaxIter, 1000)); /* max iterations */
00122   //functs[1] = rcp(new FunctionParameter(Solver, &HYPRE_PCGSetTol, 1e-7)); /* conv. tolerance */
00123   //functs[2] = rcp(new FunctionParameter(Solver, &HYPRE_PCGSetTwoNorm, 1)); /* use the two norm as the stopping criteria */
00124   //functs[3] = rcp(new FunctionParameter(Solver, &HYPRE_PCGSetPrintLevel, 2)); /* print solve info */
00125   //functs[4] = rcp(new FunctionParameter(Solver, &HYPRE_PCGSetLogging, 1)); /* needed to get run info later */
00126   //functs[5] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetPrintLevel, 1)); /* print amg solution info */
00127   //functs[6] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetCoarsenType, 6));
00128   //functs[7] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetRelaxType, 6)); /* Sym G.S./Jacobi hybrid */ 
00129   //functs[8] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetNumSweeps, 1));
00130   //functs[9] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetTol, 0.0)); /* conv. tolerance zero */
00131   //functs[10] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetMaxIter, 1)); /* do only one iteration! */
00132 
00133   //list.set("Solver", PCG);
00134   //list.set("Preconditioner", BoomerAMG);
00135   //list.set("SolveOrPrecondition", Solver);
00136   //list.set("SetPreconditioner", true);
00137   //list.set("NumFunctions", 11);
00138   //list.set<RCP<FunctionParameter>*>("Functions", functs);
00139 
00140     preconditioner.SetParameters(list);
00141     preconditioner.Compute();
00142     //delete preconditioner;
00143     delete Map;
00144     delete Matrix;
00145   }
00146   catch (Galeri::Exception& rhs)
00147   {
00148     if (Comm.MyPID() == 0)
00149     {
00150       cerr << "Caught exception: ";
00151       rhs.Print();
00152     }
00153   }
00154 
00155 }
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