From 1da4c6d2b87aaeb921e599df45d0b6b33515c267 Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Fri, 15 Jan 2021 12:46:25 +0100 Subject: [PATCH] Implement ReferenceCell::unit_normal_vectors() --- include/deal.II/grid/reference_cell.h | 40 ++++++++++++++++++- tests/simplex/unit_tangential_vectors_01.cc | 17 +++++--- .../simplex/unit_tangential_vectors_01.output | 27 +++++++++++++ 3 files changed, 78 insertions(+), 6 deletions(-) diff --git a/include/deal.II/grid/reference_cell.h b/include/deal.II/grid/reference_cell.h index 971fa17cbd..cf680f4537 100644 --- a/include/deal.II/grid/reference_cell.h +++ b/include/deal.II/grid/reference_cell.h @@ -250,7 +250,7 @@ namespace ReferenceCell return Point(+0.0, +0.0, +0.0); } - /* + /** * Return i-th unit tangential vector of a face of the reference cell. * The vectors are arranged such that the * cross product between the two vectors returns the unit normal vector. @@ -330,6 +330,44 @@ namespace ReferenceCell return {}; } + /** + * Return the unit normal vector of a face of the reference cell. + */ + template + inline Tensor<1, dim> + unit_normal_vectors(const Type &reference_cell, const unsigned int face_no) + { + AssertDimension(dim, get_dimension(reference_cell)); + + if (reference_cell == get_hypercube(dim)) + { + AssertIndexRange(face_no, GeometryInfo::faces_per_cell); + return GeometryInfo::unit_normal_vector[face_no]; + } + else if (dim == 2) + { + const auto tangential = + unit_tangential_vectors(reference_cell, face_no, 0); + + Tensor<1, dim> result; + + result[0] = tangential[1]; + result[1] = -tangential[0]; + + return result; + } + else if (dim == 3) + { + return cross_product_3d( + unit_tangential_vectors(reference_cell, face_no, 0), + unit_tangential_vectors(reference_cell, face_no, 1)); + } + + Assert(false, ExcNotImplemented()); + + return {}; + } + /* * Create a (coarse) grid with a single cell of the shape of the provided * reference cell. diff --git a/tests/simplex/unit_tangential_vectors_01.cc b/tests/simplex/unit_tangential_vectors_01.cc index 660cb585f9..fae80a25ba 100644 --- a/tests/simplex/unit_tangential_vectors_01.cc +++ b/tests/simplex/unit_tangential_vectors_01.cc @@ -14,7 +14,8 @@ // --------------------------------------------------------------------- -// Test ReferenceCell::unit_tangential_vectors() for all reference-cell types. +// Test ReferenceCell::unit_tangential_vectors() and ::unit_normal_vectors() +// for all reference-cell types. #include @@ -31,11 +32,17 @@ test(const ReferenceCell::Type &reference_cell) { for (const auto face_no : ReferenceCell::internal::Info::get_cell(reference_cell).face_indices()) - for (unsigned int i = 0; i < dim - 1; ++i) - deallog << ReferenceCell::unit_tangential_vectors(reference_cell, - face_no, - i) + { + deallog << ReferenceCell::unit_normal_vectors(reference_cell, + face_no) << std::endl; + + for (unsigned int i = 0; i < dim - 1; ++i) + deallog << ReferenceCell::unit_tangential_vectors(reference_cell, + face_no, + i) + << std::endl; + } deallog << std::endl; } diff --git a/tests/simplex/unit_tangential_vectors_01.output b/tests/simplex/unit_tangential_vectors_01.output index 46a477ea04..9684a9bcd0 100644 --- a/tests/simplex/unit_tangential_vectors_01.output +++ b/tests/simplex/unit_tangential_vectors_01.output @@ -1,54 +1,81 @@ +DEAL::0.00000 -1.00000 DEAL::1.00000 0.00000 +DEAL::0.707107 0.707107 DEAL::-0.707107 0.707107 +DEAL::-1.00000 0.00000 DEAL::0.00000 -1.00000 DEAL:: +DEAL::-1.00000 0.00000 DEAL::0.00000 -1.00000 +DEAL::1.00000 0.00000 DEAL::0.00000 1.00000 +DEAL::0.00000 -1.00000 DEAL::1.00000 0.00000 +DEAL::0.00000 1.00000 DEAL::-1.00000 0.00000 DEAL:: +DEAL::0.00000 0.00000 -1.00000 DEAL::0.00000 1.00000 0.00000 DEAL::1.00000 0.00000 0.00000 +DEAL::0.00000 -1.00000 0.00000 DEAL::1.00000 0.00000 0.00000 DEAL::0.00000 0.00000 1.00000 +DEAL::-1.00000 0.00000 0.00000 DEAL::0.00000 0.00000 1.00000 DEAL::0.00000 1.00000 0.00000 +DEAL::0.577350 0.577350 0.577350 DEAL::-0.759836 0.759836 0.00000 DEAL::-0.759836 0.00000 0.759836 DEAL:: +DEAL::0.00000 0.00000 -1.00000 DEAL::0.00000 1.00000 0.00000 DEAL::1.00000 0.00000 0.00000 +DEAL::-0.707107 0.00000 0.707107 DEAL::0.707107 0.00000 0.707107 DEAL::0.00000 1.00000 0.00000 +DEAL::0.707107 0.00000 0.707107 DEAL::0.707107 0.00000 -0.707107 DEAL::0.00000 1.00000 0.00000 +DEAL::0.00000 -0.707107 0.707107 DEAL::1.00000 0.00000 0.00000 DEAL::0.00000 0.707107 0.707107 +DEAL::0.00000 0.707107 0.707107 DEAL::1.00000 0.00000 0.00000 DEAL::0.00000 0.707107 -0.707107 DEAL:: +DEAL::0.00000 0.00000 -1.00000 DEAL::0.00000 1.00000 0.00000 DEAL::1.00000 0.00000 0.00000 +DEAL::0.00000 -1.00000 0.00000 DEAL::1.00000 0.00000 0.00000 DEAL::0.00000 0.00000 1.00000 +DEAL::0.707107 0.707107 0.00000 DEAL::-0.707107 0.707107 0.00000 DEAL::0.00000 0.00000 1.00000 +DEAL::-1.00000 0.00000 0.00000 DEAL::0.00000 0.00000 1.00000 DEAL::0.00000 1.00000 0.00000 +DEAL::0.00000 -1.00000 0.00000 DEAL::1.00000 0.00000 0.00000 DEAL::0.00000 0.00000 1.00000 DEAL:: +DEAL::-1.00000 0.00000 0.00000 DEAL::0.00000 -1.00000 0.00000 DEAL::0.00000 0.00000 1.00000 +DEAL::1.00000 0.00000 0.00000 DEAL::0.00000 1.00000 0.00000 DEAL::0.00000 0.00000 1.00000 +DEAL::0.00000 -1.00000 0.00000 DEAL::0.00000 0.00000 -1.00000 DEAL::1.00000 0.00000 0.00000 +DEAL::0.00000 1.00000 0.00000 DEAL::0.00000 0.00000 1.00000 DEAL::1.00000 0.00000 0.00000 +DEAL::0.00000 0.00000 -1.00000 DEAL::-1.00000 0.00000 0.00000 DEAL::0.00000 1.00000 0.00000 +DEAL::0.00000 0.00000 1.00000 DEAL::1.00000 0.00000 0.00000 DEAL::0.00000 1.00000 0.00000 DEAL:: -- 2.39.5