From 6e96cc182c3a39e606d89e22606fc076cdbb3b71 Mon Sep 17 00:00:00 2001 From: Marc Fehling Date: Sat, 20 Aug 2022 20:24:23 -0600 Subject: [PATCH] Change get_active_fe_indices() to return the result. --- .../changes/incompatibilities/20220820Fehling | 5 ++++ include/deal.II/dofs/dof_accessor.templates.h | 7 +----- include/deal.II/dofs/dof_handler.h | 16 ++++++++++--- include/deal.II/dofs/dof_tools.h | 4 +++- source/dofs/dof_handler.cc | 24 ++++++++++++++----- source/dofs/dof_tools.cc | 3 +-- tests/hp/get_active_fe_indices.cc | 13 ++++------ 7 files changed, 46 insertions(+), 26 deletions(-) create mode 100644 doc/news/changes/incompatibilities/20220820Fehling diff --git a/doc/news/changes/incompatibilities/20220820Fehling b/doc/news/changes/incompatibilities/20220820Fehling new file mode 100644 index 0000000000..654e48a303 --- /dev/null +++ b/doc/news/changes/incompatibilities/20220820Fehling @@ -0,0 +1,5 @@ +Changed: The function DoFHandler::get_active_fe_indices() now returns +the result vector. The previous version that writes into the argument +as well as DoFTools::get_active_fe_indices() have been deprecated. +
+(Marc Fehling, 08/20/2022) diff --git a/include/deal.II/dofs/dof_accessor.templates.h b/include/deal.II/dofs/dof_accessor.templates.h index 982da7e0a0..cbad821178 100644 --- a/include/deal.II/dofs/dof_accessor.templates.h +++ b/include/deal.II/dofs/dof_accessor.templates.h @@ -2333,15 +2333,10 @@ namespace internal accessor.dof_handler->hp_cell_future_fe_indices.size(), ExcMessage("DoFHandler not initialized")); - // TODO - using active_fe_index_type = unsigned short int; - static const active_fe_index_type invalid_active_fe_index = - static_cast(-1); - accessor.dof_handler ->hp_cell_future_fe_indices[accessor.level()] [accessor.present_index] = - invalid_active_fe_index; + DoFHandler::invalid_active_fe_index; } }; } // namespace DoFCellAccessorImplementation diff --git a/include/deal.II/dofs/dof_handler.h b/include/deal.II/dofs/dof_handler.h index 2c9417b7be..957ce517ea 100644 --- a/include/deal.II/dofs/dof_handler.h +++ b/include/deal.II/dofs/dof_handler.h @@ -573,16 +573,26 @@ public: /** * Go through the triangulation and set the active FE indices of all - * active cells to the values given in @p active_fe_indices. + * locally owned cells to the values given in @p active_fe_indices. */ void set_active_fe_indices(const std::vector &active_fe_indices); + /** + * Go through the triangulation and return a vector of active FE indices of + * all locally relevant cells. + */ + std::vector + get_active_fe_indices() const; + /** * Go through the triangulation and store the active FE indices of all - * active cells to the vector @p active_fe_indices. This vector is - * resized, if necessary. + * locally relevant cells to the vector @p active_fe_indices. This vector + * is resized, if necessary. + * + * @deprecated Use the function that returns the result vector. */ + DEAL_II_DEPRECATED_EARLY void get_active_fe_indices(std::vector &active_fe_indices) const; diff --git a/include/deal.II/dofs/dof_tools.h b/include/deal.II/dofs/dof_tools.h index 24320c89cc..7d9c983803 100644 --- a/include/deal.II/dofs/dof_tools.h +++ b/include/deal.II/dofs/dof_tools.h @@ -2133,9 +2133,11 @@ namespace DoFTools * For DoFHandler objects without hp-capabilities given as first argument, the * returned vector will consist of only zeros, indicating that all cells use * the same finite element. In hp-mode, the values may be different, though. + * + * @deprecated Use DoFHandler::get_active_fe_indices() instead. */ template - void + DEAL_II_DEPRECATED_EARLY void get_active_fe_indices(const DoFHandler &dof_handler, std::vector & active_fe_indices); diff --git a/source/dofs/dof_handler.cc b/source/dofs/dof_handler.cc index bd2b7bc949..4bff572969 100644 --- a/source/dofs/dof_handler.cc +++ b/source/dofs/dof_handler.cc @@ -1,6 +1,6 @@ // --------------------------------------------------------------------- // -// Copyright (C) 1998 - 2021 by the deal.II authors +// Copyright (C) 1998 - 2022 by the deal.II authors // // This file is part of the deal.II library. // @@ -2645,11 +2645,11 @@ DoFHandler::set_active_fe_indices( template -void -DoFHandler::get_active_fe_indices( - std::vector &active_fe_indices) const +std::vector +DoFHandler::get_active_fe_indices() const { - active_fe_indices.resize(this->get_triangulation().n_active_cells()); + std::vector active_fe_indices( + this->get_triangulation().n_active_cells(), invalid_active_fe_index); // we could try to extract the values directly, since they are // stored as protected data of this object, but for simplicity we @@ -2657,6 +2657,18 @@ DoFHandler::get_active_fe_indices( for (const auto &cell : this->active_cell_iterators()) if (!cell->is_artificial()) active_fe_indices[cell->active_cell_index()] = cell->active_fe_index(); + + return active_fe_indices; +} + + + +template +void +DoFHandler::get_active_fe_indices( + std::vector &active_fe_indices) const +{ + active_fe_indices = get_active_fe_indices(); } @@ -3026,7 +3038,7 @@ DoFHandler::prepare_for_serialization_of_active_fe_indices() // active FE indices since ownership of cells may change. // Gather all current active FE indices - get_active_fe_indices(active_fe_index_transfer->active_fe_indices); + active_fe_index_transfer->active_fe_indices = get_active_fe_indices(); // Attach to transfer object active_fe_index_transfer->cell_data_transfer->prepare_for_serialization( diff --git a/source/dofs/dof_tools.cc b/source/dofs/dof_tools.cc index 5785431fd8..2283ff3f25 100644 --- a/source/dofs/dof_tools.cc +++ b/source/dofs/dof_tools.cc @@ -1373,8 +1373,7 @@ namespace DoFTools AssertDimension(active_fe_indices.size(), dof_handler.get_triangulation().n_active_cells()); - for (const auto &cell : dof_handler.active_cell_iterators()) - active_fe_indices[cell->active_cell_index()] = cell->active_fe_index(); + active_fe_indices = dof_handler.get_active_fe_indices(); } template diff --git a/tests/hp/get_active_fe_indices.cc b/tests/hp/get_active_fe_indices.cc index e67830f868..e4319dba37 100644 --- a/tests/hp/get_active_fe_indices.cc +++ b/tests/hp/get_active_fe_indices.cc @@ -1,6 +1,6 @@ // --------------------------------------------------------------------- // -// Copyright (C) 2005 - 2020 by the deal.II authors +// Copyright (C) 2005 - 2022 by the deal.II authors // // This file is part of the deal.II library. // @@ -16,7 +16,7 @@ // distribute different finite elements randomly across the domain, then use -// DoFTools::get_active_fe_indices() +// DoFHandler::get_active_fe_indices() #include @@ -54,16 +54,13 @@ test() DoFHandler dof_handler(tria); - for (typename DoFHandler::active_cell_iterator cell = - dof_handler.begin_active(); - cell != dof_handler.end(); - ++cell) + for (const auto &cell : dof_handler.active_cell_iterators()) cell->set_active_fe_index(Testing::rand() % fe_collection.size()); dof_handler.distribute_dofs(fe_collection); - std::vector active_fe_indices(tria.n_active_cells()); - DoFTools::get_active_fe_indices(dof_handler, active_fe_indices); + std::vector active_fe_indices = + dof_handler.get_active_fe_indices(); for (unsigned int i = 0; i < tria.n_active_cells(); ++i) deallog << active_fe_indices[i] << std::endl; } -- 2.39.5