From 0891ee610cb77409ca041ebdafbcb4a75c369646 Mon Sep 17 00:00:00 2001 From: David Wells Date: Tue, 31 Dec 2024 00:49:49 -0500 Subject: [PATCH] Add ReferenceCell::max_n_lines(). --- include/deal.II/grid/reference_cell.h | 20 ++++++++++++++++++++ include/deal.II/grid/tria_accessor.h | 8 ++++---- source/grid/tria.cc | 10 ++++++---- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/include/deal.II/grid/reference_cell.h b/include/deal.II/grid/reference_cell.h index dca975c3ad..64268f40a6 100644 --- a/include/deal.II/grid/reference_cell.h +++ b/include/deal.II/grid/reference_cell.h @@ -311,6 +311,17 @@ public: unsigned int n_lines() const; + /** + * Return the maximum number of lines an object of dimension `structdim` can + * have. This is always the number of lines of a `structdim`-dimensional + * hypercube. + * + * @see ReferenceCell::max_n_faces() + */ + template + static constexpr unsigned int + max_n_lines(); + /** * Return an object that can be thought of as an array containing all * indices from zero to n_lines(). @@ -1610,6 +1621,15 @@ ReferenceCell::n_lines() const +template +inline constexpr unsigned int +ReferenceCell::max_n_lines() +{ + return GeometryInfo::lines_per_cell; +} + + + template Point ReferenceCell::vertex(const unsigned int v) const diff --git a/include/deal.II/grid/tria_accessor.h b/include/deal.II/grid/tria_accessor.h index 4808a109c7..509995fea5 100644 --- a/include/deal.II/grid/tria_accessor.h +++ b/include/deal.II/grid/tria_accessor.h @@ -5586,11 +5586,11 @@ TriaAccessor::line_orientation( else if constexpr (structdim == 2 && dim == 3) { // line orientations in 3d are stored in their own array - Assert(this->present_index * GeometryInfo<3>::lines_per_face + line < + Assert(this->present_index * ReferenceCell::max_n_lines<2>() + line < this->tria->faces->quads_line_orientations.size(), ExcInternalError()); return this->tria->faces->quads_line_orientations - [this->present_index * GeometryInfo<3>::lines_per_face + line]; + [this->present_index * ReferenceCell::max_n_lines<2>() + line]; } else if constexpr (structdim == 3 && dim == 3) { @@ -5644,11 +5644,11 @@ TriaAccessor::set_line_orientation( // We set line orientations per face, not per cell, so this only works for // faces in 3d Assert(structdim == 2, ExcNotImplemented()); - Assert(this->present_index * GeometryInfo<3>::lines_per_face + line < + Assert(this->present_index * ReferenceCell::max_n_lines<2>() + line < this->tria->faces->quads_line_orientations.size(), ExcInternalError()); this->tria->faces->quads_line_orientations - [this->present_index * GeometryInfo<3>::lines_per_face + line] = value; + [this->present_index * ReferenceCell::max_n_lines<2>() + line] = value; } } diff --git a/source/grid/tria.cc b/source/grid/tria.cc index 4aa54eb69a..2427d4017c 100644 --- a/source/grid/tria.cc +++ b/source/grid/tria.cc @@ -2070,7 +2070,7 @@ namespace internal { // reserve the field of the derived class tria_faces.quads_line_orientations.resize( - new_size * GeometryInfo<3>::lines_per_face, true); + new_size * ReferenceCell::max_n_lines<2>(), true); auto &q_is_q = tria_faces.quad_is_quadrilateral; q_is_q.reserve(new_size); @@ -3289,14 +3289,16 @@ namespace internal for (unsigned int q = 0, k = 0; q < n_quads; ++q) { // set entity type of quads - faces.set_quad_type(q, connectivity.entity_types(2)[q]); + const auto reference_cell = connectivity.entity_types(2)[q]; + faces.set_quad_type(q, reference_cell); // loop over all its lines for (unsigned int i = crs.ptr[q], j = 0; i < crs.ptr[q + 1]; ++i, ++j, ++k) { + AssertIndexRange(j, reference_cell.n_lines()); // set line index - quads_0.cells[q * GeometryInfo<3>::lines_per_face + j] = + quads_0.cells[q * ReferenceCell::max_n_lines<2>() + j] = crs.col[i]; // set line orientations @@ -3312,7 +3314,7 @@ namespace internal ReferenceCell::reversed_combined_line_orientation(), ExcInternalError()); faces.quads_line_orientations - [q * GeometryInfo<3>::lines_per_face + j] = + [q * ReferenceCell::max_n_lines<2>() + j] = combined_orientation == ReferenceCell::default_combined_face_orientation(); } -- 2.39.5