From ac09ba68e276c5c669a99ea0418f47ebe8bc44d3 Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Tue, 7 May 2019 19:34:19 +0200 Subject: [PATCH] add tests for HSFC with degenerate input --- tests/base/utilities_17.cc | 95 ++++++++++++++++++++++++++++++++++ tests/base/utilities_17.output | 55 ++++++++++++++++++++ tests/base/utilities_18.cc | 75 +++++++++++++++++++++++++++ tests/base/utilities_18.output | 22 ++++++++ tests/base/utilities_19.cc | 56 ++++++++++++++++++++ tests/base/utilities_19.output | 13 +++++ 6 files changed, 316 insertions(+) create mode 100644 tests/base/utilities_17.cc create mode 100644 tests/base/utilities_17.output create mode 100644 tests/base/utilities_18.cc create mode 100644 tests/base/utilities_18.output create mode 100644 tests/base/utilities_19.cc create mode 100644 tests/base/utilities_19.output diff --git a/tests/base/utilities_17.cc b/tests/base/utilities_17.cc new file mode 100644 index 0000000000..9506284260 --- /dev/null +++ b/tests/base/utilities_17.cc @@ -0,0 +1,95 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2018 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. +// +// --------------------------------------------------------------------- + + +// similar to utilities_14, test +// Utilities::inverse_Hilbert_space_filling_curve in 3D for point on the planes +// with bits=2. +// the test output is made to be exactly the same as utilities_14 + +// 3 | 5---6 9---10 +// | | | | | +// 2 | 4 7---8 11 +// | | | +// 1 | 3---2 13--12 +// | | | +// 0 | 0---1 14--15 +// | +// ------------------ +// 0 1 2 3 + +#include + +#include "../tests.h" + + +void +test(const unsigned int plane = 1) +{ + Assert(plane < 3, ExcInternalError()); + const std::vector> points = {Point<2>(0, 0), + Point<2>(1, 0), + Point<2>(1, 1), + Point<2>(0, 1), + Point<2>(0, 2), + Point<2>(0, 3), + Point<2>(1, 3), + Point<2>(1, 2), + Point<2>(2, 2), + Point<2>(2, 3), + Point<2>(3, 3), + Point<2>(3, 2), + Point<2>(3, 1), + Point<2>(2, 1), + Point<2>(2, 0), + Point<2>(3, 0)}; + + std::vector> points_degenerate(points.size()); + for (unsigned int i = 0; i < points.size(); ++i) + { + unsigned int eff_d = 0; + for (unsigned int d = 0; d < 3; ++d) + if (d != plane) + { + points_degenerate[i][d] = points[i][eff_d]; + ++eff_d; + } + } + + + const int bit_depth = 2; + const auto res = + Utilities::inverse_Hilbert_space_filling_curve(points_degenerate, + bit_depth); + + deallog << plane << ":" << std::endl; + for (const auto &p : res) + { + AssertThrow(p[0] == 0, ExcInternalError()); + deallog << p[1] << " " << p[2] << " " + << Utilities::pack_integers<3>(p, bit_depth) << std::endl; + } + deallog << std::endl; +} + +int +main() +{ + initlog(); + + test(0); + test(1); + test(2); +} diff --git a/tests/base/utilities_17.output b/tests/base/utilities_17.output new file mode 100644 index 0000000000..7470d56436 --- /dev/null +++ b/tests/base/utilities_17.output @@ -0,0 +1,55 @@ + +DEAL::0: +DEAL::0 0 0 +DEAL::0 1 1 +DEAL::0 2 2 +DEAL::0 3 3 +DEAL::1 0 4 +DEAL::1 1 5 +DEAL::1 2 6 +DEAL::1 3 7 +DEAL::2 0 8 +DEAL::2 1 9 +DEAL::2 2 10 +DEAL::2 3 11 +DEAL::3 0 12 +DEAL::3 1 13 +DEAL::3 2 14 +DEAL::3 3 15 +DEAL:: +DEAL::1: +DEAL::0 0 0 +DEAL::0 1 1 +DEAL::0 2 2 +DEAL::0 3 3 +DEAL::1 0 4 +DEAL::1 1 5 +DEAL::1 2 6 +DEAL::1 3 7 +DEAL::2 0 8 +DEAL::2 1 9 +DEAL::2 2 10 +DEAL::2 3 11 +DEAL::3 0 12 +DEAL::3 1 13 +DEAL::3 2 14 +DEAL::3 3 15 +DEAL:: +DEAL::2: +DEAL::0 0 0 +DEAL::0 1 1 +DEAL::0 2 2 +DEAL::0 3 3 +DEAL::1 0 4 +DEAL::1 1 5 +DEAL::1 2 6 +DEAL::1 3 7 +DEAL::2 0 8 +DEAL::2 1 9 +DEAL::2 2 10 +DEAL::2 3 11 +DEAL::3 0 12 +DEAL::3 1 13 +DEAL::3 2 14 +DEAL::3 3 15 +DEAL:: diff --git a/tests/base/utilities_18.cc b/tests/base/utilities_18.cc new file mode 100644 index 0000000000..71d7adeb9f --- /dev/null +++ b/tests/base/utilities_18.cc @@ -0,0 +1,75 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2018 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. +// +// --------------------------------------------------------------------- + + +// test Utilities::inverse_Hilbert_space_filling_curve in (effectively) 1D +// take utilities_16 input and put on a coordinate line in 3D. +// output is made exactly the same as in utilities_16 + +#include + +#include "../tests.h" + + +void +test(unsigned int plane = 1) +{ + Assert(plane < 3, ExcInternalError()); + const std::vector> points = { + Point<1>(1), Point<1>(0), Point<1>(13), Point<1>(-2), Point<1>(22)}; + + std::vector> points_degenerate(points.size()); + for (unsigned int i = 0; i < points.size(); ++i) + points_degenerate[i][plane] = points[i][0]; + + const int bit_depth = 5; + const auto res = + Utilities::inverse_Hilbert_space_filling_curve(points_degenerate, + bit_depth); + + std::vector index(points.size()); + for (unsigned int i = 0; i < index.size(); ++i) + index[i] = i; + + std::sort(index.begin(), + index.end(), + [&](const unsigned int &a, const unsigned int &b) { + AssertIndexRange(a, res.size()); + AssertIndexRange(b, res.size()); + return std::lexicographical_compare(res[a].begin(), + res[a].end(), + res[b].begin(), + res[b].end()); + }); + + deallog << plane << ":" << std::endl; + for (const auto ind : index) + { + AssertThrow(res[ind][0] == 0, ExcInternalError()); + AssertThrow(res[ind][1] == 0, ExcInternalError()); + deallog << points[ind][0] << std::endl; + } + deallog << std::endl; +} + +int +main() +{ + initlog(); + + test(0); + test(1); + test(2); +} diff --git a/tests/base/utilities_18.output b/tests/base/utilities_18.output new file mode 100644 index 0000000000..71438d429c --- /dev/null +++ b/tests/base/utilities_18.output @@ -0,0 +1,22 @@ + +DEAL::0: +DEAL::-2.00000 +DEAL::0.00000 +DEAL::1.00000 +DEAL::13.0000 +DEAL::22.0000 +DEAL:: +DEAL::1: +DEAL::-2.00000 +DEAL::0.00000 +DEAL::1.00000 +DEAL::13.0000 +DEAL::22.0000 +DEAL:: +DEAL::2: +DEAL::-2.00000 +DEAL::0.00000 +DEAL::1.00000 +DEAL::13.0000 +DEAL::22.0000 +DEAL:: diff --git a/tests/base/utilities_19.cc b/tests/base/utilities_19.cc new file mode 100644 index 0000000000..6ea80350c4 --- /dev/null +++ b/tests/base/utilities_19.cc @@ -0,0 +1,56 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2018 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. +// +// --------------------------------------------------------------------- + + +// test Utilities::inverse_Hilbert_space_filling_curve with +// effective dimension == 0 + +#include + +#include "../tests.h" + + +template +void +test() +{ + deallog << "dim=" << dim << std::endl; + const std::vector> points_degenerate = {Point(), + Point(), + Point()}; + + const int bit_depth = 5; + const auto res = + Utilities::inverse_Hilbert_space_filling_curve(points_degenerate, + bit_depth); + + for (unsigned int i = 0; i < res.size(); ++i) + { + for (unsigned int d = 0; d < dim; ++d) + deallog << " " << res[i][d]; + + deallog << std::endl; + } +} + +int +main() +{ + initlog(); + + test<1>(); + test<2>(); + test<3>(); +} diff --git a/tests/base/utilities_19.output b/tests/base/utilities_19.output new file mode 100644 index 0000000000..39e7a65e0d --- /dev/null +++ b/tests/base/utilities_19.output @@ -0,0 +1,13 @@ + +DEAL::dim=1 +DEAL:: 0 +DEAL:: 1 +DEAL:: 2 +DEAL::dim=2 +DEAL:: 0 0 +DEAL:: 0 1 +DEAL:: 0 2 +DEAL::dim=3 +DEAL:: 0 0 0 +DEAL:: 0 0 1 +DEAL:: 0 0 2 -- 2.39.5