Ifpack Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test/PreconditionerFactory/cxx_main.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 #ifdef NDEBUG
44 #undef NDEBUG
45 #endif
46 
47 #include "Ifpack_ConfigDefs.h"
48 
49 #ifdef HAVE_MPI
50 #include "Epetra_MpiComm.h"
51 #else
52 #include "Epetra_SerialComm.h"
53 #endif
54 #include "Epetra_CrsMatrix.h"
55 #include "Epetra_Vector.h"
56 #include "Epetra_LinearProblem.h"
57 #include "Epetra_Map.h"
58 #include "Galeri_Maps.h"
59 #include "Galeri_CrsMatrices.h"
60  #include "Teuchos_ParameterList.hpp"
61 #include "Teuchos_RefCountPtr.hpp"
62 #include "Ifpack_Preconditioner.h"
63 #include "Ifpack.h"
64 #include "AztecOO.h"
65 #ifdef HAVE_IFPACK_AMESOS
66 #include "Amesos_TestRowMatrix.h"
67 #endif
68 
69 
70 
71 
72 // =======================================================================
73 // GOAL: test that the names in the factory do not change. This test
74 // will not solve any linear system.
75 //
76 int main(int argc, char *argv[])
77 {
78 #ifdef HAVE_MPI
79  MPI_Init(&argc,&argv);
80  Epetra_MpiComm Comm( MPI_COMM_WORLD );
81 #else
82  Epetra_SerialComm Comm;
83 #endif
84 
85  Teuchos::ParameterList GaleriList;
86  const int n = 9;
87  GaleriList.set("n", n);
88  Teuchos::RefCountPtr<Epetra_Map> Map = Teuchos::rcp( Galeri::CreateMap("Linear", Comm, GaleriList) );
89  Teuchos::RefCountPtr<Epetra_CrsMatrix> A = Teuchos::rcp( Galeri::CreateCrsMatrix("Minij", &*Map, GaleriList) );
90 
91  Ifpack Factory;
92  Teuchos::RefCountPtr<Ifpack_Preconditioner> Prec;
93 
94  Prec = Teuchos::rcp( Factory.Create("point relaxation", &*A) );
95  assert (Prec != Teuchos::null);
96  IFPACK_CHK_ERR(Prec->Initialize());
97  IFPACK_CHK_ERR(Prec->Compute());
98  cout << *Prec;
99 
100  Prec = Teuchos::rcp( Factory.Create("point relaxation stand-alone", &*A) );
101  assert (Prec != Teuchos::null);
102  IFPACK_CHK_ERR(Prec->Initialize());
103  IFPACK_CHK_ERR(Prec->Compute());
104  cout << *Prec;
105 
106  Prec = Teuchos::rcp( Factory.Create("block relaxation", &*A) );
107  assert (Prec != Teuchos::null);
108  IFPACK_CHK_ERR(Prec->Initialize());
109  IFPACK_CHK_ERR(Prec->Compute());
110  cout << *Prec;
111 
112  Prec = Teuchos::rcp( Factory.Create("block relaxation stand-alone", &*A) );
113  assert (Prec != Teuchos::null);
114  IFPACK_CHK_ERR(Prec->Initialize());
115  IFPACK_CHK_ERR(Prec->Compute());
116  cout << *Prec;
117 
118  Prec = Teuchos::rcp( Factory.Create("IC", &*A) );
119  assert (Prec != Teuchos::null);
120  IFPACK_CHK_ERR(Prec->Initialize());
121  IFPACK_CHK_ERR(Prec->Compute());
122  cout << *Prec;
123 
124  Prec = Teuchos::rcp( Factory.Create("ICT", &*A) );
125  assert (Prec != Teuchos::null);
126  IFPACK_CHK_ERR(Prec->Initialize());
127  IFPACK_CHK_ERR(Prec->Compute());
128  cout << *Prec;
129 
130  Prec = Teuchos::rcp( Factory.Create("ILU", &*A) );
131  assert (Prec != Teuchos::null);
132  IFPACK_CHK_ERR(Prec->Initialize());
133  IFPACK_CHK_ERR(Prec->Compute());
134  cout << *Prec;
135 
136  Prec = Teuchos::rcp( Factory.Create("ILUT", &*A) );
137  assert (Prec != Teuchos::null);
138  IFPACK_CHK_ERR(Prec->Initialize());
139  IFPACK_CHK_ERR(Prec->Compute());
140  cout << *Prec;
141 
142  Prec = Teuchos::rcp( Factory.Create("IC stand-alone", &*A) );
143  assert (Prec != Teuchos::null);
144  IFPACK_CHK_ERR(Prec->Initialize());
145  IFPACK_CHK_ERR(Prec->Compute());
146  cout << *Prec;
147 
148  Prec = Teuchos::rcp( Factory.Create("ICT stand-alone", &*A) );
149  assert (Prec != Teuchos::null);
150  IFPACK_CHK_ERR(Prec->Initialize());
151  IFPACK_CHK_ERR(Prec->Compute());
152  cout << *Prec;
153 
154  Prec = Teuchos::rcp( Factory.Create("ILU stand-alone", &*A) );
155  assert (Prec != Teuchos::null);
156  IFPACK_CHK_ERR(Prec->Initialize());
157  IFPACK_CHK_ERR(Prec->Compute());
158  cout << *Prec;
159 
160  Prec = Teuchos::rcp( Factory.Create("ILUT stand-alone", &*A) );
161  assert (Prec != Teuchos::null);
162  IFPACK_CHK_ERR(Prec->Initialize());
163  IFPACK_CHK_ERR(Prec->Compute());
164  cout << *Prec;
165 
166 #ifdef HAVE_IFPACK_AMESOS
167  Prec = Teuchos::rcp( Factory.Create("Amesos", &*A) );
168  assert (Prec != Teuchos::null);
169  IFPACK_CHK_ERR(Prec->Initialize());
170  IFPACK_CHK_ERR(Prec->Compute());
171  cout << *Prec;
172 
173  Prec = Teuchos::rcp( Factory.Create("Amesos stand-alone", &*A) );
174  assert (Prec != Teuchos::null);
175  IFPACK_CHK_ERR(Prec->Initialize());
176  IFPACK_CHK_ERR(Prec->Compute());
177  cout << *Prec;
178 #endif
179 
180  Prec = Teuchos::rcp( Factory.Create("Chebyshev", &*A) );
181  assert (Prec != Teuchos::null);
182  IFPACK_CHK_ERR(Prec->Initialize());
183  IFPACK_CHK_ERR(Prec->Compute());
184  cout << *Prec;
185 
186  Prec = Teuchos::rcp( Factory.Create("Polynomial", &*A) );
187  assert (Prec != Teuchos::null);
188  IFPACK_CHK_ERR(Prec->Initialize());
189  IFPACK_CHK_ERR(Prec->Compute());
190  cout << *Prec;
191 
192  Prec = Teuchos::rcp( Factory.Create("Krylov", &*A) );
193  assert (Prec != Teuchos::null);
194  IFPACK_CHK_ERR(Prec->Initialize());
195  IFPACK_CHK_ERR(Prec->Compute());
196  cout << *Prec;
197 
198 
199 
200 
201 
202 #if defined (HAVE_IFPACK_SUPPORTGRAPH) && defined (HAVE_IFPACK_AMESOS)
203  Prec = Teuchos::rcp( Factory.Create("MSF Amesos", &*A) );
204  assert (Prec !=Teuchos::null);
205  IFPACK_CHK_ERR(Prec->Initialize());
206  IFPACK_CHK_ERR(Prec->Compute());
207  cout << *Prec;
208 
209 
210 #endif
211 
212 
213 
214 #ifdef HAVE_IFPACK_SUPPORTGRAPH
215  Prec = Teuchos::rcp( Factory.Create("MSF IC", &*A) );
216  assert (Prec != Teuchos::null);
217  IFPACK_CHK_ERR(Prec->Initialize());
218  IFPACK_CHK_ERR(Prec->Compute());
219  cout << *Prec;
220 
221 
222 #endif
223 
224  if (Comm.MyPID() == 0)
225  cout << "Test `PrecondititonerFactory.exe' passed!" << endl;
226 
227 
228 
229 #ifdef HAVE_MPI
230  MPI_Finalize() ;
231 #endif
232 
233  return(EXIT_SUCCESS);
234 }
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
int MyPID() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
int main(int argc, char *argv[])
Ifpack: a function class to define Ifpack preconditioners.
Definition: Ifpack.h:138
static Ifpack_Preconditioner * Create(EPrecType PrecType, Epetra_RowMatrix *Matrix, const int overlap=0, bool overrideSerialDefault=false)
Creates an instance of Ifpack_Preconditioner given the enum value of the preconditioner type (can not...
Definition: Ifpack.cpp:253
#define IFPACK_CHK_ERR(ifpack_err)
int n