From 550dd973736e67031636eb678881bce8d7100c6b Mon Sep 17 00:00:00 2001 From: Marc Fehling Date: Thu, 12 Dec 2019 15:40:57 +0100 Subject: [PATCH] Separated hp/p_adaptivity_* tests. --- tests/hp/p_adaptivity_absolute_threshold.cc | 148 ++++++++++++++++ .../hp/p_adaptivity_absolute_threshold.output | 16 ++ tests/hp/p_adaptivity_fixed_number.cc | 145 ++++++++++++++++ tests/hp/p_adaptivity_fixed_number.output | 16 ++ tests/hp/p_adaptivity_flags.cc | 159 +++--------------- tests/hp/p_adaptivity_flags.output | 36 +--- tests/hp/p_adaptivity_full.cc | 128 ++++++++++++++ tests/hp/p_adaptivity_full.output | 16 ++ tests/hp/p_adaptivity_reference.cc | 155 +++++++++++++++++ tests/hp/p_adaptivity_reference.output | 16 ++ tests/hp/p_adaptivity_regularity.cc | 145 ++++++++++++++++ tests/hp/p_adaptivity_regularity.output | 16 ++ tests/hp/p_adaptivity_relative_threshold.cc | 145 ++++++++++++++++ .../hp/p_adaptivity_relative_threshold.output | 16 ++ 14 files changed, 985 insertions(+), 172 deletions(-) create mode 100644 tests/hp/p_adaptivity_absolute_threshold.cc create mode 100644 tests/hp/p_adaptivity_absolute_threshold.output create mode 100644 tests/hp/p_adaptivity_fixed_number.cc create mode 100644 tests/hp/p_adaptivity_fixed_number.output create mode 100644 tests/hp/p_adaptivity_full.cc create mode 100644 tests/hp/p_adaptivity_full.output create mode 100644 tests/hp/p_adaptivity_reference.cc create mode 100644 tests/hp/p_adaptivity_reference.output create mode 100644 tests/hp/p_adaptivity_regularity.cc create mode 100644 tests/hp/p_adaptivity_regularity.output create mode 100644 tests/hp/p_adaptivity_relative_threshold.cc create mode 100644 tests/hp/p_adaptivity_relative_threshold.output diff --git a/tests/hp/p_adaptivity_absolute_threshold.cc b/tests/hp/p_adaptivity_absolute_threshold.cc new file mode 100644 index 0000000000..e6bdac9bab --- /dev/null +++ b/tests/hp/p_adaptivity_absolute_threshold.cc @@ -0,0 +1,148 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 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. +// +// --------------------------------------------------------------------- + + + +// validate algorithms that will flag cells for p-adaptivity: +// - hp::Refinement::p_adaptivity_from_absolute_threshold + + +#include + +#include + +#include +#include + +#include +#include +#include + +#include + +#include "../tests.h" + + + +template +void +validate(const hp::DoFHandler &dh) +{ + deallog << " fe_indices:"; + for (const auto &cell : dh.active_cell_iterators()) + deallog << " " << cell->future_fe_index(); + deallog << std::endl; +} + + + +template +void +setup(Triangulation & tria, + hp::DoFHandler & dh, + const hp::FECollection &fes) +{ + // Initialize triangulation and dofhandler. + GridGenerator::hyper_cube(tria); + tria.refine_global(2); + dh.initialize(tria, fes); + + // Set all active fe indices to 1. + // Flag first half of cells for refinement, and the other half for coarsening. + typename hp::DoFHandler::cell_iterator cell = dh.begin(1), + endc = dh.end(1); + for (unsigned int counter = 0; cell != endc; ++counter, ++cell) + { + Assert(!cell->active(), ExcInternalError()); + for (unsigned int child_index = 0; child_index < cell->n_children(); + ++child_index) + { + const auto &child = cell->child(child_index); + Assert(child->active(), ExcInternalError()); + + child->set_active_fe_index(1); + + if (counter < 0.5 * GeometryInfo::max_children_per_cell) + child->set_refine_flag(); + else + child->set_coarsen_flag(); + } + } +} + + + +template +void +test() +{ + hp::FECollection fes; + for (unsigned int d = 1; d <= 3; ++d) + fes.push_back(FE_Q(d)); + + Triangulation tria; + hp::DoFHandler dh; + setup(tria, dh, fes); + + deallog << "starting situation" << std::endl; + validate(dh); + + + // We flag the first half of all cells to be refined and the last half of all + // cells to be coarsened for p adapativity. Ultimately, the first quarter of + // all cells will be flagged for p refinement, and the last quarter for p + // coarsening. + + const unsigned int n_active = tria.n_active_cells(); + Vector indicators(n_active); + for (unsigned int i = 0; i < n_active; ++i) + { + if (i < .25 * n_active) + indicators[i] = 2.; + else if (i < .75 * n_active) + indicators[i] = 1.; + else + indicators[i] = 0.; + } + + hp::Refinement::p_adaptivity_from_absolute_threshold(dh, + indicators, + 1 + 1e-4, + 1 - 1e-4); + + deallog << "p-adaptivity from absolute threshold" << std::endl; + validate(dh); + + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char *argv[]) +{ + initlog(); + + deallog.push("1d"); + test<1>(); + deallog.pop(); + deallog.push("2d"); + test<2>(); + deallog.pop(); + deallog.push("3d"); + test<3>(); + deallog.pop(); +} diff --git a/tests/hp/p_adaptivity_absolute_threshold.output b/tests/hp/p_adaptivity_absolute_threshold.output new file mode 100644 index 0000000000..fac6dc2fc7 --- /dev/null +++ b/tests/hp/p_adaptivity_absolute_threshold.output @@ -0,0 +1,16 @@ + +DEAL:1d::starting situation +DEAL:1d:: fe_indices: 1 1 1 1 +DEAL:1d::p-adaptivity from absolute threshold +DEAL:1d:: fe_indices: 2 1 1 0 +DEAL:1d::OK +DEAL:2d::starting situation +DEAL:2d:: fe_indices: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +DEAL:2d::p-adaptivity from absolute threshold +DEAL:2d:: fe_indices: 2 2 2 2 1 1 1 1 1 1 1 1 0 0 0 0 +DEAL:2d::OK +DEAL:3d::starting situation +DEAL:3d:: fe_indices: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +DEAL:3d::p-adaptivity from absolute threshold +DEAL:3d:: fe_indices: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:3d::OK diff --git a/tests/hp/p_adaptivity_fixed_number.cc b/tests/hp/p_adaptivity_fixed_number.cc new file mode 100644 index 0000000000..324fbed0f8 --- /dev/null +++ b/tests/hp/p_adaptivity_fixed_number.cc @@ -0,0 +1,145 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 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. +// +// --------------------------------------------------------------------- + + + +// validate algorithms that will flag cells for p-adaptivity: +// - hp::Refinement::p_adaptivity_fixed_number + + +#include + +#include + +#include +#include + +#include +#include +#include + +#include + +#include "../tests.h" + + + +template +void +validate(const hp::DoFHandler &dh) +{ + deallog << " fe_indices:"; + for (const auto &cell : dh.active_cell_iterators()) + deallog << " " << cell->future_fe_index(); + deallog << std::endl; +} + + + +template +void +setup(Triangulation & tria, + hp::DoFHandler & dh, + const hp::FECollection &fes) +{ + // Initialize triangulation and dofhandler. + GridGenerator::hyper_cube(tria); + tria.refine_global(2); + dh.initialize(tria, fes); + + // Set all active fe indices to 1. + // Flag first half of cells for refinement, and the other half for coarsening. + typename hp::DoFHandler::cell_iterator cell = dh.begin(1), + endc = dh.end(1); + for (unsigned int counter = 0; cell != endc; ++counter, ++cell) + { + Assert(!cell->active(), ExcInternalError()); + for (unsigned int child_index = 0; child_index < cell->n_children(); + ++child_index) + { + const auto &child = cell->child(child_index); + Assert(child->active(), ExcInternalError()); + + child->set_active_fe_index(1); + + if (counter < 0.5 * GeometryInfo::max_children_per_cell) + child->set_refine_flag(); + else + child->set_coarsen_flag(); + } + } +} + + + +template +void +test() +{ + hp::FECollection fes; + for (unsigned int d = 1; d <= 3; ++d) + fes.push_back(FE_Q(d)); + + Triangulation tria; + hp::DoFHandler dh; + setup(tria, dh, fes); + + deallog << "starting situation" << std::endl; + validate(dh); + + + // We flag the first half of all cells to be refined and the last half of all + // cells to be coarsened for p adapativity. Ultimately, the first quarter of + // all cells will be flagged for p refinement, and the last quarter for p + // coarsening. + + const unsigned int n_active = tria.n_active_cells(); + Vector indicators(n_active); + for (unsigned int i = 0; i < n_active; ++i) + { + if (i < .25 * n_active) + indicators[i] = 2.; + else if (i < .75 * n_active) + indicators[i] = 1.; + else + indicators[i] = 0.; + } + + hp::Refinement::p_adaptivity_fixed_number(dh, indicators); + + deallog << "p-adaptivity fixed number" << std::endl; + validate(dh); + + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char *argv[]) +{ + initlog(); + + deallog.push("1d"); + test<1>(); + deallog.pop(); + deallog.push("2d"); + test<2>(); + deallog.pop(); + deallog.push("3d"); + test<3>(); + deallog.pop(); +} diff --git a/tests/hp/p_adaptivity_fixed_number.output b/tests/hp/p_adaptivity_fixed_number.output new file mode 100644 index 0000000000..fb8ca2a555 --- /dev/null +++ b/tests/hp/p_adaptivity_fixed_number.output @@ -0,0 +1,16 @@ + +DEAL:1d::starting situation +DEAL:1d:: fe_indices: 1 1 1 1 +DEAL:1d::p-adaptivity fixed number +DEAL:1d:: fe_indices: 2 1 1 0 +DEAL:1d::OK +DEAL:2d::starting situation +DEAL:2d:: fe_indices: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +DEAL:2d::p-adaptivity fixed number +DEAL:2d:: fe_indices: 2 2 2 2 1 1 1 1 1 1 1 1 0 0 0 0 +DEAL:2d::OK +DEAL:3d::starting situation +DEAL:3d:: fe_indices: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +DEAL:3d::p-adaptivity fixed number +DEAL:3d:: fe_indices: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:3d::OK diff --git a/tests/hp/p_adaptivity_flags.cc b/tests/hp/p_adaptivity_flags.cc index d074e7b371..0438bc7d76 100644 --- a/tests/hp/p_adaptivity_flags.cc +++ b/tests/hp/p_adaptivity_flags.cc @@ -1,4 +1,4 @@ -// --------------------------------------------------------------------- +// --------------------------------------------------------------------- // // Copyright (C) 2019 by the deal.II authors // @@ -15,7 +15,8 @@ -// validate algorithms that will flag cells for p-adaptivity +// validate algorithms that will flag cells for p-adaptivity: +// - hp::Refinement::p_adaptivity_from_flags #include @@ -37,7 +38,7 @@ template void -validate(const Triangulation &tria, const hp::DoFHandler &dh) +validate(const hp::DoFHandler &dh) { deallog << " fe_indices:"; for (const auto &cell : dh.active_cell_iterators()) @@ -91,149 +92,29 @@ test() for (unsigned int d = 1; d <= 3; ++d) fes.push_back(FE_Q(d)); - deallog << "starting situation: "; - { - Triangulation tria; - hp::DoFHandler dh; - setup(tria, dh, fes); + Triangulation tria; + hp::DoFHandler dh; + setup(tria, dh, fes); - deallog << "ncells: " << tria.n_active_cells() << std::endl; - validate(tria, dh); - } + deallog << "starting situation" << std::endl; + validate(dh); - deallog << "full p-adaptivity" << std::endl; - { - Triangulation tria; - hp::DoFHandler dh; - setup(tria, dh, fes); - hp::Refinement::full_p_adaptivity(dh); + // We flag the first half of all cells to be refined and the last half of all + // cells to be coarsened for p adapativity. Ultimately, the first quarter of + // all cells will be flagged for p refinement, and the last quarter for p + // coarsening. - validate(tria, dh); - } + const unsigned int n_active = tria.n_active_cells(); + std::vector p_flags(n_active, false); + std::fill(p_flags.begin(), p_flags.begin() + .25 * n_active, true); + std::fill(p_flags.end() - .25 * n_active, p_flags.end(), true); - // In the following cases, we flag the first half of all cells to be refined - // and the last half of all cells to be coarsened for p adapativity. - // Ultimately, the first quarter of all cells will be flagged for - // p refinement, and the last quarter for p coarsening. + hp::Refinement::p_adaptivity_from_flags(dh, p_flags); deallog << "p-adaptivity from flags" << std::endl; - { - Triangulation tria; - hp::DoFHandler dh; - setup(tria, dh, fes); - - unsigned int n_active = tria.n_active_cells(); - std::vector p_flags(n_active, false); - - std::fill(p_flags.begin(), p_flags.begin() + n_active / 4, true); - std::fill(p_flags.end() - n_active / 4, p_flags.end(), true); - - hp::Refinement::p_adaptivity_from_flags(dh, p_flags); - - validate(tria, dh); - } - - deallog << "p-adaptivity from absolute threshold" << std::endl; - { - Triangulation tria; - hp::DoFHandler dh; - setup(tria, dh, fes); - - unsigned int n_active = tria.n_active_cells(); - Vector indicators(n_active); - for (unsigned int i = 0; i < n_active; ++i) - { - if (i < .25 * n_active) - indicators[i] = 2.; - else if (i < .75 * n_active) - indicators[i] = 1.; - else - indicators[i] = 0.; - } - hp::Refinement::p_adaptivity_from_absolute_threshold(dh, - indicators, - 1 + 1e-4, - 1 - 1e-4); - - validate(tria, dh); - } - - deallog << "p-adaptivity from relative threshold" << std::endl; - { - Triangulation tria; - hp::DoFHandler dh; - setup(tria, dh, fes); - - unsigned int n_active = tria.n_active_cells(); - Vector indicators(n_active); - for (unsigned int i = 0; i < n_active; ++i) - { - if (i < .25 * n_active) - indicators[i] = 2.; - else if (i < .75 * n_active) - indicators[i] = 1.; - else - indicators[i] = 0.; - } - hp::Refinement::p_adaptivity_from_relative_threshold(dh, indicators); - - validate(tria, dh); - } - - deallog << "p-adaptivity from regularity" << std::endl; - { - Triangulation tria; - hp::DoFHandler dh; - setup(tria, dh, fes); - - unsigned int n_active = tria.n_active_cells(); - Vector sobolev_indices(n_active); - for (unsigned int i = 0; i < n_active; ++i) - { - if (i < .25 * n_active) - sobolev_indices[i] = 3. + 1e-4; - else if (i < .75 * n_active) - sobolev_indices[i] = 2.; - else - sobolev_indices[i] = 1. - 1e-4; - } - hp::Refinement::p_adaptivity_from_regularity(dh, sobolev_indices); - - validate(tria, dh); - } - - deallog << "p-adaptivity from reference" << std::endl; - { - Triangulation tria; - hp::DoFHandler dh; - setup(tria, dh, fes); - - unsigned int n_active = tria.n_active_cells(); - Vector references(n_active), criteria(n_active); - for (unsigned int i = 0; i < n_active; ++i) - { - if (i < .25 * n_active) - { - references[i] = 1. + 1e-4; - criteria[i] = 1.; - } - else if (i < .75 * n_active) - { - references[i] = 1.; - criteria[i] = 1.; - } - else - { - references[i] = 1. - 1e-4; - criteria[i] = 1.; - } - } - hp::Refinement::p_adaptivity_from_reference( - dh, criteria, references, std::less(), std::greater()); - - validate(tria, dh); - } + validate(dh); + deallog << "OK" << std::endl; } diff --git a/tests/hp/p_adaptivity_flags.output b/tests/hp/p_adaptivity_flags.output index bb046b4c0e..a74a95f002 100644 --- a/tests/hp/p_adaptivity_flags.output +++ b/tests/hp/p_adaptivity_flags.output @@ -1,46 +1,16 @@ -DEAL:1d::starting situation: ncells: 4 +DEAL:1d::starting situation DEAL:1d:: fe_indices: 1 1 1 1 -DEAL:1d::full p-adaptivity -DEAL:1d:: fe_indices: 2 2 0 0 DEAL:1d::p-adaptivity from flags DEAL:1d:: fe_indices: 2 1 1 0 -DEAL:1d::p-adaptivity from absolute threshold -DEAL:1d:: fe_indices: 2 1 1 0 -DEAL:1d::p-adaptivity from relative threshold -DEAL:1d:: fe_indices: 2 1 1 0 -DEAL:1d::p-adaptivity from regularity -DEAL:1d:: fe_indices: 2 1 1 0 -DEAL:1d::p-adaptivity from reference -DEAL:1d:: fe_indices: 2 1 1 0 DEAL:1d::OK -DEAL:2d::starting situation: ncells: 16 +DEAL:2d::starting situation DEAL:2d:: fe_indices: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -DEAL:2d::full p-adaptivity -DEAL:2d:: fe_indices: 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 DEAL:2d::p-adaptivity from flags DEAL:2d:: fe_indices: 2 2 2 2 1 1 1 1 1 1 1 1 0 0 0 0 -DEAL:2d::p-adaptivity from absolute threshold -DEAL:2d:: fe_indices: 2 2 2 2 1 1 1 1 1 1 1 1 0 0 0 0 -DEAL:2d::p-adaptivity from relative threshold -DEAL:2d:: fe_indices: 2 2 2 2 1 1 1 1 1 1 1 1 0 0 0 0 -DEAL:2d::p-adaptivity from regularity -DEAL:2d:: fe_indices: 2 2 2 2 1 1 1 1 1 1 1 1 0 0 0 0 -DEAL:2d::p-adaptivity from reference -DEAL:2d:: fe_indices: 2 2 2 2 1 1 1 1 1 1 1 1 0 0 0 0 DEAL:2d::OK -DEAL:3d::starting situation: ncells: 64 +DEAL:3d::starting situation DEAL:3d:: fe_indices: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -DEAL:3d::full p-adaptivity -DEAL:3d:: fe_indices: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 DEAL:3d::p-adaptivity from flags DEAL:3d:: fe_indices: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -DEAL:3d::p-adaptivity from absolute threshold -DEAL:3d:: fe_indices: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -DEAL:3d::p-adaptivity from relative threshold -DEAL:3d:: fe_indices: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -DEAL:3d::p-adaptivity from regularity -DEAL:3d:: fe_indices: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -DEAL:3d::p-adaptivity from reference -DEAL:3d:: fe_indices: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 DEAL:3d::OK diff --git a/tests/hp/p_adaptivity_full.cc b/tests/hp/p_adaptivity_full.cc new file mode 100644 index 0000000000..a9c65d5a45 --- /dev/null +++ b/tests/hp/p_adaptivity_full.cc @@ -0,0 +1,128 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 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. +// +// --------------------------------------------------------------------- + + + +// validate algorithms that will flag cells for p-adaptivity: +// - hp::Refinement::full_p_adaptivity + + +#include + +#include + +#include +#include + +#include +#include +#include + +#include + +#include "../tests.h" + + + +template +void +validate(const hp::DoFHandler &dh) +{ + deallog << " fe_indices:"; + for (const auto &cell : dh.active_cell_iterators()) + deallog << " " << cell->future_fe_index(); + deallog << std::endl; +} + + + +template +void +setup(Triangulation & tria, + hp::DoFHandler & dh, + const hp::FECollection &fes) +{ + // Initialize triangulation and dofhandler. + GridGenerator::hyper_cube(tria); + tria.refine_global(2); + dh.initialize(tria, fes); + + // Set all active fe indices to 1. + // Flag first half of cells for refinement, and the other half for coarsening. + typename hp::DoFHandler::cell_iterator cell = dh.begin(1), + endc = dh.end(1); + for (unsigned int counter = 0; cell != endc; ++counter, ++cell) + { + Assert(!cell->active(), ExcInternalError()); + for (unsigned int child_index = 0; child_index < cell->n_children(); + ++child_index) + { + const auto &child = cell->child(child_index); + Assert(child->active(), ExcInternalError()); + + child->set_active_fe_index(1); + + if (counter < 0.5 * GeometryInfo::max_children_per_cell) + child->set_refine_flag(); + else + child->set_coarsen_flag(); + } + } +} + + + +template +void +test() +{ + hp::FECollection fes; + for (unsigned int d = 1; d <= 3; ++d) + fes.push_back(FE_Q(d)); + + Triangulation tria; + hp::DoFHandler dh; + setup(tria, dh, fes); + + deallog << "starting situation" << std::endl; + validate(dh); + + + hp::Refinement::full_p_adaptivity(dh); + + deallog << "full p-adaptivity" << std::endl; + validate(dh); + + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char *argv[]) +{ + initlog(); + + deallog.push("1d"); + test<1>(); + deallog.pop(); + deallog.push("2d"); + test<2>(); + deallog.pop(); + deallog.push("3d"); + test<3>(); + deallog.pop(); +} diff --git a/tests/hp/p_adaptivity_full.output b/tests/hp/p_adaptivity_full.output new file mode 100644 index 0000000000..ba1d1222a8 --- /dev/null +++ b/tests/hp/p_adaptivity_full.output @@ -0,0 +1,16 @@ + +DEAL:1d::starting situation +DEAL:1d:: fe_indices: 1 1 1 1 +DEAL:1d::full p-adaptivity +DEAL:1d:: fe_indices: 2 2 0 0 +DEAL:1d::OK +DEAL:2d::starting situation +DEAL:2d:: fe_indices: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +DEAL:2d::full p-adaptivity +DEAL:2d:: fe_indices: 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 +DEAL:2d::OK +DEAL:3d::starting situation +DEAL:3d:: fe_indices: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +DEAL:3d::full p-adaptivity +DEAL:3d:: fe_indices: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:3d::OK diff --git a/tests/hp/p_adaptivity_reference.cc b/tests/hp/p_adaptivity_reference.cc new file mode 100644 index 0000000000..ecb0f89080 --- /dev/null +++ b/tests/hp/p_adaptivity_reference.cc @@ -0,0 +1,155 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 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. +// +// --------------------------------------------------------------------- + + + +// validate algorithms that will flag cells for p-adaptivity: +// - hp::Refinement::p_adaptivity_from_reference + + +#include + +#include + +#include +#include + +#include +#include +#include + +#include + +#include "../tests.h" + + + +template +void +validate(const hp::DoFHandler &dh) +{ + deallog << " fe_indices:"; + for (const auto &cell : dh.active_cell_iterators()) + deallog << " " << cell->future_fe_index(); + deallog << std::endl; +} + + + +template +void +setup(Triangulation & tria, + hp::DoFHandler & dh, + const hp::FECollection &fes) +{ + // Initialize triangulation and dofhandler. + GridGenerator::hyper_cube(tria); + tria.refine_global(2); + dh.initialize(tria, fes); + + // Set all active fe indices to 1. + // Flag first half of cells for refinement, and the other half for coarsening. + typename hp::DoFHandler::cell_iterator cell = dh.begin(1), + endc = dh.end(1); + for (unsigned int counter = 0; cell != endc; ++counter, ++cell) + { + Assert(!cell->active(), ExcInternalError()); + for (unsigned int child_index = 0; child_index < cell->n_children(); + ++child_index) + { + const auto &child = cell->child(child_index); + Assert(child->active(), ExcInternalError()); + + child->set_active_fe_index(1); + + if (counter < 0.5 * GeometryInfo::max_children_per_cell) + child->set_refine_flag(); + else + child->set_coarsen_flag(); + } + } +} + + + +template +void +test() +{ + hp::FECollection fes; + for (unsigned int d = 1; d <= 3; ++d) + fes.push_back(FE_Q(d)); + + Triangulation tria; + hp::DoFHandler dh; + setup(tria, dh, fes); + + deallog << "starting situation" << std::endl; + validate(dh); + + + // We flag the first half of all cells to be refined and the last half of all + // cells to be coarsened for p adapativity. Ultimately, the first quarter of + // all cells will be flagged for p refinement, and the last quarter for p + // coarsening. + + const unsigned int n_active = tria.n_active_cells(); + Vector references(n_active), criteria(n_active); + for (unsigned int i = 0; i < n_active; ++i) + { + if (i < .25 * n_active) + { + references[i] = 1. + 1e-4; + criteria[i] = 1.; + } + else if (i < .75 * n_active) + { + references[i] = 1.; + criteria[i] = 1.; + } + else + { + references[i] = 1. - 1e-4; + criteria[i] = 1.; + } + } + + hp::Refinement::p_adaptivity_from_reference( + dh, criteria, references, std::less(), std::greater()); + + deallog << "p-adaptivity from reference" << std::endl; + validate(dh); + + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char *argv[]) +{ + initlog(); + + deallog.push("1d"); + test<1>(); + deallog.pop(); + deallog.push("2d"); + test<2>(); + deallog.pop(); + deallog.push("3d"); + test<3>(); + deallog.pop(); +} diff --git a/tests/hp/p_adaptivity_reference.output b/tests/hp/p_adaptivity_reference.output new file mode 100644 index 0000000000..dcf94a92f7 --- /dev/null +++ b/tests/hp/p_adaptivity_reference.output @@ -0,0 +1,16 @@ + +DEAL:1d::starting situation +DEAL:1d:: fe_indices: 1 1 1 1 +DEAL:1d::p-adaptivity from reference +DEAL:1d:: fe_indices: 2 1 1 0 +DEAL:1d::OK +DEAL:2d::starting situation +DEAL:2d:: fe_indices: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +DEAL:2d::p-adaptivity from reference +DEAL:2d:: fe_indices: 2 2 2 2 1 1 1 1 1 1 1 1 0 0 0 0 +DEAL:2d::OK +DEAL:3d::starting situation +DEAL:3d:: fe_indices: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +DEAL:3d::p-adaptivity from reference +DEAL:3d:: fe_indices: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:3d::OK diff --git a/tests/hp/p_adaptivity_regularity.cc b/tests/hp/p_adaptivity_regularity.cc new file mode 100644 index 0000000000..9a75e20fb6 --- /dev/null +++ b/tests/hp/p_adaptivity_regularity.cc @@ -0,0 +1,145 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 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. +// +// --------------------------------------------------------------------- + + + +// validate algorithms that will flag cells for p-adaptivity: +// - hp::Refinement::p_adaptivity_from_regularity + + +#include + +#include + +#include +#include + +#include +#include +#include + +#include + +#include "../tests.h" + + + +template +void +validate(const hp::DoFHandler &dh) +{ + deallog << " fe_indices:"; + for (const auto &cell : dh.active_cell_iterators()) + deallog << " " << cell->future_fe_index(); + deallog << std::endl; +} + + + +template +void +setup(Triangulation & tria, + hp::DoFHandler & dh, + const hp::FECollection &fes) +{ + // Initialize triangulation and dofhandler. + GridGenerator::hyper_cube(tria); + tria.refine_global(2); + dh.initialize(tria, fes); + + // Set all active fe indices to 1. + // Flag first half of cells for refinement, and the other half for coarsening. + typename hp::DoFHandler::cell_iterator cell = dh.begin(1), + endc = dh.end(1); + for (unsigned int counter = 0; cell != endc; ++counter, ++cell) + { + Assert(!cell->active(), ExcInternalError()); + for (unsigned int child_index = 0; child_index < cell->n_children(); + ++child_index) + { + const auto &child = cell->child(child_index); + Assert(child->active(), ExcInternalError()); + + child->set_active_fe_index(1); + + if (counter < 0.5 * GeometryInfo::max_children_per_cell) + child->set_refine_flag(); + else + child->set_coarsen_flag(); + } + } +} + + + +template +void +test() +{ + hp::FECollection fes; + for (unsigned int d = 1; d <= 3; ++d) + fes.push_back(FE_Q(d)); + + Triangulation tria; + hp::DoFHandler dh; + setup(tria, dh, fes); + + deallog << "starting situation" << std::endl; + validate(dh); + + + // We flag the first half of all cells to be refined and the last half of all + // cells to be coarsened for p adapativity. Ultimately, the first quarter of + // all cells will be flagged for p refinement, and the last quarter for p + // coarsening. + + const unsigned int n_active = tria.n_active_cells(); + Vector sobolev_indices(n_active); + for (unsigned int i = 0; i < n_active; ++i) + { + if (i < .25 * n_active) + sobolev_indices[i] = 3. + 1e-4; + else if (i < .75 * n_active) + sobolev_indices[i] = 2.; + else + sobolev_indices[i] = 1. - 1e-4; + } + + hp::Refinement::p_adaptivity_from_regularity(dh, sobolev_indices); + + deallog << "p-adaptivity from regularity" << std::endl; + validate(dh); + + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char *argv[]) +{ + initlog(); + + deallog.push("1d"); + test<1>(); + deallog.pop(); + deallog.push("2d"); + test<2>(); + deallog.pop(); + deallog.push("3d"); + test<3>(); + deallog.pop(); +} diff --git a/tests/hp/p_adaptivity_regularity.output b/tests/hp/p_adaptivity_regularity.output new file mode 100644 index 0000000000..2d55772c9f --- /dev/null +++ b/tests/hp/p_adaptivity_regularity.output @@ -0,0 +1,16 @@ + +DEAL:1d::starting situation +DEAL:1d:: fe_indices: 1 1 1 1 +DEAL:1d::p-adaptivity from regularity +DEAL:1d:: fe_indices: 2 1 1 0 +DEAL:1d::OK +DEAL:2d::starting situation +DEAL:2d:: fe_indices: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +DEAL:2d::p-adaptivity from regularity +DEAL:2d:: fe_indices: 2 2 2 2 1 1 1 1 1 1 1 1 0 0 0 0 +DEAL:2d::OK +DEAL:3d::starting situation +DEAL:3d:: fe_indices: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +DEAL:3d::p-adaptivity from regularity +DEAL:3d:: fe_indices: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:3d::OK diff --git a/tests/hp/p_adaptivity_relative_threshold.cc b/tests/hp/p_adaptivity_relative_threshold.cc new file mode 100644 index 0000000000..63897637fa --- /dev/null +++ b/tests/hp/p_adaptivity_relative_threshold.cc @@ -0,0 +1,145 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 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. +// +// --------------------------------------------------------------------- + + + +// validate algorithms that will flag cells for p-adaptivity: +// - hp::Refinement::p_adaptivity_from_relative_threshold + + +#include + +#include + +#include +#include + +#include +#include +#include + +#include + +#include "../tests.h" + + + +template +void +validate(const hp::DoFHandler &dh) +{ + deallog << " fe_indices:"; + for (const auto &cell : dh.active_cell_iterators()) + deallog << " " << cell->future_fe_index(); + deallog << std::endl; +} + + + +template +void +setup(Triangulation & tria, + hp::DoFHandler & dh, + const hp::FECollection &fes) +{ + // Initialize triangulation and dofhandler. + GridGenerator::hyper_cube(tria); + tria.refine_global(2); + dh.initialize(tria, fes); + + // Set all active fe indices to 1. + // Flag first half of cells for refinement, and the other half for coarsening. + typename hp::DoFHandler::cell_iterator cell = dh.begin(1), + endc = dh.end(1); + for (unsigned int counter = 0; cell != endc; ++counter, ++cell) + { + Assert(!cell->active(), ExcInternalError()); + for (unsigned int child_index = 0; child_index < cell->n_children(); + ++child_index) + { + const auto &child = cell->child(child_index); + Assert(child->active(), ExcInternalError()); + + child->set_active_fe_index(1); + + if (counter < 0.5 * GeometryInfo::max_children_per_cell) + child->set_refine_flag(); + else + child->set_coarsen_flag(); + } + } +} + + + +template +void +test() +{ + hp::FECollection fes; + for (unsigned int d = 1; d <= 3; ++d) + fes.push_back(FE_Q(d)); + + Triangulation tria; + hp::DoFHandler dh; + setup(tria, dh, fes); + + deallog << "starting situation" << std::endl; + validate(dh); + + + // We flag the first half of all cells to be refined and the last half of all + // cells to be coarsened for p adapativity. Ultimately, the first quarter of + // all cells will be flagged for p refinement, and the last quarter for p + // coarsening. + + const unsigned int n_active = tria.n_active_cells(); + Vector indicators(n_active); + for (unsigned int i = 0; i < n_active; ++i) + { + if (i < .25 * n_active) + indicators[i] = 2.; + else if (i < .75 * n_active) + indicators[i] = 1.; + else + indicators[i] = 0.; + } + + hp::Refinement::p_adaptivity_from_relative_threshold(dh, indicators); + + deallog << "p-adaptivity from relative threshold" << std::endl; + validate(dh); + + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char *argv[]) +{ + initlog(); + + deallog.push("1d"); + test<1>(); + deallog.pop(); + deallog.push("2d"); + test<2>(); + deallog.pop(); + deallog.push("3d"); + test<3>(); + deallog.pop(); +} diff --git a/tests/hp/p_adaptivity_relative_threshold.output b/tests/hp/p_adaptivity_relative_threshold.output new file mode 100644 index 0000000000..2dfb89c7f4 --- /dev/null +++ b/tests/hp/p_adaptivity_relative_threshold.output @@ -0,0 +1,16 @@ + +DEAL:1d::starting situation +DEAL:1d:: fe_indices: 1 1 1 1 +DEAL:1d::p-adaptivity from relative threshold +DEAL:1d:: fe_indices: 2 1 1 0 +DEAL:1d::OK +DEAL:2d::starting situation +DEAL:2d:: fe_indices: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +DEAL:2d::p-adaptivity from relative threshold +DEAL:2d:: fe_indices: 2 2 2 2 1 1 1 1 1 1 1 1 0 0 0 0 +DEAL:2d::OK +DEAL:3d::starting situation +DEAL:3d:: fe_indices: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +DEAL:3d::p-adaptivity from relative threshold +DEAL:3d:: fe_indices: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:3d::OK -- 2.39.5