]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add test for EllipticalManifold::push_forward_gradient
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Tue, 5 Mar 2019 17:41:56 +0000 (18:41 +0100)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Tue, 5 Mar 2019 17:44:11 +0000 (18:44 +0100)
tests/manifold/elliptical_manifold_03.cc [new file with mode: 0644]
tests/manifold/elliptical_manifold_03.output [new file with mode: 0644]

diff --git a/tests/manifold/elliptical_manifold_03.cc b/tests/manifold/elliptical_manifold_03.cc
new file mode 100644 (file)
index 0000000..ad72999
--- /dev/null
@@ -0,0 +1,78 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2019 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.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+// Check gradient of elliptical manifold
+
+#include "../tests.h"
+
+
+// all include files you need here
+#include <deal.II/base/exceptions.h>
+#include <deal.II/base/numbers.h>
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_out.h>
+#include <deal.II/grid/grid_tools.h>
+#include <deal.II/grid/manifold_lib.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/tria_iterator.h>
+
+#include <vector>
+
+
+
+int
+main()
+{
+  initlog();
+
+  deallog << std::setprecision(10);
+
+  // setup elliptical manifold
+  const Tensor<1, 2> major_axis({2.0, 1.0});
+  const Point<2>     center(7.0, 6.0);
+  const double       eccentricity = 0.1;
+
+  const EllipticalManifold<2> ellipse(center, major_axis, eccentricity);
+
+  // reference point for computing gradient
+  const Point<2> chart_point(1.0, 0.25 * numbers::PI);
+
+  // compute gradient by central finite differences
+  const double   h = 1e-6;
+  const Point<2> chart_point_plusc(chart_point[0] + h, chart_point[1]);
+  const Point<2> chart_point_minusc(chart_point[0] - h, chart_point[1]);
+  const Point<2> chart_point_plusphi(chart_point[0], chart_point[1] + h);
+  const Point<2> chart_point_minusphi(chart_point[0], chart_point[1] - h);
+
+  const Point<2> space_point_plusc  = ellipse.push_forward(chart_point_plusc);
+  const Point<2> space_point_minusc = ellipse.push_forward(chart_point_minusc);
+  const Point<2> space_point_plusphi =
+    ellipse.push_forward(chart_point_plusphi);
+  const Point<2> space_point_minusphi =
+    ellipse.push_forward(chart_point_minusphi);
+
+  deallog << "Gradient by finite differences: "
+          << (space_point_plusc - space_point_minusc) / (2.0 * h) << " "
+          << (space_point_plusphi - space_point_minusphi) / (2.0 * h)
+          << std::endl;
+  deallog << "Analytic gradient:              "
+          << transpose(Tensor<2, 2>(ellipse.push_forward_gradient(chart_point)))
+          << std::endl;
+
+  return 0;
+}
diff --git a/tests/manifold/elliptical_manifold_03.output b/tests/manifold/elliptical_manifold_03.output
new file mode 100644 (file)
index 0000000..602c91b
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::Gradient by finite differences: 3.178128775 9.455130749 -9.470981865 3.130575430
+DEAL::Analytic gradient:              3.178128776 9.455130749 -9.470981865 3.130575429

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.