From: Martin Kronbichler Date: Thu, 29 Jun 2023 10:34:31 +0000 (+0200) Subject: Shorten compilation time of two MatrixFree tests X-Git-Tag: relicensing~831^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0e86065562c6fa81fc51e85f851d8ea80474479;p=dealii.git Shorten compilation time of two MatrixFree tests --- diff --git a/tests/matrix_free/matrix_vector_hp.cc b/tests/matrix_free/matrix_vector_hp.cc index fbba9210b5..8dcc984c39 100644 --- a/tests/matrix_free/matrix_vector_hp.cc +++ b/tests/matrix_free/matrix_vector_hp.cc @@ -23,12 +23,21 @@ #include #include +#include + +#include +#include #include +#include +#include + +#include + #include "../tests.h" -#include "matrix_vector_common.h" +#include "matrix_vector_mf.h" @@ -45,7 +54,6 @@ public: const Vector & src, const std::pair &cell_range) const { - // ask MatrixFree for cell_range for different orders std::pair subrange_deg = data.create_cell_subrange_hp(cell_range, 1); if (subrange_deg.second > subrange_deg.first) @@ -65,30 +73,6 @@ public: dst, src, subrange_deg); - subrange_deg = data.create_cell_subrange_hp(cell_range, 4); - if (subrange_deg.second > subrange_deg.first) - helmholtz_operator, 5>(data, - dst, - src, - subrange_deg); - subrange_deg = data.create_cell_subrange_hp(cell_range, 5); - if (subrange_deg.second > subrange_deg.first) - helmholtz_operator, 6>(data, - dst, - src, - subrange_deg); - subrange_deg = data.create_cell_subrange_hp(cell_range, 6); - if (subrange_deg.second > subrange_deg.first) - helmholtz_operator, 7>(data, - dst, - src, - subrange_deg); - subrange_deg = data.create_cell_subrange_hp(cell_range, 7); - if (subrange_deg.second > subrange_deg.first) - helmholtz_operator, 8>(data, - dst, - src, - subrange_deg); } void @@ -104,20 +88,15 @@ private: -template +template void test() { - if (fe_degree > 1) - return; - using number = double; const SphericalManifold manifold; Triangulation tria; GridGenerator::hyper_ball(tria); - typename Triangulation::active_cell_iterator cell = tria.begin_active(), - endc = tria.end(); - for (; cell != endc; ++cell) + for (const auto &cell : tria.active_cell_iterators()) for (const unsigned int f : GeometryInfo::face_indices()) if (cell->at_boundary(f)) cell->face(f)->set_all_manifold_ids(0); @@ -127,17 +106,14 @@ test() // refine a few cells for (unsigned int i = 0; i < 11 - 3 * dim; ++i) { - typename Triangulation::active_cell_iterator cell = - tria.begin_active(), - endc = tria.end(); - unsigned int counter = 0; - for (; cell != endc; ++cell, ++counter) - if (counter % (7 - i) == 0) + unsigned int counter = 0; + for (const auto &cell : tria.active_cell_iterators()) + if ((counter++) % (7 - i) == 0) cell->set_refine_flag(); tria.execute_coarsening_and_refinement(); } - const unsigned int max_degree = 9 - 2 * dim; + const unsigned int max_degree = 3; hp::FECollection fe_collection; hp::QCollection quadrature_collection; @@ -156,9 +132,7 @@ test() DoFHandler dof(tria); // set the active FE index in a random order { - typename DoFHandler::active_cell_iterator cell = dof.begin_active(), - endc = dof.end(); - for (; cell != endc; ++cell) + for (const auto &cell : dof.active_cell_iterators()) { const unsigned int fe_index = Testing::rand() % max_degree; cell->set_active_fe_index(fe_index + 1); @@ -166,8 +140,7 @@ test() // We cannot set random cells to FE_Nothing. We get the following error // The violated condition was: dominating_fe.n_dofs_per_face(face) <= // subface_fe.n_dofs_per_face(face) - cell = dof.begin_active(); - cell->set_active_fe_index(0); + dof.begin_active()->set_active_fe_index(0); } // setup DoFs @@ -208,9 +181,7 @@ test() FullMatrix cell_matrix; std::vector local_dof_indices; - typename DoFHandler::active_cell_iterator cell = dof.begin_active(), - endc = dof.end(); - for (; cell != endc; ++cell) + for (const auto &cell : dof.active_cell_iterators()) { const unsigned int dofs_per_cell = cell->get_fe().dofs_per_cell; @@ -259,3 +230,13 @@ test() const double diff_norm = result_mf.linfty_norm(); deallog << "Norm of difference: " << diff_norm << std::endl << std::endl; } + + + +int +main() +{ + initlog(); + + test<2>(); +} diff --git a/tests/matrix_free/matrix_vector_hp.output b/tests/matrix_free/matrix_vector_hp.output index 7252835322..444fbc53b0 100644 --- a/tests/matrix_free/matrix_vector_hp.output +++ b/tests/matrix_free/matrix_vector_hp.output @@ -1,5 +1,3 @@ -DEAL:2d::Norm of difference: 0 -DEAL:2d:: -DEAL:3d::Norm of difference: 0 -DEAL:3d:: +DEAL::Norm of difference: 1.06581e-14 +DEAL:: diff --git a/tests/matrix_free/matrix_vector_mf.h b/tests/matrix_free/matrix_vector_mf.h index 984515067a..877dd5efd6 100644 --- a/tests/matrix_free/matrix_vector_mf.h +++ b/tests/matrix_free/matrix_vector_mf.h @@ -56,6 +56,35 @@ helmholtz_operator(const MatrixFree &data, +template +void +helmholtz_operator_no_template( + const MatrixFree &data, + VectorType & dst, + const VectorType & src, + const std::pair & cell_range) +{ + using Number = typename VectorType::value_type; + FEEvaluation fe_eval(data, cell_range); + const unsigned int n_q_points = fe_eval.n_q_points; + + for (unsigned int cell = cell_range.first; cell < cell_range.second; ++cell) + { + fe_eval.reinit(cell); + fe_eval.read_dof_values(src); + fe_eval.evaluate(EvaluationFlags::values | EvaluationFlags::gradients); + for (unsigned int q = 0; q < n_q_points; ++q) + { + fe_eval.submit_value(Number(10) * fe_eval.get_value(q), q); + fe_eval.submit_gradient(fe_eval.get_gradient(q), q); + } + fe_eval.integrate(EvaluationFlags::values | EvaluationFlags::gradients); + fe_eval.distribute_local_to_global(dst); + } +} + + + template void helmholtz_operator_no_template( diff --git a/tests/matrix_free/thread_correctness_hp.cc b/tests/matrix_free/thread_correctness_hp.cc index 88a6d7df4c..c85f458100 100644 --- a/tests/matrix_free/thread_correctness_hp.cc +++ b/tests/matrix_free/thread_correctness_hp.cc @@ -46,26 +46,7 @@ public: const Vector & src, const std::pair &cell_range) const { - // Ask MatrixFree for cell_range for different - // orders - std::pair subrange_deg; -#define CALL_METHOD(degree) \ - subrange_deg = data.create_cell_subrange_hp(cell_range, degree); \ - if (subrange_deg.second > subrange_deg.first) \ - helmholtz_operator, degree + 1>(data, \ - dst, \ - src, \ - subrange_deg) - - CALL_METHOD(1); - CALL_METHOD(2); - CALL_METHOD(3); - CALL_METHOD(4); - CALL_METHOD(5); - CALL_METHOD(6); - CALL_METHOD(7); - -#undef CALL_METHOD + helmholtz_operator_no_template(data, dst, src, cell_range); } void