From 5ebf98f355ab940717ad2d035d0180534614fb4f Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Thu, 21 May 2026 14:32:16 +0200 Subject: [PATCH 01/47] feat: implements healpix geometry --- src/CMakeLists.txt | 2 + .../t8_cmesh_healpix/t8_cmesh_healpix.cxx | 158 ++++++++++++++++++ .../t8_cmesh_healpix/t8_cmesh_healpix.h | 26 +++ .../t8_cmesh_healpix/t8_geometry_healpix.cxx | 76 +++++++++ .../t8_cmesh_healpix/t8_geometry_healpix.hxx | 90 ++++++++++ 5 files changed, 352 insertions(+) create mode 100644 src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx create mode 100644 src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h create mode 100644 src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx create mode 100644 src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a9a421db91..a070ff5b83 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -150,6 +150,8 @@ target_sources( T8 PRIVATE t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_conn_tree_to_vertex.cxx t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_conn_vertex_to_tree.cxx t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_connectivity.cxx + t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx + t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx t8_cmesh/t8_cmesh_io/t8_cmesh_readmshfile.cxx t8_cmesh/t8_cmesh_io/t8_cmesh_save.cxx t8_cmesh/t8_cmesh_io/t8_cmesh_triangle.cxx diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx new file mode 100644 index 0000000000..59a53a2493 --- /dev/null +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -0,0 +1,158 @@ +/* + This file is part of t8code. + t8code is a C library to manage a collection (a forest) of multiple + connected adaptive space-trees of general element classes in parallel. + + Copyright (C) 2015 the developers + + t8code is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + t8code is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with t8code; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include +#include +#include + +std::vector getCoordsUpperRing(int k) { + if (k < 0 || k > 3) { + return {}; + } + + const double phi = M_PI / 2; + std::vector coords(3); + + coords[0] = cos(k * phi); + coords[1] = sin(k * phi); + coords[2] = 2.0 / 3; + + return coords; +} + +std::vector getCoordsBottomRing (int k){ + if (k < 0 || k > 3) { + return {}; + } + std::vector coords(3); + const double phi = M_PI / 2 ; + coords[0]= cos(k*phi); + coords[1]= sin(k*phi); + coords[2]= -2.0/3; + return coords; +} + + +std::vector getCoordsEquator (int k){ + if(k < 0 || k > 3) { + return {}; + } + std::vector coords(3); + const double phi = M_PI / 2 ; + const double shift = M_PI / 4; + + coords[0]= cos(k*phi - shift); + coords[1]= sin(k*phi - shift); + coords[2]= 0; + return coords; +} + +t8_cmesh_t +t8_cmesh_new_healpix (const double radius, sc_MPI_Comm comm) +{ + /* Initialization of the mesh */ + t8_cmesh_t cmesh; + t8_cmesh_init (&cmesh); + + // t8_cmesh_register_geometry (cmesh); /* Use spherical geometry. */ + + const int ntrees = 12; + const int nverts = 4; /* Number of vertices per cmesh element. */ + std::vector verts; + t8_eclass_t *all_eclasses = T8_ALLOC (t8_eclass_t, ntrees); + std::vector all_verts; + t8_cmesh_register_geometry (cmesh); + /* Defitition of the tree class. */ + for (int itree = 0; itree < ntrees; itree++) { + t8_cmesh_set_tree_class (cmesh, itree, T8_ECLASS_QUAD); + all_eclasses[itree] = T8_ECLASS_QUAD; + } + std::vector northPole = {0,0,1}; + std::vector southPole = {0,0,-1}; + int itree = 0; + // every side section has 4 quads, this builds the upper layer + // build upper section +for (int k = 0; k < 4; k++) { + verts.clear(); + + auto equator = getCoordsEquator((k+1) % 4); + auto upper0 = getCoordsUpperRing(k % 4); + auto upper1 = getCoordsUpperRing((k + 1) % 4); + + verts.insert(verts.end(), northPole.begin(), northPole.end()); + verts.insert(verts.end(), upper1.begin(), upper1.end()); + verts.insert(verts.end(), upper0.begin(), upper0.end()); + verts.insert(verts.end(), equator.begin(), equator.end()); + + all_verts.insert(std::end(all_verts), std::begin(verts), std::end(verts)); + t8_cmesh_set_tree_vertices(cmesh, itree, verts.data(), nverts); + + itree++; +} + +// build middle section +for (int k = 0; k < 4; k++) { + verts.clear(); + + auto bottom0 = getCoordsBottomRing(k % 4); + auto equator1 = getCoordsEquator((k + 1) % 4); + auto equator0 = getCoordsEquator(k % 4); + auto upper0 = getCoordsUpperRing(k % 4); + + verts.insert(verts.end(), bottom0.begin(), bottom0.end()); + verts.insert(verts.end(), equator0.begin(), equator0.end()); + verts.insert(verts.end(), equator1.begin(), equator1.end()); + verts.insert(verts.end(), upper0.begin(), upper0.end()); + + all_verts.insert(std::end(all_verts), std::begin(verts), std::end(verts)); + t8_cmesh_set_tree_vertices(cmesh, itree, verts.data(), nverts); + + itree++; +} + +// build lower section +for (int k = 0; k < 4; k++) { + verts.clear(); + + auto bottom1 = getCoordsBottomRing((k + 1) % 4); + auto bottom0 = getCoordsBottomRing(k % 4); + auto equator = getCoordsEquator((k+1) % 4); + + verts.insert(verts.end(), southPole.begin(), southPole.end()); + verts.insert(verts.end(), bottom0.begin(), bottom0.end()); + verts.insert(verts.end(), bottom1.begin(), bottom1.end()); + verts.insert(verts.end(), equator.begin(), equator.end()); + + all_verts.insert(std::end(all_verts), std::begin(verts), std::end(verts)); + t8_cmesh_set_tree_vertices(cmesh, itree, verts.data(), nverts); + + itree++; +} + + t8_cmesh_set_join_by_vertices(cmesh, 12, all_eclasses, all_verts.data(), nullptr, 0); + T8_FREE(all_eclasses); + t8_cmesh_commit (cmesh, comm); + return cmesh; +} diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h new file mode 100644 index 0000000000..dd35b4a1f2 --- /dev/null +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h @@ -0,0 +1,26 @@ +/* + This file is part of t8code. + t8code is a C library to manage a collection (a forest) of multiple + connected adaptive space-trees of general element classes in parallel. + + Copyright (C) 2015 the developers + + t8code is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + t8code is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with t8code; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include + +t8_cmesh_t +t8_cmesh_new_healpix (const double radius, sc_MPI_Comm comm); \ No newline at end of file diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx new file mode 100644 index 0000000000..2633b9590c --- /dev/null +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx @@ -0,0 +1,76 @@ +/* + This file is part of t8code. + t8code is a C library to manage a collection (a forest) of multiple + connected adaptive space-trees of general element classes in parallel. + + Copyright (C) 2015 the developers + + t8code is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + t8code is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with t8code; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include + +void +t8_geometry_healpix::t8_geom_evaluate ([[maybe_unused]] t8_cmesh_t cmesh, + [[maybe_unused]] t8_gloidx_t gtreeid, const double *ref_coords, + const size_t num_coords, double *out_coords) const +{ + const t8_gloidx_t layer = gtreeid / 4; + const t8_gloidx_t face = gtreeid % 4; + + // Calculate the offsets based on the specific layer and face of this tree. + const double offset_y = static_cast(layer) - 1.0; + const double offset_x = 2.0 * face + ((layer + 1) % 2); + + for (size_t i = 0; i < num_coords; ++i) { + size_t base_idx_2d = i * 2; + size_t base_idx_3d = i * 3; // t8code outputs 3D Cartesian coordinates (x, y, z) + + const double xi = std::clamp(ref_coords[base_idx_2d + 0], 1e-10, 1.0 - 1e-10); + const double eta = std::clamp(ref_coords[base_idx_2d + 1], 1e-10, 1.0 - 1e-10); + + // Transform reference coordinates into the HEALPix intermediate project space (dX, dY) + const double dX = offset_x + (xi - eta); + const double dY = offset_y + (xi + eta - 1.0); + + double z = 0.0; + double phi = 0.0; + + if (std::abs(dY) <= 1.0) { + z = (2.0 / 3.0) * dY; + phi = (std::numbers::pi / 4.0) * dX; + } + else if (dY > 1.0) { + z = 1.0 - (1.0 / 3.0) * std::pow(2.0 - dY, 2.0); + phi = (std::numbers::pi / 4.0) * (offset_x + (dX - offset_x) / (2.0 - dY)); + } + else { + z = -1.0 + (1.0 / 3.0) * std::pow(2.0 + dY, 2.0); + phi = (std::numbers::pi / 4.0) * (offset_x + (dX - offset_x) / (2.0 + dY)); + } + + z = std::clamp(z, -1.0, 1.0); + + // Convert Spherical coordinates (z, phi) to 3D Cartesian coordinates (x, y, z) + const double theta = std::acos(z); + const double sin_theta = std::sin(theta); + + out_coords[base_idx_3d + 0] = sin_theta * std::cos(phi); + out_coords[base_idx_3d + 1] = sin_theta * std::sin(phi); + out_coords[base_idx_3d + 2] = z; + } +} diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx new file mode 100644 index 0000000000..b31f46bd8c --- /dev/null +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx @@ -0,0 +1,90 @@ +/* + This file is part of t8code. + t8code is a C library to manage a collection (a forest) of multiple + connected adaptive space-trees of general element classes in parallel. + + Copyright (C) 2023 the developers + + t8code is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + t8code is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with t8code; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include + + +struct t8_geometry_healpix: public t8_geometry_with_vertices +{ + public: + /* Basic constructor that sets the dimension and the name. */ + t8_geometry_healpix (): t8_geometry_with_vertices ("t8_geometry_healpix") + { + std::cout<<"done1"< Date: Thu, 21 May 2026 14:39:43 +0200 Subject: [PATCH 02/47] Bugfix: removes unused radius parameter --- src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx | 2 +- src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index 59a53a2493..3ed70b773a 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -70,7 +70,7 @@ std::vector getCoordsEquator (int k){ } t8_cmesh_t -t8_cmesh_new_healpix (const double radius, sc_MPI_Comm comm) +t8_cmesh_new_healpix (sc_MPI_Comm comm) { /* Initialization of the mesh */ t8_cmesh_t cmesh; diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h index dd35b4a1f2..fe4dcd0278 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h @@ -23,4 +23,4 @@ #include t8_cmesh_t -t8_cmesh_new_healpix (const double radius, sc_MPI_Comm comm); \ No newline at end of file +t8_cmesh_new_healpix (sc_MPI_Comm comm); \ No newline at end of file From a4ad38418d884312aae9d51b063c74d696247e9b Mon Sep 17 00:00:00 2001 From: faouziH21 <109729343+faouziH21@users.noreply.github.com> Date: Tue, 2 Jun 2026 14:11:22 +0200 Subject: [PATCH 03/47] docs: Updates copyright Co-authored-by: David Knapp --- src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx | 2 +- src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h | 2 +- src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx | 2 +- src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index 3ed70b773a..ad82ad5547 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -3,7 +3,7 @@ t8code is a C library to manage a collection (a forest) of multiple connected adaptive space-trees of general element classes in parallel. - Copyright (C) 2015 the developers + Copyright (C) 2026 the developers t8code is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h index fe4dcd0278..2b21222c89 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h @@ -3,7 +3,7 @@ t8code is a C library to manage a collection (a forest) of multiple connected adaptive space-trees of general element classes in parallel. - Copyright (C) 2015 the developers + Copyright (C) 2026 the developers t8code is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx index 2633b9590c..12d5dae0b3 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx @@ -3,7 +3,7 @@ t8code is a C library to manage a collection (a forest) of multiple connected adaptive space-trees of general element classes in parallel. - Copyright (C) 2015 the developers + Copyright (C) 2026 the developers t8code is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx index b31f46bd8c..c355cf04c2 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx @@ -3,7 +3,7 @@ t8code is a C library to manage a collection (a forest) of multiple connected adaptive space-trees of general element classes in parallel. - Copyright (C) 2023 the developers + Copyright (C) 2026 the developers t8code is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -46,7 +46,7 @@ struct t8_geometry_healpix: public t8_geometry_with_vertices * \param [in] num_coords The number of points to map. * \param [out] out_coords The mapped coordinates in physical space of \a ref_coords. The length is \a num_coords * 3. * - * This routine expects an input mesh of six hexaeders arranged into a cube. + * This routine expects an input mesh of twelve quadrilaterals in a configuration of the healpix base-mesh * */ void From e3431bf8abea22d1de26e1c5659de9d12977edf0 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Tue, 2 Jun 2026 16:01:23 +0200 Subject: [PATCH 04/47] Other: applies review suggestions --- .../t8_cmesh_healpix/t8_cmesh_healpix.cxx | 62 +++++++++---------- .../t8_cmesh_healpix/t8_cmesh_healpix.h | 6 +- .../t8_cmesh_healpix/t8_geometry_healpix.cxx | 3 +- 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index ad82ad5547..3fed42f000 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -27,44 +27,44 @@ #include #include -std::vector getCoordsUpperRing(int k) { - if (k < 0 || k > 3) { +std::array getCoordsUpperRing(int side) { + if (side < 0 || side > 3) { return {}; } const double phi = M_PI / 2; - std::vector coords(3); + std::array coords; - coords[0] = cos(k * phi); - coords[1] = sin(k * phi); + coords[0] = cos(side * phi); + coords[1] = sin(side * phi); coords[2] = 2.0 / 3; return coords; } -std::vector getCoordsBottomRing (int k){ - if (k < 0 || k > 3) { +std::array getCoordsBottomRing (int side){ + if (side < 0 || side > 3) { return {}; } - std::vector coords(3); + std::array coords; const double phi = M_PI / 2 ; - coords[0]= cos(k*phi); - coords[1]= sin(k*phi); + coords[0]= cos(side*phi); + coords[1]= sin(side*phi); coords[2]= -2.0/3; return coords; } -std::vector getCoordsEquator (int k){ - if(k < 0 || k > 3) { +std::array getCoordsEquator (int side){ + if(side < 0 || side > 3) { return {}; } - std::vector coords(3); + std::array coords; const double phi = M_PI / 2 ; const double shift = M_PI / 4; - coords[0]= cos(k*phi - shift); - coords[1]= sin(k*phi - shift); + coords[0]= cos(side*phi - shift); + coords[1]= sin(side*phi - shift); coords[2]= 0; return coords; } @@ -81,7 +81,7 @@ t8_cmesh_new_healpix (sc_MPI_Comm comm) const int ntrees = 12; const int nverts = 4; /* Number of vertices per cmesh element. */ std::vector verts; - t8_eclass_t *all_eclasses = T8_ALLOC (t8_eclass_t, ntrees); + t8_eclass_t all_eclasses[ntrees]; std::vector all_verts; t8_cmesh_register_geometry (cmesh); /* Defitition of the tree class. */ @@ -89,17 +89,17 @@ t8_cmesh_new_healpix (sc_MPI_Comm comm) t8_cmesh_set_tree_class (cmesh, itree, T8_ECLASS_QUAD); all_eclasses[itree] = T8_ECLASS_QUAD; } - std::vector northPole = {0,0,1}; - std::vector southPole = {0,0,-1}; + std::array northPole = {0,0,1}; + std::array southPole = {0,0,-1}; int itree = 0; // every side section has 4 quads, this builds the upper layer // build upper section -for (int k = 0; k < 4; k++) { +for (int side = 0; side < 4; side++) { verts.clear(); - auto equator = getCoordsEquator((k+1) % 4); - auto upper0 = getCoordsUpperRing(k % 4); - auto upper1 = getCoordsUpperRing((k + 1) % 4); + auto equator = getCoordsEquator((side+1) % 4); + auto upper0 = getCoordsUpperRing(side % 4); + auto upper1 = getCoordsUpperRing((side + 1) % 4); verts.insert(verts.end(), northPole.begin(), northPole.end()); verts.insert(verts.end(), upper1.begin(), upper1.end()); @@ -113,13 +113,13 @@ for (int k = 0; k < 4; k++) { } // build middle section -for (int k = 0; k < 4; k++) { +for (int side = 0; side < 4; side++) { verts.clear(); - auto bottom0 = getCoordsBottomRing(k % 4); - auto equator1 = getCoordsEquator((k + 1) % 4); - auto equator0 = getCoordsEquator(k % 4); - auto upper0 = getCoordsUpperRing(k % 4); + auto bottom0 = getCoordsBottomRing(side % 4); + auto equator1 = getCoordsEquator((side + 1) % 4); + auto equator0 = getCoordsEquator(side % 4); + auto upper0 = getCoordsUpperRing(side % 4); verts.insert(verts.end(), bottom0.begin(), bottom0.end()); verts.insert(verts.end(), equator0.begin(), equator0.end()); @@ -133,12 +133,12 @@ for (int k = 0; k < 4; k++) { } // build lower section -for (int k = 0; k < 4; k++) { +for (int side = 0; side < 4; side++) { verts.clear(); - auto bottom1 = getCoordsBottomRing((k + 1) % 4); - auto bottom0 = getCoordsBottomRing(k % 4); - auto equator = getCoordsEquator((k+1) % 4); + auto bottom1 = getCoordsBottomRing((side + 1) % 4); + auto bottom0 = getCoordsBottomRing(side % 4); + auto equator = getCoordsEquator((side + 1) % 4); verts.insert(verts.end(), southPole.begin(), southPole.end()); verts.insert(verts.end(), bottom0.begin(), bottom0.end()); diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h index 2b21222c89..45e889a6eb 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h @@ -21,6 +21,10 @@ */ #include - +/** Creates a t8code cmesh consisting of 12 quadrilateral trees arranged + * according to the HEALPix base decomposition + * \param [in] comm MPI Communicator to use. + * \return A coarse mesh representing the HEALPix base grid. + */ t8_cmesh_t t8_cmesh_new_healpix (sc_MPI_Comm comm); \ No newline at end of file diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx index 12d5dae0b3..cb23b4d13a 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx @@ -26,9 +26,10 @@ void t8_geometry_healpix::t8_geom_evaluate ([[maybe_unused]] t8_cmesh_t cmesh, - [[maybe_unused]] t8_gloidx_t gtreeid, const double *ref_coords, + t8_gloidx_t gtreeid, const double *ref_coords, const size_t num_coords, double *out_coords) const { + // This geometry is inspired by HEALPix const t8_gloidx_t layer = gtreeid / 4; const t8_gloidx_t face = gtreeid % 4; From 20c98b2136cd81c3897f397ab5467360a1c9c9ec Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Tue, 2 Jun 2026 16:42:17 +0200 Subject: [PATCH 05/47] Other: lints all files according to indentation script --- .../t8_cmesh_healpix/t8_cmesh_healpix.cxx | 203 +++++++++--------- .../t8_cmesh_healpix/t8_cmesh_healpix.h | 2 +- .../t8_cmesh_healpix/t8_geometry_healpix.cxx | 75 ++++--- .../t8_cmesh_healpix/t8_geometry_healpix.hxx | 3 +- 4 files changed, 143 insertions(+), 140 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index 3fed42f000..ed85e27c77 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -27,132 +27,137 @@ #include #include -std::array getCoordsUpperRing(int side) { - if (side < 0 || side > 3) { - return {}; - } +std::array +getCoordsUpperRing (int side) +{ + if (side < 0 || side > 3) { + return {}; + } - const double phi = M_PI / 2; - std::array coords; + const double phi = M_PI / 2; + std::array coords; - coords[0] = cos(side * phi); - coords[1] = sin(side * phi); - coords[2] = 2.0 / 3; + coords[0] = cos (side * phi); + coords[1] = sin (side * phi); + coords[2] = 2.0 / 3; - return coords; + return coords; } -std::array getCoordsBottomRing (int side){ - if (side < 0 || side > 3) { - return {}; - } - std::array coords; - const double phi = M_PI / 2 ; - coords[0]= cos(side*phi); - coords[1]= sin(side*phi); - coords[2]= -2.0/3; - return coords; +std::array +getCoordsBottomRing (int side) +{ + if (side < 0 || side > 3) { + return {}; + } + std::array coords; + const double phi = M_PI / 2; + coords[0] = cos (side * phi); + coords[1] = sin (side * phi); + coords[2] = -2.0 / 3; + return coords; } - -std::array getCoordsEquator (int side){ - if(side < 0 || side > 3) { - return {}; - } - std::array coords; - const double phi = M_PI / 2 ; - const double shift = M_PI / 4; - - coords[0]= cos(side*phi - shift); - coords[1]= sin(side*phi - shift); - coords[2]= 0; - return coords; +std::array +getCoordsEquator (int side) +{ + if (side < 0 || side > 3) { + return {}; + } + std::array coords; + const double phi = M_PI / 2; + const double shift = M_PI / 4; + + coords[0] = cos (side * phi - shift); + coords[1] = sin (side * phi - shift); + coords[2] = 0; + return coords; } t8_cmesh_t t8_cmesh_new_healpix (sc_MPI_Comm comm) { - /* Initialization of the mesh */ - t8_cmesh_t cmesh; - t8_cmesh_init (&cmesh); - - // t8_cmesh_register_geometry (cmesh); /* Use spherical geometry. */ - - const int ntrees = 12; - const int nverts = 4; /* Number of vertices per cmesh element. */ - std::vector verts; - t8_eclass_t all_eclasses[ntrees]; - std::vector all_verts; - t8_cmesh_register_geometry (cmesh); - /* Defitition of the tree class. */ - for (int itree = 0; itree < ntrees; itree++) { - t8_cmesh_set_tree_class (cmesh, itree, T8_ECLASS_QUAD); - all_eclasses[itree] = T8_ECLASS_QUAD; - } - std::array northPole = {0,0,1}; - std::array southPole = {0,0,-1}; - int itree = 0; - // every side section has 4 quads, this builds the upper layer - // build upper section -for (int side = 0; side < 4; side++) { - verts.clear(); - - auto equator = getCoordsEquator((side+1) % 4); - auto upper0 = getCoordsUpperRing(side % 4); - auto upper1 = getCoordsUpperRing((side + 1) % 4); - - verts.insert(verts.end(), northPole.begin(), northPole.end()); - verts.insert(verts.end(), upper1.begin(), upper1.end()); - verts.insert(verts.end(), upper0.begin(), upper0.end()); - verts.insert(verts.end(), equator.begin(), equator.end()); - - all_verts.insert(std::end(all_verts), std::begin(verts), std::end(verts)); - t8_cmesh_set_tree_vertices(cmesh, itree, verts.data(), nverts); + /* Initialization of the mesh */ + t8_cmesh_t cmesh; + t8_cmesh_init (&cmesh); + + // t8_cmesh_register_geometry (cmesh); /* Use spherical geometry. */ + + const int ntrees = 12; + const int nverts = 4; /* Number of vertices per cmesh element. */ + std::vector verts; + t8_eclass_t all_eclasses[ntrees]; + std::vector all_verts; + t8_cmesh_register_geometry (cmesh); + /* Defitition of the tree class. */ + for (int itree = 0; itree < ntrees; itree++) { + t8_cmesh_set_tree_class (cmesh, itree, T8_ECLASS_QUAD); + all_eclasses[itree] = T8_ECLASS_QUAD; + } + std::array northPole = { 0, 0, 1 }; + std::array southPole = { 0, 0, -1 }; + int itree = 0; + // every side section has 4 quads, this builds the upper layer + // build upper section + for (int side = 0; side < 4; side++) { + verts.clear (); + + auto equator = getCoordsEquator ((side + 1) % 4); + auto upper0 = getCoordsUpperRing (side % 4); + auto upper1 = getCoordsUpperRing ((side + 1) % 4); + + verts.insert (verts.end (), northPole.begin (), northPole.end ()); + verts.insert (verts.end (), upper1.begin (), upper1.end ()); + verts.insert (verts.end (), upper0.begin (), upper0.end ()); + verts.insert (verts.end (), equator.begin (), equator.end ()); + + all_verts.insert (std::end (all_verts), std::begin (verts), std::end (verts)); + t8_cmesh_set_tree_vertices (cmesh, itree, verts.data (), nverts); itree++; -} + } -// build middle section -for (int side = 0; side < 4; side++) { - verts.clear(); + // build middle section + for (int side = 0; side < 4; side++) { + verts.clear (); - auto bottom0 = getCoordsBottomRing(side % 4); - auto equator1 = getCoordsEquator((side + 1) % 4); - auto equator0 = getCoordsEquator(side % 4); - auto upper0 = getCoordsUpperRing(side % 4); + auto bottom0 = getCoordsBottomRing (side % 4); + auto equator1 = getCoordsEquator ((side + 1) % 4); + auto equator0 = getCoordsEquator (side % 4); + auto upper0 = getCoordsUpperRing (side % 4); - verts.insert(verts.end(), bottom0.begin(), bottom0.end()); - verts.insert(verts.end(), equator0.begin(), equator0.end()); - verts.insert(verts.end(), equator1.begin(), equator1.end()); - verts.insert(verts.end(), upper0.begin(), upper0.end()); + verts.insert (verts.end (), bottom0.begin (), bottom0.end ()); + verts.insert (verts.end (), equator0.begin (), equator0.end ()); + verts.insert (verts.end (), equator1.begin (), equator1.end ()); + verts.insert (verts.end (), upper0.begin (), upper0.end ()); - all_verts.insert(std::end(all_verts), std::begin(verts), std::end(verts)); - t8_cmesh_set_tree_vertices(cmesh, itree, verts.data(), nverts); + all_verts.insert (std::end (all_verts), std::begin (verts), std::end (verts)); + t8_cmesh_set_tree_vertices (cmesh, itree, verts.data (), nverts); itree++; -} + } -// build lower section -for (int side = 0; side < 4; side++) { - verts.clear(); + // build lower section + for (int side = 0; side < 4; side++) { + verts.clear (); - auto bottom1 = getCoordsBottomRing((side + 1) % 4); - auto bottom0 = getCoordsBottomRing(side % 4); - auto equator = getCoordsEquator((side + 1) % 4); + auto bottom1 = getCoordsBottomRing ((side + 1) % 4); + auto bottom0 = getCoordsBottomRing (side % 4); + auto equator = getCoordsEquator ((side + 1) % 4); - verts.insert(verts.end(), southPole.begin(), southPole.end()); - verts.insert(verts.end(), bottom0.begin(), bottom0.end()); - verts.insert(verts.end(), bottom1.begin(), bottom1.end()); - verts.insert(verts.end(), equator.begin(), equator.end()); + verts.insert (verts.end (), southPole.begin (), southPole.end ()); + verts.insert (verts.end (), bottom0.begin (), bottom0.end ()); + verts.insert (verts.end (), bottom1.begin (), bottom1.end ()); + verts.insert (verts.end (), equator.begin (), equator.end ()); - all_verts.insert(std::end(all_verts), std::begin(verts), std::end(verts)); - t8_cmesh_set_tree_vertices(cmesh, itree, verts.data(), nverts); + all_verts.insert (std::end (all_verts), std::begin (verts), std::end (verts)); + t8_cmesh_set_tree_vertices (cmesh, itree, verts.data (), nverts); itree++; -} + } - t8_cmesh_set_join_by_vertices(cmesh, 12, all_eclasses, all_verts.data(), nullptr, 0); - T8_FREE(all_eclasses); + t8_cmesh_set_join_by_vertices (cmesh, 12, all_eclasses, all_verts.data (), nullptr, 0); + T8_FREE (all_eclasses); t8_cmesh_commit (cmesh, comm); return cmesh; } diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h index 45e889a6eb..55c35cd9b9 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h @@ -27,4 +27,4 @@ * \return A coarse mesh representing the HEALPix base grid. */ t8_cmesh_t -t8_cmesh_new_healpix (sc_MPI_Comm comm); \ No newline at end of file +t8_cmesh_new_healpix (sc_MPI_Comm comm); diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx index cb23b4d13a..a9d9403fd2 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx @@ -25,53 +25,52 @@ #include void -t8_geometry_healpix::t8_geom_evaluate ([[maybe_unused]] t8_cmesh_t cmesh, - t8_gloidx_t gtreeid, const double *ref_coords, +t8_geometry_healpix::t8_geom_evaluate ([[maybe_unused]] t8_cmesh_t cmesh, t8_gloidx_t gtreeid, const double *ref_coords, const size_t num_coords, double *out_coords) const { - // This geometry is inspired by HEALPix - const t8_gloidx_t layer = gtreeid / 4; - const t8_gloidx_t face = gtreeid % 4; + // This geometry is inspired by HEALPix + const t8_gloidx_t layer = gtreeid / 4; + const t8_gloidx_t face = gtreeid % 4; - // Calculate the offsets based on the specific layer and face of this tree. - const double offset_y = static_cast(layer) - 1.0; - const double offset_x = 2.0 * face + ((layer + 1) % 2); + // Calculate the offsets based on the specific layer and face of this tree. + const double offset_y = static_cast (layer) - 1.0; + const double offset_x = 2.0 * face + ((layer + 1) % 2); - for (size_t i = 0; i < num_coords; ++i) { - size_t base_idx_2d = i * 2; - size_t base_idx_3d = i * 3; // t8code outputs 3D Cartesian coordinates (x, y, z) + for (size_t i = 0; i < num_coords; ++i) { + size_t base_idx_2d = i * 2; + size_t base_idx_3d = i * 3; // t8code outputs 3D Cartesian coordinates (x, y, z) - const double xi = std::clamp(ref_coords[base_idx_2d + 0], 1e-10, 1.0 - 1e-10); - const double eta = std::clamp(ref_coords[base_idx_2d + 1], 1e-10, 1.0 - 1e-10); + const double xi = std::clamp (ref_coords[base_idx_2d + 0], 1e-10, 1.0 - 1e-10); + const double eta = std::clamp (ref_coords[base_idx_2d + 1], 1e-10, 1.0 - 1e-10); - // Transform reference coordinates into the HEALPix intermediate project space (dX, dY) - const double dX = offset_x + (xi - eta); - const double dY = offset_y + (xi + eta - 1.0); + // Transform reference coordinates into the HEALPix intermediate project space (dX, dY) + const double dX = offset_x + (xi - eta); + const double dY = offset_y + (xi + eta - 1.0); - double z = 0.0; - double phi = 0.0; + double z = 0.0; + double phi = 0.0; - if (std::abs(dY) <= 1.0) { - z = (2.0 / 3.0) * dY; - phi = (std::numbers::pi / 4.0) * dX; - } - else if (dY > 1.0) { - z = 1.0 - (1.0 / 3.0) * std::pow(2.0 - dY, 2.0); - phi = (std::numbers::pi / 4.0) * (offset_x + (dX - offset_x) / (2.0 - dY)); - } - else { - z = -1.0 + (1.0 / 3.0) * std::pow(2.0 + dY, 2.0); - phi = (std::numbers::pi / 4.0) * (offset_x + (dX - offset_x) / (2.0 + dY)); - } + if (std::abs (dY) <= 1.0) { + z = (2.0 / 3.0) * dY; + phi = (std::numbers::pi / 4.0) * dX; + } + else if (dY > 1.0) { + z = 1.0 - (1.0 / 3.0) * std::pow (2.0 - dY, 2.0); + phi = (std::numbers::pi / 4.0) * (offset_x + (dX - offset_x) / (2.0 - dY)); + } + else { + z = -1.0 + (1.0 / 3.0) * std::pow (2.0 + dY, 2.0); + phi = (std::numbers::pi / 4.0) * (offset_x + (dX - offset_x) / (2.0 + dY)); + } - z = std::clamp(z, -1.0, 1.0); + z = std::clamp (z, -1.0, 1.0); - // Convert Spherical coordinates (z, phi) to 3D Cartesian coordinates (x, y, z) - const double theta = std::acos(z); - const double sin_theta = std::sin(theta); + // Convert Spherical coordinates (z, phi) to 3D Cartesian coordinates (x, y, z) + const double theta = std::acos (z); + const double sin_theta = std::sin (theta); - out_coords[base_idx_3d + 0] = sin_theta * std::cos(phi); - out_coords[base_idx_3d + 1] = sin_theta * std::sin(phi); - out_coords[base_idx_3d + 2] = z; - } + out_coords[base_idx_3d + 0] = sin_theta * std::cos (phi); + out_coords[base_idx_3d + 1] = sin_theta * std::sin (phi); + out_coords[base_idx_3d + 2] = z; + } } diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx index c355cf04c2..f3eb3426b1 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx @@ -23,14 +23,13 @@ #include #include - struct t8_geometry_healpix: public t8_geometry_with_vertices { public: /* Basic constructor that sets the dimension and the name. */ t8_geometry_healpix (): t8_geometry_with_vertices ("t8_geometry_healpix") { - std::cout<<"done1"< Date: Thu, 25 Jun 2026 14:41:15 +0200 Subject: [PATCH 06/47] feat: adds a test suit for healpix --- test/t8_cmesh/t8_gtest_cmesh_healpix.cxx | 79 ++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 test/t8_cmesh/t8_gtest_cmesh_healpix.cxx diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx new file mode 100644 index 0000000000..023c0cc891 --- /dev/null +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx @@ -0,0 +1,79 @@ +/* + This file is part of t8code. + t8code is a C library to manage a collection (a forest) of multiple + connected adaptive space-trees of general element classes in parallel. + + Copyright (C) 2026 the developers + + t8code is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + t8code is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with t8code; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +/* This gtest checks whether a cmesh of a healpix is committed and whether the points have the same radius*/ + +#include +#include +#include +#include +#include +#include +#include +/* Test whether the healpix geometry has an equal radius all across the geometry. */ +TEST (T8GeometryHealpixTest, AllTreesAreOnUnitSphere) +{ + t8_geometry_healpix geom; + t8_cmesh_t cmesh; + t8_cmesh_init (&cmesh); + + std::random_device rd; + std::mt19937 gen (rd ()); + std::uniform_real_distribution dist (0.0, 1.0); + + // A set of 2D reference coordinates within the element + std::vector ref_coords = { + 0.0, 0.0, // Corners + 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.5, 0.5, // Center + }; + int num_gen_coords = 0; +// in addition to the basic test cases generate random coordinated to test out implementation +#if T8_TEST_LEVEL_INT >= 2 + num_gen_coords = 10; // Test level basic +#else + num_gen_coords = 20; +#endif + + for (int i = 0; i < num_gen_coords; i++) { + std::cout << i << std::endl; + double point_x = dist (gen); + double point_y = dist (gen); + ref_coords.push_back (point_x); + ref_coords.push_back (point_y); + } + + const size_t num_coords = ref_coords.size () / 2; + std::vector out_coords (num_coords * 3, 0.0); + // Loop through all 12 base trees of the HEALPix projection + for (t8_gloidx_t gtreeid = 0; gtreeid < 12; ++gtreeid) { + geom.t8_geom_evaluate (cmesh, gtreeid, ref_coords.data (), num_coords, out_coords.data ()); + + for (size_t i = 0; i < num_coords; ++i) { + std::span point (out_coords.data () + 3 * i, 3); + double distance = t8_norm (point); + // Expect distance to be 1.0 (Unit Sphere) + EXPECT_NEAR (distance, 1.0, 1e-7) << "Radius check failed at Tree ID: " << gtreeid << " for point index: " << i + << " (xi=" << ref_coords[i * 2] << ", eta=" << ref_coords[i * 2 + 1] << ")"; + } + } + t8_cmesh_destroy (&cmesh); +} From 703da180c6e58c7e6d924f7b942016bc860c46d1 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Thu, 25 Jun 2026 14:49:00 +0200 Subject: [PATCH 07/47] docs: documents t8_geometry_healpix and removes print --- src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx index f3eb3426b1..309f25c3f0 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx @@ -22,14 +22,18 @@ #include #include - +/** +* The t8_geometry_healpix struct implements a spherical geometry mapping +* based on the HEALPix (Hierarchical Equal Area isoLatitude Pixelization) +* base-mesh configuration. It inherits from t8_geometry_with_vertices and +* is designed to map planar quadrilateral faces onto a spherical surface. +*/ struct t8_geometry_healpix: public t8_geometry_with_vertices { public: /* Basic constructor that sets the dimension and the name. */ t8_geometry_healpix (): t8_geometry_with_vertices ("t8_geometry_healpix") { - std::cout << "done1" << std::endl; } /* The destructor. */ From ed7febab78a3d304ef724af460e9f80250ff0364 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Thu, 25 Jun 2026 16:21:36 +0200 Subject: [PATCH 08/47] docs: fixes spacing and typo --- test/t8_cmesh/t8_gtest_cmesh_healpix.cxx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx index 023c0cc891..6c93dcc0e7 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx @@ -42,11 +42,14 @@ TEST (T8GeometryHealpixTest, AllTreesAreOnUnitSphere) // A set of 2D reference coordinates within the element std::vector ref_coords = { - 0.0, 0.0, // Corners - 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.5, 0.5, // Center + 0.0, 0.0, // Corners + 1.0, 0.0, + 0.0, 1.0, + 1.0, 1.0, + 0.5, 0.5, // Center }; int num_gen_coords = 0; -// in addition to the basic test cases generate random coordinated to test out implementation +// in addition to the basic test cases generate random coordinates to test out implementation #if T8_TEST_LEVEL_INT >= 2 num_gen_coords = 10; // Test level basic #else From 4fa8e86cf14e69063af1f4eaa21e3b12320b22a3 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 7 Sep 2026 17:12:06 +0200 Subject: [PATCH 09/47] fix: fixes geometry and links the test to CMake --- .../t8_cmesh_healpix/t8_cmesh_healpix.cxx | 145 +++++------------- .../t8_cmesh_healpix/t8_geometry_healpix.cxx | 74 ++++----- .../t8_cmesh_healpix/t8_geometry_healpix.hxx | 2 + test/CMakeLists.txt | 7 +- 4 files changed, 80 insertions(+), 148 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index ed85e27c77..35e636c1fa 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -27,53 +27,6 @@ #include #include -std::array -getCoordsUpperRing (int side) -{ - if (side < 0 || side > 3) { - return {}; - } - - const double phi = M_PI / 2; - std::array coords; - - coords[0] = cos (side * phi); - coords[1] = sin (side * phi); - coords[2] = 2.0 / 3; - - return coords; -} - -std::array -getCoordsBottomRing (int side) -{ - if (side < 0 || side > 3) { - return {}; - } - std::array coords; - const double phi = M_PI / 2; - coords[0] = cos (side * phi); - coords[1] = sin (side * phi); - coords[2] = -2.0 / 3; - return coords; -} - -std::array -getCoordsEquator (int side) -{ - if (side < 0 || side > 3) { - return {}; - } - std::array coords; - const double phi = M_PI / 2; - const double shift = M_PI / 4; - - coords[0] = cos (side * phi - shift); - coords[1] = sin (side * phi - shift); - coords[2] = 0; - return coords; -} - t8_cmesh_t t8_cmesh_new_healpix (sc_MPI_Comm comm) { @@ -81,83 +34,55 @@ t8_cmesh_new_healpix (sc_MPI_Comm comm) t8_cmesh_t cmesh; t8_cmesh_init (&cmesh); - // t8_cmesh_register_geometry (cmesh); /* Use spherical geometry. */ - const int ntrees = 12; const int nverts = 4; /* Number of vertices per cmesh element. */ - std::vector verts; t8_eclass_t all_eclasses[ntrees]; std::vector all_verts; - t8_cmesh_register_geometry (cmesh); - /* Defitition of the tree class. */ - for (int itree = 0; itree < ntrees; itree++) { - t8_cmesh_set_tree_class (cmesh, itree, T8_ECLASS_QUAD); - all_eclasses[itree] = T8_ECLASS_QUAD; - } - std::array northPole = { 0, 0, 1 }; - std::array southPole = { 0, 0, -1 }; - int itree = 0; - // every side section has 4 quads, this builds the upper layer - // build upper section - for (int side = 0; side < 4; side++) { - verts.clear (); - - auto equator = getCoordsEquator ((side + 1) % 4); - auto upper0 = getCoordsUpperRing (side % 4); - auto upper1 = getCoordsUpperRing ((side + 1) % 4); - - verts.insert (verts.end (), northPole.begin (), northPole.end ()); - verts.insert (verts.end (), upper1.begin (), upper1.end ()); - verts.insert (verts.end (), upper0.begin (), upper0.end ()); - verts.insert (verts.end (), equator.begin (), equator.end ()); - - all_verts.insert (std::end (all_verts), std::begin (verts), std::end (verts)); - t8_cmesh_set_tree_vertices (cmesh, itree, verts.data (), nverts); - - itree++; - } + all_verts.reserve(ntrees * nverts * 3); - // build middle section - for (int side = 0; side < 4; side++) { - verts.clear (); + /* Register geometry and retain the pointer */ + t8_geometry_c *geom = t8_cmesh_register_geometry (cmesh); - auto bottom0 = getCoordsBottomRing (side % 4); - auto equator1 = getCoordsEquator ((side + 1) % 4); - auto equator0 = getCoordsEquator (side % 4); - auto upper0 = getCoordsUpperRing (side % 4); + /* Reference coordinates for the 4 corners of a quad element */ + double ref_corners[4][2] = { + {0.0, 0.0}, + {1.0, 0.0}, + {1.0, 1.0}, + {0.0, 1.0} + }; - verts.insert (verts.end (), bottom0.begin (), bottom0.end ()); - verts.insert (verts.end (), equator0.begin (), equator0.end ()); - verts.insert (verts.end (), equator1.begin (), equator1.end ()); - verts.insert (verts.end (), upper0.begin (), upper0.end ()); - - all_verts.insert (std::end (all_verts), std::begin (verts), std::end (verts)); - t8_cmesh_set_tree_vertices (cmesh, itree, verts.data (), nverts); + /* Build trees for all 3 layers (upper, middle, lower) */ + for (int itree = 0; itree < ntrees; itree++) { + const t8_gloidx_t layer = itree / 4; + const t8_gloidx_t face = itree % 4; - itree++; - } + t8_cmesh_set_tree_class (cmesh, itree, T8_ECLASS_QUAD); + all_eclasses[itree] = T8_ECLASS_QUAD; - // build lower section - for (int side = 0; side < 4; side++) { - verts.clear (); + /* Associate the custom HEALPix geometry with this tree */ + t8_cmesh_set_tree_geometry (cmesh, itree, geom); - auto bottom1 = getCoordsBottomRing ((side + 1) % 4); - auto bottom0 = getCoordsBottomRing (side % 4); - auto equator = getCoordsEquator ((side + 1) % 4); + std::vector verts; + verts.reserve (nverts * 3); - verts.insert (verts.end (), southPole.begin (), southPole.end ()); - verts.insert (verts.end (), bottom0.begin (), bottom0.end ()); - verts.insert (verts.end (), bottom1.begin (), bottom1.end ()); - verts.insert (verts.end (), equator.begin (), equator.end ()); + for (int i = 0; i < nverts; i++) { + double coord[3]; + const double xi = std::clamp (ref_corners[i][0], 1e-10, 1.0 - 1e-10); + const double eta = std::clamp (ref_corners[i][1], 1e-10, 1.0 - 1e-10); - all_verts.insert (std::end (all_verts), std::begin (verts), std::end (verts)); - t8_cmesh_set_tree_vertices (cmesh, itree, verts.data (), nverts); + t8_eval_geom_point (layer, face, xi, eta, coord); + verts.push_back (coord[0]); + verts.push_back (coord[1]); + verts.push_back (coord[2]); + } - itree++; + all_verts.insert (all_verts.end(), verts.begin(), verts.end()); + t8_cmesh_set_tree_vertices (cmesh, itree, verts.data(), nverts); } - t8_cmesh_set_join_by_vertices (cmesh, 12, all_eclasses, all_verts.data (), nullptr, 0); - T8_FREE (all_eclasses); + /* Compute face connectivity using topological vertices */ + t8_cmesh_set_join_by_vertices (cmesh, 12, all_eclasses, all_verts.data(), nullptr, 0); + t8_cmesh_commit (cmesh, comm); return cmesh; -} +} \ No newline at end of file diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx index a9d9403fd2..c4afd07271 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx @@ -24,6 +24,41 @@ #include #include +void t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, double *out_coord) +{ + const double offset_y = static_cast (layer) - 1.0; + const double offset_x = 2.0 * face + ((layer + 1) % 2); + + const double dX = offset_x + (xi - eta); + const double dY = offset_y + (xi + eta - 1.0); + + double z = 0.0; + double phi = 0.0; + + if (std::abs (dY) <= 1.0) { + z = (2.0 / 3.0) * dY; + phi = (std::numbers::pi / 4.0) * dX; + } + else if (dY > 1.0) { + z = 1.0 - (1.0 / 3.0) * std::pow (2.0 - dY, 2.0); + phi = (std::numbers::pi / 4.0) * (offset_x + (dX - offset_x) / (2.0 - dY)); + } + else { + z = -1.0 + (1.0 / 3.0) * std::pow (2.0 + dY, 2.0); + phi = (std::numbers::pi / 4.0) * (offset_x + (dX - offset_x) / (2.0 + dY)); + } + + z = std::clamp (z, -1.0, 1.0); + + // Convert Spherical coordinates (z, phi) to 3D Cartesian coordinates (x, y, z) + const double theta = std::acos (z); + const double sin_theta = std::sin (theta); + + out_coord[0] = sin_theta * std::cos (phi); + out_coord[1] = sin_theta * std::sin (phi); + out_coord[2] = z; +} + void t8_geometry_healpix::t8_geom_evaluate ([[maybe_unused]] t8_cmesh_t cmesh, t8_gloidx_t gtreeid, const double *ref_coords, const size_t num_coords, double *out_coords) const @@ -32,45 +67,14 @@ t8_geometry_healpix::t8_geom_evaluate ([[maybe_unused]] t8_cmesh_t cmesh, t8_glo const t8_gloidx_t layer = gtreeid / 4; const t8_gloidx_t face = gtreeid % 4; - // Calculate the offsets based on the specific layer and face of this tree. - const double offset_y = static_cast (layer) - 1.0; - const double offset_x = 2.0 * face + ((layer + 1) % 2); - for (size_t i = 0; i < num_coords; ++i) { - size_t base_idx_2d = i * 2; - size_t base_idx_3d = i * 3; // t8code outputs 3D Cartesian coordinates (x, y, z) + const size_t base_idx_2d = i * 2; + const size_t base_idx_3d = i * 3; // t8code outputs 3D Cartesian coordinates (x, y, z) const double xi = std::clamp (ref_coords[base_idx_2d + 0], 1e-10, 1.0 - 1e-10); const double eta = std::clamp (ref_coords[base_idx_2d + 1], 1e-10, 1.0 - 1e-10); - // Transform reference coordinates into the HEALPix intermediate project space (dX, dY) - const double dX = offset_x + (xi - eta); - const double dY = offset_y + (xi + eta - 1.0); - - double z = 0.0; - double phi = 0.0; - - if (std::abs (dY) <= 1.0) { - z = (2.0 / 3.0) * dY; - phi = (std::numbers::pi / 4.0) * dX; - } - else if (dY > 1.0) { - z = 1.0 - (1.0 / 3.0) * std::pow (2.0 - dY, 2.0); - phi = (std::numbers::pi / 4.0) * (offset_x + (dX - offset_x) / (2.0 - dY)); - } - else { - z = -1.0 + (1.0 / 3.0) * std::pow (2.0 + dY, 2.0); - phi = (std::numbers::pi / 4.0) * (offset_x + (dX - offset_x) / (2.0 + dY)); - } - - z = std::clamp (z, -1.0, 1.0); - - // Convert Spherical coordinates (z, phi) to 3D Cartesian coordinates (x, y, z) - const double theta = std::acos (z); - const double sin_theta = std::sin (theta); - - out_coords[base_idx_3d + 0] = sin_theta * std::cos (phi); - out_coords[base_idx_3d + 1] = sin_theta * std::sin (phi); - out_coords[base_idx_3d + 2] = z; + // Pass the pointer offset for 3D coordinates: out_coords + base_idx_3d + t8_eval_geom_point (layer, face, xi, eta, out_coords + base_idx_3d); } } diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx index 309f25c3f0..53c6c919e4 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx @@ -91,3 +91,5 @@ struct t8_geometry_healpix: public t8_geometry_with_vertices /* Load tree data is inherited from t8_geometry_with_vertices. */ }; + +void t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, double *out_coord); \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 55753ff638..07a34f2125 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -29,7 +29,7 @@ function( add_t8_test ) # Get the path of the first file listed in the SOURCES list and use it to determine the build directory. list (LENGTH ADD_T8_TEST_SOURCES TEST_SOURCES_LENGTH) list(GET ADD_T8_TEST_SOURCES 0 TEST_SOURCE) - + get_filename_component(TEST_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/${TEST_SOURCE}" DIRECTORY) file(RELATIVE_PATH TEST_RELATIVE_DIR "${CMAKE_SOURCE_DIR}" "${TEST_SOURCE_DIR}") set(TEST_BUILD_DIR "${CMAKE_BINARY_DIR}/${TEST_RELATIVE_DIR}") @@ -47,7 +47,7 @@ function( add_t8_test ) string( FIND ${ADD_T8_TEST_NAME} "fortran" is_fortran_file ) string( FIND ${TEST_BUILD_DIR} "mesh_handle" is_mesh_handle_file ) - if ( (${is_fortran_file} GREATER_EQUAL 0) AND T8CODE_ENABLE_MPI ) + if ( (${is_fortran_file} GREATER_EQUAL 0) AND T8CODE_ENABLE_MPI ) target_link_libraries( ${ADD_T8_TEST_NAME} PRIVATE MPI::MPI_Fortran ) endif () if ( (${is_mesh_handle_file} GREATER_EQUAL 0) ) @@ -139,6 +139,7 @@ add_t8_cpp_test( NAME t8_gtest_compute_first_element_serial SOUR add_t8_cpp_test( NAME t8_gtest_multiple_attributes_parallel SOURCES t8_cmesh/t8_gtest_multiple_attributes.cxx ) add_t8_cpp_test( NAME t8_gtest_attribute_gloidx_array_serial SOURCES t8_cmesh/t8_gtest_attribute_gloidx_array.cxx ) add_t8_cpp_test( NAME t8_gtest_cmesh_bounding_box_serial SOURCES t8_cmesh/t8_gtest_cmesh_bounding_box.cxx ) +add_t8_cpp_test( NAME t8_gtest_cmesh_healpix SOURCES t8_cmesh/t8_gtest_cmesh_healpix.cxx ) add_t8_cpp_test( NAME t8_gtest_shmem_parallel SOURCES t8_data/t8_gtest_shmem.cxx ) add_t8_cpp_test( NAME t8_gtest_data_pack_parallel SOURCES t8_data/t8_gtest_data_handler.cxx t8_data/t8_data_handler_specs.cxx) @@ -216,7 +217,7 @@ if( T8CODE_BUILD_FORTRAN_INTERFACE AND T8CODE_ENABLE_MPI ) add_t8_test( NAME t8_test_fortran_mpi_interface_cmesh_parallel SOURCES api/t8_fortran_interface/t8_test_cmesh.f90 ) add_t8_test( NAME t8_test_fortran_mpi_interface_forest_parallel SOURCES api/t8_fortran_interface/t8_test_forest.f90 ) endif() - + add_t8_cpp_test( NAME t8_gtest_vector_split_serial SOURCES t8_helper_functions/t8_gtest_vector_split.cxx ) if( T8CODE_BUILD_MESH_HANDLE ) From 8893292c5edc883cf01dbd4df4af39700b2a5f8f Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 14 Sep 2026 10:51:58 +0200 Subject: [PATCH 10/47] lint: lints the files according to t8code linting script --- .../t8_cmesh_healpix/t8_cmesh_healpix.cxx | 17 ++++++----------- .../t8_cmesh_healpix/t8_geometry_healpix.cxx | 3 ++- .../t8_cmesh_healpix/t8_geometry_healpix.hxx | 3 ++- test/t8_cmesh/t8_gtest_cmesh_healpix.cxx | 7 ++----- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index 35e636c1fa..d9d4e621c5 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -38,18 +38,13 @@ t8_cmesh_new_healpix (sc_MPI_Comm comm) const int nverts = 4; /* Number of vertices per cmesh element. */ t8_eclass_t all_eclasses[ntrees]; std::vector all_verts; - all_verts.reserve(ntrees * nverts * 3); + all_verts.reserve (ntrees * nverts * 3); /* Register geometry and retain the pointer */ t8_geometry_c *geom = t8_cmesh_register_geometry (cmesh); /* Reference coordinates for the 4 corners of a quad element */ - double ref_corners[4][2] = { - {0.0, 0.0}, - {1.0, 0.0}, - {1.0, 1.0}, - {0.0, 1.0} - }; + double ref_corners[4][2] = { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } }; /* Build trees for all 3 layers (upper, middle, lower) */ for (int itree = 0; itree < ntrees; itree++) { @@ -76,13 +71,13 @@ t8_cmesh_new_healpix (sc_MPI_Comm comm) verts.push_back (coord[2]); } - all_verts.insert (all_verts.end(), verts.begin(), verts.end()); - t8_cmesh_set_tree_vertices (cmesh, itree, verts.data(), nverts); + all_verts.insert (all_verts.end (), verts.begin (), verts.end ()); + t8_cmesh_set_tree_vertices (cmesh, itree, verts.data (), nverts); } /* Compute face connectivity using topological vertices */ - t8_cmesh_set_join_by_vertices (cmesh, 12, all_eclasses, all_verts.data(), nullptr, 0); + t8_cmesh_set_join_by_vertices (cmesh, 12, all_eclasses, all_verts.data (), nullptr, 0); t8_cmesh_commit (cmesh, comm); return cmesh; -} \ No newline at end of file +} diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx index c4afd07271..d24ed758ae 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx @@ -24,7 +24,8 @@ #include #include -void t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, double *out_coord) +void +t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, double *out_coord) { const double offset_y = static_cast (layer) - 1.0; const double offset_x = 2.0 * face + ((layer + 1) % 2); diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx index 53c6c919e4..deb04077eb 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx @@ -92,4 +92,5 @@ struct t8_geometry_healpix: public t8_geometry_with_vertices /* Load tree data is inherited from t8_geometry_with_vertices. */ }; -void t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, double *out_coord); \ No newline at end of file +void +t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, double *out_coord); diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx index 6c93dcc0e7..60bd8d369b 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx @@ -42,11 +42,8 @@ TEST (T8GeometryHealpixTest, AllTreesAreOnUnitSphere) // A set of 2D reference coordinates within the element std::vector ref_coords = { - 0.0, 0.0, // Corners - 1.0, 0.0, - 0.0, 1.0, - 1.0, 1.0, - 0.5, 0.5, // Center + 0.0, 0.0, // Corners + 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.5, 0.5, // Center }; int num_gen_coords = 0; // in addition to the basic test cases generate random coordinates to test out implementation From a29e30017a17518c1c2454a678edca417f53c472 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 14 Sep 2026 11:06:08 +0200 Subject: [PATCH 11/47] fix: attempts to fix ninja CI --- src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx index d24ed758ae..2aba93ed08 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx @@ -23,7 +23,7 @@ #include #include #include - +#include void t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, double *out_coord) { From cd9235f3c4b5c9b9e7022af0b79914ec71fb4603 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Fri, 9 Oct 2026 11:43:16 +0200 Subject: [PATCH 12/47] feat: changes the struct inheritance to t8_geometry instead of t8_geom_with_verticies --- .../t8_cmesh_healpix/t8_cmesh_healpix.cxx | 68 ++++++++++--------- .../t8_cmesh_healpix/t8_geometry_healpix.cxx | 5 ++ .../t8_cmesh_healpix/t8_geometry_healpix.hxx | 12 +++- 3 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index d9d4e621c5..52f7023417 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -27,6 +27,32 @@ #include #include + +struct t8_healpix_join { + t8_gloidx_t tree1; + int face1; + t8_gloidx_t tree2; + int face2; + int orient; +}; + +static const struct t8_healpix_join healpix_joins[24] = { + /* North Ring Connections */ + {0, 1, 1, 3, 0}, {0, 3, 3, 1, 0}, {1, 1, 2, 3, 0}, {2, 1, 3, 3, 0}, + + /* North-to-Equator Connections */ + {0, 0, 4, 2, 0}, {0, 2, 5, 3, 1}, {1, 0, 5, 2, 0}, {1, 2, 6, 3, 1}, + {2, 0, 6, 2, 0}, {2, 2, 7, 3, 1}, {3, 0, 7, 2, 0}, {3, 2, 4, 3, 1}, + + /* Equatorial Connections */ + {4, 1, 5, 0, 1}, {5, 1, 6, 0, 1}, {6, 1, 7, 0, 1}, {7, 1, 4, 0, 1}, + + /* Equator-to-South Connections */ + {4, 0, 8, 3, 1}, {5, 0, 9, 3, 1}, {6, 0, 10, 3, 1}, {7, 0, 11, 3, 1}, + + /* South Ring Connections */ + {8, 1, 9, 3, 0}, {8, 2, 11, 0, 0}, {9, 1, 10, 3, 0}, {10, 1, 11, 3, 0} +}; t8_cmesh_t t8_cmesh_new_healpix (sc_MPI_Comm comm) { @@ -35,48 +61,26 @@ t8_cmesh_new_healpix (sc_MPI_Comm comm) t8_cmesh_init (&cmesh); const int ntrees = 12; - const int nverts = 4; /* Number of vertices per cmesh element. */ - t8_eclass_t all_eclasses[ntrees]; - std::vector all_verts; - all_verts.reserve (ntrees * nverts * 3); /* Register geometry and retain the pointer */ t8_geometry_c *geom = t8_cmesh_register_geometry (cmesh); - /* Reference coordinates for the 4 corners of a quad element */ - double ref_corners[4][2] = { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } }; + t8_eclass_t all_eclasses[ntrees]; - /* Build trees for all 3 layers (upper, middle, lower) */ for (int itree = 0; itree < ntrees; itree++) { - const t8_gloidx_t layer = itree / 4; - const t8_gloidx_t face = itree % 4; t8_cmesh_set_tree_class (cmesh, itree, T8_ECLASS_QUAD); all_eclasses[itree] = T8_ECLASS_QUAD; - - /* Associate the custom HEALPix geometry with this tree */ - t8_cmesh_set_tree_geometry (cmesh, itree, geom); - - std::vector verts; - verts.reserve (nverts * 3); - - for (int i = 0; i < nverts; i++) { - double coord[3]; - const double xi = std::clamp (ref_corners[i][0], 1e-10, 1.0 - 1e-10); - const double eta = std::clamp (ref_corners[i][1], 1e-10, 1.0 - 1e-10); - - t8_eval_geom_point (layer, face, xi, eta, coord); - verts.push_back (coord[0]); - verts.push_back (coord[1]); - verts.push_back (coord[2]); - } - - all_verts.insert (all_verts.end (), verts.begin (), verts.end ()); - t8_cmesh_set_tree_vertices (cmesh, itree, verts.data (), nverts); } - - /* Compute face connectivity using topological vertices */ - t8_cmesh_set_join_by_vertices (cmesh, 12, all_eclasses, all_verts.data (), nullptr, 0); + /* Explicit O(1) manual face joining */ + for (size_t i = 0; i < 24; ++i) { + t8_cmesh_set_join (cmesh, + healpix_joins[i].tree1, + healpix_joins[i].tree2, + healpix_joins[i].face1, + healpix_joins[i].face2, + healpix_joins[i].orient); + } t8_cmesh_commit (cmesh, comm); return cmesh; diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx index 2aba93ed08..cb4fc58f32 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx @@ -79,3 +79,8 @@ t8_geometry_healpix::t8_geom_evaluate ([[maybe_unused]] t8_cmesh_t cmesh, t8_glo t8_eval_geom_point (layer, face, xi, eta, out_coords + base_idx_3d); } } +t8_geometry_type_t +t8_geometry_healpix::t8_geom_get_type () const +{ + return T8_GEOMETRY_TYPE_ZERO; // Or the specific t8_geometry_type_t enum value for HEALPix +} diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx index deb04077eb..d8e262faca 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx @@ -21,18 +21,18 @@ */ #include -#include +#include /** * The t8_geometry_healpix struct implements a spherical geometry mapping * based on the HEALPix (Hierarchical Equal Area isoLatitude Pixelization) * base-mesh configuration. It inherits from t8_geometry_with_vertices and * is designed to map planar quadrilateral faces onto a spherical surface. */ -struct t8_geometry_healpix: public t8_geometry_with_vertices +struct t8_geometry_healpix: public t8_geometry { public: /* Basic constructor that sets the dimension and the name. */ - t8_geometry_healpix (): t8_geometry_with_vertices ("t8_geometry_healpix") + t8_geometry_healpix (): t8_geometry ("t8_geometry_healpix") { } @@ -89,6 +89,12 @@ struct t8_geometry_healpix: public t8_geometry_with_vertices return true; } + /** + * Get the type of this geometry. + * \return The type. + */ + t8_geometry_type_t t8_geom_get_type () const override; + /* Load tree data is inherited from t8_geometry_with_vertices. */ }; From 3d4bb02a24f75b70872dc717a487fc78ba5e40c0 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Fri, 9 Oct 2026 13:56:46 +0200 Subject: [PATCH 13/47] fix: adheres to ninja --- src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index 52f7023417..dd8f7cf263 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -63,14 +63,10 @@ t8_cmesh_new_healpix (sc_MPI_Comm comm) const int ntrees = 12; /* Register geometry and retain the pointer */ - t8_geometry_c *geom = t8_cmesh_register_geometry (cmesh); - - t8_eclass_t all_eclasses[ntrees]; + t8_cmesh_register_geometry (cmesh); for (int itree = 0; itree < ntrees; itree++) { - t8_cmesh_set_tree_class (cmesh, itree, T8_ECLASS_QUAD); - all_eclasses[itree] = T8_ECLASS_QUAD; } /* Explicit O(1) manual face joining */ for (size_t i = 0; i < 24; ++i) { From a119c4187b10b5876f76d715a13a0a12e5920339 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Fri, 9 Oct 2026 14:32:53 +0200 Subject: [PATCH 14/47] docs: docs missing docs and lints files --- .../t8_cmesh_healpix/t8_cmesh_healpix.cxx | 42 ++++++++++++------- .../t8_cmesh_healpix/t8_geometry_healpix.cxx | 16 ++++++- .../t8_cmesh_healpix/t8_geometry_healpix.hxx | 3 +- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index dd8f7cf263..74a6d402d2 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -27,8 +27,8 @@ #include #include - -struct t8_healpix_join { +struct t8_healpix_join +{ t8_gloidx_t tree1; int face1; t8_gloidx_t tree2; @@ -38,20 +38,38 @@ struct t8_healpix_join { static const struct t8_healpix_join healpix_joins[24] = { /* North Ring Connections */ - {0, 1, 1, 3, 0}, {0, 3, 3, 1, 0}, {1, 1, 2, 3, 0}, {2, 1, 3, 3, 0}, + { 0, 1, 1, 3, 0 }, + { 0, 3, 3, 1, 0 }, + { 1, 1, 2, 3, 0 }, + { 2, 1, 3, 3, 0 }, /* North-to-Equator Connections */ - {0, 0, 4, 2, 0}, {0, 2, 5, 3, 1}, {1, 0, 5, 2, 0}, {1, 2, 6, 3, 1}, - {2, 0, 6, 2, 0}, {2, 2, 7, 3, 1}, {3, 0, 7, 2, 0}, {3, 2, 4, 3, 1}, + { 0, 0, 4, 2, 0 }, + { 0, 2, 5, 3, 1 }, + { 1, 0, 5, 2, 0 }, + { 1, 2, 6, 3, 1 }, + { 2, 0, 6, 2, 0 }, + { 2, 2, 7, 3, 1 }, + { 3, 0, 7, 2, 0 }, + { 3, 2, 4, 3, 1 }, /* Equatorial Connections */ - {4, 1, 5, 0, 1}, {5, 1, 6, 0, 1}, {6, 1, 7, 0, 1}, {7, 1, 4, 0, 1}, + { 4, 1, 5, 0, 1 }, + { 5, 1, 6, 0, 1 }, + { 6, 1, 7, 0, 1 }, + { 7, 1, 4, 0, 1 }, /* Equator-to-South Connections */ - {4, 0, 8, 3, 1}, {5, 0, 9, 3, 1}, {6, 0, 10, 3, 1}, {7, 0, 11, 3, 1}, + { 4, 0, 8, 3, 1 }, + { 5, 0, 9, 3, 1 }, + { 6, 0, 10, 3, 1 }, + { 7, 0, 11, 3, 1 }, /* South Ring Connections */ - {8, 1, 9, 3, 0}, {8, 2, 11, 0, 0}, {9, 1, 10, 3, 0}, {10, 1, 11, 3, 0} + { 8, 1, 9, 3, 0 }, + { 8, 2, 11, 0, 0 }, + { 9, 1, 10, 3, 0 }, + { 10, 1, 11, 3, 0 } }; t8_cmesh_t t8_cmesh_new_healpix (sc_MPI_Comm comm) @@ -70,12 +88,8 @@ t8_cmesh_new_healpix (sc_MPI_Comm comm) } /* Explicit O(1) manual face joining */ for (size_t i = 0; i < 24; ++i) { - t8_cmesh_set_join (cmesh, - healpix_joins[i].tree1, - healpix_joins[i].tree2, - healpix_joins[i].face1, - healpix_joins[i].face2, - healpix_joins[i].orient); + t8_cmesh_set_join (cmesh, healpix_joins[i].tree1, healpix_joins[i].tree2, healpix_joins[i].face1, + healpix_joins[i].face2, healpix_joins[i].orient); } t8_cmesh_commit (cmesh, comm); diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx index cb4fc58f32..9a40f7fd6e 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx @@ -24,6 +24,20 @@ #include #include #include + +/** + * Evaluates a point on a sphere surface geometry from mesh layer and face parameters. + * + * Maps 2D parametric reference coordinates (\p xi, \p eta) of a specific mesh element, + * identified by its \p layer and \p face indices, to 3D Cartesian coordinates on a unit sphere. + * + * @param[in] layer The layer index of the mesh element. + * @param[in] face The face index of the mesh element within the layer. + * @param[in] xi The reference coordinate in the first parametric direction (typically [0, 1]). + * @param[in] eta The reference coordinate in the second parametric direction (typically [0, 1]). + * @param[out] out_coord Pointer to an array of size 3 where the resulting (x, y, z) + * Cartesian coordinates will be stored. + */ void t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, double *out_coord) { @@ -82,5 +96,5 @@ t8_geometry_healpix::t8_geom_evaluate ([[maybe_unused]] t8_cmesh_t cmesh, t8_glo t8_geometry_type_t t8_geometry_healpix::t8_geom_get_type () const { - return T8_GEOMETRY_TYPE_ZERO; // Or the specific t8_geometry_type_t enum value for HEALPix + return T8_GEOMETRY_TYPE_ZERO; // Or the specific t8_geometry_type_t enum value for HEALPix } diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx index d8e262faca..e7b30b24cd 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx @@ -93,7 +93,8 @@ struct t8_geometry_healpix: public t8_geometry * Get the type of this geometry. * \return The type. */ - t8_geometry_type_t t8_geom_get_type () const override; + t8_geometry_type_t + t8_geom_get_type () const override; /* Load tree data is inherited from t8_geometry_with_vertices. */ }; From 9c364d3f7433ec68b3dab98d363b4e1808f0c9ec Mon Sep 17 00:00:00 2001 From: faouziH21 <109729343+faouziH21@users.noreply.github.com> Date: Fri, 9 Oct 2026 14:35:25 +0200 Subject: [PATCH 15/47] Apply batched suggestions from code review removes unnecessary variables Co-authored-by: David Knapp --- test/t8_cmesh/t8_gtest_cmesh_healpix.cxx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx index 60bd8d369b..f0f4ce93f4 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx @@ -55,10 +55,8 @@ TEST (T8GeometryHealpixTest, AllTreesAreOnUnitSphere) for (int i = 0; i < num_gen_coords; i++) { std::cout << i << std::endl; - double point_x = dist (gen); - double point_y = dist (gen); - ref_coords.push_back (point_x); - ref_coords.push_back (point_y); + ref_coords.push_back (dist(gen)); + ref_coords.push_back (dist(gen)); } const size_t num_coords = ref_coords.size () / 2; From 970752bee12bec24c5b88d21054cf1d6de073ba3 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Fri, 9 Oct 2026 15:10:44 +0200 Subject: [PATCH 16/47] lint: lints healpix test --- test/t8_cmesh/t8_gtest_cmesh_healpix.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx index f0f4ce93f4..ffd8ff9b22 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx @@ -55,8 +55,8 @@ TEST (T8GeometryHealpixTest, AllTreesAreOnUnitSphere) for (int i = 0; i < num_gen_coords; i++) { std::cout << i << std::endl; - ref_coords.push_back (dist(gen)); - ref_coords.push_back (dist(gen)); + ref_coords.push_back (dist (gen)); + ref_coords.push_back (dist (gen)); } const size_t num_coords = ref_coords.size () / 2; From 2240e1403dba72c46db47c41f231401a088824da Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Fri, 9 Oct 2026 16:15:53 +0200 Subject: [PATCH 17/47] docs: documents t8_cmesh_new_healpix --- src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index 74a6d402d2..dfb9042978 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -71,6 +71,17 @@ static const struct t8_healpix_join healpix_joins[24] = { { 9, 1, 10, 3, 0 }, { 10, 1, 11, 3, 0 } }; +/** + * Creates and initializes a new coarse mesh (cmesh) with HEALPix topology. + * + * Registers the HEALPix geometry and sets up a 12-tree base coarse mesh consisting + * of quadrilateral faces (`T8_ECLASS_QUAD`). It explicitly establishes $O(1)$ manual + * face connectivity between neighboring trees according to the HEALPix adjacency table + * before committing the mesh. + * + * @param[in] comm The MPI communicator used to manage parallel partitioning/commit. + * @return t8_cmesh_t A committed coarse mesh object containing the HEALPix base structure. + */ t8_cmesh_t t8_cmesh_new_healpix (sc_MPI_Comm comm) { From 6988c8c2f295d689f8da02a7c1b980fb910e1b28 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 19 Oct 2026 11:02:18 +0200 Subject: [PATCH 18/47] docs: adds docs and override keyword --- src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx | 1 + src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index dfb9042978..df7651fa0b 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -29,6 +29,7 @@ struct t8_healpix_join { + /*helper struct for joining healpix elements*/ t8_gloidx_t tree1; int face1; t8_gloidx_t tree2; diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx index e7b30b24cd..70bc50d359 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx @@ -54,7 +54,7 @@ struct t8_geometry_healpix: public t8_geometry */ void t8_geom_evaluate (t8_cmesh_t cmesh, t8_gloidx_t gtreeid, const double *ref_coords, const size_t num_coords, - double *out_coords) const; + double *out_coords) const override; /** * Jacobian, not implemented. @@ -67,7 +67,7 @@ struct t8_geometry_healpix: public t8_geometry void t8_geom_evaluate_jacobian ([[maybe_unused]] t8_cmesh_t cmesh, [[maybe_unused]] t8_gloidx_t gtreeid, [[maybe_unused]] const double *ref_coords, [[maybe_unused]] const size_t num_coords, - [[maybe_unused]] double *jacobian) const + [[maybe_unused]] double *jacobian) const override { SC_ABORT_NOT_REACHED (); } @@ -78,7 +78,7 @@ struct t8_geometry_healpix: public t8_geometry * \return True if the geometry is compatible with the tree. */ bool - t8_geom_check_tree_compatibility () const + t8_geom_check_tree_compatibility () const override { if (active_tree_class != T8_ECLASS_QUAD) { t8_productionf ("t8_geometry_healpix is not compatible with tree type %s\n" From 97da4ddb3d9ba5e1a0687e17af521ad7662f0b9f Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 19 Oct 2026 12:38:36 +0200 Subject: [PATCH 19/47] docs: adhere to doxygen --- src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx | 13 ++++++++++++- src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h | 1 - test/t8_cmesh/t8_gtest_cmesh_healpix.cxx | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index df7651fa0b..8688127fb1 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -27,13 +27,24 @@ #include #include +/** + * @brief Helper struct for joining healpix elements for t8_cmesh_set_join. + */ struct t8_healpix_join { - /*helper struct for joining healpix elements*/ + /** ID of tree 1 */ t8_gloidx_t tree1; + + /** Index of face 1 */ int face1; + + /** ID of tree 2 */ t8_gloidx_t tree2; + + /** Index of face 2 */ int face2; + + /** Orientation for face 1 and face 2 */ int orient; }; diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h index 55c35cd9b9..d69fc3d6bd 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h @@ -23,7 +23,6 @@ #include /** Creates a t8code cmesh consisting of 12 quadrilateral trees arranged * according to the HEALPix base decomposition - * \param [in] comm MPI Communicator to use. * \return A coarse mesh representing the HEALPix base grid. */ t8_cmesh_t diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx index ffd8ff9b22..6531543cde 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include From eb869dee7b777d8c4d5b891aa2b561a0cd10032a Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 19 Oct 2026 14:49:41 +0200 Subject: [PATCH 20/47] feat: adds a new formula correction test and renames unit sphere test --- test/CMakeLists.txt | 3 +- ..._gtest_cmesh_healpix_check_correctness.cxx | 150 ++++++++++++++++++ ...=> t8_gtest_cmesh_healpix_unit_sphere.cxx} | 0 3 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx rename test/t8_cmesh/{t8_gtest_cmesh_healpix.cxx => t8_gtest_cmesh_healpix_unit_sphere.cxx} (100%) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 79fe220cb3..d9a5794821 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -139,7 +139,8 @@ add_t8_cpp_test( NAME t8_gtest_cmesh_vertex_conn_serial SOUR add_t8_cpp_test( NAME t8_gtest_multiple_attributes_parallel SOURCES t8_cmesh/t8_gtest_multiple_attributes.cxx ) add_t8_cpp_test( NAME t8_gtest_attribute_gloidx_array_serial SOURCES t8_cmesh/t8_gtest_attribute_gloidx_array.cxx ) add_t8_cpp_test( NAME t8_gtest_cmesh_bounding_box_serial SOURCES t8_cmesh/t8_gtest_cmesh_bounding_box.cxx ) -add_t8_cpp_test( NAME t8_gtest_cmesh_healpix SOURCES t8_cmesh/t8_gtest_cmesh_healpix.cxx ) +add_t8_cpp_test( NAME t8_gtest_cmesh_healpix_unit_sphere SOURCES t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx ) +add_t8_cpp_test( NAME t8_gtest_cmesh_healpix_check_correctness SOURCES t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx ) add_t8_cpp_test( NAME t8_gtest_cmesh_boundary_conditions_serial SOURCES t8_cmesh/t8_gtest_cmesh_boundary_conditions.cxx ) add_t8_cpp_test( NAME t8_gtest_shmem_parallel SOURCES t8_data/t8_gtest_shmem.cxx ) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx new file mode 100644 index 0000000000..e500ea5333 --- /dev/null +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -0,0 +1,150 @@ +/* + This file is part of t8code. + t8code is a C library to manage a collection (a forest) of multiple + connected adaptive space-trees of general element classes in parallel. + + Copyright (C) 2026 the developers + + t8code is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + t8code is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with t8code; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include +#include +#include + +struct LocationResult { + double z; + double phi; + double sintheta; + bool have_sintheta; +}; + +LocationResult xyf2loc(double x, double y, int face, const int JRLL[], const int JPLL[]) { + double z = 0.0; + double nr = 0.0; + double sintheta = 0.0; + bool have_sintheta = false; + + double jr = static_cast(JRLL[face]) - x - y; + + if (jr < 1.0) { + nr = jr; + double tmp = (nr * nr) / 3.0; + z = 1.0 - tmp; + if (z > 0.99) { + sintheta = std::sqrt(tmp * (2.0 - tmp)); + have_sintheta = true; + } + } else if (jr > 3.0) { + nr = 4.0 - jr; + double tmp = (nr * nr) / 3.0; + z = tmp - 1.0; + if (z < -0.99) { + sintheta = std::sqrt(tmp * (2.0 - tmp)); + have_sintheta = true; + } + } else { + nr = 1.0; + z = (2.0 - jr) * 2.0 / 3.0; + } + + double tmp = static_cast(JPLL[face]) * nr + x - y; + if (tmp < 0.0) tmp += 8.0; + if (tmp >= 8.0) tmp -= 8.0; + + double phi = (std::abs(nr) < 1e-15) ? 0.0 : ((std::numbers::pi / 4.0 * tmp) / nr); + + return {z, phi, sintheta, have_sintheta}; +} + +TEST(HealpixGeometryTest, EvaluatesBatchAgainstXyf2LocReference) { + const int JRLL[12] = {2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4}; + const int JPLL[12] = {1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7}; + + std::vector test_samples = {0.0, 0.001, 0.25, 0.5, 0.75, 0.999, 1.0}; + const double tolerance = 1e-10; + t8_geometry_healpix geom; + + // Build a batch containing all combinations of test_samples for a single evaluation call + std::vector ref_coords; + for (double xi : test_samples) { + for (double eta : test_samples) { + ref_coords.push_back(xi); + ref_coords.push_back(eta); + } + } + size_t num_coords = test_samples.size() * test_samples.size(); + + // Loop through all t8code layers and faces + for (int layer = 0; layer < 3; ++layer) { + for (int face = 0; face < 4; ++face) { + // t8code Tree ID (0..11) + int gtreeid = layer * 4 + face; + + // HEALPix base face index corresponding to t8code's layer + // layer 0 (South) -> HEALPix faces 8..11 + // layer 1 (Equator) -> HEALPix faces 4..7 + // layer 2 (North) -> HEALPix faces 0..3 + int healpix_face = (2 - layer) * 4 + face; + + // Output buffers + std::vector t8_out(num_coords * 3); + + // Call the batch evaluation method provided + geom.t8_geom_evaluate(nullptr, gtreeid, ref_coords.data(), num_coords, t8_out.data()); + + // Validate each point in the batch against xyf2loc reference + for (size_t i = 0; i < num_coords; ++i) { + double xi = ref_coords[i * 2 + 0]; + double eta = ref_coords[i * 2 + 1]; + + // Clamped values used inside t8_geom_evaluate + double xi_clamped = std::clamp(xi, 1e-10, 1.0 - 1e-10); + double eta_clamped = std::clamp(eta, 1e-10, 1.0 - 1e-10); + + // Pass the 0..11 global face index to xyf2loc + LocationResult ref_loc = xyf2loc(xi_clamped, eta_clamped, healpix_face, JRLL, JPLL); + + double ref_sin_theta; + if (ref_loc.have_sintheta) { + ref_sin_theta = ref_loc.sintheta; + } else { + ref_sin_theta = std::sqrt(std::max(0.0, 1.0 - ref_loc.z * ref_loc.z)); + } + double ref_x = ref_sin_theta * std::cos(ref_loc.phi); + double ref_y = ref_sin_theta * std::sin(ref_loc.phi); + double ref_z = ref_loc.z; + + size_t idx3d = i * 3; + + // Allow a slightly relaxed tolerance near the poles where sin(theta) ~ 0 + double adaptive_tol = (std::abs(ref_z) > 0.99) ? 2e-10 : tolerance; + + EXPECT_NEAR(t8_out[idx3d + 0], ref_x, adaptive_tol) + << "Mismatch in X | Tree ID: " << gtreeid << " (Layer: " << layer << ", Face: " << face << ")" + << ", (xi, eta): (" << xi << ", " << eta << ")"; + EXPECT_NEAR(t8_out[idx3d + 1], ref_y, adaptive_tol) + << "Mismatch in Y | Tree ID: " << gtreeid << " (Layer: " << layer << ", Face: " << face << ")" + << ", (xi, eta): (" << xi << ", " << eta << ")"; + EXPECT_NEAR(t8_out[idx3d + 2], ref_z, adaptive_tol) + << "Mismatch in Z | Tree ID: " << gtreeid << " (Layer: " << layer << ", Face: " << face << ")" + << ", (xi, eta): (" << xi << ", " << eta << ")"; + } + } + } +} \ No newline at end of file diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx similarity index 100% rename from test/t8_cmesh/t8_gtest_cmesh_healpix.cxx rename to test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx From eb706cffa577394caa19593bc52550ff3fda5fd1 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 19 Oct 2026 15:30:52 +0200 Subject: [PATCH 21/47] docs: indent test file --- ..._gtest_cmesh_healpix_check_correctness.cxx | 232 +++++++++--------- 1 file changed, 121 insertions(+), 111 deletions(-) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx index e500ea5333..93096ccf1c 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -26,125 +26,135 @@ #include #include #include - -struct LocationResult { - double z; - double phi; - double sintheta; - bool have_sintheta; +#include + +struct LocationResult +{ + double z; + double phi; + double sintheta; + bool have_sintheta; }; -LocationResult xyf2loc(double x, double y, int face, const int JRLL[], const int JPLL[]) { - double z = 0.0; - double nr = 0.0; - double sintheta = 0.0; - bool have_sintheta = false; - - double jr = static_cast(JRLL[face]) - x - y; - - if (jr < 1.0) { - nr = jr; - double tmp = (nr * nr) / 3.0; - z = 1.0 - tmp; - if (z > 0.99) { - sintheta = std::sqrt(tmp * (2.0 - tmp)); - have_sintheta = true; - } - } else if (jr > 3.0) { - nr = 4.0 - jr; - double tmp = (nr * nr) / 3.0; - z = tmp - 1.0; - if (z < -0.99) { - sintheta = std::sqrt(tmp * (2.0 - tmp)); - have_sintheta = true; - } - } else { - nr = 1.0; - z = (2.0 - jr) * 2.0 / 3.0; +LocationResult +xyf2loc (double x, double y, int face, const int JRLL[], const int JPLL[]) +{ + double z = 0.0; + double nr = 0.0; + double sintheta = 0.0; + bool have_sintheta = false; + + double jr = static_cast (JRLL[face]) - x - y; + + if (jr < 1.0) { + nr = jr; + double tmp = (nr * nr) / 3.0; + z = 1.0 - tmp; + if (z > 0.99) { + sintheta = std::sqrt (tmp * (2.0 - tmp)); + have_sintheta = true; } + } + else if (jr > 3.0) { + nr = 4.0 - jr; + double tmp = (nr * nr) / 3.0; + z = tmp - 1.0; + if (z < -0.99) { + sintheta = std::sqrt (tmp * (2.0 - tmp)); + have_sintheta = true; + } + } + else { + nr = 1.0; + z = (2.0 - jr) * 2.0 / 3.0; + } - double tmp = static_cast(JPLL[face]) * nr + x - y; - if (tmp < 0.0) tmp += 8.0; - if (tmp >= 8.0) tmp -= 8.0; + double tmp = static_cast (JPLL[face]) * nr + x - y; + if (tmp < 0.0) + tmp += 8.0; + if (tmp >= 8.0) + tmp -= 8.0; - double phi = (std::abs(nr) < 1e-15) ? 0.0 : ((std::numbers::pi / 4.0 * tmp) / nr); + double phi = (std::abs (nr) < 1e-15) ? 0.0 : ((std::numbers::pi / 4.0 * tmp) / nr); - return {z, phi, sintheta, have_sintheta}; + return { z, phi, sintheta, have_sintheta }; } -TEST(HealpixGeometryTest, EvaluatesBatchAgainstXyf2LocReference) { - const int JRLL[12] = {2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4}; - const int JPLL[12] = {1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7}; - - std::vector test_samples = {0.0, 0.001, 0.25, 0.5, 0.75, 0.999, 1.0}; - const double tolerance = 1e-10; - t8_geometry_healpix geom; - - // Build a batch containing all combinations of test_samples for a single evaluation call - std::vector ref_coords; - for (double xi : test_samples) { - for (double eta : test_samples) { - ref_coords.push_back(xi); - ref_coords.push_back(eta); - } +TEST (HealpixGeometryTest, EvaluatesBatchAgainstXyf2LocReference) +{ + const int JRLL[12] = { 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4 }; + const int JPLL[12] = { 1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7 }; + + std::vector test_samples = { 0.0, 0.001, 0.25, 0.5, 0.75, 0.999, 1.0 }; + const double tolerance = 1e-10; + t8_geometry_healpix geom; + + // Build a batch containing all combinations of test_samples for a single evaluation call + std::vector ref_coords; + for (double xi : test_samples) { + for (double eta : test_samples) { + ref_coords.push_back (xi); + ref_coords.push_back (eta); } - size_t num_coords = test_samples.size() * test_samples.size(); - - // Loop through all t8code layers and faces - for (int layer = 0; layer < 3; ++layer) { - for (int face = 0; face < 4; ++face) { - // t8code Tree ID (0..11) - int gtreeid = layer * 4 + face; - - // HEALPix base face index corresponding to t8code's layer - // layer 0 (South) -> HEALPix faces 8..11 - // layer 1 (Equator) -> HEALPix faces 4..7 - // layer 2 (North) -> HEALPix faces 0..3 - int healpix_face = (2 - layer) * 4 + face; - - // Output buffers - std::vector t8_out(num_coords * 3); - - // Call the batch evaluation method provided - geom.t8_geom_evaluate(nullptr, gtreeid, ref_coords.data(), num_coords, t8_out.data()); - - // Validate each point in the batch against xyf2loc reference - for (size_t i = 0; i < num_coords; ++i) { - double xi = ref_coords[i * 2 + 0]; - double eta = ref_coords[i * 2 + 1]; - - // Clamped values used inside t8_geom_evaluate - double xi_clamped = std::clamp(xi, 1e-10, 1.0 - 1e-10); - double eta_clamped = std::clamp(eta, 1e-10, 1.0 - 1e-10); - - // Pass the 0..11 global face index to xyf2loc - LocationResult ref_loc = xyf2loc(xi_clamped, eta_clamped, healpix_face, JRLL, JPLL); - - double ref_sin_theta; - if (ref_loc.have_sintheta) { - ref_sin_theta = ref_loc.sintheta; - } else { - ref_sin_theta = std::sqrt(std::max(0.0, 1.0 - ref_loc.z * ref_loc.z)); - } - double ref_x = ref_sin_theta * std::cos(ref_loc.phi); - double ref_y = ref_sin_theta * std::sin(ref_loc.phi); - double ref_z = ref_loc.z; - - size_t idx3d = i * 3; - - // Allow a slightly relaxed tolerance near the poles where sin(theta) ~ 0 - double adaptive_tol = (std::abs(ref_z) > 0.99) ? 2e-10 : tolerance; - - EXPECT_NEAR(t8_out[idx3d + 0], ref_x, adaptive_tol) - << "Mismatch in X | Tree ID: " << gtreeid << " (Layer: " << layer << ", Face: " << face << ")" - << ", (xi, eta): (" << xi << ", " << eta << ")"; - EXPECT_NEAR(t8_out[idx3d + 1], ref_y, adaptive_tol) - << "Mismatch in Y | Tree ID: " << gtreeid << " (Layer: " << layer << ", Face: " << face << ")" - << ", (xi, eta): (" << xi << ", " << eta << ")"; - EXPECT_NEAR(t8_out[idx3d + 2], ref_z, adaptive_tol) - << "Mismatch in Z | Tree ID: " << gtreeid << " (Layer: " << layer << ", Face: " << face << ")" - << ", (xi, eta): (" << xi << ", " << eta << ")"; - } + } + size_t num_coords = test_samples.size () * test_samples.size (); + + // Loop through all t8code layers and faces + for (int layer = 0; layer < 3; ++layer) { + for (int face = 0; face < 4; ++face) { + // t8code Tree ID (0..11) + int gtreeid = layer * 4 + face; + + // HEALPix base face index corresponding to t8code's layer + // layer 0 (South) -> HEALPix faces 8..11 + // layer 1 (Equator) -> HEALPix faces 4..7 + // layer 2 (North) -> HEALPix faces 0..3 + int healpix_face = (2 - layer) * 4 + face; + + // Output buffers + std::vector t8_out (num_coords * 3); + + // Call the batch evaluation method provided + geom.t8_geom_evaluate (nullptr, gtreeid, ref_coords.data (), num_coords, t8_out.data ()); + + // Validate each point in the batch against xyf2loc reference + for (size_t i = 0; i < num_coords; ++i) { + double xi = ref_coords[i * 2 + 0]; + double eta = ref_coords[i * 2 + 1]; + + // Clamped values used inside t8_geom_evaluate + double xi_clamped = std::clamp (xi, 1e-10, 1.0 - 1e-10); + double eta_clamped = std::clamp (eta, 1e-10, 1.0 - 1e-10); + + // Pass the 0..11 global face index to xyf2loc + LocationResult ref_loc = xyf2loc (xi_clamped, eta_clamped, healpix_face, JRLL, JPLL); + + double ref_sin_theta; + if (ref_loc.have_sintheta) { + ref_sin_theta = ref_loc.sintheta; } + else { + ref_sin_theta = std::sqrt (std::max (0.0, 1.0 - ref_loc.z * ref_loc.z)); + } + double ref_x = ref_sin_theta * std::cos (ref_loc.phi); + double ref_y = ref_sin_theta * std::sin (ref_loc.phi); + double ref_z = ref_loc.z; + + size_t idx3d = i * 3; + + // Allow a slightly relaxed tolerance near the poles where sin(theta) ~ 0 + double adaptive_tol = (std::abs (ref_z) > 0.99) ? 2e-10 : tolerance; + + EXPECT_NEAR (t8_out[idx3d + 0], ref_x, adaptive_tol) + << "Mismatch in X | Tree ID: " << gtreeid << " (Layer: " << layer << ", Face: " << face << ")" + << ", (xi, eta): (" << xi << ", " << eta << ")"; + EXPECT_NEAR (t8_out[idx3d + 1], ref_y, adaptive_tol) + << "Mismatch in Y | Tree ID: " << gtreeid << " (Layer: " << layer << ", Face: " << face << ")" + << ", (xi, eta): (" << xi << ", " << eta << ")"; + EXPECT_NEAR (t8_out[idx3d + 2], ref_z, adaptive_tol) + << "Mismatch in Z | Tree ID: " << gtreeid << " (Layer: " << layer << ", Face: " << face << ")" + << ", (xi, eta): (" << xi << ", " << eta << ")"; + } } -} \ No newline at end of file + } +} From 1e009ec1417b70c5f6f2106061a17dd0d370a71e Mon Sep 17 00:00:00 2001 From: faouziH21 <109729343+faouziH21@users.noreply.github.com> Date: Fri, 23 Oct 2026 14:56:42 +0200 Subject: [PATCH 22/47] Apply batched suggestions from code review Suggestions from sandro Co-authored-by: Sandro Elsweijer <49643115+sandro-elsweijer@users.noreply.github.com> --- src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx | 1 - src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx | 1 - test/CMakeLists.txt | 1 - test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx | 2 +- test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx | 3 --- 5 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index 8688127fb1..a3c5d23c64 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -24,7 +24,6 @@ #include #include #include -#include #include /** diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx index 9a40f7fd6e..a2985d243f 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx @@ -21,7 +21,6 @@ */ #include -#include #include #include diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 68a47fbef7..dfa17bb0e4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -141,7 +141,6 @@ add_t8_cpp_test( NAME t8_gtest_attribute_gloidx_array_serial SOUR add_t8_cpp_test( NAME t8_gtest_cmesh_bounding_box_serial SOURCES t8_cmesh/t8_gtest_cmesh_bounding_box.cxx ) add_t8_cpp_test( NAME t8_gtest_cmesh_healpix_unit_sphere SOURCES t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx ) add_t8_cpp_test( NAME t8_gtest_cmesh_healpix_check_correctness SOURCES t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx ) -add_t8_cpp_test( NAME t8_gtest_cmesh_boundary_conditions_serial SOURCES t8_cmesh/t8_gtest_cmesh_boundary_conditions.cxx ) add_t8_cpp_test( NAME t8_gtest_cmesh_boundary_conditions_parallel SOURCES t8_cmesh/t8_gtest_cmesh_boundary_conditions.cxx ) add_t8_cpp_test( NAME t8_gtest_shmem_parallel SOURCES t8_data/t8_gtest_shmem.cxx ) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx index 93096ccf1c..5ef0562754 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -28,7 +28,7 @@ #include #include -struct LocationResult +struct t8_location_result { double z; double phi; diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx index 6531543cde..c30d430009 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx @@ -33,8 +33,6 @@ TEST (T8GeometryHealpixTest, AllTreesAreOnUnitSphere) { t8_geometry_healpix geom; - t8_cmesh_t cmesh; - t8_cmesh_init (&cmesh); std::random_device rd; std::mt19937 gen (rd ()); @@ -73,5 +71,4 @@ TEST (T8GeometryHealpixTest, AllTreesAreOnUnitSphere) << " (xi=" << ref_coords[i * 2] << ", eta=" << ref_coords[i * 2 + 1] << ")"; } } - t8_cmesh_destroy (&cmesh); } From 805d89751721f9032b77583753272432ebcca39d Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Fri, 23 Oct 2026 15:16:39 +0200 Subject: [PATCH 23/47] bugfix: naming conventions and bug fixes --- test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx | 6 +++--- test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx index 5ef0562754..09cfbcc0ba 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -36,7 +36,7 @@ struct t8_location_result bool have_sintheta; }; -LocationResult +t8_location_result xyf2loc (double x, double y, int face, const int JRLL[], const int JPLL[]) { double z = 0.0; @@ -80,7 +80,7 @@ xyf2loc (double x, double y, int face, const int JRLL[], const int JPLL[]) return { z, phi, sintheta, have_sintheta }; } -TEST (HealpixGeometryTest, EvaluatesBatchAgainstXyf2LocReference) +TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) { const int JRLL[12] = { 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4 }; const int JPLL[12] = { 1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7 }; @@ -127,7 +127,7 @@ TEST (HealpixGeometryTest, EvaluatesBatchAgainstXyf2LocReference) double eta_clamped = std::clamp (eta, 1e-10, 1.0 - 1e-10); // Pass the 0..11 global face index to xyf2loc - LocationResult ref_loc = xyf2loc (xi_clamped, eta_clamped, healpix_face, JRLL, JPLL); + t8_location_result ref_loc = xyf2loc (xi_clamped, eta_clamped, healpix_face, JRLL, JPLL); double ref_sin_theta; if (ref_loc.have_sintheta) { diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx index c30d430009..a4d4c51c54 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx @@ -30,7 +30,7 @@ #include #include /* Test whether the healpix geometry has an equal radius all across the geometry. */ -TEST (T8GeometryHealpixTest, AllTreesAreOnUnitSphere) +TEST (t8_geometry_healpix_test, test_all_trees_are_on_unit_sphere) { t8_geometry_healpix geom; @@ -52,7 +52,6 @@ TEST (T8GeometryHealpixTest, AllTreesAreOnUnitSphere) #endif for (int i = 0; i < num_gen_coords; i++) { - std::cout << i << std::endl; ref_coords.push_back (dist (gen)); ref_coords.push_back (dist (gen)); } @@ -61,7 +60,7 @@ TEST (T8GeometryHealpixTest, AllTreesAreOnUnitSphere) std::vector out_coords (num_coords * 3, 0.0); // Loop through all 12 base trees of the HEALPix projection for (t8_gloidx_t gtreeid = 0; gtreeid < 12; ++gtreeid) { - geom.t8_geom_evaluate (cmesh, gtreeid, ref_coords.data (), num_coords, out_coords.data ()); + geom.t8_geom_evaluate (nullptr, gtreeid, ref_coords.data (), num_coords, out_coords.data ()); for (size_t i = 0; i < num_coords; ++i) { std::span point (out_coords.data () + 3 * i, 3); From 8896b08418ffb8c11e7e9dd1dafc1bd4c6271169 Mon Sep 17 00:00:00 2001 From: faouziH21 <109729343+faouziH21@users.noreply.github.com> Date: Mon, 26 Oct 2026 13:29:32 +0100 Subject: [PATCH 24/47] Apply batched suggestions from code review Mostly const Co-authored-by: David Knapp --- ..._gtest_cmesh_healpix_check_correctness.cxx | 50 ++++++++----------- .../t8_gtest_cmesh_healpix_unit_sphere.cxx | 13 +++-- 2 files changed, 28 insertions(+), 35 deletions(-) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx index 09cfbcc0ba..8e80460509 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -36,19 +36,19 @@ struct t8_location_result bool have_sintheta; }; -t8_location_result -xyf2loc (double x, double y, int face, const int JRLL[], const int JPLL[]) +constexpr t8_location_result +xyf2loc (const double x, const double y, cosnt int face, const int JRLL[], const int JPLL[]) { double z = 0.0; double nr = 0.0; double sintheta = 0.0; bool have_sintheta = false; - double jr = static_cast (JRLL[face]) - x - y; + const double jr = static_cast (JRLL[face]) - x - y; if (jr < 1.0) { nr = jr; - double tmp = (nr * nr) / 3.0; + const double tmp = (nr * nr) / 3.0; z = 1.0 - tmp; if (z > 0.99) { sintheta = std::sqrt (tmp * (2.0 - tmp)); @@ -57,7 +57,7 @@ xyf2loc (double x, double y, int face, const int JRLL[], const int JPLL[]) } else if (jr > 3.0) { nr = 4.0 - jr; - double tmp = (nr * nr) / 3.0; + const double tmp = (nr * nr) / 3.0; z = tmp - 1.0; if (z < -0.99) { sintheta = std::sqrt (tmp * (2.0 - tmp)); @@ -69,13 +69,13 @@ xyf2loc (double x, double y, int face, const int JRLL[], const int JPLL[]) z = (2.0 - jr) * 2.0 / 3.0; } - double tmp = static_cast (JPLL[face]) * nr + x - y; + const double tmp = static_cast (JPLL[face]) * nr + x - y; if (tmp < 0.0) tmp += 8.0; if (tmp >= 8.0) tmp -= 8.0; - double phi = (std::abs (nr) < 1e-15) ? 0.0 : ((std::numbers::pi / 4.0 * tmp) / nr); + const double phi = (std::abs (nr) < 1e-15) ? 0.0 : ((std::numbers::pi / 4.0 * tmp) / nr); return { z, phi, sintheta, have_sintheta }; } @@ -85,7 +85,7 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) const int JRLL[12] = { 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4 }; const int JPLL[12] = { 1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7 }; - std::vector test_samples = { 0.0, 0.001, 0.25, 0.5, 0.75, 0.999, 1.0 }; + std::array test_samples = { 0.0, 0.001, 0.25, 0.5, 0.75, 0.999, 1.0 }; const double tolerance = 1e-10; t8_geometry_healpix geom; @@ -97,19 +97,19 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) ref_coords.push_back (eta); } } - size_t num_coords = test_samples.size () * test_samples.size (); + const size_t num_coords = test_samples.size () * test_samples.size (); // Loop through all t8code layers and faces for (int layer = 0; layer < 3; ++layer) { for (int face = 0; face < 4; ++face) { // t8code Tree ID (0..11) - int gtreeid = layer * 4 + face; + const t8_gloidx_t gtreeid = layer * 4 + face; // HEALPix base face index corresponding to t8code's layer // layer 0 (South) -> HEALPix faces 8..11 // layer 1 (Equator) -> HEALPix faces 4..7 // layer 2 (North) -> HEALPix faces 0..3 - int healpix_face = (2 - layer) * 4 + face; + const int healpix_face = (2 - layer) * 4 + face; // Output buffers std::vector t8_out (num_coords * 3); @@ -119,31 +119,25 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) // Validate each point in the batch against xyf2loc reference for (size_t i = 0; i < num_coords; ++i) { - double xi = ref_coords[i * 2 + 0]; - double eta = ref_coords[i * 2 + 1]; + const double xi = ref_coords[i * 2 + 0]; + const double eta = ref_coords[i * 2 + 1]; // Clamped values used inside t8_geom_evaluate - double xi_clamped = std::clamp (xi, 1e-10, 1.0 - 1e-10); - double eta_clamped = std::clamp (eta, 1e-10, 1.0 - 1e-10); + const double xi_clamped = std::clamp (xi, 1e-10, 1.0 - 1e-10); + const double eta_clamped = std::clamp (eta, 1e-10, 1.0 - 1e-10); // Pass the 0..11 global face index to xyf2loc - t8_location_result ref_loc = xyf2loc (xi_clamped, eta_clamped, healpix_face, JRLL, JPLL); + const t8_location_result ref_loc = xyf2loc (xi_clamped, eta_clamped, healpix_face, JRLL, JPLL); - double ref_sin_theta; - if (ref_loc.have_sintheta) { - ref_sin_theta = ref_loc.sintheta; - } - else { - ref_sin_theta = std::sqrt (std::max (0.0, 1.0 - ref_loc.z * ref_loc.z)); - } - double ref_x = ref_sin_theta * std::cos (ref_loc.phi); - double ref_y = ref_sin_theta * std::sin (ref_loc.phi); - double ref_z = ref_loc.z; + const double ref_sin_theta = ref_loc.have_sintheta ? ref_loc.sitheta : std::sqrt ( std::max (0.0, 1.0 - ref_loc.z * ref_loc.z)); + const double ref_x = ref_sin_theta * std::cos (ref_loc.phi); + const double ref_y = ref_sin_theta * std::sin (ref_loc.phi); + const double ref_z = ref_loc.z; - size_t idx3d = i * 3; + const size_t idx3d = i * 3; // Allow a slightly relaxed tolerance near the poles where sin(theta) ~ 0 - double adaptive_tol = (std::abs (ref_z) > 0.99) ? 2e-10 : tolerance; + const double adaptive_tol = (std::abs (ref_z) > 0.99) ? T8_PRECISION_SQRT_EPS : T8_PRECISION_EPS; EXPECT_NEAR (t8_out[idx3d + 0], ref_x, adaptive_tol) << "Mismatch in X | Tree ID: " << gtreeid << " (Layer: " << layer << ", Face: " << face << ")" diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx index a4d4c51c54..2f5eecfd98 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx @@ -43,12 +43,11 @@ TEST (t8_geometry_healpix_test, test_all_trees_are_on_unit_sphere) 0.0, 0.0, // Corners 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.5, 0.5, // Center }; - int num_gen_coords = 0; // in addition to the basic test cases generate random coordinates to test out implementation #if T8_TEST_LEVEL_INT >= 2 - num_gen_coords = 10; // Test level basic + const int num_gen_coords = 10; // Test level basic #else - num_gen_coords = 20; + const int num_gen_coords = 20; #endif for (int i = 0; i < num_gen_coords; i++) { @@ -57,16 +56,16 @@ TEST (t8_geometry_healpix_test, test_all_trees_are_on_unit_sphere) } const size_t num_coords = ref_coords.size () / 2; - std::vector out_coords (num_coords * 3, 0.0); + std::array out_coords (0.0); // Loop through all 12 base trees of the HEALPix projection for (t8_gloidx_t gtreeid = 0; gtreeid < 12; ++gtreeid) { geom.t8_geom_evaluate (nullptr, gtreeid, ref_coords.data (), num_coords, out_coords.data ()); for (size_t i = 0; i < num_coords; ++i) { - std::span point (out_coords.data () + 3 * i, 3); - double distance = t8_norm (point); + const std::span point (out_coords.data () + 3 * i, 3); + const double distance = t8_norm (point); // Expect distance to be 1.0 (Unit Sphere) - EXPECT_NEAR (distance, 1.0, 1e-7) << "Radius check failed at Tree ID: " << gtreeid << " for point index: " << i + EXPECT_NEAR (distance, 1.0, T8_PRECISION_EPS) << "Radius check failed at Tree ID: " << gtreeid << " for point index: " << i << " (xi=" << ref_coords[i * 2] << ", eta=" << ref_coords[i * 2 + 1] << ")"; } } From ad1e8bdcfc9325d5142faa02929b3de31b154847 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 26 Oct 2026 14:46:48 +0100 Subject: [PATCH 25/47] fix: fixes a bunch off issues like typos, indentation and more --- .../t8_gtest_cmesh_healpix_check_correctness.cxx | 13 ++++++------- .../t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx | 7 ++++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx index 8e80460509..634960f851 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -37,7 +37,7 @@ struct t8_location_result }; constexpr t8_location_result -xyf2loc (const double x, const double y, cosnt int face, const int JRLL[], const int JPLL[]) +xyf2loc (const double x, const double y, const int face, const int JRLL[], const int JPLL[]) { double z = 0.0; double nr = 0.0; @@ -69,7 +69,7 @@ xyf2loc (const double x, const double y, cosnt int face, const int JRLL[], const z = (2.0 - jr) * 2.0 / 3.0; } - const double tmp = static_cast (JPLL[face]) * nr + x - y; + double tmp = static_cast (JPLL[face]) * nr + x - y; if (tmp < 0.0) tmp += 8.0; if (tmp >= 8.0) @@ -85,8 +85,7 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) const int JRLL[12] = { 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4 }; const int JPLL[12] = { 1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7 }; - std::array test_samples = { 0.0, 0.001, 0.25, 0.5, 0.75, 0.999, 1.0 }; - const double tolerance = 1e-10; + std::array test_samples = { 0.0, 0.001, 0.25, 0.5, 0.75, 0.999, 1.0 }; t8_geometry_healpix geom; // Build a batch containing all combinations of test_samples for a single evaluation call @@ -129,7 +128,8 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) // Pass the 0..11 global face index to xyf2loc const t8_location_result ref_loc = xyf2loc (xi_clamped, eta_clamped, healpix_face, JRLL, JPLL); - const double ref_sin_theta = ref_loc.have_sintheta ? ref_loc.sitheta : std::sqrt ( std::max (0.0, 1.0 - ref_loc.z * ref_loc.z)); + const double ref_sin_theta + = ref_loc.have_sintheta ? ref_loc.sintheta : std::sqrt (std::max (0.0, 1.0 - ref_loc.z * ref_loc.z)); const double ref_x = ref_sin_theta * std::cos (ref_loc.phi); const double ref_y = ref_sin_theta * std::sin (ref_loc.phi); const double ref_z = ref_loc.z; @@ -137,8 +137,7 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) const size_t idx3d = i * 3; // Allow a slightly relaxed tolerance near the poles where sin(theta) ~ 0 - const double adaptive_tol = (std::abs (ref_z) > 0.99) ? T8_PRECISION_SQRT_EPS : T8_PRECISION_EPS; - + const double adaptive_tol = (std::abs (ref_z) > 0.99) ? T8_PRECISION_SQRT_EPS : (4.0 * T8_PRECISION_EPS); std::cout << adaptive_tol << std::endl; EXPECT_NEAR (t8_out[idx3d + 0], ref_x, adaptive_tol) << "Mismatch in X | Tree ID: " << gtreeid << " (Layer: " << layer << ", Face: " << face << ")" << ", (xi, eta): (" << xi << ", " << eta << ")"; diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx index 2f5eecfd98..a3b16518f1 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx @@ -56,7 +56,7 @@ TEST (t8_geometry_healpix_test, test_all_trees_are_on_unit_sphere) } const size_t num_coords = ref_coords.size () / 2; - std::array out_coords (0.0); + std::vector out_coords (num_coords * 3, 0.0); // Loop through all 12 base trees of the HEALPix projection for (t8_gloidx_t gtreeid = 0; gtreeid < 12; ++gtreeid) { geom.t8_geom_evaluate (nullptr, gtreeid, ref_coords.data (), num_coords, out_coords.data ()); @@ -65,8 +65,9 @@ TEST (t8_geometry_healpix_test, test_all_trees_are_on_unit_sphere) const std::span point (out_coords.data () + 3 * i, 3); const double distance = t8_norm (point); // Expect distance to be 1.0 (Unit Sphere) - EXPECT_NEAR (distance, 1.0, T8_PRECISION_EPS) << "Radius check failed at Tree ID: " << gtreeid << " for point index: " << i - << " (xi=" << ref_coords[i * 2] << ", eta=" << ref_coords[i * 2 + 1] << ")"; + EXPECT_NEAR (distance, 1.0, T8_PRECISION_EPS) + << "Radius check failed at Tree ID: " << gtreeid << " for point index: " << i << " (xi=" << ref_coords[i * 2] + << ", eta=" << ref_coords[i * 2 + 1] << ")"; } } } From 14a4278dc095e45c9655fcef63a1107121fef120 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 26 Oct 2026 15:17:40 +0100 Subject: [PATCH 26/47] docs: adds a doc and lints correctly --- test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx index 634960f851..cfe0713b67 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -39,6 +39,9 @@ struct t8_location_result constexpr t8_location_result xyf2loc (const double x, const double y, const int face, const int JRLL[], const int JPLL[]) { + /* + A helper fuction translated from the HEALPix julia code base. + */ double z = 0.0; double nr = 0.0; double sintheta = 0.0; @@ -137,7 +140,7 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) const size_t idx3d = i * 3; // Allow a slightly relaxed tolerance near the poles where sin(theta) ~ 0 - const double adaptive_tol = (std::abs (ref_z) > 0.99) ? T8_PRECISION_SQRT_EPS : (4.0 * T8_PRECISION_EPS); std::cout << adaptive_tol << std::endl; + const double adaptive_tol = (std::abs (ref_z) > 0.99) ? T8_PRECISION_SQRT_EPS : (4.0 * T8_PRECISION_EPS); EXPECT_NEAR (t8_out[idx3d + 0], ref_x, adaptive_tol) << "Mismatch in X | Tree ID: " << gtreeid << " (Layer: " << layer << ", Face: " << face << ")" << ", (xi, eta): (" << xi << ", " << eta << ")"; From e156a66e2c260bc700f55cd3120dee8eb68aacbb Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 26 Oct 2026 15:32:06 +0100 Subject: [PATCH 27/47] docs: document the file and fixes a typo --- .../t8_gtest_cmesh_healpix_check_correctness.cxx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx index cfe0713b67..201bfeba81 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License along with t8code; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ + */ #include #include @@ -28,6 +28,12 @@ #include #include +/* We cross reference our implementaion with this of + * xyf2loc from the HEALPix Julia source code. We evaluate + * both implementation and compare them to eachother. + * if the evaluation is close enough then the test passes. + */ + struct t8_location_result { double z; @@ -40,7 +46,7 @@ constexpr t8_location_result xyf2loc (const double x, const double y, const int face, const int JRLL[], const int JPLL[]) { /* - A helper fuction translated from the HEALPix julia code base. + A helper function translated from the HEALPix julia code base. */ double z = 0.0; double nr = 0.0; From 4f5127c4e4d30d685d66c722d396ba304ce9c0fa Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 26 Oct 2026 15:33:31 +0100 Subject: [PATCH 28/47] docs: fixes typo --- test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx index 201bfeba81..5d6bf73f14 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -28,7 +28,7 @@ #include #include -/* We cross reference our implementaion with this of +/* We cross reference our implementation with this of * xyf2loc from the HEALPix Julia source code. We evaluate * both implementation and compare them to eachother. * if the evaluation is close enough then the test passes. From 1c351f7c3fb82d04e729717dc39a3ac44415e638 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Fri, 30 Oct 2026 15:26:02 +0100 Subject: [PATCH 29/47] feat: adds an option to adjust the radius of the sphere --- src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx | 3 ++- src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h | 2 +- src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx | 10 +++++----- src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx | 8 ++++++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index a3c5d23c64..1f4f2fa76a 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -91,10 +91,11 @@ static const struct t8_healpix_join healpix_joins[24] = { * before committing the mesh. * * @param[in] comm The MPI communicator used to manage parallel partitioning/commit. + * @param[in] sphere_radius The radius of the sphere. Default to 1 * @return t8_cmesh_t A committed coarse mesh object containing the HEALPix base structure. */ t8_cmesh_t -t8_cmesh_new_healpix (sc_MPI_Comm comm) +t8_cmesh_new_healpix (sc_MPI_Comm comm, double sphere_radius = 1) { /* Initialization of the mesh */ t8_cmesh_t cmesh; diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h index d69fc3d6bd..b2fb50a2b1 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h @@ -26,4 +26,4 @@ * \return A coarse mesh representing the HEALPix base grid. */ t8_cmesh_t -t8_cmesh_new_healpix (sc_MPI_Comm comm); +t8_cmesh_new_healpix (sc_MPI_Comm comm, double sphere_radius = 1); diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx index a2985d243f..cc91dd3202 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx @@ -38,7 +38,7 @@ * Cartesian coordinates will be stored. */ void -t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, double *out_coord) +t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, double *out_coord, double radius) { const double offset_y = static_cast (layer) - 1.0; const double offset_x = 2.0 * face + ((layer + 1) % 2); @@ -68,9 +68,9 @@ t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, const double theta = std::acos (z); const double sin_theta = std::sin (theta); - out_coord[0] = sin_theta * std::cos (phi); - out_coord[1] = sin_theta * std::sin (phi); - out_coord[2] = z; + out_coord[0] = (sin_theta * std::cos (phi)) * radius; + out_coord[1] = sin_theta * std::sin (phi) * radius; + out_coord[2] = z * radius; } void @@ -89,7 +89,7 @@ t8_geometry_healpix::t8_geom_evaluate ([[maybe_unused]] t8_cmesh_t cmesh, t8_glo const double eta = std::clamp (ref_coords[base_idx_2d + 1], 1e-10, 1.0 - 1e-10); // Pass the pointer offset for 3D coordinates: out_coords + base_idx_3d - t8_eval_geom_point (layer, face, xi, eta, out_coords + base_idx_3d); + t8_eval_geom_point (layer, face, xi, eta, out_coords + base_idx_3d, sphere_radius); } } t8_geometry_type_t diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx index 70bc50d359..130ec8fe6e 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx @@ -30,10 +30,18 @@ */ struct t8_geometry_healpix: public t8_geometry { + private: + double sphere_radius; + public: /* Basic constructor that sets the dimension and the name. */ + t8_geometry_healpix (double radius): t8_geometry ("t8_geometry_healpix") + { + sphere_radius = radius; + } t8_geometry_healpix (): t8_geometry ("t8_geometry_healpix") { + sphere_radius = 1; } /* The destructor. */ From 38219b5689790d6761212b9a9a0b66ce93da5bf1 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 2 Nov 2026 12:59:19 +0100 Subject: [PATCH 30/47] docs: updates docs to adhere to doxygen and fixes unused param --- .../t8_cmesh_healpix/t8_cmesh_healpix.cxx | 2 +- .../t8_cmesh_healpix/t8_geometry_healpix.cxx | 1 + .../t8_cmesh_healpix/t8_geometry_healpix.hxx | 18 +++++++++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index 1f4f2fa76a..1a8f841cc7 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -104,7 +104,7 @@ t8_cmesh_new_healpix (sc_MPI_Comm comm, double sphere_radius = 1) const int ntrees = 12; /* Register geometry and retain the pointer */ - t8_cmesh_register_geometry (cmesh); + t8_cmesh_register_geometry (cmesh, sphere_radius); for (int itree = 0; itree < ntrees; itree++) { t8_cmesh_set_tree_class (cmesh, itree, T8_ECLASS_QUAD); diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx index cc91dd3202..3b4f26832b 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx @@ -36,6 +36,7 @@ * @param[in] eta The reference coordinate in the second parametric direction (typically [0, 1]). * @param[out] out_coord Pointer to an array of size 3 where the resulting (x, y, z) * Cartesian coordinates will be stored. + * @param[in] radius The radius of the sphere */ void t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, double *out_coord, double radius) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx index 130ec8fe6e..f889a5fee1 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx @@ -34,17 +34,28 @@ struct t8_geometry_healpix: public t8_geometry double sphere_radius; public: - /* Basic constructor that sets the dimension and the name. */ + /** + * @brief Constructs a HEALPix geometry with the specified sphere radius. + * + * @param radius The radius of the sphere. + */ t8_geometry_healpix (double radius): t8_geometry ("t8_geometry_healpix") { sphere_radius = radius; } + /** + * @brief Default constructor. + * + * Constructs a HEALPix geometry with a sphere radius of 1. + */ t8_geometry_healpix (): t8_geometry ("t8_geometry_healpix") { sphere_radius = 1; } - /* The destructor. */ + /** + * @brief Destructor. + */ virtual ~t8_geometry_healpix () { } @@ -106,6 +117,3 @@ struct t8_geometry_healpix: public t8_geometry /* Load tree data is inherited from t8_geometry_with_vertices. */ }; - -void -t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, double *out_coord); From 85988febd8db7186f2d4c4e2632ccbb5baeae833 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 2 Nov 2026 13:43:36 +0100 Subject: [PATCH 31/47] chore: changes vector to array --- test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx index 5d6bf73f14..cfb97f0f17 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -120,7 +120,7 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) const int healpix_face = (2 - layer) * 4 + face; // Output buffers - std::vector t8_out (num_coords * 3); + std::array t8_out; // Call the batch evaluation method provided geom.t8_geom_evaluate (nullptr, gtreeid, ref_coords.data (), num_coords, t8_out.data ()); From abc259e7ab70ad87c407e8fd8dafae726b1ee519 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 2 Nov 2026 13:59:48 +0100 Subject: [PATCH 32/47] fix: changes size_t to int and docs changes --- .../t8_gtest_cmesh_healpix_check_correctness.cxx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx index cfb97f0f17..3198baec51 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -105,7 +105,7 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) ref_coords.push_back (eta); } } - const size_t num_coords = test_samples.size () * test_samples.size (); + const int num_coords = test_samples.size () * test_samples.size (); // Loop through all t8code layers and faces for (int layer = 0; layer < 3; ++layer) { @@ -120,15 +120,15 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) const int healpix_face = (2 - layer) * 4 + face; // Output buffers - std::array t8_out; + std::array t8_out; // Call the batch evaluation method provided geom.t8_geom_evaluate (nullptr, gtreeid, ref_coords.data (), num_coords, t8_out.data ()); // Validate each point in the batch against xyf2loc reference - for (size_t i = 0; i < num_coords; ++i) { - const double xi = ref_coords[i * 2 + 0]; - const double eta = ref_coords[i * 2 + 1]; + for (int coord_index = 0; coord_index < num_coords; coord_index++) { + const double xi = ref_coords[coord_index * 2 + 0]; + const double eta = ref_coords[coord_index * 2 + 1]; // Clamped values used inside t8_geom_evaluate const double xi_clamped = std::clamp (xi, 1e-10, 1.0 - 1e-10); @@ -143,7 +143,7 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) const double ref_y = ref_sin_theta * std::sin (ref_loc.phi); const double ref_z = ref_loc.z; - const size_t idx3d = i * 3; + const size_t idx3d = coord_index * 3; // Allow a slightly relaxed tolerance near the poles where sin(theta) ~ 0 const double adaptive_tol = (std::abs (ref_z) > 0.99) ? T8_PRECISION_SQRT_EPS : (4.0 * T8_PRECISION_EPS); From 0b979f73812b8bae29b94cc2bd873684fa3ad891 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 2 Nov 2026 17:12:23 +0100 Subject: [PATCH 33/47] fix: changes vectors into arrays and changes ordering of the layers --- .../t8_cmesh_healpix/t8_geometry_healpix.cxx | 2 +- ...8_gtest_cmesh_healpix_check_correctness.cxx | 18 ++++++++++-------- .../t8_gtest_cmesh_healpix_unit_sphere.cxx | 16 ++++++++-------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx index 3b4f26832b..6c48f32b99 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx @@ -41,7 +41,7 @@ void t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, double *out_coord, double radius) { - const double offset_y = static_cast (layer) - 1.0; + const double offset_y = 1.0 - static_cast (layer); const double offset_x = 2.0 * face + ((layer + 1) % 2); const double dX = offset_x + (xi - eta); diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx index 3198baec51..13c471475b 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -28,7 +28,7 @@ #include #include -/* We cross reference our implementation with this of +/** \file We cross reference our implementation with this of * xyf2loc from the HEALPix Julia source code. We evaluate * both implementation and compare them to eachother. * if the evaluation is close enough then the test passes. @@ -94,18 +94,20 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) const int JRLL[12] = { 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4 }; const int JPLL[12] = { 1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7 }; - std::array test_samples = { 0.0, 0.001, 0.25, 0.5, 0.75, 0.999, 1.0 }; + constexpr std::array test_samples = { 0.0, 0.001, 0.25, 0.5, 0.75, 0.999, 1.0 }; t8_geometry_healpix geom; - // Build a batch containing all combinations of test_samples for a single evaluation call - std::vector ref_coords; + // Build a batch containing all combinations of test_samples for a single evaluation call using std::array + constexpr size_t num_samples = test_samples.size (); + constexpr int num_coords = num_samples * num_samples; + std::array ref_coords; + size_t coord_idx = 0; for (double xi : test_samples) { for (double eta : test_samples) { - ref_coords.push_back (xi); - ref_coords.push_back (eta); + ref_coords[coord_idx++] = xi; + ref_coords[coord_idx++] = eta; } } - const int num_coords = test_samples.size () * test_samples.size (); // Loop through all t8code layers and faces for (int layer = 0; layer < 3; ++layer) { @@ -117,7 +119,7 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) // layer 0 (South) -> HEALPix faces 8..11 // layer 1 (Equator) -> HEALPix faces 4..7 // layer 2 (North) -> HEALPix faces 0..3 - const int healpix_face = (2 - layer) * 4 + face; + const int healpix_face = layer * 4 + face; // Output buffers std::array t8_out; diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx index a3b16518f1..1ecdd42f04 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx @@ -38,21 +38,21 @@ TEST (t8_geometry_healpix_test, test_all_trees_are_on_unit_sphere) std::mt19937 gen (rd ()); std::uniform_real_distribution dist (0.0, 1.0); - // A set of 2D reference coordinates within the element - std::vector ref_coords = { - 0.0, 0.0, // Corners - 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.5, 0.5, // Center - }; +// A set of 2D reference coordinates within the element // in addition to the basic test cases generate random coordinates to test out implementation #if T8_TEST_LEVEL_INT >= 2 const int num_gen_coords = 10; // Test level basic #else const int num_gen_coords = 20; #endif + std::array ref_coords = { + 0.0, 0.0, // Corners + 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.5, 0.5, // Center + }; - for (int i = 0; i < num_gen_coords; i++) { - ref_coords.push_back (dist (gen)); - ref_coords.push_back (dist (gen)); + for (int coord_index = 0; coord_index < num_gen_coords; coord_index++) { + ref_coords[2 * coord_index + 10] = (dist (gen)); + ref_coords[2 * coord_index + 11] = (dist (gen)); } const size_t num_coords = ref_coords.size () / 2; From a114acac86f8f58718d297970234049e5ef8fb33 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Fri, 6 Nov 2026 14:45:43 +0100 Subject: [PATCH 34/47] fix: tests with regard of the radius --- ..._gtest_cmesh_healpix_check_correctness.cxx | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx index 13c471475b..3ddb9ba31a 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -43,7 +43,7 @@ struct t8_location_result }; constexpr t8_location_result -xyf2loc (const double x, const double y, const int face, const int JRLL[], const int JPLL[]) +xyf2loc (const double x, const double y, const int face, const int JRLL[], const int JPLL[], const double radius = 1.0) { /* A helper function translated from the HEALPix julia code base. @@ -86,7 +86,7 @@ xyf2loc (const double x, const double y, const int face, const int JRLL[], const const double phi = (std::abs (nr) < 1e-15) ? 0.0 : ((std::numbers::pi / 4.0 * tmp) / nr); - return { z, phi, sintheta, have_sintheta }; + return { z * radius, phi, sintheta * radius, have_sintheta }; } TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) @@ -94,8 +94,13 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) const int JRLL[12] = { 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4 }; const int JPLL[12] = { 1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7 }; +#if T8_TEST_LEVEL_INT >= 2 + double radius = 0.5; +#else + double radius = 10; +#endif constexpr std::array test_samples = { 0.0, 0.001, 0.25, 0.5, 0.75, 0.999, 1.0 }; - t8_geometry_healpix geom; + t8_geometry_healpix geom (radius); // Build a batch containing all combinations of test_samples for a single evaluation call using std::array constexpr size_t num_samples = test_samples.size (); @@ -137,10 +142,11 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) const double eta_clamped = std::clamp (eta, 1e-10, 1.0 - 1e-10); // Pass the 0..11 global face index to xyf2loc - const t8_location_result ref_loc = xyf2loc (xi_clamped, eta_clamped, healpix_face, JRLL, JPLL); + const t8_location_result ref_loc = xyf2loc (xi_clamped, eta_clamped, healpix_face, JRLL, JPLL, radius); - const double ref_sin_theta - = ref_loc.have_sintheta ? ref_loc.sintheta : std::sqrt (std::max (0.0, 1.0 - ref_loc.z * ref_loc.z)); + const double ref_sin_theta = ref_loc.have_sintheta + ? ref_loc.sintheta + : std::sqrt (std::max (0.0, (radius * radius) - ref_loc.z * ref_loc.z)); const double ref_x = ref_sin_theta * std::cos (ref_loc.phi); const double ref_y = ref_sin_theta * std::sin (ref_loc.phi); const double ref_z = ref_loc.z; @@ -148,7 +154,9 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) const size_t idx3d = coord_index * 3; // Allow a slightly relaxed tolerance near the poles where sin(theta) ~ 0 - const double adaptive_tol = (std::abs (ref_z) > 0.99) ? T8_PRECISION_SQRT_EPS : (4.0 * T8_PRECISION_EPS); + // Scale the polar check and tolerance by the active radius + const double adaptive_tol + = ((std::abs (ref_z) > 0.99 * radius) ? (16.0 * T8_PRECISION_SQRT_EPS) : (64.0 * T8_PRECISION_EPS)) * radius; EXPECT_NEAR (t8_out[idx3d + 0], ref_x, adaptive_tol) << "Mismatch in X | Tree ID: " << gtreeid << " (Layer: " << layer << ", Face: " << face << ")" << ", (xi, eta): (" << xi << ", " << eta << ")"; From 5fbe524cbd97dc61ada7e827a3ada4c004cb2bff Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 9 Nov 2026 10:31:17 +0100 Subject: [PATCH 35/47] docs: updates documentation --- src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx index f889a5fee1..d85fc8036a 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx @@ -25,7 +25,7 @@ /** * The t8_geometry_healpix struct implements a spherical geometry mapping * based on the HEALPix (Hierarchical Equal Area isoLatitude Pixelization) -* base-mesh configuration. It inherits from t8_geometry_with_vertices and +* base-mesh configuration. It inherits from t8_geometry and * is designed to map planar quadrilateral faces onto a spherical surface. */ struct t8_geometry_healpix: public t8_geometry @@ -93,7 +93,7 @@ struct t8_geometry_healpix: public t8_geometry /** * Check for compatibility of the currently loaded tree with the geometry. - * Only hex elements are supported by this geometry. + * Only quad elements are supported by this geometry. * \return True if the geometry is compatible with the tree. */ bool @@ -101,7 +101,7 @@ struct t8_geometry_healpix: public t8_geometry { if (active_tree_class != T8_ECLASS_QUAD) { t8_productionf ("t8_geometry_healpix is not compatible with tree type %s\n" - "It is only compatible with hex elements.\n", + "It is only compatible with quad elements.\n", t8_eclass_to_string[active_tree_class]); return false; } @@ -115,5 +115,4 @@ struct t8_geometry_healpix: public t8_geometry t8_geometry_type_t t8_geom_get_type () const override; - /* Load tree data is inherited from t8_geometry_with_vertices. */ }; From 0d324a39e4969fb24159c65e68ef9fb62ed407a0 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 9 Nov 2026 11:03:51 +0100 Subject: [PATCH 36/47] fix: fixes zero division issue --- .../t8_cmesh_healpix/t8_geometry_healpix.cxx | 28 +++++++++++++++---- .../t8_cmesh_healpix/t8_geometry_healpix.hxx | 1 - 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx index 6c48f32b99..8cefeccbae 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx @@ -55,12 +55,28 @@ t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, phi = (std::numbers::pi / 4.0) * dX; } else if (dY > 1.0) { - z = 1.0 - (1.0 / 3.0) * std::pow (2.0 - dY, 2.0); - phi = (std::numbers::pi / 4.0) * (offset_x + (dX - offset_x) / (2.0 - dY)); + const double denominator = 2.0 - dY; + z = 1.0 - (1.0 / 3.0) * std::pow (denominator, 2.0); + + if (denominator > 0.0) { + phi = (std::numbers::pi / 4.0) * (offset_x + (dX - offset_x) / denominator); + } + else { + // At the north pole, phi is arbitrary. + phi = (std::numbers::pi / 4.0) * offset_x; + } } else { - z = -1.0 + (1.0 / 3.0) * std::pow (2.0 + dY, 2.0); - phi = (std::numbers::pi / 4.0) * (offset_x + (dX - offset_x) / (2.0 + dY)); + const double denominator = 2.0 + dY; + z = -1.0 + (1.0 / 3.0) * std::pow (denominator, 2.0); + + if (denominator > 0.0) { + phi = (std::numbers::pi / 4.0) * (offset_x + (dX - offset_x) / denominator); + } + else { + // At the south pole, phi is arbitrary. + phi = (std::numbers::pi / 4.0) * offset_x; + } } z = std::clamp (z, -1.0, 1.0); @@ -86,8 +102,8 @@ t8_geometry_healpix::t8_geom_evaluate ([[maybe_unused]] t8_cmesh_t cmesh, t8_glo const size_t base_idx_2d = i * 2; const size_t base_idx_3d = i * 3; // t8code outputs 3D Cartesian coordinates (x, y, z) - const double xi = std::clamp (ref_coords[base_idx_2d + 0], 1e-10, 1.0 - 1e-10); - const double eta = std::clamp (ref_coords[base_idx_2d + 1], 1e-10, 1.0 - 1e-10); + const double xi = (ref_coords[base_idx_2d + 0]); + const double eta = (ref_coords[base_idx_2d + 1]); // Pass the pointer offset for 3D coordinates: out_coords + base_idx_3d t8_eval_geom_point (layer, face, xi, eta, out_coords + base_idx_3d, sphere_radius); diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx index d85fc8036a..cb2d0a3e04 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx @@ -114,5 +114,4 @@ struct t8_geometry_healpix: public t8_geometry */ t8_geometry_type_t t8_geom_get_type () const override; - }; From b19c191b884a16a50d70094332ad9c8d23c63af8 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 9 Nov 2026 11:23:49 +0100 Subject: [PATCH 37/47] fix: adds a base tolerance --- .../t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx index 3ddb9ba31a..407d7ed1d1 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -155,8 +155,12 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) // Allow a slightly relaxed tolerance near the poles where sin(theta) ~ 0 // Scale the polar check and tolerance by the active radius - const double adaptive_tol - = ((std::abs (ref_z) > 0.99 * radius) ? (16.0 * T8_PRECISION_SQRT_EPS) : (64.0 * T8_PRECISION_EPS)) * radius; + const double base_tol + = (std::abs (ref_z) > 0.99 * radius) ? (16.0 * T8_PRECISION_SQRT_EPS) : (128.0 * T8_PRECISION_EPS); + + // Add a minimum absolute floor (e.g., 1e-8) to gracefully handle near-zero values + // where microscopic rounding noise in reference data shouldn't trigger a failure. + const double adaptive_tol = std::max (base_tol * radius, 1e-8); EXPECT_NEAR (t8_out[idx3d + 0], ref_x, adaptive_tol) << "Mismatch in X | Tree ID: " << gtreeid << " (Layer: " << layer << ", Face: " << face << ")" << ", (xi, eta): (" << xi << ", " << eta << ")"; From 72da295920128096f6783d624da0d23b2eca3e10 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Mon, 16 Nov 2026 13:35:29 +0100 Subject: [PATCH 38/47] fix: fixes conncetivity of the mesh --- .../t8_cmesh_healpix/t8_cmesh_healpix.cxx | 47 +++++-------------- .../t8_cmesh_healpix/t8_geometry_healpix.hxx | 10 ++++ 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index 1a8f841cc7..467bcd226f 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -47,41 +47,18 @@ struct t8_healpix_join int orient; }; -static const struct t8_healpix_join healpix_joins[24] = { - /* North Ring Connections */ - { 0, 1, 1, 3, 0 }, - { 0, 3, 3, 1, 0 }, - { 1, 1, 2, 3, 0 }, - { 2, 1, 3, 3, 0 }, - - /* North-to-Equator Connections */ - { 0, 0, 4, 2, 0 }, - { 0, 2, 5, 3, 1 }, - { 1, 0, 5, 2, 0 }, - { 1, 2, 6, 3, 1 }, - { 2, 0, 6, 2, 0 }, - { 2, 2, 7, 3, 1 }, - { 3, 0, 7, 2, 0 }, - { 3, 2, 4, 3, 1 }, - - /* Equatorial Connections */ - { 4, 1, 5, 0, 1 }, - { 5, 1, 6, 0, 1 }, - { 6, 1, 7, 0, 1 }, - { 7, 1, 4, 0, 1 }, - - /* Equator-to-South Connections */ - { 4, 0, 8, 3, 1 }, - { 5, 0, 9, 3, 1 }, - { 6, 0, 10, 3, 1 }, - { 7, 0, 11, 3, 1 }, - - /* South Ring Connections */ - { 8, 1, 9, 3, 0 }, - { 8, 2, 11, 0, 0 }, - { 9, 1, 10, 3, 0 }, - { 10, 1, 11, 3, 0 } -}; +static const struct t8_healpix_join healpix_joins[24] + = { { 1, 0, 0, 2, 0 }, { 2, 0, 1, 2, 0 }, { 3, 0, 2, 2, 0 }, { 3, 2, 0, 0, 0 }, + + { 4, 0, 3, 1, 0 }, { 4, 2, 0, 3, 0 }, { 5, 0, 0, 1, 0 }, { 5, 2, 1, 3, 0 }, + + { 6, 0, 1, 1, 0 }, { 6, 2, 2, 3, 0 }, { 7, 0, 2, 1, 0 }, { 7, 2, 3, 3, 0 }, + + { 8, 0, 4, 1, 0 }, { 8, 2, 5, 3, 0 }, { 9, 0, 5, 1, 0 }, { 9, 2, 6, 3, 0 }, + + { 9, 3, 8, 1, 0 }, { 10, 0, 6, 1, 0 }, { 10, 2, 7, 3, 0 }, { 10, 3, 9, 1, 0 }, + + { 11, 0, 7, 1, 0 }, { 11, 1, 8, 3, 0 }, { 11, 2, 4, 3, 0 }, { 11, 3, 10, 1, 0 } }; /** * Creates and initializes a new coarse mesh (cmesh) with HEALPix topology. * diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx index cb2d0a3e04..abc5a351dc 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx @@ -114,4 +114,14 @@ struct t8_geometry_healpix: public t8_geometry */ t8_geometry_type_t t8_geom_get_type () const override; + + /** + * Override to suppress warning. + * \return True if the currently loaded tree has a negative volume. + */ + virtual bool + t8_geom_tree_negative_volume () const override + { + return 0; + }; }; From 59e6b9445b22c7aa48b8b7b70de61d007041a386 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Wed, 18 Nov 2026 10:27:58 +0100 Subject: [PATCH 39/47] fix: fixes the connectivity due to a previous error in layer numbering --- .../t8_cmesh_healpix/t8_cmesh_healpix.cxx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index 467bcd226f..59486f3192 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -47,18 +47,21 @@ struct t8_healpix_join int orient; }; -static const struct t8_healpix_join healpix_joins[24] - = { { 1, 0, 0, 2, 0 }, { 2, 0, 1, 2, 0 }, { 3, 0, 2, 2, 0 }, { 3, 2, 0, 0, 0 }, +struct t8_healpix_join healpix_joins[24] + = { { 1, 3, 0, 1, 0 }, { 2, 3, 1, 1, 0 }, { 3, 1, 0, 3, 0 }, { 3, 3, 2, 1, 0 }, - { 4, 0, 3, 1, 0 }, { 4, 2, 0, 3, 0 }, { 5, 0, 0, 1, 0 }, { 5, 2, 1, 3, 0 }, + { 4, 1, 0, 0, 0 }, { 4, 3, 3, 2, 0 }, { 5, 1, 1, 0, 0 }, { 5, 3, 0, 2, 0 }, - { 6, 0, 1, 1, 0 }, { 6, 2, 2, 3, 0 }, { 7, 0, 2, 1, 0 }, { 7, 2, 3, 3, 0 }, + { 6, 1, 2, 0, 0 }, { 6, 3, 1, 2, 0 }, { 7, 1, 3, 0, 0 }, { 7, 3, 2, 2, 0 }, - { 8, 0, 4, 1, 0 }, { 8, 2, 5, 3, 0 }, { 9, 0, 5, 1, 0 }, { 9, 2, 6, 3, 0 }, + { 8, 1, 5, 0, 0 }, { 8, 3, 4, 2, 0 }, { 9, 0, 8, 2, 0 }, { 9, 1, 6, 0, 0 }, - { 9, 3, 8, 1, 0 }, { 10, 0, 6, 1, 0 }, { 10, 2, 7, 3, 0 }, { 10, 3, 9, 1, 0 }, + { 9, 3, 5, 2, 0 }, { 10, 0, 9, 2, 0 }, { 10, 1, 7, 0, 0 }, { 10, 3, 6, 2, 0 }, + + { 11, 0, 10, 2, 0 }, { 11, 1, 4, 0, 0 }, { 11, 2, 8, 0, 0 }, { 11, 3, 7, 2, 0 } + + }; - { 11, 0, 7, 1, 0 }, { 11, 1, 8, 3, 0 }, { 11, 2, 4, 3, 0 }, { 11, 3, 10, 1, 0 } }; /** * Creates and initializes a new coarse mesh (cmesh) with HEALPix topology. * From 8d643d56d638f7af8662016cad3cc28080b5e40c Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Fri, 27 Nov 2026 11:28:22 +0100 Subject: [PATCH 40/47] feat: allows for the mesh to have thickness --- .../t8_cmesh_healpix/t8_cmesh_healpix.cxx | 20 +++++++--- .../t8_cmesh_healpix/t8_cmesh_healpix.h | 2 +- .../t8_cmesh_healpix/t8_geometry_healpix.cxx | 38 ++++++++++++------- .../t8_cmesh_healpix/t8_geometry_healpix.hxx | 29 +++++++++++--- 4 files changed, 63 insertions(+), 26 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index 59486f3192..bc2e3b70cb 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -71,11 +71,12 @@ struct t8_healpix_join healpix_joins[24] * before committing the mesh. * * @param[in] comm The MPI communicator used to manage parallel partitioning/commit. - * @param[in] sphere_radius The radius of the sphere. Default to 1 + * @param[in] sphere_outer_radius The outer radius of the sphere. Default to 1 + * @param[in] sphere_inner_radius The inner radius of the sphere. Default to 0 * @return t8_cmesh_t A committed coarse mesh object containing the HEALPix base structure. */ t8_cmesh_t -t8_cmesh_new_healpix (sc_MPI_Comm comm, double sphere_radius = 1) +t8_cmesh_new_healpix (sc_MPI_Comm comm, double sphere_outer_radius = 1, double sphere_inner_radius = 0) { /* Initialization of the mesh */ t8_cmesh_t cmesh; @@ -84,10 +85,17 @@ t8_cmesh_new_healpix (sc_MPI_Comm comm, double sphere_radius = 1) const int ntrees = 12; /* Register geometry and retain the pointer */ - t8_cmesh_register_geometry (cmesh, sphere_radius); - - for (int itree = 0; itree < ntrees; itree++) { - t8_cmesh_set_tree_class (cmesh, itree, T8_ECLASS_QUAD); + t8_cmesh_register_geometry (cmesh, sphere_outer_radius, sphere_inner_radius); + // If the mesh has no depth, set the class to quads to remove unnecessary elements + if (sphere_outer_radius == sphere_inner_radius) { + for (int itree = 0; itree < ntrees; itree++) { + t8_cmesh_set_tree_class (cmesh, itree, T8_ECLASS_QUAD); + } + } + else { + for (int itree = 0; itree < ntrees; itree++) { + t8_cmesh_set_tree_class (cmesh, itree, T8_ECLASS_HEX); + } } /* Explicit O(1) manual face joining */ for (size_t i = 0; i < 24; ++i) { diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h index b2fb50a2b1..ef5a97ce56 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h @@ -26,4 +26,4 @@ * \return A coarse mesh representing the HEALPix base grid. */ t8_cmesh_t -t8_cmesh_new_healpix (sc_MPI_Comm comm, double sphere_radius = 1); +t8_cmesh_new_healpix (sc_MPI_Comm comm, double sphere_outer_radius = 1, double sphere_inner_radius = 0); diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx index 8cefeccbae..d27578260e 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx @@ -27,20 +27,30 @@ /** * Evaluates a point on a sphere surface geometry from mesh layer and face parameters. * - * Maps 2D parametric reference coordinates (\p xi, \p eta) of a specific mesh element, + * Maps 3D parametric reference coordinates (\p xi, \p eta) of a specific mesh element, * identified by its \p layer and \p face indices, to 3D Cartesian coordinates on a unit sphere. * * @param[in] layer The layer index of the mesh element. * @param[in] face The face index of the mesh element within the layer. * @param[in] xi The reference coordinate in the first parametric direction (typically [0, 1]). * @param[in] eta The reference coordinate in the second parametric direction (typically [0, 1]). + * @param[in] radial_pos Normalized radial position in [0.0, 1.0] (0.0 -> inner_radius, 1.0 -> outer_radius). * @param[out] out_coord Pointer to an array of size 3 where the resulting (x, y, z) * Cartesian coordinates will be stored. - * @param[in] radius The radius of the sphere + * @param[in] inner_radius Inner radius of the shell (clamped to [0.0, outer_radius]). + * @param[in] outer_radius Outer radius of the shell. */ void -t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, double *out_coord, double radius) +t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, double radial_pos, double *out_coord, + double inner_radius, double outer_radius) { + const double safe_outer = std::max (0.0, outer_radius); + const double safe_inner = std::clamp (inner_radius, 0.0, safe_outer); + const double clamped_pos = std::clamp (radial_pos, 0.0, 1.0); + + // Interpolate between inner_radius and outer_radius; as safe_inner -> safe_outer, shell becomes thin + const double r = safe_inner + clamped_pos * (safe_outer - safe_inner); + const double offset_y = 1.0 - static_cast (layer); const double offset_x = 2.0 * face + ((layer + 1) % 2); @@ -81,13 +91,13 @@ t8_eval_geom_point (t8_gloidx_t layer, t8_gloidx_t face, double xi, double eta, z = std::clamp (z, -1.0, 1.0); - // Convert Spherical coordinates (z, phi) to 3D Cartesian coordinates (x, y, z) + // Convert unit-sphere spherical coordinates (z, phi) to Cartesian coordinates at radius r const double theta = std::acos (z); const double sin_theta = std::sin (theta); - out_coord[0] = (sin_theta * std::cos (phi)) * radius; - out_coord[1] = sin_theta * std::sin (phi) * radius; - out_coord[2] = z * radius; + out_coord[0] = (sin_theta * std::cos (phi)) * r; + out_coord[1] = (sin_theta * std::sin (phi)) * r; + out_coord[2] = z * r; } void @@ -99,18 +109,18 @@ t8_geometry_healpix::t8_geom_evaluate ([[maybe_unused]] t8_cmesh_t cmesh, t8_glo const t8_gloidx_t face = gtreeid % 4; for (size_t i = 0; i < num_coords; ++i) { - const size_t base_idx_2d = i * 2; - const size_t base_idx_3d = i * 3; // t8code outputs 3D Cartesian coordinates (x, y, z) + const size_t base_idx_ref = i * 3; // 3D reference coordinates (xi, eta, zeta) + const size_t base_idx_3d = i * 3; // 3D Cartesian coordinates (x, y, z) - const double xi = (ref_coords[base_idx_2d + 0]); - const double eta = (ref_coords[base_idx_2d + 1]); + const double xi = ref_coords[base_idx_ref + 0]; + const double eta = ref_coords[base_idx_ref + 1]; + const double zeta = ref_coords[base_idx_ref + 2]; // Radial parameter in [0, 1] - // Pass the pointer offset for 3D coordinates: out_coords + base_idx_3d - t8_eval_geom_point (layer, face, xi, eta, out_coords + base_idx_3d, sphere_radius); + t8_eval_geom_point (layer, face, xi, eta, zeta, out_coords + base_idx_3d, sphere_inner_radius, sphere_outer_radius); } } t8_geometry_type_t t8_geometry_healpix::t8_geom_get_type () const { - return T8_GEOMETRY_TYPE_ZERO; // Or the specific t8_geometry_type_t enum value for HEALPix + return T8_GEOMETRY_TYPE_ANALYTIC; // Or the specific t8_geometry_type_t enum value for HEALPix } diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx index abc5a351dc..a5378675f6 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx @@ -31,17 +31,36 @@ struct t8_geometry_healpix: public t8_geometry { private: - double sphere_radius; + double sphere_outer_radius; + double sphere_inner_radius = 0; public: /** - * @brief Constructs a HEALPix geometry with the specified sphere radius. + * @brief Constructs a HEALPix geometry with the specified sphere inner and outer radius. * - * @param radius The radius of the sphere. + * @param outer_radius The outer radius of the sphere. + * @param inner_radius The inner radius of the sphere. + */ + t8_geometry_healpix (double outer_radius, double inner_radius): t8_geometry ("t8_geometry_healpix") + { + if (inner_radius > outer_radius) { + t8_errorf ("\n[t8_healpix] Warning inner radius is greater than outer radius \n[t8_healpix] defaulting to a " + "radius of 1\n"); + } + else if (inner_radius == outer_radius) { + t8_errorf ("\n[t8_healpix] Warning inner radius is equal to outer radius \n[t8_healpix] thickness is zero \n"); + } + sphere_outer_radius = outer_radius; + sphere_inner_radius = inner_radius; + } + /** + * @brief Default constructor. + * + * Constructs a HEALPix geometry with a given sphere radius. */ t8_geometry_healpix (double radius): t8_geometry ("t8_geometry_healpix") { - sphere_radius = radius; + sphere_outer_radius = radius; } /** * @brief Default constructor. @@ -50,7 +69,7 @@ struct t8_geometry_healpix: public t8_geometry */ t8_geometry_healpix (): t8_geometry ("t8_geometry_healpix") { - sphere_radius = 1; + sphere_outer_radius = 1; } /** From bfbca0f25302e1ab722f32a748bce9fc7859c66c Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Fri, 27 Nov 2026 12:13:03 +0100 Subject: [PATCH 41/47] fix: adjusts the tests to handle thickness --- ..._gtest_cmesh_healpix_check_correctness.cxx | 38 +++++++++++-------- .../t8_gtest_cmesh_healpix_unit_sphere.cxx | 37 ++++++++++++------ 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx index 407d7ed1d1..81cb4d669b 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -29,9 +29,9 @@ #include /** \file We cross reference our implementation with this of - * xyf2loc from the HEALPix Julia source code. We evaluate - * both implementation and compare them to eachother. - * if the evaluation is close enough then the test passes. +- xyf2loc from the HEALPix Julia source code. We evaluate +- both implementation and compare them to eachother. +- if the evaluation is close enough then the test passes. */ struct t8_location_result @@ -95,22 +95,27 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) const int JPLL[12] = { 1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7 }; #if T8_TEST_LEVEL_INT >= 2 - double radius = 0.5; + const double outer_radius = 0.5; + const double inner_radius = 0.25; #else - double radius = 10; + const double outer_radius = 10.0; + const double inner_radius = 4.0; #endif constexpr std::array test_samples = { 0.0, 0.001, 0.25, 0.5, 0.75, 0.999, 1.0 }; - t8_geometry_healpix geom (radius); - // Build a batch containing all combinations of test_samples for a single evaluation call using std::array + // Construct t8_geometry_healpix with (inner_radius, outer_radius) + t8_geometry_healpix geom (outer_radius, inner_radius); + + // Build 3D reference coordinates (xi, eta, zeta) with zeta = 1.0 (outer boundary) constexpr size_t num_samples = test_samples.size (); constexpr int num_coords = num_samples * num_samples; - std::array ref_coords; + std::array ref_coords; size_t coord_idx = 0; for (double xi : test_samples) { for (double eta : test_samples) { ref_coords[coord_idx++] = xi; ref_coords[coord_idx++] = eta; + ref_coords[coord_idx++] = 1.0; // Outer surface of the shell matches xyf2loc at outer_radius } } @@ -134,19 +139,19 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) // Validate each point in the batch against xyf2loc reference for (int coord_index = 0; coord_index < num_coords; coord_index++) { - const double xi = ref_coords[coord_index * 2 + 0]; - const double eta = ref_coords[coord_index * 2 + 1]; + const double xi = ref_coords[coord_index * 3 + 0]; + const double eta = ref_coords[coord_index * 3 + 1]; // Clamped values used inside t8_geom_evaluate const double xi_clamped = std::clamp (xi, 1e-10, 1.0 - 1e-10); const double eta_clamped = std::clamp (eta, 1e-10, 1.0 - 1e-10); - // Pass the 0..11 global face index to xyf2loc - const t8_location_result ref_loc = xyf2loc (xi_clamped, eta_clamped, healpix_face, JRLL, JPLL, radius); + const t8_location_result ref_loc = xyf2loc (xi_clamped, eta_clamped, healpix_face, JRLL, JPLL, outer_radius); - const double ref_sin_theta = ref_loc.have_sintheta - ? ref_loc.sintheta - : std::sqrt (std::max (0.0, (radius * radius) - ref_loc.z * ref_loc.z)); + const double ref_sin_theta + = ref_loc.have_sintheta + ? ref_loc.sintheta + : std::sqrt (std::max (0.0, (outer_radius * outer_radius) - ref_loc.z * ref_loc.z)); const double ref_x = ref_sin_theta * std::cos (ref_loc.phi); const double ref_y = ref_sin_theta * std::sin (ref_loc.phi); const double ref_z = ref_loc.z; @@ -156,7 +161,8 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) // Allow a slightly relaxed tolerance near the poles where sin(theta) ~ 0 // Scale the polar check and tolerance by the active radius const double base_tol - = (std::abs (ref_z) > 0.99 * radius) ? (16.0 * T8_PRECISION_SQRT_EPS) : (128.0 * T8_PRECISION_EPS); + = (std::abs (ref_z) > 0.99 * outer_radius) ? (16.0 * T8_PRECISION_SQRT_EPS) : (128.0 * T8_PRECISION_EPS); + const double adaptive_tol = std::max (base_tol * outer_radius, 1e-8); // Add a minimum absolute floor (e.g., 1e-8) to gracefully handle near-zero values // where microscopic rounding noise in reference data shouldn't trigger a failure. diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx index 1ecdd42f04..4c89a55262 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_unit_sphere.cxx @@ -32,7 +32,10 @@ /* Test whether the healpix geometry has an equal radius all across the geometry. */ TEST (t8_geometry_healpix_test, test_all_trees_are_on_unit_sphere) { - t8_geometry_healpix geom; + const double outer_radius = 1.0; + const double inner_radius = 0.5; + + t8_geometry_healpix geom (outer_radius, inner_radius); std::random_device rd; std::mt19937 gen (rd ()); @@ -45,29 +48,41 @@ TEST (t8_geometry_healpix_test, test_all_trees_are_on_unit_sphere) #else const int num_gen_coords = 20; #endif - std::array ref_coords = { - 0.0, 0.0, // Corners - 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.5, 0.5, // Center + + std::array ref_coords = { + 0.0, 0.0, 1.0, // Corner, outer surface + 1.0, 0.0, 1.0, // Corner, outer surface + 0.0, 1.0, 1.0, // Corner, outer surface + 1.0, 1.0, 1.0, // Corner, outer surface + 0.5, 0.5, 1.0, // Center, outer surface + 0.5, 0.5, 0.0 // Center, inner surface }; for (int coord_index = 0; coord_index < num_gen_coords; coord_index++) { - ref_coords[2 * coord_index + 10] = (dist (gen)); - ref_coords[2 * coord_index + 11] = (dist (gen)); + const size_t base = 18 + 3 * static_cast (coord_index); + ref_coords[base + 0] = dist (gen); + ref_coords[base + 1] = dist (gen); + ref_coords[base + 2] = dist (gen); } - const size_t num_coords = ref_coords.size () / 2; + const size_t num_coords = ref_coords.size () / 3; std::vector out_coords (num_coords * 3, 0.0); // Loop through all 12 base trees of the HEALPix projection for (t8_gloidx_t gtreeid = 0; gtreeid < 12; ++gtreeid) { geom.t8_geom_evaluate (nullptr, gtreeid, ref_coords.data (), num_coords, out_coords.data ()); for (size_t i = 0; i < num_coords; ++i) { + const double xi = ref_coords[i * 3 + 0]; + const double eta = ref_coords[i * 3 + 1]; + const double zeta = ref_coords[i * 3 + 2]; + const double expected_radius = inner_radius + zeta * (outer_radius - inner_radius); + const std::span point (out_coords.data () + 3 * i, 3); const double distance = t8_norm (point); - // Expect distance to be 1.0 (Unit Sphere) - EXPECT_NEAR (distance, 1.0, T8_PRECISION_EPS) - << "Radius check failed at Tree ID: " << gtreeid << " for point index: " << i << " (xi=" << ref_coords[i * 2] - << ", eta=" << ref_coords[i * 2 + 1] << ")"; + + EXPECT_NEAR (distance, expected_radius, T8_PRECISION_EPS * outer_radius) + << "Radius check failed at Tree ID: " << gtreeid << " for point index: " << i << " (xi=" << xi + << ", eta=" << eta << ", zeta=" << zeta << ")"; } } } From 07720d47b6cc9007eaf7fb6241ebdc23dffdc3d1 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Fri, 27 Nov 2026 12:31:32 +0100 Subject: [PATCH 42/47] fix: fixes double declaration of adaptive_tol --- test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx index 81cb4d669b..7f66b6cab4 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -149,9 +149,8 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) const t8_location_result ref_loc = xyf2loc (xi_clamped, eta_clamped, healpix_face, JRLL, JPLL, outer_radius); const double ref_sin_theta - = ref_loc.have_sintheta - ? ref_loc.sintheta - : std::sqrt (std::max (0.0, (outer_radius * outer_radius) - ref_loc.z * ref_loc.z)); + = ref_loc.have_sintheta ? ref_loc.sintheta + : std::sqrt (std::max (0.0, (outer_radius * outer_radius) - ref_loc.z * ref_loc.z)); const double ref_x = ref_sin_theta * std::cos (ref_loc.phi); const double ref_y = ref_sin_theta * std::sin (ref_loc.phi); const double ref_z = ref_loc.z; @@ -166,7 +165,6 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) // Add a minimum absolute floor (e.g., 1e-8) to gracefully handle near-zero values // where microscopic rounding noise in reference data shouldn't trigger a failure. - const double adaptive_tol = std::max (base_tol * radius, 1e-8); EXPECT_NEAR (t8_out[idx3d + 0], ref_x, adaptive_tol) << "Mismatch in X | Tree ID: " << gtreeid << " (Layer: " << layer << ", Face: " << face << ")" << ", (xi, eta): (" << xi << ", " << eta << ")"; From 3422f56f5b9c6dfa0d1a06cad4ddd6c65c6b943c Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Fri, 27 Nov 2026 15:15:34 +0100 Subject: [PATCH 43/47] fix: sperates the dynamic assigning of the eclass --- .../t8_cmesh_healpix/t8_cmesh_healpix.cxx | 56 +++++++++++-------- .../t8_cmesh_healpix/t8_cmesh_healpix.h | 11 +++- .../t8_cmesh_healpix/t8_geometry_healpix.hxx | 4 +- ..._gtest_cmesh_healpix_check_correctness.cxx | 2 +- 4 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index bc2e3b70cb..584feeb23d 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -62,23 +62,10 @@ struct t8_healpix_join healpix_joins[24] }; -/** - * Creates and initializes a new coarse mesh (cmesh) with HEALPix topology. - * - * Registers the HEALPix geometry and sets up a 12-tree base coarse mesh consisting - * of quadrilateral faces (`T8_ECLASS_QUAD`). It explicitly establishes $O(1)$ manual - * face connectivity between neighboring trees according to the HEALPix adjacency table - * before committing the mesh. - * - * @param[in] comm The MPI communicator used to manage parallel partitioning/commit. - * @param[in] sphere_outer_radius The outer radius of the sphere. Default to 1 - * @param[in] sphere_inner_radius The inner radius of the sphere. Default to 0 - * @return t8_cmesh_t A committed coarse mesh object containing the HEALPix base structure. - */ t8_cmesh_t -t8_cmesh_new_healpix (sc_MPI_Comm comm, double sphere_outer_radius = 1, double sphere_inner_radius = 0) +t8_healpix_init (sc_MPI_Comm comm, t8_eclass eclass, double sphere_outer_radius, double sphere_inner_radius) { - /* Initialization of the mesh */ + t8_cmesh_t cmesh; t8_cmesh_init (&cmesh); @@ -87,16 +74,10 @@ t8_cmesh_new_healpix (sc_MPI_Comm comm, double sphere_outer_radius = 1, double s /* Register geometry and retain the pointer */ t8_cmesh_register_geometry (cmesh, sphere_outer_radius, sphere_inner_radius); // If the mesh has no depth, set the class to quads to remove unnecessary elements - if (sphere_outer_radius == sphere_inner_radius) { - for (int itree = 0; itree < ntrees; itree++) { - t8_cmesh_set_tree_class (cmesh, itree, T8_ECLASS_QUAD); - } - } - else { - for (int itree = 0; itree < ntrees; itree++) { - t8_cmesh_set_tree_class (cmesh, itree, T8_ECLASS_HEX); - } + for (int itree = 0; itree < ntrees; itree++) { + t8_cmesh_set_tree_class (cmesh, itree, eclass); } + /* Explicit O(1) manual face joining */ for (size_t i = 0; i < 24; ++i) { t8_cmesh_set_join (cmesh, healpix_joins[i].tree1, healpix_joins[i].tree2, healpix_joins[i].face1, @@ -106,3 +87,30 @@ t8_cmesh_new_healpix (sc_MPI_Comm comm, double sphere_outer_radius = 1, double s t8_cmesh_commit (cmesh, comm); return cmesh; } + +/** + * Creates and initializes a new coarse mesh (cmesh) with HEALPix topology. + * + * Registers the HEALPix geometry and sets up a 12-tree base coarse mesh consisting + * of quadrilateral faces (`T8_ECLASS_QUAD`). It explicitly establishes $O(1)$ manual + * face connectivity between neighboring trees according to the HEALPix adjacency table + * before committing the mesh. + * + * @param[in] comm The MPI communicator used to manage parallel partitioning/commit. + * @param[in] sphere_outer_radius The outer radius of the sphere. Default to 1 + * @param[in] sphere_inner_radius The inner radius of the sphere. Default to 0 + * @return t8_cmesh_t A committed coarse mesh object containing the HEALPix base structure. + */ +t8_cmesh_t +t8_cmesh_new_healpix_surface (sc_MPI_Comm comm, double sphere_outer_radius, double sphere_inner_radius) +{ + t8_cmesh_t cmesh = t8_healpix_init (comm, T8_ECLASS_HEX, sphere_outer_radius, sphere_inner_radius); + return cmesh; +} + +t8_cmesh_t +t8_cmesh_new_healpix_sphere (sc_MPI_Comm comm, double sphere_radius) +{ + t8_cmesh_t cmesh = t8_healpix_init (comm, T8_ECLASS_QUAD, sphere_radius, sphere_radius); + return cmesh; +} diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h index ef5a97ce56..d07cca0371 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h @@ -22,8 +22,15 @@ #include /** Creates a t8code cmesh consisting of 12 quadrilateral trees arranged - * according to the HEALPix base decomposition + * according to the HEALPix base decomposition as a surface * \return A coarse mesh representing the HEALPix base grid. */ t8_cmesh_t -t8_cmesh_new_healpix (sc_MPI_Comm comm, double sphere_outer_radius = 1, double sphere_inner_radius = 0); +t8_cmesh_new_healpix_surface (sc_MPI_Comm comm, double sphere_outer_radius = 1, double sphere_inner_radius = 0); + +/** Creates a t8code cmesh consisting of 12 quadrilateral trees arranged + * according to the HEALPix base decomposition as a sphere + * \return A coarse mesh representing the HEALPix base grid. + */ +t8_cmesh_t +t8_cmesh_new_healpix_sphere (sc_MPI_Comm comm, double sphere_radius); diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx index a5378675f6..c7a9376e0f 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx @@ -47,9 +47,7 @@ struct t8_geometry_healpix: public t8_geometry t8_errorf ("\n[t8_healpix] Warning inner radius is greater than outer radius \n[t8_healpix] defaulting to a " "radius of 1\n"); } - else if (inner_radius == outer_radius) { - t8_errorf ("\n[t8_healpix] Warning inner radius is equal to outer radius \n[t8_healpix] thickness is zero \n"); - } + sphere_outer_radius = outer_radius; sphere_inner_radius = inner_radius; } diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx index 7f66b6cab4..4cd48f23f8 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -103,7 +103,7 @@ TEST (t8_healpix_geometry_test, test_batch_against_xyf2loc_reference) #endif constexpr std::array test_samples = { 0.0, 0.001, 0.25, 0.5, 0.75, 0.999, 1.0 }; - // Construct t8_geometry_healpix with (inner_radius, outer_radius) + // Construct t8_geometry_healpix with (outer_radius, inner_radius) t8_geometry_healpix geom (outer_radius, inner_radius); // Build 3D reference coordinates (xi, eta, zeta) with zeta = 1.0 (outer boundary) From 5fa9d7c3558ad853180360829090460794ca7ee3 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Fri, 27 Nov 2026 15:24:24 +0100 Subject: [PATCH 44/47] docs: adds docs for the new healpix geometries --- .../t8_cmesh_healpix/t8_cmesh_healpix.cxx | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index 584feeb23d..28baa5ff72 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -62,6 +62,20 @@ struct t8_healpix_join healpix_joins[24] }; +/** + * The main logic for the HEALPix topology. + * + * Registers the HEALPix geometry and sets up a 12-tree base coarse mesh consisting + * of quadrilateral faces. It explicitly establishes $O(1)$ manual + * face connectivity between neighboring trees according to the HEALPix adjacency table + * before committing the mesh. + * + * @param[in] comm The MPI communicator used to manage parallel partitioning/commit. + * @param[in] eclass The eclass that should be assigned + * @param[in] sphere_outer_radius The outer radius of the sphere. + * @param[in] sphere_inner_radius The inner radius of the sphere + * @return t8_cmesh_t A committed coarse mesh object containing the HEALPix base structure as a surface. + */ t8_cmesh_t t8_healpix_init (sc_MPI_Comm comm, t8_eclass eclass, double sphere_outer_radius, double sphere_inner_radius) { @@ -92,14 +106,14 @@ t8_healpix_init (sc_MPI_Comm comm, t8_eclass eclass, double sphere_outer_radius, * Creates and initializes a new coarse mesh (cmesh) with HEALPix topology. * * Registers the HEALPix geometry and sets up a 12-tree base coarse mesh consisting - * of quadrilateral faces (`T8_ECLASS_QUAD`). It explicitly establishes $O(1)$ manual + * of quadrilateral faces (`T8_ECLASS_HEX`). It explicitly establishes $O(1)$ manual * face connectivity between neighboring trees according to the HEALPix adjacency table * before committing the mesh. * * @param[in] comm The MPI communicator used to manage parallel partitioning/commit. - * @param[in] sphere_outer_radius The outer radius of the sphere. Default to 1 - * @param[in] sphere_inner_radius The inner radius of the sphere. Default to 0 - * @return t8_cmesh_t A committed coarse mesh object containing the HEALPix base structure. + * @param[in] sphere_outer_radius The outer radius of the sphere. + * @param[in] sphere_inner_radius The inner radius of the sphere + * @return t8_cmesh_t A committed coarse mesh object containing the HEALPix base structure as a surface. */ t8_cmesh_t t8_cmesh_new_healpix_surface (sc_MPI_Comm comm, double sphere_outer_radius, double sphere_inner_radius) @@ -108,6 +122,18 @@ t8_cmesh_new_healpix_surface (sc_MPI_Comm comm, double sphere_outer_radius, doub return cmesh; } +/** + * Creates and initializes a new coarse mesh (cmesh) with HEALPix topology. + * + * Registers the HEALPix geometry and sets up a 12-tree base coarse mesh consisting + * of quadrilateral faces (`T8_ECLASS_QUAD`). It explicitly establishes $O(1)$ manual + * face connectivity between neighboring trees according to the HEALPix adjacency table + * before committing the mesh. + * + * @param[in] comm The MPI communicator used to manage parallel partitioning/commit. + * @param[in] sphere_radius The radius of the sphere. + * @return t8_cmesh_t A committed coarse mesh object containing the HEALPix base structure as a sphere. + */ t8_cmesh_t t8_cmesh_new_healpix_sphere (sc_MPI_Comm comm, double sphere_radius) { From 99722bf5121b1843da7fb1531d631f08155fe43e Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Fri, 4 Dec 2026 08:52:03 +0100 Subject: [PATCH 45/47] chore: adds suggestions --- .../t8_cmesh_healpix/t8_cmesh_healpix.cxx | 17 +++++++++-------- .../t8_cmesh_healpix/t8_cmesh_healpix.h | 4 ++-- ...t8_gtest_cmesh_healpix_check_correctness.cxx | 5 +++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index 28baa5ff72..7b0eb2ea9f 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -64,6 +64,7 @@ struct t8_healpix_join healpix_joins[24] /** * The main logic for the HEALPix topology. + * Refer to: https://healpix.sourceforge.io/credits.php * * Registers the HEALPix geometry and sets up a 12-tree base coarse mesh consisting * of quadrilateral faces. It explicitly establishes $O(1)$ manual @@ -106,19 +107,19 @@ t8_healpix_init (sc_MPI_Comm comm, t8_eclass eclass, double sphere_outer_radius, * Creates and initializes a new coarse mesh (cmesh) with HEALPix topology. * * Registers the HEALPix geometry and sets up a 12-tree base coarse mesh consisting - * of quadrilateral faces (`T8_ECLASS_HEX`). It explicitly establishes $O(1)$ manual + * of quadrilateral faces (`T8_ECLASS_QUAD`). It explicitly establishes $O(1)$ manual * face connectivity between neighboring trees according to the HEALPix adjacency table * before committing the mesh. * * @param[in] comm The MPI communicator used to manage parallel partitioning/commit. - * @param[in] sphere_outer_radius The outer radius of the sphere. - * @param[in] sphere_inner_radius The inner radius of the sphere + * @param[in] surface_outer_radius The outer radius of the sphere. + * @param[in] surface_inner_radius The inner radius of the sphere * @return t8_cmesh_t A committed coarse mesh object containing the HEALPix base structure as a surface. */ t8_cmesh_t -t8_cmesh_new_healpix_surface (sc_MPI_Comm comm, double sphere_outer_radius, double sphere_inner_radius) +t8_cmesh_new_healpix_surface (sc_MPI_Comm comm, double surface_outer_radius, double surface_inner_radius) { - t8_cmesh_t cmesh = t8_healpix_init (comm, T8_ECLASS_HEX, sphere_outer_radius, sphere_inner_radius); + t8_cmesh_t cmesh = t8_healpix_init (comm, T8_ECLASS_QUAD, surface_outer_radius, surface_inner_radius); return cmesh; } @@ -126,7 +127,7 @@ t8_cmesh_new_healpix_surface (sc_MPI_Comm comm, double sphere_outer_radius, doub * Creates and initializes a new coarse mesh (cmesh) with HEALPix topology. * * Registers the HEALPix geometry and sets up a 12-tree base coarse mesh consisting - * of quadrilateral faces (`T8_ECLASS_QUAD`). It explicitly establishes $O(1)$ manual + * of quadrilateral faces (`T8_ECLASS_HEX`). It explicitly establishes $O(1)$ manual * face connectivity between neighboring trees according to the HEALPix adjacency table * before committing the mesh. * @@ -135,8 +136,8 @@ t8_cmesh_new_healpix_surface (sc_MPI_Comm comm, double sphere_outer_radius, doub * @return t8_cmesh_t A committed coarse mesh object containing the HEALPix base structure as a sphere. */ t8_cmesh_t -t8_cmesh_new_healpix_sphere (sc_MPI_Comm comm, double sphere_radius) +t8_cmesh_new_healpix_shell (sc_MPI_Comm comm, double shell_radius) { - t8_cmesh_t cmesh = t8_healpix_init (comm, T8_ECLASS_QUAD, sphere_radius, sphere_radius); + t8_cmesh_t cmesh = t8_healpix_init (comm, T8_ECLASS_HEX, shell_radius, shell_radius); return cmesh; } diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h index d07cca0371..62319f8877 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h @@ -26,11 +26,11 @@ * \return A coarse mesh representing the HEALPix base grid. */ t8_cmesh_t -t8_cmesh_new_healpix_surface (sc_MPI_Comm comm, double sphere_outer_radius = 1, double sphere_inner_radius = 0); +t8_cmesh_new_healpix_surface (sc_MPI_Comm comm, double surface_outer_radius = 1, double surface_inner_radius = 0); /** Creates a t8code cmesh consisting of 12 quadrilateral trees arranged * according to the HEALPix base decomposition as a sphere * \return A coarse mesh representing the HEALPix base grid. */ t8_cmesh_t -t8_cmesh_new_healpix_sphere (sc_MPI_Comm comm, double sphere_radius); +t8_cmesh_new_healpix_shell (sc_MPI_Comm comm, double shell_radius); diff --git a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx index 4cd48f23f8..98732aa96b 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_healpix_check_correctness.cxx @@ -29,8 +29,9 @@ #include /** \file We cross reference our implementation with this of -- xyf2loc from the HEALPix Julia source code. We evaluate -- both implementation and compare them to eachother. +- xyf2loc from the HEALPix Julia source code. See here: + (https://github.com/JuliaAstro/Healpix.jl/blob/master/src/xyf.jl). +- We evaluate both implementation and compare them to eachother. - if the evaluation is close enough then the test passes. */ From 42d2a8d8096b108bf6111f0ebfc1423007f49ee0 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Fri, 4 Dec 2026 09:40:35 +0100 Subject: [PATCH 46/47] fix: adds include guards --- src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx | 2 +- src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx index 7b0eb2ea9f..22d69025ea 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx @@ -132,7 +132,7 @@ t8_cmesh_new_healpix_surface (sc_MPI_Comm comm, double surface_outer_radius, dou * before committing the mesh. * * @param[in] comm The MPI communicator used to manage parallel partitioning/commit. - * @param[in] sphere_radius The radius of the sphere. + * @param[in] shell_radius The radius of the sphere. * @return t8_cmesh_t A committed coarse mesh object containing the HEALPix base structure as a sphere. */ t8_cmesh_t diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx index c7a9376e0f..501588cf0e 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx @@ -19,7 +19,7 @@ along with t8code; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - +#pragma once #include #include /** From 40cf6141ef94ab7c9e0dbcfa95c420fa92c6dd24 Mon Sep 17 00:00:00 2001 From: faouziH21 <2004homsani@gmail.com> Date: Fri, 4 Dec 2026 09:53:52 +0100 Subject: [PATCH 47/47] fix: removes default parameters --- src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h index 62319f8877..2e9ce4cf23 100644 --- a/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h +++ b/src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h @@ -26,7 +26,7 @@ * \return A coarse mesh representing the HEALPix base grid. */ t8_cmesh_t -t8_cmesh_new_healpix_surface (sc_MPI_Comm comm, double surface_outer_radius = 1, double surface_inner_radius = 0); +t8_cmesh_new_healpix_surface (sc_MPI_Comm comm, double surface_outer_radius, double surface_inner_radius); /** Creates a t8code cmesh consisting of 12 quadrilateral trees arranged * according to the HEALPix base decomposition as a sphere