Ifpack_ex_ICT.cpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //                IFPACK
00005 //                 Copyright (2004) 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_ConfigDefs.h"
00030 
00031 #ifdef HAVE_MPI
00032 #include "Epetra_MpiComm.h"
00033 #else
00034 #include "Epetra_SerialComm.h"
00035 #endif
00036 #include "Epetra_CrsMatrix.h"
00037 #include "Epetra_MultiVector.h"
00038 #include "Epetra_LinearProblem.h"
00039 #include "Epetra_Time.h"
00040 #include "Galeri_Maps.h"
00041 #include "Galeri_CrsMatrices.h"
00042 #include "Teuchos_ParameterList.hpp"
00043 #include "Teuchos_RefCountPtr.hpp"
00044 #include "AztecOO.h"
00045 #include "Ifpack_AdditiveSchwarz.h"
00046 #include "Ifpack_ICT.h"
00047 
00048 int main(int argc, char *argv[])
00049 {
00050 
00051   // initialize MPI and Epetra communicator
00052 #ifdef HAVE_MPI
00053   MPI_Init(&argc,&argv);
00054   Epetra_MpiComm Comm( MPI_COMM_WORLD );
00055 #else
00056   Epetra_SerialComm Comm;
00057 #endif
00058 
00059   Teuchos::ParameterList GaleriList;
00060 
00061   // The problem is defined on a 2D grid, global size is nx * nx.
00062   int nx = 30; 
00063   GaleriList.set("nx", nx);
00064   GaleriList.set("ny", nx * Comm.NumProc());
00065   GaleriList.set("mx", 1);
00066   GaleriList.set("my", Comm.NumProc());
00067   Teuchos::RefCountPtr<Epetra_Map> Map = Teuchos::rcp( Galeri::CreateMap("Cartesian2D", Comm, GaleriList) );
00068   Teuchos::RefCountPtr<Epetra_RowMatrix> A = Teuchos::rcp( Galeri::CreateCrsMatrix("Laplace2D", &*Map, GaleriList) );
00069 
00070   // =============================================================== //
00071   // B E G I N N I N G   O F   I F P A C K   C O N S T R U C T I O N //
00072   // =============================================================== //
00073 
00074   Teuchos::ParameterList List;
00075 
00076   // builds an Ifpack_AdditiveSchwarz. This is templated with
00077   // the local solvers, in this case Ifpack_ICT. Note that any
00078   // other Ifpack_Preconditioner-derived class can be used
00079   // instead of Ifpack_ICT.
00080 
00081   // In this example the overlap is zero. Use
00082   // Prec(A,OverlapLevel) for the general case.
00083   Ifpack_AdditiveSchwarz<Ifpack_ICT> Prec(&*A);
00084 
00085   // `1.0' means that the factorization should approximatively
00086   // keep the same number of nonzeros per row of the original matrix.
00087   List.set("fact: ict level-of-fill", 1.0);
00088   // no modifications on the diagonal
00089   List.set("fact: absolute threshold", 0.0);
00090   List.set("fact: relative threshold", 1.0);
00091   List.set("fact: relaxation value", 0.0);
00092   // matrix `laplace_2d_bc' is not symmetric because of the way
00093   // boundary conditions are imposed. We can filter the singletons,
00094   // (that is, Dirichlet nodes) and end up with a symmetric
00095   // matrix (as ICT requires).
00096   List.set("schwarz: filter singletons", true);
00097 
00098   // sets the parameters
00099   IFPACK_CHK_ERR(Prec.SetParameters(List));
00100 
00101   // initialize the preconditioner. At this point the matrix must
00102   // have been FillComplete()'d, but actual values are ignored.
00103   IFPACK_CHK_ERR(Prec.Initialize());
00104 
00105   // Builds the preconditioners, by looking for the values of 
00106   // the matrix. 
00107   IFPACK_CHK_ERR(Prec.Compute());
00108 
00109   // =================================================== //
00110   // E N D   O F   I F P A C K   C O N S T R U C T I O N //
00111   // =================================================== //
00112 
00113   // At this point, we need some additional objects
00114   // to define and solve the linear system.
00115 
00116   // defines LHS and RHS
00117   Epetra_Vector LHS(A->OperatorDomainMap());
00118   Epetra_Vector RHS(A->OperatorDomainMap());
00119 
00120   LHS.PutScalar(0.0);
00121   RHS.Random();
00122 
00123   // need an Epetra_LinearProblem to define AztecOO solver
00124   Epetra_LinearProblem Problem(&*A,&LHS,&RHS);
00125 
00126   // now we can allocate the AztecOO solver
00127   AztecOO Solver(Problem);
00128 
00129   // specify solver
00130   Solver.SetAztecOption(AZ_solver,AZ_cg_condnum);
00131   Solver.SetAztecOption(AZ_output,32);
00132 
00133   // HERE WE SET THE IFPACK PRECONDITIONER
00134   Solver.SetPrecOperator(&Prec);
00135 
00136   // .. and here we solve
00137   // NOTE: with one process, the solver must converge in
00138   // one iteration.
00139   Solver.Iterate(1550,1e-5);
00140 
00141   // Prints out some information about the preconditioner
00142   cout << Prec;
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
Generated on Wed Apr 13 10:05:34 2011 for Ifpack Package Browser (Single Doxygen Collection) by  doxygen 1.6.3