From: Reza Rastak Date: Wed, 4 Sep 2019 00:03:03 +0000 (-0400) Subject: GeometryInfo::unit_normal_vector added X-Git-Tag: v9.2.0-rc1~1139^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9895d1fde94449c0ad5d6f60f5d39c5ae4c8eb59;p=dealii.git GeometryInfo::unit_normal_vector added --- diff --git a/doc/news/changes/minor/20190904RezaRastak b/doc/news/changes/minor/20190904RezaRastak new file mode 100644 index 0000000000..af807b5b51 --- /dev/null +++ b/doc/news/changes/minor/20190904RezaRastak @@ -0,0 +1,4 @@ +Added: GeometryInfo::unit_normal_vector provides outward-facing unit +vectors for each face of the reference cell in the form of Tensor<1, dim>. +
+(Reza Rastak, 2019/09/04) diff --git a/include/deal.II/base/geometry_info.h b/include/deal.II/base/geometry_info.h index 547009cae8..fa7e8fe7a5 100644 --- a/include/deal.II/base/geometry_info.h +++ b/include/deal.II/base/geometry_info.h @@ -48,6 +48,9 @@ namespace internal static constexpr std::array unit_normal_orientation{{-1, 1}}; + static constexpr std::array, 2> unit_normal_vector{ + {Tensor<1, 1>{{-1}}, Tensor<1, 1>{{1}}}}; + static constexpr std::array opposite_face{{1, 0}}; static constexpr std::array dx_to_deal{{0, 1}}; @@ -67,6 +70,12 @@ namespace internal static constexpr std::array unit_normal_orientation{ {-1, 1, -1, 1}}; + static constexpr std::array, 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 opposite_face{{1, 0, 3, 2}}; static constexpr std::array dx_to_deal{{0, 2, 1, 3}}; @@ -87,6 +96,14 @@ namespace internal static constexpr std::array unit_normal_orientation{ {-1, 1, -1, 1, -1, 1}}; + static constexpr std::array, 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 opposite_face{ {1, 0, 3, 2, 5, 4}}; @@ -131,6 +148,16 @@ namespace internal static constexpr std::array unit_normal_orientation{ {-1, 1, -1, 1, -1, 1, -1, 1}}; + static constexpr std::array, 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 opposite_face{ {1, 0, 3, 2, 5, 4, 7, 6}}; @@ -2262,6 +2289,20 @@ struct GeometryInfo static constexpr std::array unit_normal_orientation = internal::GeometryInfoHelper::Initializers::unit_normal_orientation; + /** + * Unit normal vector (Point) of a face of the reference cell. + * + * Note that this is only the standard orientation 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, faces_per_cell> + unit_normal_vector = + internal::GeometryInfoHelper::Initializers::unit_normal_vector; + /** * List of numbers which denotes which face is opposite to a given face. Its * entries are the first 2*dim entries of { 1, 0, 3, 2, 5, 4, diff --git a/source/base/geometry_info.cc b/source/base/geometry_info.cc index e2578d83a1..5eb6212816 100644 --- a/source/base/geometry_info.cc +++ b/source/base/geometry_info.cc @@ -53,6 +53,10 @@ template constexpr std::array::faces_per_cell> GeometryInfo::unit_normal_direction; +template +constexpr std::array, GeometryInfo::faces_per_cell> + GeometryInfo::unit_normal_vector; + template constexpr std::array::vertices_per_cell> GeometryInfo::dx_to_deal; diff --git a/tests/base/geometry_info_9.cc b/tests/base/geometry_info_9.cc new file mode 100644 index 0000000000..221c3fef47 --- /dev/null +++ b/tests/base/geometry_info_9.cc @@ -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::unit_normal_vector + +#include + +#include "../tests.h" + +const double eps = 1e-10; +DeclException3(ExcWrongValue, + double, + double, + double, + << arg1 << " != " << arg2 << " with delta = " << arg3); + +template +void +test() +{ + for (unsigned int i = 0; i < GeometryInfo::faces_per_cell; ++i) + { + const Tensor<1, dim> unit_normal_vector = + GeometryInfo::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::unit_normal_direction[i]) ? + static_cast( + GeometryInfo::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 index 0000000000..8f4434bc2b --- /dev/null +++ b/tests/base/geometry_info_9.output @@ -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