Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
5ebf98f
feat: implements healpix geometry
faouziH21 May 21, 2026
06586f8
Bugfix: removes unused radius parameter
faouziH21 May 21, 2026
a4ad384
docs: Updates copyright
faouziH21 Jun 2, 2026
e3431bf
Other: applies review suggestions
faouziH21 Jun 2, 2026
20c98b2
Other: lints all files according to indentation script
faouziH21 Jun 2, 2026
e1784f8
feat: adds a test suit for healpix
faouziH21 Jun 25, 2026
703da18
docs: documents t8_geometry_healpix and removes print
faouziH21 Jun 25, 2026
ed7feba
docs: fixes spacing and typo
faouziH21 Jun 25, 2026
4fa8e86
fix: fixes geometry and links the test to CMake
faouziH21 Sep 7, 2026
8893292
lint: lints the files according to t8code linting script
faouziH21 Sep 14, 2026
a29e300
fix: attempts to fix ninja CI
faouziH21 Sep 14, 2026
ce70022
Merge branch 'main' into implement-healpix-geometry
faouziH21 Sep 14, 2026
cd9235f
feat: changes the struct inheritance to t8_geometry instead of t8_geo…
faouziH21 Oct 9, 2026
3d4bb02
fix: adheres to ninja
faouziH21 Oct 9, 2026
a119c41
docs: docs missing docs and lints files
faouziH21 Oct 9, 2026
9c364d3
Apply batched suggestions from code review
faouziH21 Oct 9, 2026
970752b
lint: lints healpix test
faouziH21 Oct 9, 2026
2240e14
docs: documents t8_cmesh_new_healpix
faouziH21 Oct 9, 2026
6988c8c
docs: adds docs and override keyword
faouziH21 Oct 19, 2026
d29911d
Merge branch 'main' into implement-healpix-geometry
faouziH21 Oct 19, 2026
97da4dd
docs: adhere to doxygen
faouziH21 Oct 19, 2026
eb869de
feat: adds a new formula correction test and renames unit sphere test
faouziH21 Oct 19, 2026
eb706cf
docs: indent test file
faouziH21 Oct 19, 2026
fd66bc4
Merge branch 'main' into implement-healpix-geometry
faouziH21 Oct 19, 2026
1e009ec
Apply batched suggestions from code review
faouziH21 Oct 23, 2026
805d897
bugfix: naming conventions and bug fixes
faouziH21 Oct 23, 2026
8f4a910
Merge branch 'main' into implement-healpix-geometry
faouziH21 Oct 23, 2026
8896b08
Apply batched suggestions from code review
faouziH21 Oct 26, 2026
ad1e8bd
fix: fixes a bunch off issues like typos, indentation and more
faouziH21 Oct 26, 2026
14a4278
docs: adds a doc and lints correctly
faouziH21 Oct 26, 2026
e156a66
docs: document the file and fixes a typo
faouziH21 Oct 26, 2026
4f5127c
docs: fixes typo
faouziH21 Oct 26, 2026
1e7de7a
Merge branch 'main' into implement-healpix-geometry
faouziH21 Oct 26, 2026
8a1d1ae
Merge branch 'main' into implement-healpix-geometry
faouziH21 Oct 30, 2026
1c351f7
feat: adds an option to adjust the radius of the sphere
faouziH21 Oct 30, 2026
f3f8825
Merge remote-tracking branch 'origin/main' into implement-healpix-geo…
faouziH21 Oct 30, 2026
38219b5
docs: updates docs to adhere to doxygen and fixes unused param
faouziH21 Nov 2, 2026
85988fe
chore: changes vector to array
faouziH21 Nov 2, 2026
abc259e
fix: changes size_t to int and docs changes
faouziH21 Nov 2, 2026
0b979f7
fix: changes vectors into arrays and changes ordering of the layers
faouziH21 Nov 2, 2026
a114aca
fix: tests with regard of the radius
faouziH21 Nov 6, 2026
6e91f04
Merge branch 'main' into implement-healpix-geometry
faouziH21 Nov 6, 2026
5fbe524
docs: updates documentation
faouziH21 Nov 9, 2026
0d324a3
fix: fixes zero division issue
faouziH21 Nov 9, 2026
b19c191
fix: adds a base tolerance
faouziH21 Nov 9, 2026
72da295
fix: fixes conncetivity of the mesh
faouziH21 Nov 16, 2026
155c132
Merge branch 'main' into implement-healpix-geometry
faouziH21 Nov 16, 2026
59e6b94
fix: fixes the connectivity due to a previous error in layer numbering
faouziH21 Nov 18, 2026
8d643d5
feat: allows for the mesh to have thickness
faouziH21 Nov 27, 2026
bfbca0f
fix: adjusts the tests to handle thickness
faouziH21 Nov 27, 2026
07720d4
fix: fixes double declaration of adaptive_tol
faouziH21 Nov 27, 2026
3422f56
fix: sperates the dynamic assigning of the eclass
faouziH21 Nov 27, 2026
5fa9d7c
docs: adds docs for the new healpix geometries
faouziH21 Nov 27, 2026
99722bf
chore: adds suggestions
faouziH21 Dec 4, 2026
42d2a8d
fix: adds include guards
faouziH21 Dec 4, 2026
40cf614
fix: removes default parameters
faouziH21 Dec 4, 2026
b15b14e
Merge branch 'main' into implement-healpix-geometry
faouziH21 Dec 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,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_boundary_conditions/t8_cmesh_boundary_conditions.cxx
t8_cmesh/t8_cmesh_boundary_conditions/internal/t8_cmesh_boundary_condition_handler.cxx
t8_cmesh/t8_cmesh_boundary_conditions/internal/t8_cmesh_boundary_condition_handler_c_helper.cxx
Expand Down
143 changes: 143 additions & 0 deletions src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
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 <cmath>
#include <vector>
#include <t8_cmesh/t8_cmesh.hxx>
#include <t8_cmesh/t8_cmesh_helpers.h>
#include <t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx>

/**
* @brief Helper struct for joining healpix elements for t8_cmesh_set_join.
*/
struct t8_healpix_join
{
/** 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;
};

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, 1, 0, 0, 0 }, { 4, 3, 3, 2, 0 }, { 5, 1, 1, 0, 0 }, { 5, 3, 0, 2, 0 },

{ 6, 1, 2, 0, 0 }, { 6, 3, 1, 2, 0 }, { 7, 1, 3, 0, 0 }, { 7, 3, 2, 2, 0 },

{ 8, 1, 5, 0, 0 }, { 8, 3, 4, 2, 0 }, { 9, 0, 8, 2, 0 }, { 9, 1, 6, 0, 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 }

};

/**
* The main logic for the HEALPix topology.
* Refer to: https://healpix.sourceforge.io/credits.php
*
Comment thread
faouziH21 marked this conversation as resolved.
Resolved
* 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)
{

t8_cmesh_t cmesh;
t8_cmesh_init (&cmesh);

const int ntrees = 12;

/* Register geometry and retain the pointer */
t8_cmesh_register_geometry<t8_geometry_healpix> (cmesh, sphere_outer_radius, sphere_inner_radius);
// If the mesh has no depth, set the class to quads to remove unnecessary elements
Comment thread
faouziH21 marked this conversation as resolved.
Resolved
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,
healpix_joins[i].face2, healpix_joins[i].orient);
}

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] 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 surface_outer_radius, double surface_inner_radius)
{
t8_cmesh_t cmesh = t8_healpix_init (comm, T8_ECLASS_QUAD, surface_outer_radius, surface_inner_radius);
return cmesh;
}
Comment thread
faouziH21 marked this conversation as resolved.
Resolved

/**
* 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
* 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] 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
t8_cmesh_new_healpix_shell (sc_MPI_Comm comm, double shell_radius)
{
t8_cmesh_t cmesh = t8_healpix_init (comm, T8_ECLASS_HEX, shell_radius, shell_radius);
return cmesh;
}
36 changes: 36 additions & 0 deletions src/t8_cmesh/t8_cmesh_healpix/t8_cmesh_healpix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
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.
*/

Comment thread
Davknapp marked this conversation as resolved.
Resolved
#include <t8_cmesh/t8_cmesh.h>
/** Creates a t8code cmesh consisting of 12 quadrilateral trees arranged
* 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_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
Comment thread
faouziH21 marked this conversation as resolved.
Resolved
* \return A coarse mesh representing the HEALPix base grid.
*/
t8_cmesh_t
Comment thread
faouziH21 marked this conversation as resolved.
Resolved
t8_cmesh_new_healpix_shell (sc_MPI_Comm comm, double shell_radius);
126 changes: 126 additions & 0 deletions src/t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
Comment thread
Davknapp marked this conversation as resolved.
Resolved
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 <t8.h>
#include <t8_cmesh/t8_cmesh_healpix/t8_geometry_healpix.hxx>
#include <numbers>
Comment thread
faouziH21 marked this conversation as resolved.
Resolved

/**
* Evaluates a point on a sphere surface geometry from mesh layer and face parameters.
*
* Maps 3D parametric reference coordinates (\p xi, \p eta) of a specific mesh element,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This becomes (xi, eta, zeta), or rather (xi, eta, radial_pos) then?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the parameter case we should write radial_pos... but I understand if you would rather write zeta

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either would be fine for me. I just wanted to point out that the tuple should have 3 entries because this is referring to 3D coordinates.

* 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] 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 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<double> (layer);
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) {
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 {
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);

// 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)) * r;
out_coord[1] = (sin_theta * std::sin (phi)) * r;
out_coord[2] = z * r;
}

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
{
// This geometry is inspired by HEALPix
const t8_gloidx_t layer = gtreeid / 4;
const t8_gloidx_t face = gtreeid % 4;

for (size_t i = 0; i < num_coords; ++i) {
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_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]

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_ANALYTIC; // Or the specific t8_geometry_type_t enum value for HEALPix
}
Loading
Loading