Skip to content

Commit

Permalink
p4est_bits: add p4est_quadrant_root
Browse files Browse the repository at this point in the history
Previously we were generating a root quadrant by calling
p4est_quadrant_set_morton (q, 0, 0), which is less immediate.
  • Loading branch information
cburstedde committed Jan 30, 2025
1 parent a599301 commit 8392c19
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 8 deletions.
17 changes: 16 additions & 1 deletion src/p4est_bits.c
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,21 @@ p4est_quadrant_enlarge_last (const p4est_quadrant_t * a, p4est_quadrant_t * q)
#endif
}

void
p4est_quadrant_root (p4est_quadrant_t *root)
{
P4EST_ASSERT (root != NULL);

root->x = 0;
root->y = 0;
#ifdef P4_TO_P8
root->z = 0;
#endif
root->level = 0;

P4EST_ASSERT (p4est_quadrant_is_valid (root));
}

void
p4est_quadrant_ancestor (const p4est_quadrant_t * q,
int level, p4est_quadrant_t * r)
Expand Down Expand Up @@ -2212,7 +2227,7 @@ p4est_coordinates_transform_corner (p4est_qcoord_t coords[], int corner)
#endif

#ifdef P4EST_ENABLE_DEBUG
p4est_quadrant_set_morton (&root, 0, 0);
p4est_quadrant_root (&root);
p4est_quadrant_corner_coordinates (&root, corner, rcoords);
P4EST_ASSERT (rcoords[0] == coords[0]);
P4EST_ASSERT (rcoords[1] == coords[1]);
Expand Down
8 changes: 8 additions & 0 deletions src/p4est_bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,14 @@ void p4est_quadrant_enlarge_first (const p4est_quadrant_t * a,
void p4est_quadrant_enlarge_last (const p4est_quadrant_t * a,
p4est_quadrant_t * q);

/** Generate the root quadrant of any tree.
* \param [out] root Quadrant structure's coordinates and level are set.
* As with all other functions that generate or
* modify quadrants, the other bits of the structured
* data type are not touched at all.
*/
void p4est_quadrant_root (p4est_quadrant_t *root);

/** Compute the ancestor of a quadrant at a given level.
* \param [in] q Input quadrant.
* \param [in] level A smaller level than q.
Expand Down
2 changes: 1 addition & 1 deletion src/p4est_points.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ p4est_new_points (sc_MPI_Comm mpicomm, p4est_connectivity_t * connectivity,
/* determine largest possible last quadrant of this tree */
if (jt < next_tree) {
p4est_quadrant_last_descendant (&a, &l, maxlevel);
p4est_quadrant_set_morton_ext128 (&b, 0, &zero);
p4est_quadrant_root (&b);
p4est_quadrant_last_descendant (&b, &b, maxlevel);
if (p4est_quadrant_is_equal (&l, &b)) {
onlyone = 1;
Expand Down
12 changes: 6 additions & 6 deletions src/p4est_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ p4est_search_local (p4est_t * p4est,
tquadrants = &tree->quadrants;

/* the recursion shrinks the search quadrant whenever possible */
p4est_quadrant_set_morton (&root, 0, 0);
p4est_quadrant_root (&root);
p4est_local_recursion (rec, &root, tquadrants, NULL);
}
}
Expand Down Expand Up @@ -1033,7 +1033,7 @@ p4est_search_reorder (p4est_t * p4est, int skip_levels,
for (tt = p4est->first_local_tree; tt <= p4est->last_local_tree; ++tt) {
rit = tt - p4est->first_local_tree;
proot = (p4est_quadrant_t *) sc_array_index (tquadrants, rit);
p4est_quadrant_set_morton (proot, 0, 0);
p4est_quadrant_root (proot);
proot->p.piggy1.which_tree = tt;
*(p4est_topidx_t *) sc_array_index (root_indices, rit) = rit;
}
Expand Down Expand Up @@ -1073,7 +1073,7 @@ p4est_search_reorder (p4est_t * p4est, int skip_levels,
tquadrants = &tree->quadrants;

/* the recursion shrinks the search quadrant whenever possible */
p4est_quadrant_set_morton (&root, 0, 0);
p4est_quadrant_root (&root);
p4est_reorder_recursion (rec, &root, tquadrants, NULL);
}

Expand Down Expand Up @@ -1209,7 +1209,7 @@ static int p4est_traverse_is_valid_tree
P4EST_ASSERT (0 <= which_tree && which_tree < num_trees);
P4EST_ASSERT (0 <= pfirst && pfirst <= plast && plast < num_procs);

p4est_quadrant_set_morton (&root, 0, 0);
p4est_quadrant_root (&root);

return p4est_traverse_is_valid_quadrant
(gfp, num_procs, num_trees, which_tree, &root, pfirst, plast);
Expand Down Expand Up @@ -1538,7 +1538,7 @@ void p4est_search_partition_internal
rec->point_fn = point_fn;
rec->points = points;
rec->position_array = &position_array;
p4est_quadrant_set_morton (&root, 0, 0);
p4est_quadrant_root (&root);
for (pfirst = 0, tt = 0; tt < num_trees; pfirst = pnext, ++tt) {
/* pfirst is the first processor indexed for this tree */
rec->which_tree = root.p.which_tree = tt;
Expand Down Expand Up @@ -1909,7 +1909,7 @@ p4est_search_all (p4est_t * p4est,
rec->point_fn = point_fn;
rec->points = points;
rec->position_array = &position_array;
p4est_quadrant_set_morton (&root, 0, 0);
p4est_quadrant_root (&root);
for (pfirst = 0, tt = 0; tt < num_trees; pfirst = pnext, ++tt) {
/* pfirst is the first processor indexed for this tree */
rec->which_tree = root.p.which_tree = tt;
Expand Down
1 change: 1 addition & 0 deletions src/p4est_to_p8est.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@
#define p4est_quadrant_is_first_last p8est_quadrant_is_first_last
#define p4est_quadrant_enlarge_first p8est_quadrant_enlarge_first
#define p4est_quadrant_enlarge_last p8est_quadrant_enlarge_last
#define p4est_quadrant_root p8est_quadrant_root
#define p4est_quadrant_ancestor p8est_quadrant_ancestor
#define p4est_quadrant_parent p8est_quadrant_parent
#define p4est_quadrant_sibling p8est_quadrant_sibling
Expand Down
8 changes: 8 additions & 0 deletions src/p8est_bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,14 @@ void p8est_quadrant_enlarge_first (const p8est_quadrant_t * a,
void p8est_quadrant_enlarge_last (const p8est_quadrant_t * a,
p8est_quadrant_t * q);

/** Generate the root quadrant of any tree.
* \param [out] root Quadrant structure's coordinates and level are set.
* As with all other functions that generate or
* modify quadrants, the other bits of the structured
* data type are not touched at all.
*/
void p8est_quadrant_root (p8est_quadrant_t *root);

/** Compute the ancestor of a quadrant at a given level.
* \param [in] q Input quadrant.
* \param [in] level A smaller level than q.
Expand Down

0 comments on commit 8392c19

Please sign in to comment.