From 6fda9afbfc393cf960f306acbeb6ea46d35ba753 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Fri, 2 Oct 2020 13:05:37 +0200 Subject: [PATCH] Add test case --- tests/grid/affine_cell_approximation.cc | 115 ++++++++++++++++++++ tests/grid/affine_cell_approximation.output | 46 ++++++++ 2 files changed, 161 insertions(+) create mode 100644 tests/grid/affine_cell_approximation.cc create mode 100644 tests/grid/affine_cell_approximation.output diff --git a/tests/grid/affine_cell_approximation.cc b/tests/grid/affine_cell_approximation.cc new file mode 100644 index 0000000000..5679b9f532 --- /dev/null +++ b/tests/grid/affine_cell_approximation.cc @@ -0,0 +1,115 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2020 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. +// +// --------------------------------------------------------------------- + + +// Check GridTools::affine_cell_approximation + +#include +#include +#include +#include + +#include "../tests.h" + + +template +void +do_test(const Triangulation &tria) +{ + for (const auto &cell : tria.cell_iterators()) + { + std::array, GeometryInfo::vertices_per_cell> + vertices; + for (const unsigned int v : cell->vertex_indices()) + vertices[v] = cell->vertex(v); + deallog << "Cell " << cell->id() << " with center " << cell->center() + << ": A = ["; + const auto A = + GridTools::affine_cell_approximation(vertices).first; + for (unsigned int d = 0; d < spacedim; ++d) + { + for (unsigned int e = 0; e < dim; ++e) + deallog << A[d][e] << (e < dim - 1 ? " " : ""); + deallog << (d < spacedim - 1 ? ", " : ""); + } + deallog + << "] b = " + << GridTools::affine_cell_approximation(vertices).second + << std::endl; + } +} + + + +template +void +test1() +{ + Triangulation tria; + GridGenerator::hyper_cube(tria, -1, 1); + tria.refine_global(1); + do_test(tria); +} + + + +template +void +test2() +{ + Triangulation tria; + GridGenerator::hyper_ball(tria); + do_test(tria); +} + + + +template +void +test3() +{ + Triangulation triangulation; + GridIn grid_in; + grid_in.attach_triangulation(triangulation); + if (dim == 1) + { + std::ifstream fname(SOURCE_DIR "/../codim_one/grids/circle_1.inp"); + grid_in.read_ucd(fname); + } + else + { + std::ifstream fname(SOURCE_DIR "/../codim_one/grids/sphere_0.inp"); + grid_in.read_ucd(fname); + } + + do_test(triangulation); +} + + +int +main() +{ + initlog(); + + test1<1>(); + test1<2>(); + test1<3>(); + + test2<2>(); + test2<3>(); + + test3<1, 2>(); + test3<2, 3>(); +} diff --git a/tests/grid/affine_cell_approximation.output b/tests/grid/affine_cell_approximation.output new file mode 100644 index 0000000000..cd5e11fffd --- /dev/null +++ b/tests/grid/affine_cell_approximation.output @@ -0,0 +1,46 @@ + +DEAL::Cell 0_0: with center 0.00000: A = [2.00000] b = -1.00000 +DEAL::Cell 0_1:0 with center -0.500000: A = [1.00000] b = -1.00000 +DEAL::Cell 0_1:1 with center 0.500000: A = [1.00000] b = 0.00000 +DEAL::Cell 0_0: with center 0.00000 0.00000: A = [2.00000 0.00000, 0.00000 2.00000] b = -1.00000 -1.00000 +DEAL::Cell 0_1:0 with center -0.500000 -0.500000: A = [1.00000 0.00000, 0.00000 1.00000] b = -1.00000 -1.00000 +DEAL::Cell 0_1:1 with center 0.500000 -0.500000: A = [1.00000 0.00000, 0.00000 1.00000] b = 0.00000 -1.00000 +DEAL::Cell 0_1:2 with center -0.500000 0.500000: A = [1.00000 0.00000, 0.00000 1.00000] b = -1.00000 0.00000 +DEAL::Cell 0_1:3 with center 0.500000 0.500000: A = [1.00000 0.00000, 0.00000 1.00000] b = 0.00000 0.00000 +DEAL::Cell 0_0: with center 0.00000 0.00000 0.00000: A = [2.00000 0.00000 0.00000, 0.00000 2.00000 0.00000, 0.00000 0.00000 2.00000] b = -1.00000 -1.00000 -1.00000 +DEAL::Cell 0_1:0 with center -0.500000 -0.500000 -0.500000: A = [1.00000 0.00000 0.00000, 0.00000 1.00000 0.00000, 0.00000 0.00000 1.00000] b = -1.00000 -1.00000 -1.00000 +DEAL::Cell 0_1:1 with center 0.500000 -0.500000 -0.500000: A = [1.00000 0.00000 0.00000, 0.00000 1.00000 0.00000, 0.00000 0.00000 1.00000] b = 0.00000 -1.00000 -1.00000 +DEAL::Cell 0_1:2 with center -0.500000 0.500000 -0.500000: A = [1.00000 0.00000 0.00000, 0.00000 1.00000 0.00000, 0.00000 0.00000 1.00000] b = -1.00000 0.00000 -1.00000 +DEAL::Cell 0_1:3 with center 0.500000 0.500000 -0.500000: A = [1.00000 0.00000 0.00000, 0.00000 1.00000 0.00000, 0.00000 0.00000 1.00000] b = 0.00000 0.00000 -1.00000 +DEAL::Cell 0_1:4 with center -0.500000 -0.500000 0.500000: A = [1.00000 0.00000 0.00000, 0.00000 1.00000 0.00000, 0.00000 0.00000 1.00000] b = -1.00000 -1.00000 0.00000 +DEAL::Cell 0_1:5 with center 0.500000 -0.500000 0.500000: A = [1.00000 0.00000 0.00000, 0.00000 1.00000 0.00000, 0.00000 0.00000 1.00000] b = 0.00000 -1.00000 0.00000 +DEAL::Cell 0_1:6 with center -0.500000 0.500000 0.500000: A = [1.00000 0.00000 0.00000, 0.00000 1.00000 0.00000, 0.00000 0.00000 1.00000] b = -1.00000 0.00000 0.00000 +DEAL::Cell 0_1:7 with center 0.500000 0.500000 0.500000: A = [1.00000 0.00000 0.00000, 0.00000 1.00000 0.00000, 0.00000 0.00000 1.00000] b = 0.00000 0.00000 0.00000 +DEAL::Cell 0_0: with center 0.00000 -0.500000: A = [1.00000 0.00000, 0.00000 0.414214] b = -0.500000 -0.707107 +DEAL::Cell 1_0: with center -0.500000 -1.38778e-17: A = [0.414214 2.77556e-17, 0.00000 1.00000] b = -0.707107 -0.500000 +DEAL::Cell 2_0: with center 0.00000 0.00000: A = [0.585786 0.00000, 0.00000 0.585786] b = -0.292893 -0.292893 +DEAL::Cell 3_0: with center 0.500000 0.00000: A = [0.00000 -0.414214, 1.00000 0.00000] b = 0.707107 -0.500000 +DEAL::Cell 4_0: with center -1.38778e-17 0.500000: A = [0.00000 1.00000, -0.414214 -2.77556e-17] b = -0.500000 0.707107 +DEAL::Cell 0_0: with center 0.00000 0.00000 -6.93889e-18: A = [0.422650 0.00000 0.00000, 0.00000 0.422650 0.00000, 0.00000 0.00000 0.422650] b = -0.211325 -0.211325 -0.211325 +DEAL::Cell 1_0: with center 0.00000 0.00000 -0.394338: A = [0.788675 0.00000 0.00000, 0.00000 0.788675 0.00000, 0.00000 0.00000 0.366025] b = -0.394338 -0.394338 -0.577350 +DEAL::Cell 2_0: with center 0.394338 0.00000 2.08167e-17: A = [0.00000 -0.366025 4.16334e-17, 0.788675 0.00000 0.00000, 0.00000 1.38778e-17 0.788675] b = 0.577350 -0.394338 -0.394338 +DEAL::Cell 3_0: with center 0.00000 2.08167e-17 0.394338: A = [0.788675 0.00000 0.00000, 0.00000 1.38778e-17 0.788675, 0.00000 -0.366025 4.16334e-17] b = -0.394338 -0.394338 0.577350 +DEAL::Cell 4_0: with center -0.394338 3.46945e-18 1.73472e-17: A = [0.366025 -6.93889e-18 -3.46945e-17, 6.93889e-18 0.788675 6.93889e-18, 6.93889e-18 6.93889e-18 0.788675] b = -0.577350 -0.394338 -0.394338 +DEAL::Cell 5_0: with center 0.00000 -0.394338 2.08167e-17: A = [0.788675 0.00000 0.00000, 0.00000 0.366025 -4.16334e-17, 0.00000 1.38778e-17 0.788675] b = -0.394338 -0.577350 -0.394338 +DEAL::Cell 6_0: with center 3.46945e-18 0.394338 1.73472e-17: A = [6.93889e-18 0.788675 6.93889e-18, -0.366025 6.93889e-18 3.46945e-17, 6.93889e-18 6.93889e-18 0.788675] b = -0.394338 0.577350 -0.394338 +DEAL::Cell 0_0: with center 0.293893 0.904508: A = [0.587785, -0.190983] b = 0.00000 1.00000 +DEAL::Cell 1_0: with center 0.769421 0.559017: A = [0.363271, -0.500000] b = 0.587785 0.809017 +DEAL::Cell 2_0: with center 0.951057 0.00000: A = [0.00000, -0.618034] b = 0.951057 0.309017 +DEAL::Cell 3_0: with center 0.769421 -0.559017: A = [-0.363271, -0.500000] b = 0.951057 -0.309017 +DEAL::Cell 4_0: with center 0.293893 -0.904508: A = [-0.587785, -0.190983] b = 0.587785 -0.809017 +DEAL::Cell 5_0: with center -0.293893 -0.904508: A = [-0.587785, 0.190983] b = 0.00000 -1.00000 +DEAL::Cell 6_0: with center -0.769421 -0.559017: A = [-0.363271, 0.500000] b = -0.587785 -0.809017 +DEAL::Cell 7_0: with center -0.951057 0.00000: A = [0.00000, 0.618034] b = -0.951057 -0.309017 +DEAL::Cell 8_0: with center -0.769421 0.559017: A = [0.363271, 0.500000] b = -0.951057 0.309017 +DEAL::Cell 9_0: with center -0.293893 0.904508: A = [0.587785, 0.190983] b = -0.587785 0.809017 +DEAL::Cell 0_0: with center 0.00000 0.00000 -0.577350: A = [-1.15470 0.00000, 0.00000 1.15470, 0.00000 0.00000] b = 0.577350 -0.577350 -0.577350 +DEAL::Cell 1_0: with center 0.00000 0.00000 0.577350: A = [0.00000 -1.15470, 1.15470 0.00000, 0.00000 0.00000] b = 0.577350 -0.577350 0.577350 +DEAL::Cell 2_0: with center 0.00000 -0.577350 0.00000: A = [-1.15470 0.00000, 0.00000 0.00000, 0.00000 -1.15470] b = 0.577350 -0.577350 0.577350 +DEAL::Cell 3_0: with center 0.00000 0.577350 0.00000: A = [0.00000 -1.15470, 0.00000 0.00000, -1.15470 0.00000] b = 0.577350 0.577350 0.577350 +DEAL::Cell 4_0: with center -0.577350 0.00000 0.00000: A = [0.00000 0.00000, 1.15470 0.00000, 0.00000 -1.15470] b = -0.577350 -0.577350 0.577350 +DEAL::Cell 5_0: with center 0.577350 0.00000 0.00000: A = [0.00000 0.00000, 0.00000 1.15470, -1.15470 0.00000] b = 0.577350 -0.577350 0.577350 -- 2.39.5