]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add test for SolverSelector with a custom SolverControl.
authorheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 12 Oct 2010 18:57:50 +0000 (18:57 +0000)
committerheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 12 Oct 2010 18:57:50 +0000 (18:57 +0000)
git-svn-id: https://svn.dealii.org/trunk@22313 0785d39b-7218-0410-832d-ea1e28bc413d

tests/lac/solver_selector_02.cc [new file with mode: 0644]
tests/lac/solver_selector_02/cmp/generic [new file with mode: 0644]

diff --git a/tests/lac/solver_selector_02.cc b/tests/lac/solver_selector_02.cc
new file mode 100644 (file)
index 0000000..241ae78
--- /dev/null
@@ -0,0 +1,100 @@
+//----------------------------------------------------------------------
+//    $Id: solver_selector_01.cc 21777 2010-08-29 17:36:27Z bangerth $
+//
+//    Copyright (C) 2010 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------------------------------------------------
+
+// Test a bug in the SolverSelector when using a custom SolverControl. At one
+// point the SolverControl got "sliced".
+
+#include "../tests.h"
+#include "testmatrix.h"
+#include <base/logstream.h>
+#include <lac/sparse_matrix.h>
+#include <lac/vector.h>
+#include <lac/vector_memory.h>
+#include <lac/solver_selector.h>
+
+#include <fstream>
+
+class MySolverControl:
+   public SolverControl
+{
+  public:
+    virtual State check(const unsigned int step,const double check_value)
+      {
+       deallog << "MySolverControl " << step << std::endl;
+       return SolverControl::check(step, 0);
+      }
+};
+
+
+
+
+template <class MATRIX, class VECTOR>
+void
+check(const MATRIX& A, const VECTOR& f)
+{
+  std::vector<std::string> names;
+  names.push_back("cg");
+  names.push_back("bicgstab");
+  names.push_back("gmres");
+  names.push_back("fgmres");
+
+  MySolverControl mycont;
+  SolverSelector<VECTOR> solver;
+  PreconditionSSOR<SparseMatrix<double> > pre;
+  pre.initialize(A);
+  
+  VECTOR u;
+  u.reinit(f);
+  
+  std::vector<std::string>::const_iterator name;
+
+  solver.set_control(mycont);  
+  for (name = names.begin(); name != names.end();++name)
+    {
+      solver.select(*name);
+      u = 0.;
+      solver.solve(A, u, f, pre);
+    }
+
+                                  //test deprecated constructor too:
+  GrowingVectorMemory<VECTOR> mem;
+  SolverSelector<VECTOR> solver2("gmres", mycont, mem);
+  u = 0.;
+  solver2.solve(A, u, f, pre);
+}
+
+
+int main()
+{
+  std::ofstream logfile("solver_selector_02/output");
+  deallog << std::setprecision(4);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  unsigned int size=37;
+  unsigned int dim = (size-1)*(size-1);
+  
+  deallog << "Size " << size << " Unknowns " << dim << std::endl;
+  
+                                  // Make matrix
+  FDMatrix testproblem(size, size);
+  SparsityPattern structure(dim, dim, 5);
+  testproblem.five_point_structure(structure);
+  structure.compress();
+  SparseMatrix<double>  A(structure);
+  testproblem.five_point(A);
+  Vector<double>  f(dim);
+  f = 1.;
+  
+  check(A, f);
+}
diff --git a/tests/lac/solver_selector_02/cmp/generic b/tests/lac/solver_selector_02/cmp/generic
new file mode 100644 (file)
index 0000000..983fde2
--- /dev/null
@@ -0,0 +1,26 @@
+
+DEAL::Size 37 Unknowns 1296
+DEAL:cg::Starting value 36.00
+DEAL:cg::Convergence step 14 value 0.2102
+DEAL:Bicgstab::Starting value 36.00
+DEAL:Bicgstab::Convergence step 5 value 0.2814
+DEAL:GMRES::Starting value 34.45
+DEAL:GMRES::Convergence step 13 value 0.1890
+DEAL:FGMRES::Starting value 36.00
+DEAL:FGMRES::Convergence step 13 value 0.2928
+DEAL:cg::Starting value 36.00
+DEAL:cg::Convergence step 21 value 0.003095
+DEAL:Bicgstab::Starting value 36.00
+DEAL:Bicgstab::Convergence step 10 value 0.003158
+DEAL:GMRES::Starting value 34.45
+DEAL:GMRES::Convergence step 21 value 0.001416
+DEAL:FGMRES::Starting value 36.00
+DEAL:FGMRES::Convergence step 21 value 0.002535
+DEAL:cg::Starting value 36.00
+DEAL:cg::Convergence step 39 value 7.335e-08
+DEAL:Bicgstab::Starting value 36.00
+DEAL:Bicgstab::Convergence step 27 value 1.148e-08
+DEAL:GMRES::Starting value 34.45
+DEAL:GMRES::Convergence step 39 value 6.627e-08
+DEAL:FGMRES::Starting value 36.00
+DEAL:FGMRES::Convergence step 39 value 7.890e-08

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.