test/test_ml_laplace.cpp

Go to the documentation of this file.
00001 //
00002 // C++ Implementation: test_romberg
00003 //
00004 // Description: unit tests ML preconditioner
00005 //
00006 //
00007 // Author: Roman Geus <geus@maxwell>, (C) 2004
00008 //
00009 // Copyright: See COPYING file that comes with this distribution
00010 //
00011 //
00012 
00013 #include <cmath>
00014 #include <iostream>
00015 #include <fstream>
00016 #include <cstdlib>
00017 #include <unistd.h>
00018 #include <limits>
00019 
00020 #include <tut.h>
00021 
00022 #include "rlog/rlog.h"
00023 
00024 #include "ml_include.h"
00025 #include "Teuchos_ParameterList.hpp"
00026 #include "Epetra_Comm.h"
00027 #include "Epetra_CrsMatrix.h"
00028 #include "Epetra_Map.h"
00029 #include "Epetra_Vector.h"
00030 #include "AztecOO.h"
00031 #include "Epetra_Operator.h"
00032 #include "Epetra_MultiVector.h"
00033 #include "Epetra_LinearProblem.h"
00034 #include "ml_epetra_preconditioner.h"
00035 
00036 #include "OutputCapturer.h"
00037 #include "balancedmtxreader.h"
00038 #include "mtxreader.h"
00039 
00040 #undef RLOG_TIME_TSC
00041 #include "rlog/RLogTime.h"
00042 
00043 namespace tut {
00044     Epetra_Comm& get_comm_world();
00045 }
00046 
00047 namespace
00048 {
00049 
00050     struct testdata
00051     {
00052         testdata()
00053             : tol(100 * std::numeric_limits<double>::epsilon()),
00054               comm(tut::get_comm_world())
00055         {
00056             if (H == 0)
00057                 read_matrices(tut::get_comm_world());
00058         }
00059 
00060         static void read_matrices(Epetra_Comm& comm) {
00061             rInfo("Reading test matrices...");
00062             string filename;
00063             BaseMtxReader *reader = 0;
00064 
00065             // read matrix Y_transp
00066             filename = "test/ml_laplace/H.mtx";
00067             if (access(filename.c_str(), R_OK)) {
00068                 rError("Unable to access H matrix file.");
00069                 exit(1);
00070             }
00071             reader = new BalancedMtxReader(filename, comm);
00072             H = reader->read();
00073             delete reader;
00074         }
00075 
00076         const double tol;
00077         Epetra_Comm& comm;
00078         static Epetra_CrsMatrix* H;
00079     };
00080 
00081     // Initialise static members
00082     Epetra_CrsMatrix* testdata::H = 0;
00083 
00084     typedef tut::test_group<testdata> testgroup;
00085     typedef testgroup::object testobject;
00086     testgroup group("ml_laplace");
00087 
00089     template<>
00090     template<>
00091     void testobject::test<1>()
00092     {
00093         // Construct ML preconditioner
00094         Teuchos::ParameterList MLList;
00095         ML_Epetra::SetDefaults("SA", MLList);
00096         MLList.set("aggregation: type", "Uncoupled-MIS");
00097         ostringstream buf;
00098         buf << "ML parameters:" << endl;
00099         MLList.print(buf, 8);
00100         if (comm.MyPID() == 0)
00101             rDebug(buf.str().c_str());
00102 
00103         OutputCapturer capt;
00104         capt.begin_capture();
00105         Epetra_Operator *prec = new ML_Epetra::MultiLevelPreconditioner(*H, MLList, true);
00106         capt.end_capture();
00107         rDebug("%s", capt.get_stdout().c_str());
00108 
00109         // Right hand side
00110         Epetra_Vector b(H->OperatorRangeMap());
00111         b.PutScalar(1.0);
00112 
00113         // Initial guess
00114         Epetra_Vector x(H->OperatorDomainMap());
00115         x.PutScalar(0.0);
00116 
00117         // Setup iterative solver
00118         Epetra_LinearProblem problem(H, &x, &b);
00119         AztecOO solver(problem);
00120         solver.SetPrecOperator(prec);
00121 
00122         // Solve
00123         capt.begin_capture();
00124         solver.Iterate(1000, 1.0e-10);
00125         capt.end_capture();
00126         rDebug("%s", capt.get_stdout().c_str());
00127 
00128         // Compute Residual
00129         Epetra_Vector bcomp(H->OperatorRangeMap());
00130         H->Apply(x, bcomp);
00131         Epetra_Vector resid(H->OperatorRangeMap());
00132         resid.Update(1.0, b, -1.0, bcomp, 0.0);
00133         double residual;
00134         resid.Norm2(&residual);
00135         rDebug("Residual=%e", residual);
00136         ensure(residual < 1.0e-7);
00137     }
00138 
00139 };

Generated on Fri Oct 26 13:35:13 2007 for FEMAXX (Finite Element Maxwell Eigensolver) by  doxygen 1.4.7