]> https://gitweb.dealii.org/ - dealii.git/commitdiff
GeometryInfo<dim>::unit_normal_vector added
authorReza Rastak <rastak@stanford.edu>
Wed, 4 Sep 2019 00:03:03 +0000 (20:03 -0400)
committerReza Rastak <rastak@stanford.edu>
Wed, 4 Sep 2019 19:42:20 +0000 (12:42 -0700)
doc/news/changes/minor/20190904RezaRastak [new file with mode: 0644]
include/deal.II/base/geometry_info.h
source/base/geometry_info.cc
tests/base/geometry_info_9.cc [new file with mode: 0644]
tests/base/geometry_info_9.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20190904RezaRastak b/doc/news/changes/minor/20190904RezaRastak
new file mode 100644 (file)
index 0000000..af807b5
--- /dev/null
@@ -0,0 +1,4 @@
+Added: GeometryInfo<dim>::unit_normal_vector provides outward-facing unit
+vectors for each face of the reference cell in the form of Tensor<1, dim>.
+<br>
+(Reza Rastak, 2019/09/04)
index 547009cae87b7e650c1223085faa910aebcef001..fa7e8fe7a55b48f8ec6917f06c930880805ab9f0 100644 (file)
@@ -48,6 +48,9 @@ namespace internal
 
       static constexpr std::array<int, 2> unit_normal_orientation{{-1, 1}};
 
+      static constexpr std::array<Tensor<1, 1>, 2> unit_normal_vector{
+        {Tensor<1, 1>{{-1}}, Tensor<1, 1>{{1}}}};
+
       static constexpr std::array<unsigned int, 2> opposite_face{{1, 0}};
 
       static constexpr std::array<unsigned int, 2> dx_to_deal{{0, 1}};
@@ -67,6 +70,12 @@ namespace internal
       static constexpr std::array<int, 4> unit_normal_orientation{
         {-1, 1, -1, 1}};
 
+      static constexpr std::array<Tensor<1, 2>, 4> unit_normal_vector{
+        {Tensor<1, 2>{{-1., 0.}},
+         Tensor<1, 2>{{1., 0.}},
+         Tensor<1, 2>{{0., -1.}},
+         Tensor<1, 2>{{0., 1.}}}};
+
       static constexpr std::array<unsigned int, 4> opposite_face{{1, 0, 3, 2}};
 
       static constexpr std::array<unsigned int, 4> dx_to_deal{{0, 2, 1, 3}};
@@ -87,6 +96,14 @@ namespace internal
       static constexpr std::array<int, 6> unit_normal_orientation{
         {-1, 1, -1, 1, -1, 1}};
 
+      static constexpr std::array<Tensor<1, 3>, 6> unit_normal_vector{
+        {Tensor<1, 3>{{-1, 0, 0}},
+         Tensor<1, 3>{{1, 0, 0}},
+         Tensor<1, 3>{{0, -1, 0}},
+         Tensor<1, 3>{{0, 1, 0}},
+         Tensor<1, 3>{{0, 0, -1}},
+         Tensor<1, 3>{{0, 0, 1}}}};
+
       static constexpr std::array<unsigned int, 6> opposite_face{
         {1, 0, 3, 2, 5, 4}};
 
@@ -131,6 +148,16 @@ namespace internal
       static constexpr std::array<int, 8> unit_normal_orientation{
         {-1, 1, -1, 1, -1, 1, -1, 1}};
 
+      static constexpr std::array<Tensor<1, 4>, 8> unit_normal_vector{
+        {Tensor<1, 4>{{-1, 0, 0, 0}},
+         Tensor<1, 4>{{1, 0, 0, 0}},
+         Tensor<1, 4>{{0, -1, 0, 0}},
+         Tensor<1, 4>{{0, 1, 0, 0}},
+         Tensor<1, 4>{{0, 0, -1, 0}},
+         Tensor<1, 4>{{0, 0, 1, 0}},
+         Tensor<1, 4>{{0, 0, 0, -1}},
+         Tensor<1, 4>{{0, 0, 0, 1}}}};
+
       static constexpr std::array<unsigned int, 8> opposite_face{
         {1, 0, 3, 2, 5, 4, 7, 6}};
 
@@ -2262,6 +2289,20 @@ struct GeometryInfo
   static constexpr std::array<int, faces_per_cell> unit_normal_orientation =
     internal::GeometryInfoHelper::Initializers<dim>::unit_normal_orientation;
 
+  /**
+   * Unit normal vector (Point<dim>) of a face of the reference cell.
+   *
+   * Note that this is only the <em>standard orientation</em> of faces. At
+   * least in 3d, actual faces of cells in a triangulation can also have the
+   * opposite orientation, depending on a flag that one can query from the
+   * cell it belongs to. For more information, see the
+   * @ref GlossFaceOrientation "glossary"
+   * entry on face orientation.
+   */
+  static constexpr std::array<Tensor<1, dim>, faces_per_cell>
+    unit_normal_vector =
+      internal::GeometryInfoHelper::Initializers<dim>::unit_normal_vector;
+
   /**
    * List of numbers which denotes which face is opposite to a given face. Its
    * entries are the first <tt>2*dim</tt> entries of <tt>{ 1, 0, 3, 2, 5, 4,
index e2578d83a11d5582a521e97ee99d1a42c73fe15c..5eb62128161345b74ee8b03aa2e4acaac8619ef2 100644 (file)
@@ -53,6 +53,10 @@ template <int dim>
 constexpr std::array<unsigned int, GeometryInfo<dim>::faces_per_cell>
   GeometryInfo<dim>::unit_normal_direction;
 
+template <int dim>
+constexpr std::array<Tensor<1, dim>, GeometryInfo<dim>::faces_per_cell>
+  GeometryInfo<dim>::unit_normal_vector;
+
 template <int dim>
 constexpr std::array<unsigned int, GeometryInfo<dim>::vertices_per_cell>
   GeometryInfo<dim>::dx_to_deal;
diff --git a/tests/base/geometry_info_9.cc b/tests/base/geometry_info_9.cc
new file mode 100644 (file)
index 0000000..221c3fe
--- /dev/null
@@ -0,0 +1,70 @@
+// ---------------------------------------------------------------------
+//
+// 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.
+//
+// ---------------------------------------------------------------------
+
+// Test GeometryInfo<dim>::unit_normal_vector
+
+#include <deal.II/base/geometry_info.h>
+
+#include "../tests.h"
+
+const double eps = 1e-10;
+DeclException3(ExcWrongValue,
+               double,
+               double,
+               double,
+               << arg1 << " != " << arg2 << " with delta = " << arg3);
+
+template <int dim>
+void
+test()
+{
+  for (unsigned int i = 0; i < GeometryInfo<dim>::faces_per_cell; ++i)
+    {
+      const Tensor<1, dim> unit_normal_vector =
+        GeometryInfo<dim>::unit_normal_vector[i];
+      deallog << "Direction " << i << " = " << unit_normal_vector << std::endl;
+      // check consistency with other arrays within GeometryInfo
+      for (unsigned int j = 0; j < dim; j++)
+        {
+          const double obtained = unit_normal_vector[j];
+          const double expected =
+            (j == GeometryInfo<dim>::unit_normal_direction[i]) ?
+              static_cast<double>(
+                GeometryInfo<dim>::unit_normal_orientation[i]) :
+              0;
+          AssertThrow(obtained == expected,
+                      ExcWrongValue(obtained, expected, obtained - expected));
+        }
+    }
+  deallog << "OK" << std::endl;
+}
+
+
+int
+main()
+{
+  initlog();
+
+  deallog.push("1d");
+  test<1>();
+  deallog.pop();
+  deallog.push("2d");
+  test<2>();
+  deallog.pop();
+  deallog.push("3d");
+  test<3>();
+  deallog.pop();
+  return 0;
+}
diff --git a/tests/base/geometry_info_9.output b/tests/base/geometry_info_9.output
new file mode 100644 (file)
index 0000000..8f4434b
--- /dev/null
@@ -0,0 +1,16 @@
+
+DEAL:1d::Direction 0 = -1.00000
+DEAL:1d::Direction 1 = 1.00000
+DEAL:1d::OK
+DEAL:2d::Direction 0 = -1.00000 0.00000
+DEAL:2d::Direction 1 = 1.00000 0.00000
+DEAL:2d::Direction 2 = 0.00000 -1.00000
+DEAL:2d::Direction 3 = 0.00000 1.00000
+DEAL:2d::OK
+DEAL:3d::Direction 0 = -1.00000 0.00000 0.00000
+DEAL:3d::Direction 1 = 1.00000 0.00000 0.00000
+DEAL:3d::Direction 2 = 0.00000 -1.00000 0.00000
+DEAL:3d::Direction 3 = 0.00000 1.00000 0.00000
+DEAL:3d::Direction 4 = 0.00000 0.00000 -1.00000
+DEAL:3d::Direction 5 = 0.00000 0.00000 1.00000
+DEAL:3d::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.