]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add test for newton debug vector sizes and astyle 2537/head
authorPatrick Esser <Patrick.Esser@gmx.net>
Thu, 21 Apr 2016 15:16:17 +0000 (17:16 +0200)
committerPatrick Esser <Patrick.Esser@gmx.net>
Thu, 21 Apr 2016 15:20:31 +0000 (17:20 +0200)
tests/algorithms/newton_02.cc [new file with mode: 0644]
tests/algorithms/newton_02.output [new file with mode: 0644]

diff --git a/tests/algorithms/newton_02.cc b/tests/algorithms/newton_02.cc
new file mode 100644 (file)
index 0000000..140fd33
--- /dev/null
@@ -0,0 +1,122 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 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/grid/grid_generator.h>
+
+
+// verify that all debug vectors have the correct size
+
+using namespace dealii;
+using namespace Algorithms;
+
+template <typename VectorType, int dim>
+class TestOutputOperator : public OutputOperator<VectorType>
+{
+public:
+  void initialize(const DoFHandler<dim> &dof_handler)
+  {
+    dof = &dof_handler;
+  }
+
+  virtual OutputOperator<VectorType> &operator<<(const AnyData &vectors)
+  {
+    for (unsigned int i=0; i<vectors.size(); ++i)
+      {
+        const VectorType *p = vectors.try_read_ptr<VectorType>(i);
+        if (p!=0)
+          {
+            // this should be equal to dof->n_dofs() otherwise
+            // DoFOutputOperator will complain
+            deallog << p->size() << std::endl;
+          }
+      }
+    return *this;
+  }
+
+private:
+  SmartPointer<const DoFHandler<dim>,
+               TestOutputOperator<VectorType, dim> > dof;
+};
+
+class ZeroResidual : public Algorithms::OperatorBase
+{
+public:
+  virtual void operator ()(AnyData &out, const AnyData &in)
+  {
+    const Vector<double> &in_vector = *in.entry<const Vector<double>*>(
+                                        "Newton iterate");
+    Vector<double> &out_vector = *out.entry<Vector<double>*>(0);
+    out_vector.reinit(in_vector.size());
+  }
+};
+
+class IdentitySolver : public Algorithms::OperatorBase
+{
+public:
+  virtual void operator ()(AnyData &out, const AnyData &in)
+  {
+    const Vector<double> &in_vector = *in.entry<const Vector<double>*>(
+                                        "Newton residual");
+    Vector<double> &out_vector = *out.entry<Vector<double>*>(0);
+    out_vector = in_vector;
+  }
+};
+
+
+template <int dim>
+void test()
+{
+  Triangulation<dim> tria;
+  GridGenerator::hyper_cube(tria, -1, 1);
+  tria.refine_global(1);
+
+  FE_Q<dim> fe(1);
+  DoFHandler<dim> dofh(tria);
+  dofh.distribute_dofs(fe);
+
+  TestOutputOperator<Vector<double>, dim> output_operator;
+  output_operator.initialize(dofh);
+
+  IdentitySolver solver;
+  ZeroResidual residual;
+
+  Algorithms::Newton<Vector<double> > newton(residual, solver);
+  newton.initialize(output_operator);
+
+  AnyData in_data;
+  AnyData out_data;
+
+  Vector<double> solution(dofh.n_dofs());
+  out_data.add<Vector<double>*>(&solution, "solution");
+
+  newton.debug_vectors = true;
+  newton(out_data, in_data);
+}
+
+
+int main()
+{
+  std::string logname = "output";
+  std::ofstream logfile(logname.c_str());
+  deallog.attach(logfile);
+  deallog.threshold_double(1.e-10);
+
+  test<2>();
+}
diff --git a/tests/algorithms/newton_02.output b/tests/algorithms/newton_02.output
new file mode 100644 (file)
index 0000000..ec96505
--- /dev/null
@@ -0,0 +1,5 @@
+
+DEAL:Newton::9
+DEAL:Newton::9
+DEAL:Newton::9
+DEAL:Newton::Convergence step 0 value 0

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.