From: Wolfgang Bangerth Date: Mon, 18 Oct 2021 23:51:06 +0000 (-0600) Subject: Simplify some code by using std::any_of(). X-Git-Tag: v9.4.0-rc1~928^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F12841%2Fhead;p=dealii.git Simplify some code by using std::any_of(). Also move the variables so initialized out of the if-branch in this function because I want to use them also in the else-branch in a follow-up. --- diff --git a/include/deal.II/numerics/data_out_dof_data.templates.h b/include/deal.II/numerics/data_out_dof_data.templates.h index 6638d27691..5a3fdaa67a 100644 --- a/include/deal.II/numerics/data_out_dof_data.templates.h +++ b/include/deal.II/numerics/data_out_dof_data.templates.h @@ -52,6 +52,7 @@ #include #include +#include #include #include #include @@ -222,32 +223,68 @@ namespace internal std::vector>> &x_fe_face_values) { + // First figure out which reference cell types are present in the + // FECollections we got as arguments. To this end, use a lambda + // function that for a FECollection object tests whether one of the + // elements uses a specific reference cell. Then use this + // lambda function in a std::any_of() call that accumulates over + // all of the FECollection objects we were given. + // + // Note that in 1d, we will count a line segment as a hypercube + // even though it is *also* a simplex. Furthermore, wedges and + // pyramids can only appear in 3d set ups, so we do not need + // to test there if dim<3. + static const auto has_fe_with_reference_cell = + [](const dealii::hp::FECollection &fe_collection, + const dealii::ReferenceCell & reference_cell) { + for (unsigned int i = 0; i < fe_collection.size(); ++i) + if (fe_collection[i].reference_cell() == reference_cell) + return true; + return false; + }; + + const bool needs_hypercube_setup = std::any_of( + finite_elements.begin(), + finite_elements.end(), + [](const std::shared_ptr> + &fe_collection) { + return has_fe_with_reference_cell( + *fe_collection, ReferenceCells::get_hypercube()); + }); + const bool needs_simplex_setup = + (dim > 1 && + std::any_of( + finite_elements.begin(), + finite_elements.end(), + [](const std::shared_ptr> + &fe_collection) { + return has_fe_with_reference_cell( + *fe_collection, ReferenceCells::get_simplex()); + })); + const bool needs_wedge_setup = + (dim == 3 && + std::any_of( + finite_elements.begin(), + finite_elements.end(), + [](const std::shared_ptr> + &fe_collection) { + return has_fe_with_reference_cell(*fe_collection, + ReferenceCells::Wedge); + })); + const bool needs_pyramid_setup = + (dim == 3 && + std::any_of( + finite_elements.begin(), + finite_elements.end(), + [](const std::shared_ptr> + &fe_collection) { + return has_fe_with_reference_cell(*fe_collection, + ReferenceCells::Pyramid); + })); + unsigned int n_q_points = 0; if (use_face_values == false) { - // determine if specific quadrature rules need to set up - bool needs_hypercube_setup = false; - bool needs_simplex_setup = false; - bool needs_wedge_setup = false; - bool needs_pyramid_setup = false; - - for (const auto &fe : finite_elements) - for (unsigned int i = 0; i < fe->size(); ++i) - { - const auto reference_cell = (*fe)[i].reference_cell(); - - if (reference_cell.is_hyper_cube()) - needs_hypercube_setup = true; - else if (reference_cell.is_simplex()) - needs_simplex_setup = true; - else if (reference_cell == dealii::ReferenceCells::Wedge) - needs_wedge_setup = true; - else if (reference_cell == dealii::ReferenceCells::Pyramid) - needs_pyramid_setup = true; - else - Assert(false, ExcNotImplemented()); - } - std::unique_ptr> quadrature_simplex; std::unique_ptr> quadrature_hypercube; std::unique_ptr> quadrature_wedge;