// ------------------------------------------------------------------------ // // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (C) 2020 - 2024 by the deal.II authors // // This file is part of the deal.II library. // // Part of the source code is dual licensed under Apache-2.0 WITH // LLVM-exception OR LGPL-2.1-or-later. Detailed license information // governing the source code and code contributions can be found in // LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. // // ------------------------------------------------------------------------ #ifndef dealii_matrix_free_util_h #define dealii_matrix_free_util_h #include #include #include #include #include #include DEAL_II_NAMESPACE_OPEN namespace internal { namespace MatrixFreeFunctions { /** * Given a quadrature rule @p quad defined on a cell, return the type of * the cell and a collection of lower-dimensional quadrature rules that * are defined on each face. */ template inline std::pair> get_face_quadrature_collection(const Quadrature &quad, const bool do_assert = true) { if (dim == 2 || dim == 3) { for (unsigned int i = 1; i <= 4; ++i) if (quad == QGaussSimplex(i)) return {ReferenceCells::get_simplex(), dealii::hp::QCollection( QGaussSimplex(i))}; for (unsigned int i = 1; i <= 5; ++i) if (quad == QWitherdenVincentSimplex(i)) return {ReferenceCells::get_simplex(), dealii::hp::QCollection( QWitherdenVincentSimplex(i))}; for (unsigned int i = 1; i <= 3; ++i) { const FE_SimplexP fe(i); if (quad == Quadrature(fe.get_unit_support_points())) return {ReferenceCells::get_simplex(), dealii::hp::QCollection(Quadrature( fe.get_unit_face_support_points()))}; } } if (dim == 3) for (unsigned int i = 1; i <= 3; ++i) if (quad == QGaussWedge(i)) { QGauss quad(i); QGaussSimplex tri(i); return { ReferenceCells::Wedge, dealii::hp::QCollection(tri, tri, quad, quad, quad)}; } if (dim == 3) for (unsigned int i = 1; i <= 2; ++i) if (quad == QGaussPyramid(i)) { QGauss quad(i); QGaussSimplex tri(i); return { ReferenceCells::Pyramid, dealii::hp::QCollection(quad, tri, tri, tri, tri)}; } // note: handle hypercubes last since normally this function is not // called for hypercubes for (unsigned int i = 1; i <= 5; ++i) if (quad == QGauss(i)) return {ReferenceCells::get_hypercube(), dealii::hp::QCollection(QGauss(i))}; if (do_assert) AssertThrow(false, ExcNotImplemented()); return {ReferenceCells::Invalid, dealii::hp::QCollection()}; } /** * Return face quadrature rules. In contrast to * get_face_quadrature_collection(), it does not return the quadrature * face for each face but returns one of each type. The first entry * of the returned pair might contain a quadrature rule defined on lines and * quadrilaterals, while the second entry might contain a quadrature rule * defined on a triangle. */ template inline std::pair, Quadrature> get_unique_face_quadratures(const Quadrature &quad) { AssertThrow( quad.size() > 0, ExcMessage( "There is nothing useful you can do with a MatrixFree/FEEvaluation " "object when using a quadrature formula with zero " "quadrature points!")); if (dim == 2 || dim == 3) { for (unsigned int i = 1; i <= 4; ++i) if (quad == QGaussSimplex(i)) { if (dim == 2) return {QGaussSimplex(i), // line! Quadrature()}; else return {Quadrature(), QGaussSimplex(i)}; } for (unsigned int i = 1; i <= 5; ++i) if (quad == QWitherdenVincentSimplex(i)) { if (dim == 2) return {QWitherdenVincentSimplex(i), // line! Quadrature()}; else return {Quadrature(), QWitherdenVincentSimplex(i)}; } for (unsigned int i = 1; i <= 3; ++i) { const FE_SimplexP fe(i); if (quad == Quadrature(fe.get_unit_support_points())) { if (dim == 2) return {Quadrature( fe.get_unit_face_support_points()), // line! Quadrature()}; else return {Quadrature(), Quadrature( fe.get_unit_face_support_points())}; } } } if (dim == 3) for (unsigned int i = 1; i <= 3; ++i) if (quad == QGaussWedge(i)) return {QGauss(i), QGaussSimplex(i)}; if (dim == 3) for (unsigned int i = 1; i <= 2; ++i) if (quad == QGaussPyramid(i)) return {QGauss(i), QGaussSimplex(i)}; // note: handle hypercubes last since normally this function is not // called for hypercubes for (unsigned int i = 1; i <= 5; ++i) if (quad == QGauss(i)) return {QGauss(i), Quadrature()}; AssertThrow(false, ExcNotImplemented()); return {Quadrature(), Quadrature()}; } inline DEAL_II_ALWAYS_INLINE unsigned int indicate_power_of_two(const unsigned int vectorization_length) { unsigned int vectorization_length_bits = 0; unsigned int my_length = vectorization_length; while (my_length >>= 1) ++vectorization_length_bits; return 1 << vectorization_length_bits; } } // end of namespace MatrixFreeFunctions } // end of namespace internal DEAL_II_NAMESPACE_CLOSE #endif