]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
move Newton test and add test in compatibility mode
authorkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 10 Mar 2014 11:36:32 +0000 (11:36 +0000)
committerkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 10 Mar 2014 11:36:32 +0000 (11:36 +0000)
git-svn-id: https://svn.dealii.org/trunk@32638 0785d39b-7218-0410-832d-ea1e28bc413d

tests/algorithms/newton_01.cc [new file with mode: 0644]
tests/algorithms/newton_01.output [moved from tests/deal.II/newton_01.output with 100% similarity]
tests/algorithms/newton_01_compat.cc [moved from tests/deal.II/newton_01.cc with 100% similarity]
tests/algorithms/newton_01_compat.output [new file with mode: 0644]

diff --git a/tests/algorithms/newton_01.cc b/tests/algorithms/newton_01.cc
new file mode 100644 (file)
index 0000000..e665a58
--- /dev/null
@@ -0,0 +1,132 @@
+// ---------------------------------------------------------------------
+// $Id$
+//
+// Copyright (C) 2008 - 2013 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+#include "../tests.h"
+#include <deal.II/algorithms/operator.h>
+#include <deal.II/algorithms/newton.h>
+#include <deal.II/numerics/vector_tools.h>
+#include <deal.II/base/named_data.h>
+
+
+//test computing square root of 2 with newton's method
+
+using namespace dealii;
+
+class SquareRoot : public Subscriptor
+{
+public:
+  void start_vector (Vector<double> &start) const;
+  void residual (AnyData &out, const AnyData &in);
+  void solve (AnyData &out, const AnyData &in);
+};
+
+class SquareRootResidual : public
+  Algorithms::Operator<Vector<double> >
+{
+  SmartPointer<SquareRoot, SquareRootResidual>
+  discretization;
+public:
+
+  SquareRootResidual(SquareRoot &problem)
+    : discretization(&problem)
+  {}
+
+  virtual void operator ()(AnyData &out, const AnyData &in)
+  {
+    discretization->residual(out,in);
+  }
+};
+
+class SquareRootSolver : public
+  Algorithms::Operator<Vector<double> >
+{
+  SmartPointer<SquareRoot, SquareRootSolver>
+  solver;
+public:
+
+  SquareRootSolver(SquareRoot &problem)
+    : solver(&problem)
+  {}
+
+  virtual void operator ()(AnyData &out, const AnyData &in)
+  {
+    solver->solve(out,in);
+  }
+};
+
+void SquareRoot::residual (AnyData &out, const AnyData &in)
+{
+  Vector<double>& v = *out.entry<Vector<double>*>(0);
+  //residuum = 0
+  v(0) = 0.;
+  const Vector<double> &x = *in.entry<const Vector<double>*>("Newton iterate");
+  v(0) = x*x - 2.;
+}
+
+void SquareRoot::solve (AnyData &out, const AnyData &in)
+{
+  Vector<double>& v = *out.entry<Vector<double>*>(0);
+  v(0) = 0;
+  const Vector<double> &x = *in.entry<const Vector<double>*>("Newton iterate");
+  const Vector<double> &r = *in.entry<const Vector<double>*>("Newton residual");
+
+  v(0) = 1./2./x(0)* r(0);
+}
+
+
+
+void test ()
+{
+  SquareRoot square_root;
+  SquareRootSolver sq_solver (square_root);
+  SquareRootResidual sq_residual (square_root);
+
+  Algorithms::OutputOperator<Vector<double> > output;
+
+  Algorithms::Newton<Vector<double> > newton(
+    sq_residual,
+    sq_solver);
+  newton.initialize(output);
+
+  NamedData<Vector<double>*> in_data;
+  NamedData<Vector<double>*> out_data;
+
+  Vector<double> solution (1);
+  solution = 10.;
+  Vector<double> *p = &solution;
+  out_data.add(p, "solution");
+
+  newton.control.set_reduction(1.e-20);
+  newton.control.log_history(true);
+  newton.debug_vectors = true;
+  newton(out_data, in_data);
+  deallog << " square root " << (*out_data(0))(0) << std::endl;
+}
+
+
+
+
+int main()
+{
+  std::string logname = "output";
+  std::ofstream logfile(logname.c_str());
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  test ();
+}
diff --git a/tests/algorithms/newton_01_compat.output b/tests/algorithms/newton_01_compat.output
new file mode 100644 (file)
index 0000000..38c1c23
--- /dev/null
@@ -0,0 +1,12 @@
+
+DEAL:Newton::Check 0   98.0000
+DEAL:Newton::Starting value 98.0000
+DEAL:Newton::Check 1   24.0100
+DEAL:Newton::Check 2   5.54095
+DEAL:Newton::Check 3   1.01785
+DEAL:Newton::Check 4   0.0858237
+DEAL:Newton::Check 5   0.000882829
+DEAL:Newton::Check 6   9.73804e-08
+DEAL:Newton::Check 7   0
+DEAL:Newton::Convergence step 7 value 0
+DEAL:: square root 1.41421

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.