From: Marc Fehling Date: Thu, 31 Dec 2020 03:48:18 +0000 (-0700) Subject: Utility grid hyper_line for tests. X-Git-Tag: v9.3.0-rc1~694^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7eeffcfe342053d0c320b4f77edbf4c8091dc86;p=dealii.git Utility grid hyper_line for tests. --- diff --git a/tests/hp/error_prediction_01.cc b/tests/hp/error_prediction_01.cc index e3a8a50c0b..6a362f6c25 100644 --- a/tests/hp/error_prediction_01.cc +++ b/tests/hp/error_prediction_01.cc @@ -23,7 +23,6 @@ #include -#include #include #include @@ -36,25 +35,16 @@ #include "../tests.h" +#include "../test_grids.h" template void test() { - const unsigned int n_cells = 4; - // ----- setup ----- - Triangulation tria; - std::vector rep(dim, 1); - rep[0] = n_cells; - Point p1, p2; - for (unsigned int d = 0; d < dim; ++d) - { - p1[d] = 0; - p2[d] = (d == 0) ? n_cells : 1; - } - GridGenerator::subdivided_hyper_rectangle(tria, rep, p1, p2); + Triangulation tria; + TestGrids::hyper_line(tria, 4); tria.begin_active()->set_refine_flag(); tria.execute_coarsening_and_refinement(); diff --git a/tests/mpi/error_predictor_01.cc b/tests/mpi/error_predictor_01.cc index ff407cc404..f531365914 100644 --- a/tests/mpi/error_predictor_01.cc +++ b/tests/mpi/error_predictor_01.cc @@ -27,12 +27,12 @@ #include -#include - #include #include "../tests.h" +#include "../test_grids.h" + template void @@ -40,19 +40,9 @@ test() { const unsigned int myid = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); - const unsigned int n_cells = 4; - // ------ setup ------ parallel::distributed::Triangulation tria(MPI_COMM_WORLD); - std::vector rep(dim, 1); - rep[0] = n_cells; - Point p1, p2; - for (unsigned int d = 0; d < dim; ++d) - { - p1[d] = 0; - p2[d] = (d == 0) ? n_cells : 1; - } - GridGenerator::subdivided_hyper_rectangle(tria, rep, p1, p2); + TestGrids::hyper_line(tria, 4); { auto first = tria.begin(0); diff --git a/tests/mpi/error_predictor_02.cc b/tests/mpi/error_predictor_02.cc index 2c1242c734..3de8ff0bbd 100644 --- a/tests/mpi/error_predictor_02.cc +++ b/tests/mpi/error_predictor_02.cc @@ -27,12 +27,12 @@ #include -#include - #include #include "../tests.h" +#include "../test_grids.h" + template void @@ -40,19 +40,9 @@ test() { const unsigned int myid = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); - const unsigned int n_cells = 4; - // ------ setup ------ parallel::distributed::Triangulation tria(MPI_COMM_WORLD); - std::vector rep(dim, 1); - rep[0] = n_cells; - Point p1, p2; - for (unsigned int d = 0; d < dim; ++d) - { - p1[d] = 0; - p2[d] = (d == 0) ? n_cells : 1; - } - GridGenerator::subdivided_hyper_rectangle(tria, rep, p1, p2); + TestGrids::hyper_line(tria, 4); for (auto cell = tria.begin(0); cell != tria.end(0); ++cell) if (cell->id().to_string() == "0_0:" || cell->id().to_string() == "1_0:") diff --git a/tests/particles/particle_handler_14.cc b/tests/particles/particle_handler_14.cc index ae31bf7713..bb0c0b4fb4 100644 --- a/tests/particles/particle_handler_14.cc +++ b/tests/particles/particle_handler_14.cc @@ -23,33 +23,22 @@ #include -#include - #include #include "../tests.h" +#include "../test_grids.h" + + template void test() { parallel::distributed::Triangulation tr(MPI_COMM_WORLD); + TestGrids::hyper_line(tr, 2); MappingQ mapping(1); - // setup triangulation - const unsigned int n_cells = 2; - - std::vector rep(dim, 1); - rep[0] = n_cells; - Point p1, p2; - for (unsigned int d = 0; d < dim; ++d) - { - p1[d] = 0; - p2[d] = (d == 0) ? n_cells : 1; - } - GridGenerator::subdivided_hyper_rectangle(tr, rep, p1, p2); - // setup one particle in first cell Particles::ParticleHandler particle_handler(tr, mapping); diff --git a/tests/sharedtria/hp_choose_p_over_h.cc b/tests/sharedtria/hp_choose_p_over_h.cc index 6490f47f68..5ad88c3d4b 100644 --- a/tests/sharedtria/hp_choose_p_over_h.cc +++ b/tests/sharedtria/hp_choose_p_over_h.cc @@ -25,21 +25,19 @@ #include -#include - #include #include #include "../tests.h" +#include "../test_grids.h" + template void test() { // setup - const unsigned int n_cells = 2; - parallel::shared::Triangulation tr( MPI_COMM_WORLD, ::Triangulation::none, @@ -52,15 +50,7 @@ test() Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD)); }); - std::vector rep(dim, 1); - rep[0] = n_cells; - Point p1, p2; - for (unsigned int d = 0; d < dim; ++d) - { - p1[d] = 0; - p2[d] = (d == 0) ? n_cells : 1; - } - GridGenerator::subdivided_hyper_rectangle(tr, rep, p1, p2); + TestGrids::hyper_line(tr, 2); tr.refine_global(1); hp::FECollection fes; diff --git a/tests/test_grids.h b/tests/test_grids.h index 72db4ca3fb..d47a081439 100644 --- a/tests/test_grids.h +++ b/tests/test_grids.h @@ -1,6 +1,6 @@ // --------------------------------------------------------------------- // -// Copyright (C) 2006 - 2018 by the deal.II authors +// Copyright (C) 2006 - 2020 by the deal.II authors // // This file is part of the deal.II library. // @@ -13,11 +13,15 @@ // // --------------------------------------------------------------------- +#include + #include #include #include #include +#include + #include "tests.h" /** @@ -39,23 +43,21 @@ * #star_shaped(tr,2,true)method is robust if more than * usual cells meet in one vertex and local refinement exceeds one * level + * #hyper_line(tr,n)aligns n unit cells in + * x-direction * */ namespace TestGrids { /** - * Generate grids based on - * hypercube. These meshes have a - * regular geometry and topology. + * Generate grids based on hypercube. These meshes have a regular geometry and + * topology. * - * @param refinement - * denotes the number of refinement - * steps of the root cell. + * @param refinement denotes the number of refinement steps of the + * root cell. * - * @param if local is - * true, refine only the - * cell containing the corner with - * only negative coordinates. + * @param if local is true, refine only the cell containing + * the corner with only negative coordinates. */ template void @@ -96,42 +98,62 @@ namespace TestGrids } /** - * Create a star-shaped mesh, - * having more than the average - * 2dim cells - * in the central vertex. + * Create a star-shaped mesh, having more than the average + * 2dim cells in the central vertex. * - * @param refinement - * denotes the number of refinement + * @param refinement denotes the number of refinement * steps of the root mesh. * - * @param if local is - * true, refine only one - * of the coarse cells. + * @param if local is true, refine only one of + * the coarse cells. */ template void star_shaped(Triangulation &tr, unsigned int refinement = 0, bool local = false); + /** - * Local refinement of every other - * cell in a checkerboard fashion. + * Local refinement of every other cell in a checkerboard fashion. */ template void checkers(Triangulation &tr); + /** - * Islands of local refinement + * Islands of local refinement. */ template void islands(Triangulation &tr); + /** - * Local refinement with an - * unrefined hole. + * Local refinement with an unrefined hole. */ template void laguna(Triangulation &tr); + + /** + * Generates grid with @p n_cells unit cells $[0,1]^d$ aligned in the + * x-coordinate direction. + * + * The domain this grid represents covers $[0,n_cells] \times [0,1]^{d-1}$. + * Thus, integer division of the x-cordinate $x // 1$ on any point in this + * triangulation gives you the index of the cell the point is located in. + */ + template + void + hyper_line(Triangulation &tr, const int n_cells) + { + std::vector repetitions(dim, 1); + repetitions[0] = n_cells; + Point p1, p2; + for (unsigned int d = 0; d < dim; ++d) + { + p1[d] = 0; + p2[d] = (d == 0) ? n_cells : 1; + } + GridGenerator::subdivided_hyper_rectangle(tr, repetitions, p1, p2); + } } // namespace TestGrids diff --git a/tests/tests.h b/tests/tests.h index fef16c13d4..660088d293 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -418,6 +418,7 @@ filter_out_small_numbers(const Number number, const double tolerance) return number; } + // ---------------- Functions used in initializing subsystems -----------------