From 1e919eef23a6c0555f2a0755ea1c27b6c166a650 Mon Sep 17 00:00:00 2001 From: Riccardo Milani Date: Tue, 18 Jun 2024 14:51:31 +0200 Subject: [PATCH] chore: Solve format/tidy warnings --- include/CoMMA/Util.h | 8 +-- tests/DualGraphExamples.h | 12 ++-- tests/test_anisoagglo.cpp | 20 +++--- tests/test_structure.cpp | 131 ++++++++++++++++++++------------------ 4 files changed, 90 insertions(+), 81 deletions(-) diff --git a/include/CoMMA/Util.h b/include/CoMMA/Util.h index 9610ad1..0aa7ba6 100644 --- a/include/CoMMA/Util.h +++ b/include/CoMMA/Util.h @@ -449,17 +449,17 @@ void build_coarse_graph( // For these, we have the final size c_volumes.clear(); c_volumes.resize(n_cells); - std::fill(c_volumes.begin(), c_volumes.end(), RealT(0)); + std::fill(c_volumes.begin(), c_volumes.end(), RealT{0}); c_n_bnd.clear(); c_n_bnd.resize(n_cells); c_priority.clear(); c_priority.resize(n_cells); - std::fill(c_n_bnd.begin(), c_n_bnd.end(), IntT(0)); + std::fill(c_n_bnd.begin(), c_n_bnd.end(), IntT{0}); c_centers.clear(); c_centers.reserve(n_cells); for (auto cc = decltype(n_cells){0}; cc < n_cells; ++cc) { // https://stackoverflow.com/questions/18189362/how-best-to-fill-a-vector-of-vectors-avoiding-wasting-memory-and-unnecessary-al - auto tmp = std::vector(dim, RealT(0)); + auto tmp = std::vector(dim, RealT{0}); c_centers.emplace_back(std::move(tmp)); } // for cc // Now building @@ -477,7 +477,7 @@ void build_coarse_graph( } // for fc for (auto cc = decltype(n_cells){0}; cc < n_cells; ++cc) { const auto &fcs = c2f[cc]; - const RealT ov_n_fc(RealT(1.) / fcs.size()); + const RealT ov_n_fc(RealT{1.} / fcs.size()); // Finishing center for (auto xyz = decltype(dim){0}; xyz < dim; ++xyz) c_centers[cc][xyz] *= ov_n_fc; diff --git a/tests/DualGraphExamples.h b/tests/DualGraphExamples.h index 0f8f4f8..620e957 100644 --- a/tests/DualGraphExamples.h +++ b/tests/DualGraphExamples.h @@ -21,8 +21,8 @@ using DGEIndexT = comma::CoMMAIndexT; using DGEIntT = comma::CoMMAIntT; using DGEWeightT = comma::CoMMAWeightT; -constexpr DGEWeightT _1ov3 = 1. / 3.; -constexpr DGEWeightT _3_1ov3 = 10. / 3.; +constexpr DGEWeightT one_third = 1. / 3.; +constexpr DGEWeightT ten_ov_three = 10. / 3.; const DGEWeightT sqrt2 = std::sqrt(2.); const DGEWeightT sqrt101 = std::sqrt(101.); @@ -309,13 +309,13 @@ class DualGEx_Tria_BL : public BaseDualGEx { /* volumes */ {5.00, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00}, /* centers */ { // Bottom left, 0 and 1 - {-_3_1ov3, -2.*_1ov3}, {-2.*_3_1ov3, -_1ov3}, + {-ten_ov_three, -2.*one_third}, {-2.*ten_ov_three, -one_third}, // Bottom right, 2 and 3 - {+2.*_3_1ov3, -2*_1ov3}, {+_3_1ov3, -_1ov3}, + {+2.*ten_ov_three, -2*one_third}, {+ten_ov_three, -one_third}, // Top left, 4 and 5 - {-_3_1ov3, +_1ov3}, {-2.*_3_1ov3, 2.*_1ov3}, + {-ten_ov_three, +one_third}, {-2.*ten_ov_three, 2.*one_third}, // Top right, 6 and 7 - {2.*_3_1ov3, _1ov3}, {_3_1ov3, 2.*_1ov3} + {2.*ten_ov_three, one_third}, {ten_ov_three, 2.*one_third} } // clang-on ) {} diff --git a/tests/test_anisoagglo.cpp b/tests/test_anisoagglo.cpp index 0e671ed..cd175ee 100644 --- a/tests/test_anisoagglo.cpp +++ b/tests/test_anisoagglo.cpp @@ -850,16 +850,20 @@ the line grows vertically const auto n_lines = agglomerationLines_Idx.size() - 1; REQUIRE(static_cast(n_lines) == aniso_agg._nb_lines[0]); auto read_line = aniso_agg._v_lines[0].cbegin(); - for (auto ref_line = agglomerationLines_Idx.cbegin() + 1; + for (auto ref_line = next(agglomerationLines_Idx.cbegin()); ref_line != agglomerationLines_Idx.cend(); ++ref_line, ++read_line) { // I am not sure how to treat this... - // NOLINTNEXTLINE - for (auto ref_fc = agglomerationLines.cbegin() + *std::prev(ref_line); - ref_fc != agglomerationLines.cbegin() + (*ref_line); + // NOLINTBEGIN(cppcoreguidelines-narrowing-conversions) + // NOLINTBEGIN(bugprone-narrowing-conversions) + for (auto ref_fc = + next(agglomerationLines.cbegin(), *std::prev(ref_line)); + ref_fc != next(agglomerationLines.cbegin(), *ref_line); ++ref_fc) { REQUIRE_THAT(**read_line, Contains(*ref_fc)); } + // NOLINTEND(bugprone-narrowing-conversions) + // NOLINTEND(cppcoreguidelines-narrowing-conversions) } } } @@ -1214,8 +1218,8 @@ SCENARIO("Testing cell coupling", "[Anisotropic.CellCoupling]") { CoMMACellCouplingT::MIN_DISTANCE, 0 ); - const CoMMAWeightT x_dist = _3_1ov3; - const CoMMAWeightT y_dist = _1ov3; + const CoMMAWeightT x_dist = ten_ov_three; + const CoMMAWeightT y_dist = one_third; const CoMMAWeightT same_block = 1. / (_sq(x_dist) + _sq(y_dist)); const CoMMAWeightT side_block = 1. / (_sq(2. * x_dist) + _sq(y_dist)); const CoMMAWeightT vert_block = 1. / (_sq(x_dist) + _sq(2. * y_dist)); @@ -1257,8 +1261,8 @@ SCENARIO("Testing cell coupling", "[Anisotropic.CellCoupling]") { CoMMACellCouplingT::MIN_DISTANCE, 0 ); - const CoMMAWeightT x_dist = _3_1ov3; - const CoMMAWeightT y_dist = _1ov3; + const CoMMAWeightT x_dist = ten_ov_three; + const CoMMAWeightT y_dist = one_third; const CoMMAWeightT same_block = 1. / (_sq(x_dist) + _sq(y_dist)); const CoMMAWeightT side_block = 1. / (_sq(2. * x_dist) + _sq(y_dist)); const CoMMAWeightT vert_block = 1. / (_sq(x_dist) + _sq(2. * y_dist)); diff --git a/tests/test_structure.cpp b/tests/test_structure.cpp index 7cf18a0..0837a29 100644 --- a/tests/test_structure.cpp +++ b/tests/test_structure.cpp @@ -126,11 +126,11 @@ SCENARIO("Test of main function", "[structure]") { ); WHEN("We agglomerate with neighbourhood priority") { vector fc2cc(Data.nb_fc), alines_idx{}, alines{}; - const bool aniso = false, build_lines = true, odd_length = true, - correction = true; - const CoMMAIntT goal_card = 4, min_card = 4, max_card = 4; - const CoMMAWeightT aniso_thr = -4.; - const auto seed = CoMMASeedsPoolT::NEIGHBOURHOOD_PRIORITY; + constexpr bool is_anisotropic = false, build_lines = true, + odd_length = true, correction = true; + constexpr CoMMAIntT goal_card = 4, min_card = 4, max_card = 4; + constexpr CoMMAWeightT aniso_thr = -4.; + constexpr auto seed = CoMMASeedsPoolT::NEIGHBOURHOOD_PRIORITY; agglomerate_one_level( Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, @@ -141,7 +141,7 @@ SCENARIO("Test of main function", "[structure]") { Data.anisoCompliantCells, Data.n_bnd_faces, build_lines, - aniso, + is_anisotropic, odd_length, aniso_thr, seed, @@ -162,10 +162,10 @@ SCENARIO("Test of main function", "[structure]") { // It is the same test as above but we use the API with parameter classes WHEN("We agglomerate with neighbourhood priority and the parameter API") { vector fc2cc(Data.nb_fc), alines_idx{}, alines{}; - const bool is_aniso = false, correction = true; - const CoMMAIntT goal_card = 4, min_card = 4, max_card = 4; - const auto seed = CoMMASeedsPoolT::NEIGHBOURHOOD_PRIORITY; - const GraphArgs graph( + constexpr bool is_anisotropic = false, correction = true; + constexpr CoMMAIntT goal_card = 4, min_card = 4, max_card = 4; + constexpr auto seed = CoMMASeedsPoolT::NEIGHBOURHOOD_PRIORITY; + const GraphArgs graph_args( Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, @@ -175,15 +175,15 @@ SCENARIO("Test of main function", "[structure]") { Data.n_bnd_faces, Data.dim ); - const AgglomerationArgs agglo( + const AgglomerationArgs agglo_args( goal_card, min_card, max_card, correction, seed ); - const AnisotropicArgs aniso( - is_aniso, Data.anisoCompliantCells + const AnisotropicArgs aniso_args( + is_anisotropic, Data.anisoCompliantCells ); // Agglomerate agglomerate_one_level( - graph, agglo, aniso, fc2cc, alines_idx, alines + graph_args, agglo_args, aniso_args, fc2cc, alines_idx, alines ); THEN("We obtain the 16 fine cells divided in 4 coarse cells") { for (auto i = decltype(Data.nb_fc){0}; i < Data.nb_fc; ++i) @@ -192,11 +192,11 @@ SCENARIO("Test of main function", "[structure]") { } WHEN("We agglomerate with boundary priority") { vector fc2cc(Data.nb_fc), alines_idx{}, alines{}; - const bool aniso = false, build_lines = true, odd_length = true, - correction = true; - const CoMMAIntT goal_card = 4, min_card = 4, max_card = 4; - const CoMMAWeightT aniso_thr = -4.; - const auto seed = CoMMASeedsPoolT::BOUNDARY_PRIORITY; + constexpr bool is_anisotropic = false, build_lines = true, + odd_length = true, correction = true; + constexpr CoMMAIntT goal_card = 4, min_card = 4, max_card = 4; + constexpr CoMMAWeightT aniso_thr = -4.; + constexpr auto seed = CoMMASeedsPoolT::BOUNDARY_PRIORITY; agglomerate_one_level( Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, @@ -207,7 +207,7 @@ SCENARIO("Test of main function", "[structure]") { Data.anisoCompliantCells, Data.n_bnd_faces, build_lines, - aniso, + is_anisotropic, odd_length, aniso_thr, seed, @@ -228,11 +228,12 @@ SCENARIO("Test of main function", "[structure]") { WHEN("We agglomerate with neighbourhood priority one point initialization" ) { vector fc2cc(Data.nb_fc), alines_idx{}, alines{}; - const bool aniso = false, build_lines = true, odd_length = true, - correction = true; - const CoMMAIntT goal_card = 4, min_card = 4, max_card = 4; - const CoMMAWeightT aniso_thr = -4.; - const auto seed = CoMMASeedsPoolT::NEIGHBOURHOOD_PRIORITY_ONE_POINT_INIT; + constexpr bool is_anisotropic = false, build_lines = true, + odd_length = true, correction = true; + constexpr CoMMAIntT goal_card = 4, min_card = 4, max_card = 4; + constexpr CoMMAWeightT aniso_thr = -4.; + constexpr auto seed = + CoMMASeedsPoolT::NEIGHBOURHOOD_PRIORITY_ONE_POINT_INIT; agglomerate_one_level( Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, @@ -243,7 +244,7 @@ SCENARIO("Test of main function", "[structure]") { Data.anisoCompliantCells, Data.n_bnd_faces, build_lines, - aniso, + is_anisotropic, odd_length, aniso_thr, seed, @@ -263,11 +264,11 @@ SCENARIO("Test of main function", "[structure]") { } WHEN("We agglomerate with boundary priority one point initialization") { vector fc2cc(Data.nb_fc), alines_idx{}, alines{}; - const bool aniso = false, build_lines = true, odd_length = true, - correction = true; - const CoMMAIntT goal_card = 4, min_card = 4, max_card = 4; - const CoMMAWeightT aniso_thr = -4.; - const auto seed = CoMMASeedsPoolT::BOUNDARY_PRIORITY_ONE_POINT_INIT; + constexpr bool is_anisotropic = false, build_lines = true, + odd_length = true, correction = true; + constexpr CoMMAIntT goal_card = 4, min_card = 4, max_card = 4; + constexpr CoMMAWeightT aniso_thr = -4.; + constexpr auto seed = CoMMASeedsPoolT::BOUNDARY_PRIORITY_ONE_POINT_INIT; agglomerate_one_level( Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, @@ -278,7 +279,7 @@ SCENARIO("Test of main function", "[structure]") { Data.anisoCompliantCells, Data.n_bnd_faces, build_lines, - aniso, + is_anisotropic, odd_length, aniso_thr, seed, @@ -308,11 +309,11 @@ SCENARIO("Test of main function", "[structure]") { "We agglomerate with anisotropy activated, boundary priority and, full initialization" ) { vector fc2cc(Data.nb_fc), alines_idx{}, alines{}; - const bool aniso = true, build_lines = true, odd_length = ODD_LINE_LENGTH, - correction = true; - const CoMMAIntT goal_card = 4, min_card = 4, max_card = 4; - const CoMMAWeightT aniso_thr = 4.; - const auto seed = CoMMASeedsPoolT::BOUNDARY_PRIORITY; + constexpr bool is_anisotropic = true, build_lines = true, + odd_length = ODD_LINE_LENGTH, correction = true; + constexpr CoMMAIntT goal_card = 4, min_card = 4, max_card = 4; + constexpr CoMMAWeightT aniso_thr = 4.; + constexpr auto seed = CoMMASeedsPoolT::BOUNDARY_PRIORITY; agglomerate_one_level( Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, @@ -323,7 +324,7 @@ SCENARIO("Test of main function", "[structure]") { Data.anisoCompliantCells, Data.n_bnd_faces, build_lines, - aniso, + is_anisotropic, odd_length, aniso_thr, seed, @@ -345,12 +346,12 @@ SCENARIO("Test of main function", "[structure]") { "We agglomerate with anisotropy activated, boundary priority and, full initialization using the parameter classes" ) { vector fc2cc(Data.nb_fc), alines_idx{}, alines{}; - const bool is_aniso = true, build_lines = true, - odd_length = ODD_LINE_LENGTH, correction = true; - const CoMMAIntT goal_card = 4, min_card = 4, max_card = 4; - const CoMMAWeightT aniso_thr = 4.; - const auto seed = CoMMASeedsPoolT::BOUNDARY_PRIORITY; - const GraphArgs graph( + constexpr bool is_anisotropic = true, build_lines = true, + odd_length = ODD_LINE_LENGTH, correction = true; + constexpr CoMMAIntT goal_card = 4, min_card = 4, max_card = 4; + constexpr CoMMAWeightT aniso_thr = 4.; + constexpr auto seed = CoMMASeedsPoolT::BOUNDARY_PRIORITY; + const GraphArgs graph_args( Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, @@ -360,15 +361,19 @@ SCENARIO("Test of main function", "[structure]") { Data.n_bnd_faces, Data.dim ); - const AgglomerationArgs agglo( + const AgglomerationArgs agglo_args( goal_card, min_card, max_card, correction, seed ); - const AnisotropicArgs aniso( - is_aniso, Data.anisoCompliantCells, build_lines, odd_length, aniso_thr + const AnisotropicArgs aniso_args( + is_anisotropic, + Data.anisoCompliantCells, + build_lines, + odd_length, + aniso_thr ); // Agglomerate agglomerate_one_level( - graph, agglo, aniso, fc2cc, alines_idx, alines + graph_args, agglo_args, aniso_args, fc2cc, alines_idx, alines ); THEN("The result is 4 anisotropic lines and 2 isotropic cells") { for (auto i = decltype(Data.nb_fc){0}; i < Data.nb_fc; ++i) @@ -377,10 +382,10 @@ SCENARIO("Test of main function", "[structure]") { } WHEN("We agglomerate with bad argument") { vector fc2cc(Data.nb_fc), alines_idx{}, alines{}; - const bool aniso = true, build_lines = true, odd_length = true, - correction = true; - const CoMMAIntT goal_card = 4, min_card = 4, max_card = 4; - const CoMMAWeightT aniso_thr = 4.; + constexpr bool is_anisotropic = true, build_lines = true, + odd_length = true, correction = true; + constexpr CoMMAIntT goal_card = 4, min_card = 4, max_card = 4; + constexpr CoMMAWeightT aniso_thr = 4.; const auto seed = CoMMASeedsPoolT::NEIGHBOURHOOD_PRIORITY; // clang-format off // Off to highlight which parameter should be responsible for the throw @@ -390,7 +395,7 @@ SCENARIO("Test of main function", "[structure]") { agglomerate_one_level( Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes, Data.centers, Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces, - build_lines, aniso, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, + build_lines, is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, 5, goal_card, min_card, max_card) ); @@ -401,7 +406,7 @@ SCENARIO("Test of main function", "[structure]") { tmp, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes, Data.centers, Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces, - build_lines, aniso, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, + build_lines, is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, Data.dim, goal_card, min_card, max_card) ); tmp.push_back(2); @@ -411,7 +416,7 @@ SCENARIO("Test of main function", "[structure]") { tmp, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes, Data.centers, Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces, build_lines, - aniso, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, Data.dim, + is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, Data.dim, goal_card, min_card, max_card) ); // Bad graph definition: values do not correspond to indirection @@ -420,7 +425,7 @@ SCENARIO("Test of main function", "[structure]") { Data.adjMatrix_row_ptr, tmp, Data.adjMatrix_areaValues, Data.volumes, Data.centers, Data.weights, - Data.anisoCompliantCells, Data.n_bnd_faces, build_lines, aniso, + Data.anisoCompliantCells, Data.n_bnd_faces, build_lines, is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, Data.dim, goal_card, min_card, max_card) ); @@ -431,7 +436,7 @@ SCENARIO("Test of main function", "[structure]") { Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, tmp_w, Data.volumes, Data.centers, Data.weights, Data.anisoCompliantCells, - Data.n_bnd_faces, build_lines, aniso, odd_length, aniso_thr, seed, fc2cc, alines_idx, + Data.n_bnd_faces, build_lines, is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, Data.dim, goal_card, min_card, max_card) ); // Bad cardinality: min higher than goal @@ -439,7 +444,7 @@ SCENARIO("Test of main function", "[structure]") { agglomerate_one_level( Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes, Data.centers, Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces, - build_lines, aniso, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, + build_lines, is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, Data.dim, goal_card, goal_card + 1, max_card) @@ -449,7 +454,7 @@ SCENARIO("Test of main function", "[structure]") { agglomerate_one_level( Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes, Data.centers, Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces, - build_lines, aniso, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, + build_lines, is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, Data.dim, 0, min_card, max_card) @@ -462,7 +467,7 @@ SCENARIO("Test of main function", "[structure]") { Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes, Data.centers, Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces, false, - aniso, odd_length, aniso_thr, seed, fc2cc, + is_anisotropic, odd_length, aniso_thr, seed, fc2cc, tmp_idx, tmp_lines, correction, Data.dim, goal_card, min_card, max_card) ); @@ -471,7 +476,7 @@ SCENARIO("Test of main function", "[structure]") { agglomerate_one_level( Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes, Data.centers, Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces, - build_lines, aniso, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, + build_lines, is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, Data.dim, goal_card, min_card, max_card, DEFAULT_AR, 0) ); @@ -480,7 +485,7 @@ SCENARIO("Test of main function", "[structure]") { agglomerate_one_level( Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes, Data.centers, Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces, - build_lines, aniso, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, + build_lines, is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, Data.dim, goal_card, min_card, max_card, DEFAULT_AR, SING_CARD_THRESH, MAX_CELLS_IN_LINE, CELL_COUPLING_MAX, FORCE_DIRECTION, 0) @@ -490,7 +495,7 @@ SCENARIO("Test of main function", "[structure]") { agglomerate_one_level( Data.adjMatrix_row_ptr, Data.adjMatrix_col_ind, Data.adjMatrix_areaValues, Data.volumes, Data.centers, Data.weights, Data.anisoCompliantCells, Data.n_bnd_faces, - build_lines, aniso, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, + build_lines, is_anisotropic, odd_length, aniso_thr, seed, fc2cc, alines_idx, alines, correction, Data.dim, goal_card, min_card, max_card, DEFAULT_AR, SING_CARD_THRESH, MAX_CELLS_IN_LINE, CELL_COUPLING_MAX, FORCE_DIRECTION, comma::iter_agglo_max_iter + 1)