From: Peter Munch Date: Tue, 9 Nov 2021 23:33:46 +0000 (+0100) Subject: FEValues: simplify CellIteratorBase X-Git-Tag: v9.4.0-rc1~845^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F12932%2Fhead;p=dealii.git FEValues: simplify CellIteratorBase --- diff --git a/source/fe/CMakeLists.txt b/source/fe/CMakeLists.txt index f3a9205deb..c335b309e5 100644 --- a/source/fe/CMakeLists.txt +++ b/source/fe/CMakeLists.txt @@ -129,10 +129,6 @@ SET(_inst fe_tools_interpolate.inst.in fe_tools_extrapolate.inst.in fe_trace.inst.in - fe_values.decl.1.inst.in - fe_values.decl.2.inst.in - fe_values.impl.1.inst.in - fe_values.impl.2.inst.in fe_values.inst.in fe_wedge_p.inst.in mapping_c1.inst.in diff --git a/source/fe/fe_values.cc b/source/fe/fe_values.cc index c67f21b627..0cec8de637 100644 --- a/source/fe/fe_values.cc +++ b/source/fe/fe_values.cc @@ -2595,56 +2595,41 @@ template class FEValuesBase::CellIteratorBase { public: - /** - * Destructor. Made virtual since we store only - * pointers to the base class. - */ - virtual ~CellIteratorBase() = default; - - /** - * Conversion operator to an iterator for triangulations. This - * conversion is implicit for the original iterators, since they are derived - * classes. However, since here we have kind of a parallel class hierarchy, - * we have to have a conversion operator. - */ - virtual - operator typename Triangulation::cell_iterator() const = 0; + DeclExceptionMsg( + ExcNeedsDoFHandler, + "You have previously called the FEValues::reinit function with a " + "cell iterator of type Triangulation::cell_iterator. However, " + "when you do this, you cannot call some functions in the FEValues " + "class, such as the get_function_values/gradients/hessians/third_derivatives " + "functions. If you need these functions, then you need to call " + "FEValues::reinit with an iterator type that allows to extract " + "degrees of freedom, such as DoFHandler::cell_iterator."); /** - * Return the number of degrees of freedom the DoF - * handler object has to which the iterator belongs to. + * Constructor. */ - virtual types::global_dof_index - n_dofs_for_dof_handler() const = 0; - -#include "fe_values.decl.1.inst" + template + CellIteratorBase( + const TriaIterator> &cell) + : cell(cell) + , dof_handler(&cell->get_dof_handler()) + , level_dof_access(lda) + {} /** - * Call @p get_interpolated_dof_values of the iterator with the - * given arguments. + * Constructor. */ - virtual void - get_interpolated_dof_values(const IndexSet & in, - Vector &out) const = 0; -}; - -/* --- classes derived from FEValuesBase::CellIteratorBase --- */ - + CellIteratorBase( + const typename Triangulation::cell_iterator &cell) + : cell(cell) + , dof_handler(nullptr) + , level_dof_access(false) + {} -/** - * Implementation of derived classes of the CellIteratorBase - * interface. See there for a description of the use of these classes. - */ -template -template -class FEValuesBase::CellIterator - : public FEValuesBase::CellIteratorBase -{ -public: /** - * Constructor. Take an iterator and store it in this class. + * Destructor. */ - CellIterator(const CI &cell); + virtual ~CellIteratorBase() = default; /** * Conversion operator to an iterator for triangulations. This @@ -2652,215 +2637,74 @@ public: * classes. However, since here we have kind of a parallel class hierarchy, * we have to have a conversion operator. */ - virtual operator typename Triangulation::cell_iterator() - const override; - - /** - * Return the number of degrees of freedom the DoF handler object has to - * which the iterator belongs to. - */ - virtual types::global_dof_index - n_dofs_for_dof_handler() const override; - -#include "fe_values.decl.2.inst" - - /** - * Call @p get_interpolated_dof_values - * of the iterator with the given arguments. - */ - virtual void - get_interpolated_dof_values(const IndexSet & in, - Vector &out) const override; - -private: - /** - * Copy of the iterator which we use in this object. - */ - const CI cell; -}; - - -/** - * Implementation of a derived class of the CellIteratorBase - * interface. See there for a description of the use of - * these classes. - * - * This class is basically a specialization of the general template for - * iterators into Triangulation objects (but since C++ does not allow something - * like this for nested classes, it runs under a separate name). Since these do - * not implement the interface that we would like to call, the functions of this - * class cannot be implemented meaningfully. However, most functions of the - * FEValues class do not make any use of degrees of freedom at all, so it should - * be possible to call FEValues::reinit() with a tria iterator only; this class - * makes this possible, but whenever one of the functions of FEValues tries to - * call any of the functions of this class, an exception will be raised - * reminding the user that if they want to use these features, then the FEValues - * object has to be reinitialized with a cell iterator that allows to extract - * degree of freedom information. - */ -template -class FEValuesBase::TriaCellIterator - : public FEValuesBase::CellIteratorBase -{ -public: - /** - * Constructor. Take an iterator and store it in this class. - */ - TriaCellIterator( - const typename Triangulation::cell_iterator &cell); + operator typename Triangulation::cell_iterator() const + { + return cell; + } /** - * Conversion operator to an iterator for triangulations. This - * conversion is implicit for the original iterators, since they are derived - * classes. However, since here we have kind of a parallel class hierarchy, - * we have to have a conversion operator. Here, the conversion is trivial, - * from and to the same time. + * Return the number of degrees of freedom the DoF + * handler object has to which the iterator belongs to. */ - virtual operator typename Triangulation::cell_iterator() - const override; + types::global_dof_index + n_dofs_for_dof_handler() const + { + Assert(dof_handler != nullptr, ExcNeedsDoFHandler()); + return dof_handler->n_dofs(); + } /** - * Implement the respective function of the base class. Since this is not - * possible, we just raise an error. + * Call @p get_interpolated_dof_values of the iterator with the + * given arguments. */ - virtual types::global_dof_index - n_dofs_for_dof_handler() const override; - -#include "fe_values.decl.2.inst" + template + void + get_interpolated_dof_values( + const VectorType & in, + Vector &out) const + { + Assert(dof_handler != nullptr, ExcNeedsDoFHandler()); + + if (level_dof_access) + DoFCellAccessor(&cell->get_triangulation(), + cell->level(), + cell->index(), + dof_handler) + .get_interpolated_dof_values(in, out); + else + DoFCellAccessor(&cell->get_triangulation(), + cell->level(), + cell->index(), + dof_handler) + .get_interpolated_dof_values(in, out); + } /** * Call @p get_interpolated_dof_values of the iterator with the * given arguments. */ - virtual void + void get_interpolated_dof_values(const IndexSet & in, - Vector &out) const override; - -private: - /** - * Copy of the iterator which we use in this object. - */ - const typename Triangulation::cell_iterator cell; - - /** - * String to be displayed whenever one of the functions of this class is - * called. Make it a static member variable, since we show the same message - * for all member functions. - */ - static const char *const message_string; -}; - - - -/* ---------------- FEValuesBase::CellIterator --------- */ - - -template -template -FEValuesBase::CellIterator::CellIterator(const CI &cell) - : cell(cell) -{} - - - -template -template -FEValuesBase::CellIterator< - CI>::operator typename Triangulation::cell_iterator() const -{ - return cell; -} - - - -template -template -types::global_dof_index -FEValuesBase::CellIterator::n_dofs_for_dof_handler() const -{ - return cell->get_dof_handler().n_dofs(); -} - - - -#include "fe_values.impl.1.inst" - - - -template -template -void -FEValuesBase::CellIterator::get_interpolated_dof_values( - const IndexSet & in, - Vector &out) const -{ - Assert(cell->is_active(), ExcNotImplemented()); - - std::vector dof_indices( - cell->get_fe().n_dofs_per_cell()); - cell->get_dof_indices(dof_indices); - - for (unsigned int i = 0; i < cell->get_fe().n_dofs_per_cell(); ++i) - out[i] = (in.is_element(dof_indices[i]) ? 1 : 0); -} - - -/* ---------------- FEValuesBase::TriaCellIterator --------- */ - -template -const char *const FEValuesBase::TriaCellIterator::message_string = - ("You have previously called the FEValues::reinit function with a\n" - "cell iterator of type Triangulation::cell_iterator. However,\n" - "when you do this, you cannot call some functions in the FEValues\n" - "class, such as the get_function_values/gradients/hessians/third_derivatives\n" - "functions. If you need these functions, then you need to call\n" - "FEValues::reinit with an iterator type that allows to extract\n" - "degrees of freedom, such as DoFHandler::cell_iterator."); - - - -template -FEValuesBase::TriaCellIterator::TriaCellIterator( - const typename Triangulation::cell_iterator &cell) - : cell(cell) -{} - - - -template -FEValuesBase::TriaCellIterator:: -operator typename Triangulation::cell_iterator() const -{ - return cell; -} - - - -template -types::global_dof_index -FEValuesBase::TriaCellIterator::n_dofs_for_dof_handler() const -{ - Assert(false, ExcMessage(message_string)); - return 0; -} - - - -#include "fe_values.impl.2.inst" + Vector &out) const + { + Assert(dof_handler != nullptr, ExcNeedsDoFHandler()); + Assert(level_dof_access == false, ExcNotImplemented()); + const DoFCellAccessor cell_dofs( + &cell->get_triangulation(), cell->level(), cell->index(), dof_handler); + std::vector dof_indices( + cell_dofs.get_fe().n_dofs_per_cell()); + cell_dofs.get_dof_indices(dof_indices); -template -void -FEValuesBase::TriaCellIterator::get_interpolated_dof_values( - const IndexSet &, - Vector &) const -{ - Assert(false, ExcMessage(message_string)); -} - + for (unsigned int i = 0; i < cell_dofs.get_fe().n_dofs_per_cell(); ++i) + out[i] = (in.is_element(dof_indices[i]) ? 1 : 0); + } + const typename Triangulation::cell_iterator cell; + const DoFHandler * dof_handler; + const bool level_dof_access; +}; namespace internal { @@ -4498,7 +4342,7 @@ FEValues::reinit( this->check_cell_similarity(cell); reset_pointer_in_place_if_possible< - typename FEValuesBase::TriaCellIterator>(this->present_cell, + typename FEValuesBase::CellIteratorBase>(this->present_cell, cell); // this was the part of the work that is dependent on the actual @@ -4532,9 +4376,8 @@ FEValues::reinit( this->check_cell_similarity(cell); reset_pointer_in_place_if_possible< - typename FEValuesBase::template CellIterator< - TriaIterator>>>(this->present_cell, - cell); + typename FEValuesBase::CellIteratorBase>(this->present_cell, + cell); // this was the part of the work that is dependent on the actual // data type of the iterator. now pass on to the function doing @@ -4800,9 +4643,8 @@ FEFaceValues::reinit( this->maybe_invalidate_previous_present_cell(cell); reset_pointer_in_place_if_possible< - typename FEValuesBase::template CellIterator< - TriaIterator>>>(this->present_cell, - cell); + typename FEValuesBase::CellIteratorBase>(this->present_cell, + cell); // this was the part of the work that is dependent on the actual // data type of the iterator. now pass on to the function doing @@ -4835,7 +4677,7 @@ FEFaceValues::reinit( this->maybe_invalidate_previous_present_cell(cell); reset_pointer_in_place_if_possible< - typename FEValuesBase::TriaCellIterator>(this->present_cell, + typename FEValuesBase::CellIteratorBase>(this->present_cell, cell); // this was the part of the work that is dependent on the actual @@ -5048,9 +4890,8 @@ FESubfaceValues::reinit( this->maybe_invalidate_previous_present_cell(cell); reset_pointer_in_place_if_possible< - typename FEValuesBase::template CellIterator< - TriaIterator>>>(this->present_cell, - cell); + typename FEValuesBase::CellIteratorBase>(this->present_cell, + cell); // this was the part of the work that is dependent on the actual // data type of the iterator. now pass on to the function doing @@ -5096,7 +4937,7 @@ FESubfaceValues::reinit( this->maybe_invalidate_previous_present_cell(cell); reset_pointer_in_place_if_possible< - typename FEValuesBase::TriaCellIterator>(this->present_cell, + typename FEValuesBase::CellIteratorBase>(this->present_cell, cell); // this was the part of the work that is dependent on the actual diff --git a/source/fe/fe_values.decl.1.inst.in b/source/fe/fe_values.decl.1.inst.in deleted file mode 100644 index 955c949298..0000000000 --- a/source/fe/fe_values.decl.1.inst.in +++ /dev/null @@ -1,30 +0,0 @@ -// --------------------------------------------------------------------- -// -// Copyright (C) 2010 - 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. -// -// --------------------------------------------------------------------- - - - -// Declarations of member functions of FEValuesBase::CellIteratorBase -// and derived classes - -for (VEC : VECTOR_TYPES) - { - /// Call - /// @p get_interpolated_dof_values - /// of the iterator with the - /// given arguments. - virtual void get_interpolated_dof_values(const VEC & in, - Vector &out) - const = 0; - } diff --git a/source/fe/fe_values.decl.2.inst.in b/source/fe/fe_values.decl.2.inst.in deleted file mode 100644 index 389500dcc8..0000000000 --- a/source/fe/fe_values.decl.2.inst.in +++ /dev/null @@ -1,30 +0,0 @@ -// --------------------------------------------------------------------- -// -// Copyright (C) 2010 - 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. -// -// --------------------------------------------------------------------- - - - -// Declarations of member functions of FEValuesBase::CellIteratorBase -// and derived classes - -for (VEC : VECTOR_TYPES) - { - /// Call - /// @p get_interpolated_dof_values - /// of the iterator with the - /// given arguments. - virtual void get_interpolated_dof_values(const VEC & in, - Vector &out) - const override; - } diff --git a/source/fe/fe_values.impl.1.inst.in b/source/fe/fe_values.impl.1.inst.in deleted file mode 100644 index b71877d82c..0000000000 --- a/source/fe/fe_values.impl.1.inst.in +++ /dev/null @@ -1,27 +0,0 @@ -// --------------------------------------------------------------------- -// -// Copyright (C) 2010 - 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. -// -// --------------------------------------------------------------------- - - -for (VEC : VECTOR_TYPES) - { - template - template - void - FEValuesBase::CellIterator::get_interpolated_dof_values( - const VEC &in, Vector &out) const - { // - cell->get_interpolated_dof_values(in, out); - \} - } diff --git a/source/fe/fe_values.impl.2.inst.in b/source/fe/fe_values.impl.2.inst.in deleted file mode 100644 index b54481bfbb..0000000000 --- a/source/fe/fe_values.impl.2.inst.in +++ /dev/null @@ -1,26 +0,0 @@ -// --------------------------------------------------------------------- -// -// Copyright (C) 2010 - 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. -// -// --------------------------------------------------------------------- - - -for (VEC : VECTOR_TYPES) - { - template - void - FEValuesBase::TriaCellIterator::get_interpolated_dof_values( - const VEC &, Vector &) const - { // - Assert(false, ExcMessage(message_string)); - \} - } diff --git a/source/fe/fe_values.inst.in b/source/fe/fe_values.inst.in index 3c64235d74..c119bbb8b3 100644 --- a/source/fe/fe_values.inst.in +++ b/source/fe/fe_values.inst.in @@ -19,9 +19,6 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS) #if deal_II_dimension <= deal_II_space_dimension template class FEValuesBase; template class FEValues; - template class FEValuesBase:: - CellIterator< - DoFHandler::cell_iterator>; template class FEFaceValuesBase; template class FEFaceValues;