From 887bef05870bd78d7cda77c5d16527a50d3ead2b Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 19 Jun 2018 15:14:06 -0600 Subject: [PATCH] Add tests. --- .../refine_and_coarsen_fixed_fraction_02.cc | 74 +++++++++++++++++++ ...efine_and_coarsen_fixed_fraction_02.output | 4 + .../refine_and_coarsen_fixed_number_02.cc | 74 +++++++++++++++++++ .../refine_and_coarsen_fixed_number_02.output | 4 + 4 files changed, 156 insertions(+) create mode 100644 tests/grid/refine_and_coarsen_fixed_fraction_02.cc create mode 100644 tests/grid/refine_and_coarsen_fixed_fraction_02.output create mode 100644 tests/grid/refine_and_coarsen_fixed_number_02.cc create mode 100644 tests/grid/refine_and_coarsen_fixed_number_02.output diff --git a/tests/grid/refine_and_coarsen_fixed_fraction_02.cc b/tests/grid/refine_and_coarsen_fixed_fraction_02.cc new file mode 100644 index 0000000000..7a71aae252 --- /dev/null +++ b/tests/grid/refine_and_coarsen_fixed_fraction_02.cc @@ -0,0 +1,74 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2015 - 2017 by the deal.II Authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +// When setting refine_fraction=0.6 and coarsen_fraction=0.4, these +// numbers may add up to slightly larger than a total of 1.0 in +// floating point arithmetic. Make sure we allow this nevertheless. + +#include +#include +#include + +#include + +#include + +#include "../tests.h" + +using namespace dealii; + +int +main(int argc, const char *argv[]) +{ + initlog(); + + Triangulation<2> tria; + GridGenerator::hyper_cube(tria); + tria.refine_global(4); + + Vector indicator(tria.n_active_cells()); + for (unsigned int i = 0; i != indicator.size(); ++i) + { + indicator[i] = i; + } + + deallog << "n_active_cells: " << tria.n_active_cells() << std::endl; + + GridRefinement::refine_and_coarsen_fixed_fraction( + tria, + indicator, + 0.6, + 1. - 0.6 + std::numeric_limits::epsilon() * 5); + tria.execute_coarsening_and_refinement(); + + deallog << "n_active_cells: " << tria.n_active_cells() << std::endl; + + indicator.reinit(tria.n_active_cells()); + for (unsigned int i = 0; i != indicator.size(); ++i) + { + indicator[i] = i; + } + + GridRefinement::refine_and_coarsen_fixed_fraction( + tria, + indicator, + 0.4, + 1. - 0.4 + std::numeric_limits::epsilon() * 5); + tria.execute_coarsening_and_refinement(); + + deallog << "n_active_cells: " << tria.n_active_cells() << std::endl; + + return 0; +} diff --git a/tests/grid/refine_and_coarsen_fixed_fraction_02.output b/tests/grid/refine_and_coarsen_fixed_fraction_02.output new file mode 100644 index 0000000000..49e6993a3f --- /dev/null +++ b/tests/grid/refine_and_coarsen_fixed_fraction_02.output @@ -0,0 +1,4 @@ + +DEAL::n_active_cells: 256 +DEAL::n_active_cells: 442 +DEAL::n_active_cells: 523 diff --git a/tests/grid/refine_and_coarsen_fixed_number_02.cc b/tests/grid/refine_and_coarsen_fixed_number_02.cc new file mode 100644 index 0000000000..b93932bb56 --- /dev/null +++ b/tests/grid/refine_and_coarsen_fixed_number_02.cc @@ -0,0 +1,74 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2015 - 2017 by the deal.II Authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +// When setting refine_fraction=0.6 and coarsen_fraction=0.4, these +// numbers may add up to slightly larger than a total of 1.0 in +// floating point arithmetic. Make sure we allow this nevertheless. + +#include +#include +#include + +#include + +#include + +#include "../tests.h" + +using namespace dealii; + +int +main(int argc, const char *argv[]) +{ + initlog(); + + Triangulation<2> tria; + GridGenerator::hyper_cube(tria); + tria.refine_global(4); + + Vector indicator(tria.n_active_cells()); + for (unsigned int i = 0; i != indicator.size(); ++i) + { + indicator[i] = i; + } + + deallog << "n_active_cells: " << tria.n_active_cells() << std::endl; + + GridRefinement::refine_and_coarsen_fixed_number( + tria, + indicator, + 0.6, + 1. - 0.6 + std::numeric_limits::epsilon() * 5); + tria.execute_coarsening_and_refinement(); + + deallog << "n_active_cells: " << tria.n_active_cells() << std::endl; + + indicator.reinit(tria.n_active_cells()); + for (unsigned int i = 0; i != indicator.size(); ++i) + { + indicator[i] = i; + } + + GridRefinement::refine_and_coarsen_fixed_number( + tria, + indicator, + 0.4, + 1. - 0.4 + std::numeric_limits::epsilon() * 5); + tria.execute_coarsening_and_refinement(); + + deallog << "n_active_cells: " << tria.n_active_cells() << std::endl; + + return 0; +} diff --git a/tests/grid/refine_and_coarsen_fixed_number_02.output b/tests/grid/refine_and_coarsen_fixed_number_02.output new file mode 100644 index 0000000000..07020bc75d --- /dev/null +++ b/tests/grid/refine_and_coarsen_fixed_number_02.output @@ -0,0 +1,4 @@ + +DEAL::n_active_cells: 256 +DEAL::n_active_cells: 664 +DEAL::n_active_cells: 1225 -- 2.39.5