From: Peter Munch Date: Wed, 13 Jan 2021 10:45:22 +0000 (+0100) Subject: Add an assert to ReferenceCell::compute_orientation() X-Git-Tag: v9.3.0-rc1~650^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66567af0f87e2305d9810130283590783fec5009;p=dealii.git Add an assert to ReferenceCell::compute_orientation() --- diff --git a/include/deal.II/grid/reference_cell.h b/include/deal.II/grid/reference_cell.h index 406dc414a9..582f3499b9 100644 --- a/include/deal.II/grid/reference_cell.h +++ b/include/deal.II/grid/reference_cell.h @@ -250,197 +250,6 @@ namespace ReferenceCell return Point(+0.0, +0.0, +0.0); } - /** - * Determine the orientation of an entity of @p type described by its - * vertices @p var_1 relative to an entity described by @p var_0. - */ - template - inline unsigned char - compute_orientation(const ReferenceCell::Type entity_type, - const std::array & vertices_0, - const std::array & vertices_1) - { - if (entity_type == ReferenceCell::Type::Line) - { - const std::array i{{vertices_0[0], vertices_0[1]}}; - const std::array j{{vertices_1[0], vertices_1[1]}}; - - // line_orientation=true - if (i == std::array{{j[0], j[1]}}) - return 1; - - // line_orientation=false - if (i == std::array{{j[1], j[0]}}) - return 0; - } - else if (entity_type == ReferenceCell::Type::Tri) - { - const std::array i{{vertices_0[0], vertices_0[1], vertices_0[2]}}; - const std::array j{{vertices_1[0], vertices_1[1], vertices_1[2]}}; - - // face_orientation=true, face_rotation=false, face_flip=false - if (i == std::array{{j[0], j[1], j[2]}}) - return 1; - - // face_orientation=true, face_rotation=true, face_flip=false - if (i == std::array{{j[1], j[0], j[2]}}) - return 3; - - // face_orientation=true, face_rotation=false, face_flip=true - if (i == std::array{{j[2], j[0], j[1]}}) - return 5; - - // face_orientation=false, face_rotation=false, face_flip=false - if (i == std::array{{j[0], j[2], j[1]}}) - return 0; - - // face_orientation=false, face_rotation=true, face_flip=false - if (i == std::array{{j[1], j[2], j[0]}}) - return 2; - - // face_orientation=false, face_rotation=false, face_flip=true - if (i == std::array{{j[2], j[1], j[0]}}) - return 4; - } - else if (entity_type == ReferenceCell::Type::Quad) - { - const std::array i{ - {vertices_0[0], vertices_0[1], vertices_0[2], vertices_0[3]}}; - const std::array j{ - {vertices_1[0], vertices_1[1], vertices_1[2], vertices_1[3]}}; - - // face_orientation=true, face_rotation=false, face_flip=false - if (i == std::array{{j[0], j[1], j[2], j[3]}}) - return 1; - - // face_orientation=true, face_rotation=true, face_flip=false - if (i == std::array{{j[1], j[3], j[0], j[2]}}) - return 3; - - // face_orientation=true, face_rotation=false, face_flip=true - if (i == std::array{{j[3], j[2], j[1], j[0]}}) - return 5; - - // face_orientation=true, face_rotation=true, face_flip=true - if (i == std::array{{j[2], j[0], j[3], j[1]}}) - return 7; - - // face_orientation=false, face_rotation=false, face_flip=false - if (i == std::array{{j[0], j[2], j[1], j[3]}}) - return 0; - - // face_orientation=false, face_rotation=true, face_flip=false - if (i == std::array{{j[2], j[3], j[0], j[1]}}) - return 2; - - // face_orientation=false, face_rotation=false, face_flip=true - if (i == std::array{{j[3], j[1], j[2], j[0]}}) - return 4; - - // face_orientation=false, face_rotation=true, face_flip=true - if (i == std::array{{j[1], j[0], j[3], j[2]}}) - return 6; - } - - AssertThrow(false, dealii::StandardExceptions::ExcNotImplemented()); - - return -1; - } - - /** - * Inverse function of compute_orientation(). - */ - template - inline std::array - permute_according_orientation(const ReferenceCell::Type entity_type, - const std::array & vertices, - const unsigned int orientation) - { - std::array temp; - - if (entity_type == ReferenceCell::Type::Line) - { - switch (orientation) - { - case 1: - temp = {{vertices[0], vertices[1]}}; - break; - case 0: - temp = {{vertices[1], vertices[0]}}; - break; - default: - Assert(false, ExcNotImplemented()); - } - } - else if (entity_type == ReferenceCell::Type::Tri) - { - switch (orientation) - { - case 1: - temp = {{vertices[0], vertices[1], vertices[2]}}; - break; - case 3: - temp = {{vertices[1], vertices[0], vertices[2]}}; - break; - case 5: - temp = {{vertices[2], vertices[0], vertices[1]}}; - break; - case 0: - temp = {{vertices[0], vertices[2], vertices[1]}}; - break; - case 2: - temp = {{vertices[1], vertices[2], vertices[0]}}; - break; - case 4: - temp = {{vertices[2], vertices[1], vertices[0]}}; - break; - default: - Assert(false, ExcNotImplemented()); - } - } - else if (entity_type == ReferenceCell::Type::Quad) - { - switch (orientation) - { - case 1: - temp = {{vertices[0], vertices[1], vertices[2], vertices[3]}}; - break; - case 3: - temp = {{vertices[1], vertices[3], vertices[0], vertices[2]}}; - break; - case 5: - temp = {{vertices[3], vertices[2], vertices[1], vertices[0]}}; - break; - case 7: - temp = {{vertices[2], vertices[0], vertices[3], vertices[1]}}; - break; - case 0: - temp = {{vertices[0], vertices[2], vertices[1], vertices[3]}}; - break; - case 2: - temp = {{vertices[2], vertices[3], vertices[0], vertices[1]}}; - break; - case 4: - temp = {{vertices[3], vertices[1], vertices[2], vertices[0]}}; - break; - case 6: - temp = {{vertices[1], vertices[0], vertices[3], vertices[2]}}; - break; - default: - Assert(false, ExcNotImplemented()); - } - } - else - { - AssertThrow(false, ExcNotImplemented()); - } - - std::array temp_; - std::copy_n(temp.begin(), N, temp_.begin()); - - return temp_; - } - /* * Return i-th unit tangential vector of a face of the reference cell. * The vectors are arranged such that the @@ -1716,6 +1525,275 @@ namespace ReferenceCell } // namespace Info } // namespace internal + + + + namespace internal + { + template + class NoPermutation : public dealii::ExceptionBase + { + public: + /** + * Constructor. + */ + NoPermutation(const ReferenceCell::Type &entity_type, + const std::array & vertices_0, + const std::array & vertices_1) + : entity_type(entity_type) + , vertices_0(vertices_0) + , vertices_1(vertices_1) + {} + + /** + * Destructor. + */ + virtual ~NoPermutation() noexcept override = default; + + /** + * Print error message to @p out. + */ + virtual void + print_info(std::ostream &out) const override + { + out << "["; + + const unsigned int n_vertices = + ReferenceCell::internal::Info::get_cell(entity_type).n_vertices(); + + for (unsigned int i = 0; i < n_vertices; ++i) + { + out << vertices_0[i]; + if (i + 1 != n_vertices) + out << ","; + } + + out << "] is no permutation of ["; + + for (unsigned int i = 0; i < n_vertices; ++i) + { + out << vertices_1[i]; + if (i + 1 != n_vertices) + out << ","; + } + + out << "]." << std::endl; + } + + /** + * Entity type. + */ + const ReferenceCell::Type entity_type; + + /** + * First set of values. + */ + const std::array vertices_0; + + /** + * Second set of values. + */ + const std::array vertices_1; + }; + } // namespace internal + + + + /** + * Determine the orientation of an entity of @p type described by its + * vertices @p var_1 relative to an entity described by @p var_0. + */ + template + inline unsigned char + compute_orientation(const ReferenceCell::Type entity_type, + const std::array & vertices_0, + const std::array & vertices_1) + { + AssertIndexRange( + ReferenceCell::internal::Info::get_cell(entity_type).n_vertices(), N + 1); + if (entity_type == ReferenceCell::Type::Line) + { + const std::array i{{vertices_0[0], vertices_0[1]}}; + const std::array j{{vertices_1[0], vertices_1[1]}}; + + // line_orientation=true + if (i == std::array{{j[0], j[1]}}) + return 1; + + // line_orientation=false + if (i == std::array{{j[1], j[0]}}) + return 0; + } + else if (entity_type == ReferenceCell::Type::Tri) + { + const std::array i{{vertices_0[0], vertices_0[1], vertices_0[2]}}; + const std::array j{{vertices_1[0], vertices_1[1], vertices_1[2]}}; + + // face_orientation=true, face_rotation=false, face_flip=false + if (i == std::array{{j[0], j[1], j[2]}}) + return 1; + + // face_orientation=true, face_rotation=true, face_flip=false + if (i == std::array{{j[1], j[0], j[2]}}) + return 3; + + // face_orientation=true, face_rotation=false, face_flip=true + if (i == std::array{{j[2], j[0], j[1]}}) + return 5; + + // face_orientation=false, face_rotation=false, face_flip=false + if (i == std::array{{j[0], j[2], j[1]}}) + return 0; + + // face_orientation=false, face_rotation=true, face_flip=false + if (i == std::array{{j[1], j[2], j[0]}}) + return 2; + + // face_orientation=false, face_rotation=false, face_flip=true + if (i == std::array{{j[2], j[1], j[0]}}) + return 4; + } + else if (entity_type == ReferenceCell::Type::Quad) + { + const std::array i{ + {vertices_0[0], vertices_0[1], vertices_0[2], vertices_0[3]}}; + const std::array j{ + {vertices_1[0], vertices_1[1], vertices_1[2], vertices_1[3]}}; + + // face_orientation=true, face_rotation=false, face_flip=false + if (i == std::array{{j[0], j[1], j[2], j[3]}}) + return 1; + + // face_orientation=true, face_rotation=true, face_flip=false + if (i == std::array{{j[1], j[3], j[0], j[2]}}) + return 3; + + // face_orientation=true, face_rotation=false, face_flip=true + if (i == std::array{{j[3], j[2], j[1], j[0]}}) + return 5; + + // face_orientation=true, face_rotation=true, face_flip=true + if (i == std::array{{j[2], j[0], j[3], j[1]}}) + return 7; + + // face_orientation=false, face_rotation=false, face_flip=false + if (i == std::array{{j[0], j[2], j[1], j[3]}}) + return 0; + + // face_orientation=false, face_rotation=true, face_flip=false + if (i == std::array{{j[2], j[3], j[0], j[1]}}) + return 2; + + // face_orientation=false, face_rotation=false, face_flip=true + if (i == std::array{{j[3], j[1], j[2], j[0]}}) + return 4; + + // face_orientation=false, face_rotation=true, face_flip=true + if (i == std::array{{j[1], j[0], j[3], j[2]}}) + return 6; + } + + Assert( + false, + (internal::NoPermutation(entity_type, vertices_0, vertices_1))); + + return -1; + } + + /** + * Inverse function of compute_orientation(). + */ + template + inline std::array + permute_according_orientation(const ReferenceCell::Type entity_type, + const std::array & vertices, + const unsigned int orientation) + { + std::array temp; + + if (entity_type == ReferenceCell::Type::Line) + { + switch (orientation) + { + case 1: + temp = {{vertices[0], vertices[1]}}; + break; + case 0: + temp = {{vertices[1], vertices[0]}}; + break; + default: + Assert(false, ExcNotImplemented()); + } + } + else if (entity_type == ReferenceCell::Type::Tri) + { + switch (orientation) + { + case 1: + temp = {{vertices[0], vertices[1], vertices[2]}}; + break; + case 3: + temp = {{vertices[1], vertices[0], vertices[2]}}; + break; + case 5: + temp = {{vertices[2], vertices[0], vertices[1]}}; + break; + case 0: + temp = {{vertices[0], vertices[2], vertices[1]}}; + break; + case 2: + temp = {{vertices[1], vertices[2], vertices[0]}}; + break; + case 4: + temp = {{vertices[2], vertices[1], vertices[0]}}; + break; + default: + Assert(false, ExcNotImplemented()); + } + } + else if (entity_type == ReferenceCell::Type::Quad) + { + switch (orientation) + { + case 1: + temp = {{vertices[0], vertices[1], vertices[2], vertices[3]}}; + break; + case 3: + temp = {{vertices[1], vertices[3], vertices[0], vertices[2]}}; + break; + case 5: + temp = {{vertices[3], vertices[2], vertices[1], vertices[0]}}; + break; + case 7: + temp = {{vertices[2], vertices[0], vertices[3], vertices[1]}}; + break; + case 0: + temp = {{vertices[0], vertices[2], vertices[1], vertices[3]}}; + break; + case 2: + temp = {{vertices[2], vertices[3], vertices[0], vertices[1]}}; + break; + case 4: + temp = {{vertices[3], vertices[1], vertices[2], vertices[0]}}; + break; + case 6: + temp = {{vertices[1], vertices[0], vertices[3], vertices[2]}}; + break; + default: + Assert(false, ExcNotImplemented()); + } + } + else + { + AssertThrow(false, ExcNotImplemented()); + } + + std::array temp_; + std::copy_n(temp.begin(), N, temp_.begin()); + + return temp_; + } + } // namespace ReferenceCell