From: Peter Munch Date: Fri, 15 Jan 2021 11:46:25 +0000 (+0100) Subject: Implement ReferenceCell::unit_normal_vectors() X-Git-Tag: v9.3.0-rc1~618^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1da4c6d2b87aaeb921e599df45d0b6b33515c267;p=dealii.git Implement ReferenceCell::unit_normal_vectors() --- 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::