Skip to content
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

Enhancement more const args in get attribute #895

Merged
merged 6 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions src/t8_cmesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ t8_cmesh_is_initialized (t8_cmesh_t cmesh);
* False otherwise.
*/
int
t8_cmesh_is_committed (t8_cmesh_t cmesh);
t8_cmesh_is_committed (const t8_cmesh_t cmesh);

#ifdef T8_ENABLE_DEBUG
/** After a cmesh is committed, check whether all trees in a cmesh do have positive volume.
Expand Down Expand Up @@ -664,7 +664,7 @@ t8_cmesh_get_tree_vertices (t8_cmesh_t cmesh, t8_locidx_t ltreeid);
* \see t8_cmesh_set_attribute
*/
void *
t8_cmesh_get_attribute (t8_cmesh_t cmesh, int package_id, int key, t8_locidx_t ltree_id);
t8_cmesh_get_attribute (const t8_cmesh_t cmesh, const int package_id, const int key, const t8_locidx_t ltree_id);

/** Return the attribute pointer of a tree for a gloidx_t array.
* \param [in] cmesh The cmesh.
Expand All @@ -683,8 +683,8 @@ t8_cmesh_get_attribute (t8_cmesh_t cmesh, int package_id, int key, t8_locidx_t l
* \see t8_cmesh_set_attribute_gloidx_array
*/
t8_gloidx_t *
t8_cmesh_get_attribute_gloidx_array (t8_cmesh_t cmesh, int package_id, int key, t8_locidx_t ltree_id,
const size_t data_count);
t8_cmesh_get_attribute_gloidx_array (const t8_cmesh_t cmesh, const int package_id, const int key,
const t8_locidx_t ltree_id, const size_t data_count);

/** Return the shared memory array storing the partition table of
* a partitioned cmesh.
Expand Down
14 changes: 6 additions & 8 deletions src/t8_cmesh/t8_cmesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ t8_cmesh_check_trees_per_eclass (t8_cmesh_t cmesh)
#endif

int
t8_cmesh_is_committed (t8_cmesh_t cmesh)
t8_cmesh_is_committed (const t8_cmesh_t cmesh)
{
static int is_checking = 0;

Expand Down Expand Up @@ -390,16 +390,14 @@ t8_cmesh_get_tree_vertices (t8_cmesh_t cmesh, t8_locidx_t ltreeid)
}

void *
t8_cmesh_get_attribute (t8_cmesh_t cmesh, int package_id, int key, t8_locidx_t ltree_id)
t8_cmesh_get_attribute (const t8_cmesh_t cmesh, const int package_id, const int key, const t8_locidx_t ltree_id)
{
T8_ASSERT (t8_cmesh_is_committed (cmesh));
T8_ASSERT (t8_cmesh_treeid_is_local_tree (cmesh, ltree_id) || t8_cmesh_treeid_is_ghost (cmesh, ltree_id));
const int is_ghost = t8_cmesh_treeid_is_ghost (cmesh, ltree_id);

if (is_ghost) {
ltree_id = t8_cmesh_ltreeid_to_ghostid (cmesh, ltree_id);
}
return t8_cmesh_trees_get_attribute (cmesh->trees, ltree_id, package_id, key, NULL, is_ghost);
return t8_cmesh_trees_get_attribute (
cmesh->trees, is_ghost ? t8_cmesh_ltreeid_to_ghostid (cmesh, ltree_id) : ltree_id, package_id, key, NULL, is_ghost);
}

/* Return the attribute pointer of a tree for a gloidx_t array.
Expand All @@ -419,8 +417,8 @@ t8_cmesh_get_attribute (t8_cmesh_t cmesh, int package_id, int key, t8_locidx_t l
* \see t8_cmesh_set_attribute_gloidx_array
*/
t8_gloidx_t *
t8_cmesh_get_attribute_gloidx_array (t8_cmesh_t cmesh, int package_id, int key, t8_locidx_t ltree_id,
const size_t data_count)
t8_cmesh_get_attribute_gloidx_array (const t8_cmesh_t cmesh, const int package_id, const int key,
const t8_locidx_t ltree_id, const size_t data_count)
{
T8_ASSERT (0 <= data_count);
return (t8_gloidx_t *) t8_cmesh_get_attribute (cmesh, package_id, key, ltree_id);
Expand Down
10 changes: 5 additions & 5 deletions src/t8_cmesh/t8_cmesh_trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ t8_cmesh_trees_glo_lo_hash_equal (const void *v1, const void *v2, const void *u)
}

t8_part_tree_t
t8_cmesh_trees_get_part (t8_cmesh_trees_t trees, int proc)
t8_cmesh_trees_get_part (const t8_cmesh_trees_t trees, const int proc)
{
T8_ASSERT (trees != NULL);
return (t8_part_tree_t) sc_array_index_int (trees->from_proc, proc);
Expand Down Expand Up @@ -162,7 +162,7 @@ t8_cmesh_trees_get_num_procs (t8_cmesh_trees_t trees)

/* Get a tree form a part given its local id */
static t8_ctree_t
t8_part_tree_get_tree (t8_part_tree_t P, t8_locidx_t tree_id)
t8_part_tree_get_tree (const t8_part_tree_t P, const t8_locidx_t tree_id)
{
T8_ASSERT (0 <= tree_id);
return ((t8_ctree_t) P->first_tree) + tree_id - P->first_tree_id;
Expand Down Expand Up @@ -725,8 +725,8 @@ t8_cmesh_trees_compare_keyattr (const void *A1, const void *A2)

/* The size of the attribute is not returned, but would be accessible */
void *
t8_cmesh_trees_get_attribute (t8_cmesh_trees_t trees, t8_locidx_t ltree_id, int package_id, int key, size_t *size,
int is_ghost)
t8_cmesh_trees_get_attribute (const t8_cmesh_trees_t trees, const t8_locidx_t ltree_id, const int package_id,
const int key, size_t *size, const int is_ghost)
{
int proc;
t8_ctree_t tree;
Expand Down Expand Up @@ -789,7 +789,7 @@ t8_cmesh_trees_get_attribute (t8_cmesh_trees_t trees, t8_locidx_t ltree_id, int
}

size_t
t8_cmesh_trees_get_numproc (t8_cmesh_trees_t trees)
t8_cmesh_trees_get_numproc (const t8_cmesh_trees_t trees)
{
return trees->from_proc->elem_count;
}
Expand Down
8 changes: 4 additions & 4 deletions src/t8_cmesh/t8_cmesh_trees.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ t8_cmesh_trees_init (t8_cmesh_trees_t *ptrees, int num_procs, t8_locidx_t num_tr
* \return The part number \a proc of \a trees.
*/
t8_part_tree_t
t8_cmesh_trees_get_part (t8_cmesh_trees_t trees, int proc);
t8_cmesh_trees_get_part (const t8_cmesh_trees_t trees, const int proc);

/* !!! This does only allocate memory for the trees and ghosts
* not yet for the face data and the attributes. See below !!!
Expand Down Expand Up @@ -407,8 +407,8 @@ t8_cmesh_trees_init_attributes (t8_cmesh_trees_t trees, t8_locidx_t ltree_id, si
* does not exist.
*/
void *
t8_cmesh_trees_get_attribute (t8_cmesh_trees_t trees, t8_locidx_t ltree_id, int package_id, int key, size_t *size,
int is_ghost);
t8_cmesh_trees_get_attribute (const t8_cmesh_trees_t trees, const t8_locidx_t ltree_id, const int package_id,
const int key, size_t *size, int is_ghost);

/** Return the total size of all attributes stored at a specified tree.
* \param [in] tree A tree structure.
Expand Down Expand Up @@ -441,7 +441,7 @@ t8_cmesh_trees_add_ghost_attribute (t8_cmesh_trees_t trees, int proc, t8_stash_a
* \return The number of parts in \a trees.
*/
size_t
t8_cmesh_trees_get_numproc (t8_cmesh_trees_t trees);
t8_cmesh_trees_get_numproc (const t8_cmesh_trees_t trees);

/** Compute the tree-to-face information given a face and orientation value
* of a face connection.
Expand Down