]> https://gitweb.dealii.org/ - dealii.git/commitdiff
another test for spherical-cartesian transformation 3869/head
authorDenis Davydov <davydden@gmail.com>
Mon, 30 Jan 2017 10:11:31 +0000 (11:11 +0100)
committerDenis Davydov <davydden@gmail.com>
Mon, 30 Jan 2017 12:24:06 +0000 (13:24 +0100)
tests/base/geometric_utilities_02.cc [new file with mode: 0644]
tests/base/geometric_utilities_02.output [new file with mode: 0644]

diff --git a/tests/base/geometric_utilities_02.cc b/tests/base/geometric_utilities_02.cc
new file mode 100644 (file)
index 0000000..3f6e5a6
--- /dev/null
@@ -0,0 +1,68 @@
+// ---------------------------------------------------------------------
+//
+// 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.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check GeometricUtilities::Coordinates::to_spherical and
+// GeometricUtilities::Coordinates::from_spherical.
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/geometric_utilities.h>
+#include <deal.II/base/exceptions.h>
+
+#include <fstream>
+#include <cstdlib>
+
+DeclException3(DifferentComponent,
+               int,
+               double,
+               double,
+               << arg1 <<"-th component is different: " << arg2 << "!=" << arg3);
+
+
+template <int dim>
+void test ()
+{
+  for (double r = 0.1; r < 10; r+= 0.35)
+    for (double theta = 0; theta < 2*numbers::PI; theta+= numbers::PI/3.)
+      // Note: for phi=0 or Pi, \theta can be arbitrary and thereby we can't
+      // have one-to-one correspondence
+      for (double phi = 0.01; phi <= numbers::PI; phi+= numbers::PI/4.)
+        {
+          std_cxx11::array<double, dim> sp;
+          sp[0] = r;
+          sp[1] = theta;
+          sp[2] = phi;
+          Point<dim> p = GeometricUtilities::Coordinates::from_spherical(sp);
+          const std_cxx11::array<double, dim> sp2 = GeometricUtilities::Coordinates::to_spherical(p);
+          for (unsigned int i = 0; i <dim; i++)
+            AssertThrow (std::fabs(sp[i]-sp2[i]) <= std::fabs(sp[i])*1e-10,
+                         DifferentComponent(i,sp[i],sp2[i]));
+        }
+
+  deallog << "OK" << std::endl;
+}
+
+int main ()
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.threshold_double(1.e-10);
+
+  test<3> ();
+
+  return 0;
+}
diff --git a/tests/base/geometric_utilities_02.output b/tests/base/geometric_utilities_02.output
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK

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.