Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
fdea0bf
initial Commit
tunxu May 15, 2026
0ab2e07
Create a cmesh from bounding box around given cmesh
tunxu May 19, 2026
2c69750
Added check for required refinement level
tunxu May 26, 2026
a480c71
working test
tunxu Jun 3, 2026
06be9b5
Zwischencommit zum Umwechseln
tunxu Jun 15, 2026
82e1524
Fixed some issues
Jun 24, 2026
54bfb09
Reindex performed on stash
Jul 6, 2026
03d22ae
Working test
Jul 9, 2026
e68eb53
deleted vtk file writes
Jul 9, 2026
25114ab
removed old assertion
Jul 9, 2026
47bb76b
Iterating through list of vertices once now
Jul 15, 2026
98aa58a
Merge branch 'main' into feature-tree_reindexing
Jul 15, 2026
2775f8b
Commit in between
Jul 16, 2026
eba4e31
Added flag into t8_cmesh_types, reindexing now during commit activatable
Jul 21, 2026
d1159ca
Merge branch 'main' into feature-tree_reindexing
Jul 22, 2026
180d2a8
Added flag to the cmesh
Jul 28, 2026
2425890
Merge main
tunxu Jul 29, 2026
50b2dde
Clean up of code, with some comments
Sep 23, 2026
2cb21a9
Added docstrings in .h-file
Sep 23, 2026
c54385c
Fixed Merging issues
Sep 23, 2026
a22865b
Test Precommit [run ci]
Sep 23, 2026
b055340
Fixed Test
Sep 23, 2026
0c634e2
Fixed Docstrings
Sep 23, 2026
a8ed3f7
Merge branch 'main' into feature-tree_reindexing
Sep 23, 2026
f05db75
Removed t8_config.h
Sep 23, 2026
f29fc87
Fixed indentation t8_cmesh.cxx
Sep 23, 2026
02d4060
Trigger CI [run ci]
Sep 23, 2026
a5af226
rewritten code, so no std::span is used [run ci]
Sep 23, 2026
45303af
Merge branch 'main' into feature-tree_reindexing
tunxu Oct 1, 2026
3a6d72a
Resolved first review
Oct 5, 2026
67f539c
Fixed one Assertion
Oct 7, 2026
095a340
Removed t8_cmesh_get_num_trees() call as cmesh is not committed
Oct 7, 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
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ target_sources( T8 PRIVATE
t8_cmesh/t8_cmesh_internal/t8_cmesh_partition.cxx
t8_cmesh/t8_cmesh_internal/t8_cmesh_stash.c
t8_cmesh/t8_cmesh_internal/t8_cmesh_trees.cxx
t8_cmesh/t8_cmesh_internal/t8_cmesh_tree_reindex.cxx
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
Expand Down
7 changes: 7 additions & 0 deletions src/t8_cmesh/t8_cmesh.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ t8_cmesh_disable_negative_volume_check ([[maybe_unused]] t8_cmesh_t cmesh)
#endif
}

void
t8_cmesh_enable_tree_reordering (t8_cmesh_t cmesh)
{
cmesh->reindex_trees = 1;
}

#if T8_ENABLE_DEBUG
int
t8_cmesh_validate_geometry (const t8_cmesh_t cmesh, const int check_for_negative_volume)
Expand Down Expand Up @@ -239,6 +245,7 @@ t8_cmesh_init (t8_cmesh_t *pcmesh)
#if T8_ENABLE_DEBUG
cmesh->negative_volume_check = 1;
#endif /* T8_ENABLE_DEBUG */
cmesh->reindex_trees = 0;

T8_ASSERT (t8_cmesh_is_initialized (cmesh));
}
Expand Down
8 changes: 7 additions & 1 deletion src/t8_cmesh/t8_cmesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ t8_cmesh_stash_is_empty (const t8_cmesh_t cmesh);
void
t8_cmesh_disable_negative_volume_check (t8_cmesh_t cmesh);

/**
* Enable localitly based indexing of trees during \ref t8_cmesh_commit.
* \param [in, out] cmesh
*/
void
t8_cmesh_enable_tree_reordering (t8_cmesh_t cmesh);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it would be nice to have a second parameter and getter to retrieve the reindex map. The user could have data linked to the trees and reordering would mix that up.
so maybe something like
void t8_cmesh_enable_tree_reordering (t8_cmesh_t cmesh, int keep_reindex_map);
and
map_type t8_ cmesh_get_reindex_map (t8_cmesh_t cmesh);
The reindex map would be saved in an additional pointer inside the cmesh and xould be retrieved using the cmesh_get_reindex_map function.


#if T8_ENABLE_DEBUG
/** Check the geometry of the mesh for validity, this means checking if trees and their geometries
* are compatible and if they have negative volume.
Expand All @@ -140,7 +147,6 @@ t8_cmesh_disable_negative_volume_check (t8_cmesh_t cmesh);
* \return True if the geometry of the cmesh is valid.
*/
int

t8_cmesh_validate_geometry (const t8_cmesh_t cmesh, const int check_for_negative_volume);
#endif

Expand Down
5 changes: 5 additions & 0 deletions src/t8_cmesh/t8_cmesh_internal/t8_cmesh_commit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <t8_cmesh/t8_cmesh_geometry.hxx>
#include <t8_geometry/t8_geometry_handler.hxx>
#include <t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_connectivity.hxx>
#include <t8_cmesh/t8_cmesh_internal/t8_cmesh_tree_reindex.hxx>

/**
* A struct to hold the information about a ghost facejoin.
Expand Down Expand Up @@ -148,6 +149,10 @@ t8_cmesh_commit_replicated_new (t8_cmesh_t cmesh)
t8_stash_class_struct_t *entry;
t8_locidx_t num_trees = class_entries->elem_count, ltree;

if (cmesh->reindex_trees) {
t8_cmesh_tree_perform_reindex_inplace (stash, t8_cmesh_reindex_tree (cmesh));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With one function I meant more like

t8_cmesh_reindex_trees (cmesh);

}

t8_cmesh_trees_init (&cmesh->trees, 1, num_trees, 0);
t8_cmesh_trees_start_part (cmesh->trees, 0, 0, num_trees, 0, 0, 1);
/* set tree classes */
Expand Down
399 changes: 399 additions & 0 deletions src/t8_cmesh/t8_cmesh_internal/t8_cmesh_tree_reindex.cxx

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions src/t8_cmesh/t8_cmesh_internal/t8_cmesh_tree_reindex.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
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.
*/

#ifndef T8_CMESH_REINDEX_TREES_H
#define T8_CMESH_REINDEX_TREES_H

#include <t8.h>
#include <t8_cmesh/t8_cmesh.h>
#include <t8_cmesh/t8_cmesh_internal/t8_cmesh_types.h>
#include <map>

/**
* Compute a spatially coherent reindexing of the coarse mesh trees.
*
* Constructs an auxiliary bounding box forest containing the centers of the
* original coarse mesh trees. The forest is adaptively refined until each
* leaf element contains at most one tree center. The leaves are then traversed
* in SFC order to assign new indices to the original trees.
*
* \param [in] cmesh The original coarse mesh whose trees are to be reindexed.
* \param [in] comm MPI communicator used to construct the auxiliary forest.
*
* \return A map from the original global tree IDs to their new SFC-based indices.
*
* \note This function only computes the reindexing and does not modify the
* original coarse mesh.
*/

std::map<t8_gloidx_t, t8_gloidx_t>
t8_cmesh_reindex_tree (t8_cmesh_t cmesh, sc_MPI_Comm comm = sc_MPI_COMM_SELF);

/**
* Apply a tree reindexing to the coarse mesh stash in place.
*
* Updates the tree IDs stored in the stash according to the given mapping,
* allowing the coarse mesh to use the newly computed tree ordering.
*
* \param [in,out] stash The coarse mesh stash to be modified.
* \param [in] tree_reindex Mapping from original global tree IDs to
* their new indices.
*/
void
t8_cmesh_tree_perform_reindex_inplace (t8_stash_t &stash, const std::map<t8_gloidx_t, t8_gloidx_t> &tree_reindex);

#endif /* !T8_CMESH_REINDEX_TREES_H */
2 changes: 2 additions & 0 deletions src/t8_cmesh/t8_cmesh_internal/t8_cmesh_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ typedef struct t8_cmesh
int face_knowledge; /**< If partitioned the level of face knowledge that is expected.
*/

int reindex_trees; /**< If nonzero the trees will be indexed according to their geometric locality */

const t8_scheme_c *set_partition_scheme; /**< If the cmesh is to be partitioned according to a uniform level,
the scheme that describes the refinement pattern. */
int8_t set_partition_level; /**< Non-negative if the cmesh should be partitioned from an already existing cmesh
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ add_t8_cpp_test( NAME t8_gtest_cmesh_add_attributes_when_derive_parallel SOUR
add_t8_cpp_test( NAME t8_gtest_cmesh_vertex_conn_tree_to_vertex_parallel SOURCES t8_cmesh/t8_gtest_cmesh_vertex_conn_tree_to_vertex.cxx )
add_t8_cpp_test( NAME t8_gtest_cmesh_vertex_conn_vertex_to_tree_parallel SOURCES t8_cmesh/t8_gtest_cmesh_vertex_conn_vertex_to_tree.cxx )
add_t8_cpp_test( NAME t8_gtest_cmesh_vertex_conn_serial SOURCES t8_cmesh/t8_gtest_cmesh_vertex_conn.cxx )
add_t8_cpp_test( NAME t8_gtest_cmesh_tree_reindex_serial SOURCES t8_cmesh/t8_gtest_cmesh_tree_reindex.cxx)
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 )
Expand Down
Loading
Loading