]> https://gitweb.dealii.org/ - dealii.git/commitdiff
new test for Newton's method
authorBaerbel Jannsen <baerbel.janssen@gmail.com>
Fri, 27 Aug 2010 09:51:01 +0000 (09:51 +0000)
committerBaerbel Jannsen <baerbel.janssen@gmail.com>
Fri, 27 Aug 2010 09:51:01 +0000 (09:51 +0000)
git-svn-id: https://svn.dealii.org/trunk@21745 0785d39b-7218-0410-832d-ea1e28bc413d

tests/deal.II/Makefile
tests/deal.II/newton_01.cc [new file with mode: 0644]
tests/deal.II/newton_01/cmp/generic [new file with mode: 0644]

index 135a11efd6a244b1b3ddd16c2445794ff2ed0f3c..7b36bd8a93aa3312db5a6f3029e76f1caed194ea 100644 (file)
@@ -87,7 +87,8 @@ tests_x = block_info block_matrices \
        number_cache_* \
        kelly_crash_* \
        recursively_set_material_id \
-       point_value_history_*
+       point_value_history_* \
+       newton_*
 
 # from above list of regular expressions, generate the real set of
 # tests
diff --git a/tests/deal.II/newton_01.cc b/tests/deal.II/newton_01.cc
new file mode 100644 (file)
index 0000000..f14efdf
--- /dev/null
@@ -0,0 +1,134 @@
+//-----------------------------------------------------------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2008, 2009 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.
+//
+//-----------------------------------------------------------------------------
+
+#include <numerics/operator.h>
+#include <numerics/newton.h>
+#include <numerics/vectors.h>
+#include <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 (NamedData<Vector<double>*>& out, 
+        const NamedData<Vector<double>*>& in);
+    void solve (NamedData<Vector<double>*>& out, 
+        const NamedData<Vector<double>*>& in);
+};
+
+class SquareRootResidual : public 
+                       Algorithms::Operator<Vector<double> >
+{
+    SmartPointer<SquareRoot, SquareRootResidual>
+      discretization;
+  public:
+
+    SquareRootResidual(SquareRoot& problem)
+      : discretization(&problem)
+    {}
+
+    virtual void operator ()(
+        NamedData<Vector<double>*>& out, 
+        const NamedData<Vector<double>*>& 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 ()(
+        NamedData<Vector<double>*>& out, 
+        const NamedData<Vector<double>*>& in) 
+    {
+      solver->solve(out,in);
+    }
+};
+
+void SquareRoot::residual (
+    NamedData<Vector<double>*>& out, 
+    const NamedData<Vector<double>*>& in) 
+{
+  //residuum = 0
+  *out(0) = 0.;
+  const Vector<double> &x = *in(in.find("Newton iterate")); 
+  *out(0) = x*x - 2.;
+}
+
+void SquareRoot::solve (
+    NamedData<Vector<double>*>& out, 
+    const NamedData<Vector<double>*>& in)
+{
+  *out(0) = 0;
+  const Vector<double> &x = *in(in.find("Newton iterate")); 
+  const Vector<double> &r = *in(in.find("Newton residual"));
+
+  (*out(0))(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::ofstream logfile("newton_01/output");
+  deallog.attach(logfile);
+  deallog.depth_console(10);
+  deallog.threshold_double(1.e-10);
+
+  test ();
+}
diff --git a/tests/deal.II/newton_01/cmp/generic b/tests/deal.II/newton_01/cmp/generic
new file mode 100644 (file)
index 0000000..bc020eb
--- /dev/null
@@ -0,0 +1,21 @@
+
+DEAL::0
+DEAL::2
+DEAL::4
+DEAL::6
+DEAL::8
+DEAL::10
+DEAL::12
+DEAL::14
+DEAL::16
+DEAL::18
+DEAL::20
+DEAL::22
+DEAL::24
+DEAL::26
+DEAL::28
+DEAL::30
+DEAL::32
+DEAL::34
+DEAL::36
+DEAL::38

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.