Ifpack Package Browser (Single Doxygen Collection) Development
test/SetParameters/cxx_main.cpp
Go to the documentation of this file.
00001 //@HEADER
00002 // ************************************************************************
00003 // 
00004 //       Ifpack: Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2002) 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 // SetParameters Test routine
00030 #include <Ifpack_ConfigDefs.h>
00031 #include <Ifpack_IlukGraph.h>
00032 #include <Ifpack_CrsRiluk.h>
00033 #include <Ifpack_CrsIct.h>
00034 #include <Ifpack_OverlapGraph.h>
00035 
00036 #include <Epetra_CombineMode.h>
00037 #include <Epetra_CrsGraph.h>
00038 #include <Epetra_CrsMatrix.h>
00039 #include <Epetra_Map.h>
00040 
00041 #include <Teuchos_ParameterList.hpp>
00042 
00043 #include <ifp_parameters.h>
00044 #include <Epetra_SerialComm.h>
00045 
00046 #ifdef HAVE_MPI
00047 #include <mpi.h>
00048 #include <Epetra_MpiComm.h>
00049 #endif
00050 
00051 int main(int argc, char* argv[]) {
00052   //bool verbose = false;  // used to set verbose false on non-root processors
00053   bool verbose1 = false; // user's command-line argument
00054 
00055   int returnierr = 0;
00056   //int size = 1;
00057   //int rank = 0;
00058 
00059 #ifdef HAVE_MPI
00060   MPI_Init(&argc, &argv);
00061   Epetra_MpiComm Comm(MPI_COMM_WORLD);
00062 #else
00063   Epetra_SerialComm Comm;
00064 #endif
00065 
00066   Ifpack::param_struct params;
00067   params.double_params[Ifpack::absolute_threshold] = -99.9;
00068 
00069   Teuchos::ParameterList paramlist;
00070   paramlist.set("absolute_threshold", 44.0);
00071   paramlist.set("level_fill", 2);
00072   paramlist.set("LEVEL_OVERLAP", 2);
00073   paramlist.set("relative_threshold", 1.e-2);
00074   paramlist.set("fill_tolerance", 2.0);
00075   paramlist.set("use_reciprocal", false);
00076   paramlist.set("level_overlap", 2);
00077   paramlist.set("overlap_mode", Add);
00078 
00079   Ifpack::set_parameters(paramlist, params);
00080 
00081   if (params.double_params[Ifpack::absolute_threshold] != 44.0) {
00082     if (verbose1) {
00083       cerr << "SetParameters test failed to correctly set absolute_threshold."<<endl;
00084     }
00085     return(-1);
00086   }
00087 
00088   int i, local_n = 5;
00089   int my_pid = Comm.MyPID();
00090   int num_procs = Comm.NumProc();
00091   int global_n = num_procs*local_n;
00092 
00093   Epetra_Map map(global_n, 0, Comm);
00094   Epetra_CrsGraph graph(Copy, map, 1);
00095   int first_global_row = my_pid*local_n;
00096 
00097   for(i=0; i<local_n; ++i) {
00098     int row = first_global_row + i;
00099     graph.InsertGlobalIndices(row, 1, &row);
00100   }
00101 
00102   graph.FillComplete();
00103 
00104   Ifpack_IlukGraph ilukgraph(graph, 1,1);
00105   Ifpack_CrsRiluk crsriluk(ilukgraph);
00106   // MS // this was failing
00107 #if 0
00108   Ifpack_OverlapGraph overlapgraph(&graph, 1);
00109 #endif
00110 
00111   Epetra_CrsMatrix A(Copy, graph);
00112 
00113   for(i=0; i<local_n; ++i) {
00114     int row = first_global_row + i;
00115     double val = 2.0;
00116     A.SumIntoGlobalValues(row, 1, &val, &row);
00117   }
00118 
00119   Ifpack_CrsIct crsict(A, 1.0, 1);
00120 
00121   ilukgraph.SetParameters(paramlist);
00122  
00123   int levelfill = ilukgraph.LevelFill();
00124   if (levelfill != 2) {
00125     cerr << "SetParameters test failed to correctly set level_fill."
00126         << endl;
00127     return(-1);
00128   }
00129  
00130   int leveloverlap = ilukgraph.LevelOverlap();
00131   if (leveloverlap != 2) {
00132     cerr << "SetParameters test failed to correctly set level_overlap."
00133         << endl;
00134     return(-1);
00135   }
00136 
00137   crsriluk.SetParameters(paramlist);
00138 
00139   double athresh = crsriluk.GetAbsoluteThreshold();
00140   if (athresh != 44.0) {
00141     cerr << "SetParameters test failed to correctly set absolute_threshold."
00142         << endl;
00143     return(-1);
00144   }
00145 
00146   Epetra_CombineMode overlapmode = crsriluk.GetOverlapMode();
00147   if (overlapmode != Add) {
00148     cerr << "SetParameters test failed to correctly set overlapmode."
00149         << endl;
00150     return(-1);
00151   }
00152 
00153   crsict.SetParameters(paramlist);
00154 
00155   double rthresh = crsict.GetRelativeThreshold();
00156   if (rthresh != 1.e-2) {
00157     cerr << "SetParameters test failed to correctly set relative_threshold."
00158         << endl;
00159     return(-1);
00160   }
00161 
00162   overlapmode = crsict.GetOverlapMode();
00163   if (overlapmode != Add) {
00164     cerr << "SetParameters test failed to correctly set overlapmode."
00165         << endl;
00166     return(-1);
00167   }
00168 
00169 #if 0
00170   overlapgraph.SetParameters(paramlist);
00171 
00172   int overlaplevel = overlapgraph.OverlapLevel();
00173   if (overlaplevel != 2) {
00174     cerr << "SetParameters test failed to correctly set overlaplevel."
00175         << endl;
00176     return(-1);
00177   }
00178 #endif
00179 
00180   if (verbose1==true) {
00181     cout << "********* Test passed **********" << endl;
00182   }
00183 
00184 #ifdef HAVE_MPI
00185   MPI_Finalize();
00186 #endif
00187 
00188   return(returnierr);
00189 }
00190 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines