From: Peter Munch Date: Sun, 27 Dec 2020 07:47:28 +0000 (+0100) Subject: Introduce ReferenceCell::compute_orientation and ::permute_according_orientation X-Git-Tag: v9.3.0-rc1~709^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73dd3a921cdd6604fbb93e26034b251c9dfdff35;p=dealii.git Introduce ReferenceCell::compute_orientation and ::permute_according_orientation --- diff --git a/include/deal.II/grid/connectivity.h b/include/deal.II/grid/connectivity.h index 47b5912f63..3e422c9a94 100644 --- a/include/deal.II/grid/connectivity.h +++ b/include/deal.II/grid/connectivity.h @@ -986,107 +986,6 @@ 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) - { - 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; - } - - - /** * Build entities of dimension d (with 0(+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_; + } + + + namespace internal { /** diff --git a/source/base/qprojector.cc b/source/base/qprojector.cc index b0cd657d78..62604c078a 100644 --- a/source/base/qprojector.cc +++ b/source/base/qprojector.cc @@ -645,52 +645,26 @@ QProjector<3>::project_to_all_faces( { const auto support_points_tri = [](const auto &face, const auto &orientation) -> std::vector> { - // determine support point of the current line with the correct - // orientation - switch (orientation) - { - case 1: - return {{face.first[0], face.first[1], face.first[2]}}; - case 3: - return {{face.first[1], face.first[0], face.first[2]}}; - case 5: - return {{face.first[2], face.first[0], face.first[1]}}; - case 0: - return {{face.first[0], face.first[2], face.first[1]}}; - case 2: - return {{face.first[1], face.first[2], face.first[0]}}; - case 4: - return {{face.first[2], face.first[1], face.first[0]}}; - default: - Assert(false, ExcNotImplemented()); - return {{}}; - } + std::array, 3> vertices; + std::copy_n(face.first.begin(), face.first.size(), vertices.begin()); + const auto temp = + ReferenceCell::permute_according_orientation(ReferenceCell::Type::Tri, + vertices, + orientation); + return std::vector>(temp.begin(), + temp.begin() + face.first.size()); }; const auto support_points_quad = [](const auto &face, const auto &orientation) -> std::vector> { - switch (orientation) - { - case 1: - return {{face.first[0], face.first[1], face.first[2], face.first[3]}}; - case 3: - return {{face.first[1], face.first[3], face.first[0], face.first[2]}}; - case 5: - return {{face.first[3], face.first[2], face.first[1], face.first[0]}}; - case 7: - return {{face.first[2], face.first[0], face.first[3], face.first[1]}}; - case 0: - return {{face.first[0], face.first[2], face.first[1], face.first[3]}}; - case 2: - return {{face.first[2], face.first[3], face.first[0], face.first[1]}}; - case 4: - return {{face.first[3], face.first[1], face.first[2], face.first[0]}}; - case 6: - return {{face.first[1], face.first[0], face.first[3], face.first[2]}}; - default: - Assert(false, ExcNotImplemented()); - return {{}}; - } + std::array, 4> vertices; + std::copy_n(face.first.begin(), face.first.size(), vertices.begin()); + const auto temp = + ReferenceCell::permute_according_orientation(ReferenceCell::Type::Quad, + vertices, + orientation); + return std::vector>(temp.begin(), + temp.begin() + face.first.size()); }; const auto process = [&](const auto faces) {