From: Wolfgang Bangerth Date: Thu, 29 May 2025 13:16:33 +0000 (-0600) Subject: Centralize the places where we call P4EST_QUADRANT_INIT/P8EST_QUADRANT_INIT. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a4612cf032b067205840a60deced20035b539ae;p=dealii.git Centralize the places where we call P4EST_QUADRANT_INIT/P8EST_QUADRANT_INIT. --- diff --git a/include/deal.II/distributed/p4est_wrappers.h b/include/deal.II/distributed/p4est_wrappers.h index bdf69e8089..c7aba1df5f 100644 --- a/include/deal.II/distributed/p4est_wrappers.h +++ b/include/deal.II/distributed/p4est_wrappers.h @@ -120,11 +120,17 @@ namespace internal /** - * A structure whose explicit specializations contain pointers to the + * A structure whose explicit specializations represent the * relevant p4est_* and p8est_* functions. Using this structure, for - * example by saying functions::quadrant_compare, we can write code - * in a dimension independent way, either calling p4est_quadrant_compare - * or p8est_quadrant_compare, depending on template argument. + * example by saying functions::quadrant_compare(...), we can write + * code in a dimension independent way, either calling + * p4est_quadrant_compare or p8est_quadrant_compare, depending on template + * argument. + * + * In most cases, the members of this class are simply pointers to + * p4est_* or p8est_* functions. In one case, it's simply a static + * member function that dispatches to things p4est chooses to + * implement via a macro. */ template struct functions; @@ -144,6 +150,9 @@ namespace internal int level, std::uint64_t id); + static void + quadrant_init(types<2>::quadrant &q); + static int (&quadrant_is_equal)(const types<2>::quadrant *q1, const types<2>::quadrant *q2); @@ -345,6 +354,9 @@ namespace internal int level, std::uint64_t id); + static void + quadrant_init(types<3>::quadrant &q); + static int (&quadrant_is_equal)(const types<3>::quadrant *q1, const types<3>::quadrant *q2); diff --git a/source/distributed/p4est_wrappers.cc b/source/distributed/p4est_wrappers.cc index 773f3ec095..4c62e0857c 100644 --- a/source/distributed/p4est_wrappers.cc +++ b/source/distributed/p4est_wrappers.cc @@ -354,6 +354,12 @@ namespace internal std::uint64_t id) = p4est_quadrant_set_morton; + void + functions<2>::quadrant_init(types<2>::quadrant &q) + { + P4EST_QUADRANT_INIT(&q); + } + int (&functions<2>::quadrant_is_equal)(const types<2>::quadrant *q1, const types<2>::quadrant *q2) = p4est_quadrant_is_equal; @@ -567,6 +573,12 @@ namespace internal std::uint64_t id) = p8est_quadrant_set_morton; + void + functions<3>::quadrant_init(types<3>::quadrant &q) + { + P8EST_QUADRANT_INIT(&q); + } + int (&functions<3>::quadrant_is_equal)(const types<3>::quadrant *q1, const types<3>::quadrant *q2) = p8est_quadrant_is_equal; @@ -782,18 +794,7 @@ namespace internal for (unsigned int c = 0; c < dealii::GeometryInfo::max_children_per_cell; ++c) - switch (dim) - { - case 2: - P4EST_QUADRANT_INIT(&p4est_children[c]); - break; - case 3: - P8EST_QUADRANT_INIT(&p4est_children[c]); - break; - default: - DEAL_II_NOT_IMPLEMENTED(); - } - + functions::quadrant_init(p4est_children[c]); functions::quadrant_childrenv(&p4est_cell, p4est_children); } @@ -802,17 +803,7 @@ namespace internal void init_coarse_quadrant(typename types::quadrant &quad) { - switch (dim) - { - case 2: - P4EST_QUADRANT_INIT(&quad); - break; - case 3: - P8EST_QUADRANT_INIT(&quad); - break; - default: - DEAL_II_NOT_IMPLEMENTED(); - } + functions::quadrant_init(quad); functions::quadrant_set_morton(&quad, /*level=*/0, /*index=*/0); diff --git a/source/distributed/tria.cc b/source/distributed/tria.cc index 3712897afd..187846291d 100644 --- a/source/distributed/tria.cc +++ b/source/distributed/tria.cc @@ -463,17 +463,7 @@ namespace p4est_child[GeometryInfo::max_children_per_cell]; for (unsigned int c = 0; c < GeometryInfo::max_children_per_cell; ++c) - switch (dim) - { - case 2: - P4EST_QUADRANT_INIT(&p4est_child[c]); - break; - case 3: - P8EST_QUADRANT_INIT(&p4est_child[c]); - break; - default: - DEAL_II_NOT_IMPLEMENTED(); - } + internal::p4est::functions::quadrant_init(p4est_child[c]); internal::p4est::functions::quadrant_childrenv(&p4est_cell, @@ -531,18 +521,7 @@ namespace for (unsigned int c = 0; c < GeometryInfo::max_children_per_cell; ++c) - switch (dim) - { - case 2: - P4EST_QUADRANT_INIT(&p4est_child[c]); - break; - case 3: - P8EST_QUADRANT_INIT(&p4est_child[c]); - break; - default: - DEAL_II_NOT_IMPLEMENTED(); - } - + internal::p4est::functions::quadrant_init(p4est_child[c]); internal::p4est::functions::quadrant_childrenv(&p4est_cell, p4est_child); @@ -1353,17 +1332,7 @@ namespace p4est_child[GeometryInfo::max_children_per_cell]; for (unsigned int c = 0; c < GeometryInfo::max_children_per_cell; ++c) - switch (dim) - { - case 2: - P4EST_QUADRANT_INIT(&p4est_child[c]); - break; - case 3: - P8EST_QUADRANT_INIT(&p4est_child[c]); - break; - default: - DEAL_II_NOT_IMPLEMENTED(); - } + internal::p4est::functions::quadrant_init(p4est_child[c]); internal::p4est::functions::quadrant_childrenv(&p4est_cell, p4est_child); for (unsigned int c = 0; c < GeometryInfo::max_children_per_cell; @@ -1643,17 +1612,7 @@ namespace for (unsigned int c = 0; c < GeometryInfo::max_children_per_cell; ++c) - switch (dim) - { - case 2: - P4EST_QUADRANT_INIT(&p4est_child[c]); - break; - case 3: - P8EST_QUADRANT_INIT(&p4est_child[c]); - break; - default: - DEAL_II_NOT_IMPLEMENTED(); - } + internal::p4est::functions::quadrant_init(p4est_child[c]); dealii::internal::p4est::functions::quadrant_childrenv( &p4est_cell, p4est_child); @@ -1684,17 +1643,7 @@ namespace p4est_child[GeometryInfo::max_children_per_cell]; for (unsigned int c = 0; c < GeometryInfo::max_children_per_cell; ++c) - switch (dim) - { - case 2: - P4EST_QUADRANT_INIT(&p4est_child[c]); - break; - case 3: - P8EST_QUADRANT_INIT(&p4est_child[c]); - break; - default: - DEAL_II_NOT_IMPLEMENTED(); - } + internal::p4est::functions::quadrant_init(p4est_child[c]); dealii::internal::p4est::functions::quadrant_childrenv( &p4est_cell, p4est_child);