Repository navigation
Feature: implements healpix geometry #2327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5ebf98f
06586f8
a4ad384
e3431bf
20c98b2
e1784f8
703da18
ed7feba
4fa8e86
8893292
a29e300
ce70022
cd9235f
3d4bb02
a119c41
9c364d3
970752b
2240e14
6988c8c
d29911d
97da4dd
eb869de
eb706cf
fd66bc4
1e009ec
805d897
8f4a910
8896b08
ad1e8bd
14a4278
e156a66
4f5127c
1e7de7a
8a1d1ae
1c351f7
f3f8825
38219b5
85988fe
abc259e
0b979f7
a114aca
6e91f04
5fbe524
0d324a3
b19c191
72da295
155c132
59e6b94
8d643d5
bfbca0f
07720d4
3422f56
5fa9d7c
99722bf
42d2a8d
40cf614
b15b14e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| * | ||
| * 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 | ||
|
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; | ||
| } | ||
|
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; | ||
| } | ||
| 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. | ||
| */ | ||
|
|
||
|
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 | ||
|
faouziH21 marked this conversation as resolved.
Resolved
|
||
| * \return A coarse mesh representing the HEALPix base grid. | ||
| */ | ||
| t8_cmesh_t | ||
|
faouziH21 marked this conversation as resolved.
Resolved
|
||
| t8_cmesh_new_healpix_shell (sc_MPI_Comm comm, double shell_radius); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| /* | ||
|
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> | ||
|
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, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This becomes (xi, eta, zeta), or rather (xi, eta, radial_pos) then?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.