From: Julius Witte Date: Wed, 25 Sep 2019 18:17:50 +0000 (-0400) Subject: add and test MatrixFree::get_cell_level_and_index() X-Git-Tag: v9.2.0-rc1~1010^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bbf8fb99f785c43249f5a5ed5591538458076493;p=dealii.git add and test MatrixFree::get_cell_level_and_index() --- diff --git a/include/deal.II/matrix_free/matrix_free.h b/include/deal.II/matrix_free/matrix_free.h index eec8213bea..e70bdfbaaa 100644 --- a/include/deal.II/matrix_free/matrix_free.h +++ b/include/deal.II/matrix_free/matrix_free.h @@ -1455,6 +1455,15 @@ public: const unsigned int vector_number, const unsigned int dof_handler_index = 0) const; + /** + * This returns the level and index for the cell that would be + * returned by get_cell_iterator() for the same arguments @p + * macro_cell_number and @p vector_number. + */ + std::pair + get_cell_level_and_index(const unsigned int macro_cell_number, + const unsigned int vector_number) const; + /** * This returns the cell iterator in deal.II speak to a given cell in the * renumbering of this structure. This function returns an exception in case diff --git a/include/deal.II/matrix_free/matrix_free.templates.h b/include/deal.II/matrix_free/matrix_free.templates.h index 23a95f1083..75ab6f44ab 100644 --- a/include/deal.II/matrix_free/matrix_free.templates.h +++ b/include/deal.II/matrix_free/matrix_free.templates.h @@ -188,6 +188,24 @@ MatrixFree::get_cell_iterator( +template +std::pair +MatrixFree::get_cell_level_and_index( + const unsigned int macro_cell_number, + const unsigned int vector_number) const +{ + const unsigned int vectorization_length = + VectorizedArrayType::n_array_elements; + AssertIndexRange(macro_cell_number, task_info.cell_partition_data.back()); + AssertIndexRange(vector_number, n_components_filled(macro_cell_number)); + + std::pair level_index_pair = + cell_level_index[macro_cell_number * vectorization_length + vector_number]; + return level_index_pair; +} + + + template typename hp::DoFHandler::active_cell_iterator MatrixFree::get_hp_cell_iterator( diff --git a/tests/matrix_free/cell_level_and_index.cc b/tests/matrix_free/cell_level_and_index.cc new file mode 100644 index 0000000000..ac16715d5d --- /dev/null +++ b/tests/matrix_free/cell_level_and_index.cc @@ -0,0 +1,133 @@ +// --------------------------------------------------------------------- +// +// 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. +// +// --------------------------------------------------------------------- + + +// test MatrixFree::get_cell_level_and_index() + +#include + +#include +#include + +#include + +#include +#include + +#include + +#include + +#include + +#include + +#include "../tests.h" + + + +template +void +compare_indices(const MatrixFree *mf_data) +{ + const unsigned int n_batches = mf_data->n_macro_cells(); + constexpr unsigned int batch_size = VectorizedArray::n_array_elements; + for (unsigned int batch_no = 0; batch_no < n_batches; ++batch_no) + { + const unsigned int n_lanes_filled = + mf_data->n_components_filled(batch_no); + for (unsigned int lane = 0; lane < n_lanes_filled; ++lane) + { + const auto cell = mf_data->get_cell_iterator(batch_no, lane); + const auto level_index_pair = + mf_data->get_cell_level_and_index(batch_no, lane); + std::cout << "(cell->level(), cell->index) = (" << cell->level() + << ", " << cell->index() << ") " + << "versus get_cell_level_and_index() = (" + << level_index_pair.first << ", " << level_index_pair.second + << ")\n"; + AssertThrow((cell->level() == level_index_pair.first), + ExcMessage("mismatching cell levels")); + AssertThrow((cell->index() == level_index_pair.second), + ExcMessage("mismatching cell indices")); + } + } +} + + + +template +void +test(const bool adaptive_ref = true) +{ + Triangulation tria( + Triangulation::limit_level_difference_at_vertices); + GridGenerator::hyper_cube(tria, 0, 1, true); + tria.refine_global(1); + if (adaptive_ref) + { + for (auto &cell : tria.active_cell_iterators()) + if (cell->is_locally_owned()) + if (cell->center().norm() < 0.5) + cell->set_refine_flag(); + tria.execute_coarsening_and_refinement(); + for (auto &cell : tria.active_cell_iterators()) + if (cell->is_locally_owned()) + if (cell->center()[0] < 0.2) + cell->set_refine_flag(); + tria.execute_coarsening_and_refinement(); + } + else + { + tria.refine_global(1); + } + + FE_Q fe(fe_degree); + DoFHandler dof(tria); + dof.distribute_dofs(fe); + dof.distribute_mg_dofs(fe); + + AffineConstraints constraints; + constraints.close(); + const QGauss<1> quad(fe_degree + 1); + typename MatrixFree::AdditionalData additional_data; + additional_data.tasks_parallel_scheme = + MatrixFree::AdditionalData::none; + auto mf_data = std::make_shared>(); + + { + std::cout << "Compare active indices." << std::endl; + mf_data->reinit(dof, constraints, quad, additional_data); + compare_indices(mf_data.get()); + } + + { + std::cout << "Compare level indices." << std::endl; + const unsigned int level = tria.n_global_levels() - 1; + additional_data.level_mg_handler = level; + mf_data->reinit(dof, constraints, quad, additional_data); + compare_indices(mf_data.get()); + } +} + + + +int +main(int argc, char **argv) +{ + test<2, 1>(); + test<2, 1, float>(); + test<2, 1>(false); +} diff --git a/tests/matrix_free/cell_level_and_index.output b/tests/matrix_free/cell_level_and_index.output new file mode 100644 index 0000000000..089f418aeb --- /dev/null +++ b/tests/matrix_free/cell_level_and_index.output @@ -0,0 +1,86 @@ +Compare active indices. +(cell->level(), cell->index) = (3, 0) versus get_cell_level_and_index() = (3, 0) +(cell->level(), cell->index) = (3, 1) versus get_cell_level_and_index() = (3, 1) +(cell->level(), cell->index) = (3, 2) versus get_cell_level_and_index() = (3, 2) +(cell->level(), cell->index) = (3, 3) versus get_cell_level_and_index() = (3, 3) +(cell->level(), cell->index) = (2, 1) versus get_cell_level_and_index() = (2, 1) +(cell->level(), cell->index) = (3, 4) versus get_cell_level_and_index() = (3, 4) +(cell->level(), cell->index) = (3, 5) versus get_cell_level_and_index() = (3, 5) +(cell->level(), cell->index) = (3, 6) versus get_cell_level_and_index() = (3, 6) +(cell->level(), cell->index) = (3, 7) versus get_cell_level_and_index() = (3, 7) +(cell->level(), cell->index) = (2, 3) versus get_cell_level_and_index() = (2, 3) +(cell->level(), cell->index) = (1, 1) versus get_cell_level_and_index() = (1, 1) +(cell->level(), cell->index) = (2, 4) versus get_cell_level_and_index() = (2, 4) +(cell->level(), cell->index) = (2, 5) versus get_cell_level_and_index() = (2, 5) +(cell->level(), cell->index) = (2, 6) versus get_cell_level_and_index() = (2, 6) +(cell->level(), cell->index) = (2, 7) versus get_cell_level_and_index() = (2, 7) +(cell->level(), cell->index) = (1, 3) versus get_cell_level_and_index() = (1, 3) +Compare level indices. +(cell->level(), cell->index) = (3, 0) versus get_cell_level_and_index() = (3, 0) +(cell->level(), cell->index) = (3, 1) versus get_cell_level_and_index() = (3, 1) +(cell->level(), cell->index) = (3, 2) versus get_cell_level_and_index() = (3, 2) +(cell->level(), cell->index) = (3, 3) versus get_cell_level_and_index() = (3, 3) +(cell->level(), cell->index) = (3, 4) versus get_cell_level_and_index() = (3, 4) +(cell->level(), cell->index) = (3, 5) versus get_cell_level_and_index() = (3, 5) +(cell->level(), cell->index) = (3, 6) versus get_cell_level_and_index() = (3, 6) +(cell->level(), cell->index) = (3, 7) versus get_cell_level_and_index() = (3, 7) +Compare active indices. +(cell->level(), cell->index) = (3, 0) versus get_cell_level_and_index() = (3, 0) +(cell->level(), cell->index) = (3, 1) versus get_cell_level_and_index() = (3, 1) +(cell->level(), cell->index) = (3, 2) versus get_cell_level_and_index() = (3, 2) +(cell->level(), cell->index) = (3, 3) versus get_cell_level_and_index() = (3, 3) +(cell->level(), cell->index) = (2, 1) versus get_cell_level_and_index() = (2, 1) +(cell->level(), cell->index) = (3, 4) versus get_cell_level_and_index() = (3, 4) +(cell->level(), cell->index) = (3, 5) versus get_cell_level_and_index() = (3, 5) +(cell->level(), cell->index) = (3, 6) versus get_cell_level_and_index() = (3, 6) +(cell->level(), cell->index) = (3, 7) versus get_cell_level_and_index() = (3, 7) +(cell->level(), cell->index) = (2, 3) versus get_cell_level_and_index() = (2, 3) +(cell->level(), cell->index) = (1, 1) versus get_cell_level_and_index() = (1, 1) +(cell->level(), cell->index) = (2, 4) versus get_cell_level_and_index() = (2, 4) +(cell->level(), cell->index) = (2, 5) versus get_cell_level_and_index() = (2, 5) +(cell->level(), cell->index) = (2, 6) versus get_cell_level_and_index() = (2, 6) +(cell->level(), cell->index) = (2, 7) versus get_cell_level_and_index() = (2, 7) +(cell->level(), cell->index) = (1, 3) versus get_cell_level_and_index() = (1, 3) +Compare level indices. +(cell->level(), cell->index) = (3, 0) versus get_cell_level_and_index() = (3, 0) +(cell->level(), cell->index) = (3, 1) versus get_cell_level_and_index() = (3, 1) +(cell->level(), cell->index) = (3, 2) versus get_cell_level_and_index() = (3, 2) +(cell->level(), cell->index) = (3, 3) versus get_cell_level_and_index() = (3, 3) +(cell->level(), cell->index) = (3, 4) versus get_cell_level_and_index() = (3, 4) +(cell->level(), cell->index) = (3, 5) versus get_cell_level_and_index() = (3, 5) +(cell->level(), cell->index) = (3, 6) versus get_cell_level_and_index() = (3, 6) +(cell->level(), cell->index) = (3, 7) versus get_cell_level_and_index() = (3, 7) +Compare active indices. +(cell->level(), cell->index) = (2, 0) versus get_cell_level_and_index() = (2, 0) +(cell->level(), cell->index) = (2, 1) versus get_cell_level_and_index() = (2, 1) +(cell->level(), cell->index) = (2, 2) versus get_cell_level_and_index() = (2, 2) +(cell->level(), cell->index) = (2, 3) versus get_cell_level_and_index() = (2, 3) +(cell->level(), cell->index) = (2, 4) versus get_cell_level_and_index() = (2, 4) +(cell->level(), cell->index) = (2, 5) versus get_cell_level_and_index() = (2, 5) +(cell->level(), cell->index) = (2, 6) versus get_cell_level_and_index() = (2, 6) +(cell->level(), cell->index) = (2, 7) versus get_cell_level_and_index() = (2, 7) +(cell->level(), cell->index) = (2, 8) versus get_cell_level_and_index() = (2, 8) +(cell->level(), cell->index) = (2, 9) versus get_cell_level_and_index() = (2, 9) +(cell->level(), cell->index) = (2, 10) versus get_cell_level_and_index() = (2, 10) +(cell->level(), cell->index) = (2, 11) versus get_cell_level_and_index() = (2, 11) +(cell->level(), cell->index) = (2, 12) versus get_cell_level_and_index() = (2, 12) +(cell->level(), cell->index) = (2, 13) versus get_cell_level_and_index() = (2, 13) +(cell->level(), cell->index) = (2, 14) versus get_cell_level_and_index() = (2, 14) +(cell->level(), cell->index) = (2, 15) versus get_cell_level_and_index() = (2, 15) +Compare level indices. +(cell->level(), cell->index) = (2, 0) versus get_cell_level_and_index() = (2, 0) +(cell->level(), cell->index) = (2, 1) versus get_cell_level_and_index() = (2, 1) +(cell->level(), cell->index) = (2, 2) versus get_cell_level_and_index() = (2, 2) +(cell->level(), cell->index) = (2, 3) versus get_cell_level_and_index() = (2, 3) +(cell->level(), cell->index) = (2, 4) versus get_cell_level_and_index() = (2, 4) +(cell->level(), cell->index) = (2, 5) versus get_cell_level_and_index() = (2, 5) +(cell->level(), cell->index) = (2, 6) versus get_cell_level_and_index() = (2, 6) +(cell->level(), cell->index) = (2, 7) versus get_cell_level_and_index() = (2, 7) +(cell->level(), cell->index) = (2, 8) versus get_cell_level_and_index() = (2, 8) +(cell->level(), cell->index) = (2, 9) versus get_cell_level_and_index() = (2, 9) +(cell->level(), cell->index) = (2, 10) versus get_cell_level_and_index() = (2, 10) +(cell->level(), cell->index) = (2, 11) versus get_cell_level_and_index() = (2, 11) +(cell->level(), cell->index) = (2, 12) versus get_cell_level_and_index() = (2, 12) +(cell->level(), cell->index) = (2, 13) versus get_cell_level_and_index() = (2, 13) +(cell->level(), cell->index) = (2, 14) versus get_cell_level_and_index() = (2, 14) +(cell->level(), cell->index) = (2, 15) versus get_cell_level_and_index() = (2, 15)