Ifpack Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LL/hypre_UnitTest.cpp
Go to the documentation of this file.
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack: Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2002) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #include "Ifpack.h"
44 #include "AztecOO.h"
45 #include "Galeri_Maps.h"
46 #include "Galeri_CrsMatrices.h"
47 #include "Galeri_Utils.h"
48 #include "Epetra_MultiVector.h"
49 
50 #include "Teuchos_UnitTestHarness.hpp"
51 #include "Teuchos_RCP.hpp"
52 #include "Epetra_ConfigDefs.h"
53 #include "Epetra_Vector.h"
54 #include "Epetra_RowMatrix.h"
55 #include "Epetra_MultiVector.h"
56 #include "Epetra_CrsMatrix.h"
57 #include "Epetra_Map.h"
58 #ifdef HAVE_MPI
59 #include "mpi.h"
60 #include "Epetra_MpiComm.h"
61 #else
62 #include "Epetra_SerialComm.h"
63 #endif
64 
65 #include "Teuchos_Array.hpp"
66 #include <string>
67 #include <stdio.h>
68 #include <map>
69 
70 using Teuchos::RCP;
71 using Teuchos::rcp;
72 
73 const int N = 10;
74 const int MatType = 3; //0 -> Unit diagonal, 1 -> Dense, val=col, 2 -> Random Dense, 3 -> Random Sparse
75 const double tol = 1E-6;
76 
77 TEUCHOS_UNIT_TEST( Ifpack_Hypre, Construct ) {
78 
79  Epetra_MpiComm comm(MPI_COMM_WORLD);
80  Epetra_Map RowMap(N, 0, comm);
81  Epetra_CrsMatrix Matrix(Copy, RowMap, 1);
82  for(int i = 0; i < N; i++){
83  int indices[1];
84  double values[1];
85  indices[0] = i;
86  values[0] = 1.0;
87  Matrix.InsertGlobalValues(i, 1, values, indices);
88  }
89  Matrix.FillComplete();
90  //Ifpack_Hypre preconditioner(&Matrix);
91  //preconditioner.Initialize();
92 }
93 
94 TEUCHOS_UNIT_TEST( Ifpack_Hypre, ParameterList ){
95 
96  Epetra_MpiComm Comm(MPI_COMM_WORLD);
97 
98  Epetra_Map* Map;
99  // pointer to the matrix to be created
100  Epetra_CrsMatrix* Matrix;
101  // container for parameters
102  Teuchos::ParameterList GaleriList;
103  // here we specify the global dimension of the problem
104  int nx = 10 * Comm.NumProc();
105  int ny = 10 * Comm.NumProc();
106  GaleriList.set("nx", nx);
107  GaleriList.set("ny", ny);
108 
109  try
110  {
111  // Creates a simple linear map; for more details on the map creation
112  // refer to the documentation
113  Map = Galeri::CreateMap("Cartesian2D", Comm, GaleriList);
114 
115  // Creates a diagonal matrix with 1's on the diagonal
116  Matrix = Galeri::CreateCrsMatrix("Biharmonic2D", Map, GaleriList);
117 
118  // To created objects must be free'd using delete
119  Ifpack_Hypre preconditioner(Matrix);
120 
121 
122  int numVec = 2;
123  Epetra_MultiVector X(Matrix->RowMatrixRowMap(), 2);
124  Epetra_MultiVector KnownX(Matrix->RowMatrixRowMap(), 2);
125  KnownX.Random();
126  Epetra_MultiVector B(Matrix->RowMatrixRowMap(), 2);
127  Matrix->Multiply(false, KnownX, B);
128 
129  //AztecOO problem(&matrix, &X, &B);
130  //problem.SetPrecOperator(&matrix);
131  //problem.Iterate(1000, 1e-7);
132 
133  Teuchos::ParameterList list("Preconditioner List");
134  //RCP<FunctionParameter> functs[11];
135  //functs[0] = rcp(new FunctionParameter(Solver, &HYPRE_PCGSetMaxIter, 1000)); /* max iterations */
136  //functs[1] = rcp(new FunctionParameter(Solver, &HYPRE_PCGSetTol, 1e-7)); /* conv. tolerance */
137  //functs[2] = rcp(new FunctionParameter(Solver, &HYPRE_PCGSetTwoNorm, 1)); /* use the two norm as the stopping criteria */
138  //functs[3] = rcp(new FunctionParameter(Solver, &HYPRE_PCGSetPrintLevel, 2)); /* print solve info */
139  //functs[4] = rcp(new FunctionParameter(Solver, &HYPRE_PCGSetLogging, 1)); /* needed to get run info later */
140  //functs[5] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetPrintLevel, 1)); /* print amg solution info */
141  //functs[6] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetCoarsenType, 6));
142  //functs[7] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetRelaxType, 6)); /* Sym G.S./Jacobi hybrid */
143  //functs[8] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetNumSweeps, 1));
144  //functs[9] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetTol, 0.0)); /* conv. tolerance zero */
145  //functs[10] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetMaxIter, 1)); /* do only one iteration! */
146 
147  //list.set("Solver", PCG);
148  //list.set("Preconditioner", BoomerAMG);
149  //list.set("SolveOrPrecondition", Solver);
150  //list.set("SetPreconditioner", true);
151  //list.set("NumFunctions", 11);
152  //list.set<RCP<FunctionParameter>*>("Functions", functs);
153 
154  preconditioner.SetParameters(list);
155  preconditioner.Compute();
156  //delete preconditioner;
157  delete Map;
158  delete Matrix;
159  }
160  catch (Galeri::Exception& rhs)
161  {
162  if (Comm.MyPID() == 0)
163  {
164  cerr << "Caught exception: ";
165  rhs.Print();
166  }
167  }
168 
169 }
170 
int Multiply(bool TransA, const Epetra_Vector &x, Epetra_Vector &y) const
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
virtual int InsertGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
int NumProc() const
const Epetra_Map & RowMatrixRowMap() const
int FillComplete(bool OptimizeDataStorage=true)
const int MatType
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
const double tol
virtual void Print(std::ostream &os) const
TEUCHOS_UNIT_TEST(Ifpack_Hypre, Construct)
const int N
int MyPID() const