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: */
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"
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
65: #include "Teuchos_Array.hpp"
66: #include <string>
67: #include <stdio.h>
68: #include <map>
70: using Teuchos::RCP;
71: using Teuchos::rcp;
73: #include petsc.h 75: int main(int argc, char *argv[]) {
76: // Teuchos::GlobalMPISession mpiSession(&argc,&argv);
77: PetscInitialize(&argc,&argv,NULL,NULL);
78: 79: Epetra_MpiComm Comm(MPI_COMM_WORLD);
81: Epetra_Map* Map;
82: // pointer to the matrix to be created
83: Epetra_CrsMatrix* Matrix;
84: // container for parameters
85: Teuchos::ParameterList GaleriList;
86: // here we specify the global dimension of the problem
87: int nx = 10 * Comm.NumProc();
88: int ny = 10 * Comm.NumProc();
89: GaleriList.set("nx", nx);
90: GaleriList.set("ny", ny);
92: try
93: {
94: // Creates a simple linear map; for more details on the map creation
95: // refer to the documentation
96: Map = Galeri::CreateMap("Cartesian2D", Comm, GaleriList);
98: // Creates a diagonal matrix with 1's on the diagonal
99: Matrix = Galeri::CreateCrsMatrix("Biharmonic2D", Map, GaleriList);
101: // To created objects must be free'd using delete
102: Ifpack_Hypre preconditioner(Matrix);
104: Epetra_MultiVector X(Matrix->RowMatrixRowMap(), 2);
105: Epetra_MultiVector KnownX(Matrix->RowMatrixRowMap(), 2);
106: KnownX.Random();
107: Epetra_MultiVector B(Matrix->RowMatrixRowMap(), 2);
108: Matrix->Multiply(false, KnownX, B);
110: Teuchos::ParameterList list("Preconditioner List");
111: RCP<FunctionParameter> functs[11];
112: functs[0] = rcp(new FunctionParameter(Solver, &HYPRE_PCGSetMaxIter, 1000)); /* max iterations */
113: functs[1] = rcp(new FunctionParameter(Solver, &HYPRE_PCGSetTol, 1e-7)); /* conv. tolerance */
114: functs[2] = rcp(new FunctionParameter(Solver, &HYPRE_PCGSetTwoNorm, 1)); /* use the two norm as the stopping criteria */
115: functs[3] = rcp(new FunctionParameter(Solver, &HYPRE_PCGSetPrintLevel, 2)); /* print solve info */
116: functs[4] = rcp(new FunctionParameter(Solver, &HYPRE_PCGSetLogging, 1)); /* needed to get run info later */
117: functs[5] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetPrintLevel, 3)); /* print amg solution info */
118: functs[6] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetCoarsenType, 6));
119: functs[7] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetRelaxType, 6)); /* Sym G.S./Jacobi hybrid */
120: functs[8] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetNumSweeps, 1));
121: functs[9] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetTol, 0.0)); /* conv. tolerance zero */
122: functs[10] = rcp(new FunctionParameter(Preconditioner, &HYPRE_BoomerAMGSetMaxIter, 1)); /* do only one iteration! */
124: list.set("Solver", PCG);
125: list.set("Preconditioner", BoomerAMG);
126: list.set("SolveOrPrecondition", Solver);
127: list.set("SetPreconditioner", true);
128: list.set("NumFunctions", 11);
129: list.set<RCP<FunctionParameter>*>("Functions", functs);
131: preconditioner.SetParameters(list);
132: // what is this code actually doing? Even though I have a PrintLevel of 3 it prints nothing, why?
133: preconditioner.Compute();
134: //delete preconditioner;
135: delete Map;
136: delete Matrix;
137: }
138: catch (Galeri::Exception& rhs)
139: {
140: if (Comm.MyPID() == 0)
141: {
142: cerr << "Caught exception: ";
143: rhs.Print();
144: }
145: }
147: PetscFinalize();
148: return 0;
149: }