From: Wolfgang Bangerth Date: Tue, 2 Jun 2020 20:35:42 +0000 (-0600) Subject: Get rid of TriaObject. X-Git-Tag: v9.3.0-rc1~1479^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f553fe2392867ff80841bcbb5ced7bf783e8b00;p=dealii.git Get rid of TriaObject. TriaObject was a class that was a barely disguised ArrayView, but the class name wouldn't have told you that. It's not actually very difficult to replace it by ArrayView, which is what this patch does. In the process, rename the TriaObjects::get_object() function to TriaObjects::get_bounding_object_indices() which is both a more descriptive name of what it returns, and matches the recently introduced set_bounding_object_indices() function. --- diff --git a/include/deal.II/grid/tria_accessor.h b/include/deal.II/grid/tria_accessor.h index 82998f111b..862002957e 100644 --- a/include/deal.II/grid/tria_accessor.h +++ b/include/deal.II/grid/tria_accessor.h @@ -1629,14 +1629,15 @@ private: * denotes the indices of the vertices that bound it. And so on. */ void - set_bounding_object_indices(const std::initializer_list &o) const; + set_bounding_object_indices( + const std::initializer_list &new_indices) const; /** * The same as above but for `unsigned int`. */ void set_bounding_object_indices( - const std::initializer_list &o) const; + const std::initializer_list &new_indices) const; /** * Set the flag indicating, what line_orientation() will diff --git a/include/deal.II/grid/tria_accessor.templates.h b/include/deal.II/grid/tria_accessor.templates.h index bbd52503ee..2df91d87a1 100644 --- a/include/deal.II/grid/tria_accessor.templates.h +++ b/include/deal.II/grid/tria_accessor.templates.h @@ -525,7 +525,8 @@ namespace internal line_index(const TriaAccessor<2, dim, spacedim> &accessor, const unsigned int i) { - return accessor.objects().get_object(accessor.present_index).face(i); + return accessor.objects().get_bounding_object_indices( + accessor.present_index)[i]; } @@ -570,8 +571,7 @@ namespace internal const unsigned int i) { return accessor.tria->levels[accessor.present_level] - ->cells.get_object(accessor.present_index) - .face(i); + ->cells.get_bounding_object_indices(accessor.present_index)[i]; } @@ -1006,9 +1006,8 @@ namespace internal vertex_index(const TriaAccessor<1, dim, spacedim> &accessor, const unsigned int corner) { - return accessor.objects() - .get_object(accessor.present_index) - .face(corner); + return accessor.objects().get_bounding_object_indices( + accessor.present_index)[corner]; } diff --git a/include/deal.II/grid/tria_faces.h b/include/deal.II/grid/tria_faces.h index b89e0d54a8..7b5445b4e6 100644 --- a/include/deal.II/grid/tria_faces.h +++ b/include/deal.II/grid/tria_faces.h @@ -18,7 +18,6 @@ #include -#include #include diff --git a/include/deal.II/grid/tria_levels.h b/include/deal.II/grid/tria_levels.h index 251d3cfbaa..b5ea3b01f3 100644 --- a/include/deal.II/grid/tria_levels.h +++ b/include/deal.II/grid/tria_levels.h @@ -21,7 +21,6 @@ #include -#include #include #include diff --git a/include/deal.II/grid/tria_object.h b/include/deal.II/grid/tria_object.h deleted file mode 100644 index c7d6ed589f..0000000000 --- a/include/deal.II/grid/tria_object.h +++ /dev/null @@ -1,112 +0,0 @@ -// --------------------------------------------------------------------- -// -// Copyright (C) 1998 - 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. -// -// --------------------------------------------------------------------- - -#ifndef dealii_tria_object_h -#define dealii_tria_object_h - - -#include - -#include -#include -#include - -DEAL_II_NAMESPACE_OPEN - -namespace internal -{ - namespace TriangulationImplementation - { - /** - * View onto the current geometric object and its faces. - * - * @note The geometric objects are not saved as separate instances of - * TriaObject but in a single vector in TriaObjects. - */ - class TriaObject - { - public: - /** - * Constructor. - * - * @param faces ArrayView inside of the vector in TriaObjects. - */ - TriaObject(const ArrayView &faces) - : faces(faces) - {} - - /** - * Store the content of @p other in the vector of TriaObjects. - */ - TriaObject & - operator=(const std::initializer_list &other) - { - AssertDimension(faces.size(), other.size()); - - const std::vector other_v = other; - - for (unsigned int i = 0; i < faces.size(); ++i) - faces[i] = other_v[i]; - - return *this; - } - - /** - * The same as above but for `unsigned int`. - */ - TriaObject & - operator=(const std::initializer_list &other) - { - AssertDimension(faces.size(), other.size()); - - const std::vector other_v = other; - - for (unsigned int i = 0; i < faces.size(); ++i) - faces[i] = other_v[i]; - - return *this; - } - - /** - * Return index of the @p i-th face. - */ - int - face(const unsigned int i) const - { - return faces[i]; - } - - /** - * Set index of the @p i-th face. - */ - void - set_face(const unsigned int i, const int index) - { - faces[i] = index; - } - - private: - /** - * List of face this object is made up. - */ - const ArrayView faces; - }; - } // namespace TriangulationImplementation -} // namespace internal - - -DEAL_II_NAMESPACE_CLOSE - -#endif diff --git a/include/deal.II/grid/tria_objects.h b/include/deal.II/grid/tria_objects.h index 592224a442..982bd75a86 100644 --- a/include/deal.II/grid/tria_objects.h +++ b/include/deal.II/grid/tria_objects.h @@ -22,8 +22,6 @@ #include #include -#include - #include DEAL_II_NAMESPACE_OPEN @@ -82,10 +80,14 @@ namespace internal n_objects() const; /** - * Return a view on the @p index-th geometric object. + * Return a view on the indices of the objects that bound the @p + * index-th object stored by the current object. For example, if + * the current object stores cells, then this function returns + * the equivalent of an array containing the indices of the + * faces that bound the @p index-th cell. */ - TriaObject - get_object(const unsigned int index); + ArrayView + get_bounding_object_indices(const unsigned int index); /** * Index of the even children of an object. Since when objects are @@ -389,8 +391,8 @@ namespace internal - inline TriaObject - TriaObjects::get_object(const unsigned int index) + inline ArrayView + TriaObjects::get_bounding_object_indices(const unsigned int index) { // assume that each cell has the same number of faces @@ -405,8 +407,8 @@ namespace internal else AssertThrow(false, ExcNotImplemented()); - return { - ArrayView(cells.data() + index * faces_per_cell, faces_per_cell)}; + return ArrayView(cells.data() + index * faces_per_cell, + faces_per_cell); } diff --git a/source/grid/tria.cc b/source/grid/tria.cc index 7ee5647dba..4540facbfd 100644 --- a/source/grid/tria.cc +++ b/source/grid/tria.cc @@ -4365,17 +4365,18 @@ namespace internal for (const unsigned int q : GeometryInfo::face_indices()) { - const int index = triangulation.levels[l] - ->cells.get_object(h) - .face(q); + const int index = + triangulation.levels[l] + ->cells.get_bounding_object_indices( + h)[q]; if (index == switch_1_index) triangulation.levels[l] - ->cells.get_object(h) - .set_face(q, switch_2_index); + ->cells.get_bounding_object_indices( + h)[q] = switch_2_index; else if (index == switch_2_index) triangulation.levels[l] - ->cells.get_object(h) - .set_face(q, switch_1_index); + ->cells.get_bounding_object_indices( + h)[q] = switch_1_index; } // now we have to copy // all information of the @@ -6338,14 +6339,16 @@ namespace internal ++l) { const int this_index = - triangulation.faces->quads.get_object(q) - .face(l); + triangulation.faces->quads + .get_bounding_object_indices(q)[l]; if (this_index == old_index_0) - triangulation.faces->quads.get_object(q) - .set_face(l, new_index_0); + triangulation.faces->quads + .get_bounding_object_indices(q)[l] = + new_index_0; else if (this_index == old_index_1) - triangulation.faces->quads.get_object(q) - .set_face(l, new_index_1); + triangulation.faces->quads + .get_bounding_object_indices(q)[l] = + new_index_1; } // now we have to copy all information of // the two lines @@ -6437,16 +6440,16 @@ namespace internal { const int face_index = triangulation.levels[l] - ->cells.get_object(h) - .face(q); + ->cells.get_bounding_object_indices( + h)[q]; if (face_index == switch_1_index) triangulation.levels[l] - ->cells.get_object(h) - .set_face(q, switch_2_index); + ->cells.get_bounding_object_indices( + h)[q] = switch_2_index; else if (face_index == switch_2_index) triangulation.levels[l] - ->cells.get_object(h) - .set_face(q, switch_1_index); + ->cells.get_bounding_object_indices( + h)[q] = switch_1_index; } // now we have to copy all information of // the two quads diff --git a/source/grid/tria_accessor.cc b/source/grid/tria_accessor.cc index 8fadc24480..51a0971543 100644 --- a/source/grid/tria_accessor.cc +++ b/source/grid/tria_accessor.cc @@ -1489,9 +1489,19 @@ const unsigned int template void TriaAccessor::set_bounding_object_indices( - const std::initializer_list &object) const + const std::initializer_list &new_indices) const { - this->objects().get_object(this->present_index) = object; + const ArrayView bounding_object_index_ref = + this->objects().get_bounding_object_indices(this->present_index); + + AssertDimension(bounding_object_index_ref.size(), new_indices.size()); + + unsigned int i = 0; + for (const auto &new_index : new_indices) + { + bounding_object_index_ref[i] = new_index; + ++i; + } } @@ -1499,9 +1509,19 @@ TriaAccessor::set_bounding_object_indices( template void TriaAccessor::set_bounding_object_indices( - const std::initializer_list &object) const + const std::initializer_list &new_indices) const { - this->objects().get_object(this->present_index) = object; + const ArrayView bounding_object_index_ref = + this->objects().get_bounding_object_indices(this->present_index); + + AssertDimension(bounding_object_index_ref.size(), new_indices.size()); + + unsigned int i = 0; + for (const auto &new_index : new_indices) + { + bounding_object_index_ref[i] = new_index; + ++i; + } }