-
Notifications
You must be signed in to change notification settings - Fork 52
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
Introduce populate functionality according to cmesh borders #998
base: main
Are you sure you want to change the base?
Changes from all commits
4a6b447
a576755
a7d0677
aca7d18
f4a73e4
d96024c
f93958f
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 | ||||
---|---|---|---|---|---|---|
|
@@ -192,6 +192,9 @@ t8_forest_compute_maxlevel (t8_forest_t forest) | |||||
} | ||||||
} | ||||||
} | ||||||
int global_maxlevel; | ||||||
sc_MPI_Allreduce (&forest->maxlevel, &global_maxlevel, 1, sc_MPI_INT, sc_MPI_MAX, forest->mpicomm); | ||||||
forest->maxlevel = global_maxlevel; | ||||||
T8_ASSERT (forest->maxlevel >= 0); | ||||||
t8_debugf ("Computed maxlevel %i\n", forest->maxlevel); | ||||||
} | ||||||
|
@@ -1153,86 +1156,155 @@ t8_forest_compute_desc (t8_forest_t forest) | |||||
} | ||||||
} | ||||||
|
||||||
void | ||||||
t8_forest_populate_according_to_cmesh (t8_forest_t forest) | ||||||
{ | ||||||
SC_CHECK_ABORT (!forest->cmesh->first_tree_shared, "Cmesh needs to be partitioned without shared elements \n"); | ||||||
forest->first_local_tree = t8_cmesh_get_first_treeid (forest->cmesh); | ||||||
int num_local_trees = t8_cmesh_get_num_local_trees (forest->cmesh); | ||||||
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.
Suggested change
|
||||||
forest->last_local_tree = forest->first_local_tree + num_local_trees - 1; | ||||||
|
||||||
forest->global_num_elements = forest->local_num_elements = 0; | ||||||
int is_empty = (num_local_trees == 0); | ||||||
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.
Suggested change
|
||||||
t8_linearidx_t count_elements; | ||||||
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.
Suggested change
|
||||||
/* create only the non-empty tree objects */ | ||||||
if (is_empty) { | ||||||
t8_debugf ("is empty\n"); | ||||||
/* This processor is empty | ||||||
* we still set the tree array to store 0 as the number of trees here */ | ||||||
forest->trees = sc_array_new (sizeof (t8_tree_struct_t)); | ||||||
count_elements = 0; | ||||||
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.
Suggested change
|
||||||
/* Set the first local tree larger than the last local tree to | ||||||
* indicate empty forest */ | ||||||
forest->first_local_tree = forest->last_local_tree + 1; | ||||||
} | ||||||
else { | ||||||
t8_debugf ("has %i trees\n", num_local_trees); | ||||||
/* for each tree, allocate elements */ | ||||||
T8_ASSERT (num_local_trees == forest->last_local_tree - forest->first_local_tree + 1); | ||||||
|
||||||
forest->trees = sc_array_new_count (sizeof (t8_tree_struct_t), num_local_trees); | ||||||
t8_gloidx_t first_ctree = t8_cmesh_get_first_treeid (forest->cmesh); | ||||||
count_elements = 0; /** apparently this cannot be in the for loop initialisation. */ | ||||||
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.
Suggested change
|
||||||
for (t8_gloidx_t jt = forest->first_local_tree; jt <= forest->last_local_tree; jt++) { | ||||||
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. jt is not a good name for a variable. |
||||||
t8_tree_t tree = (t8_tree_t) t8_sc_array_index_locidx (forest->trees, jt - forest->first_local_tree); | ||||||
t8_eclass_t tree_class = tree->eclass = t8_cmesh_get_tree_class (forest->cmesh, jt - first_ctree); | ||||||
tree->elements_offset = count_elements; | ||||||
t8_eclass_scheme_c *eclass_scheme = forest->scheme_cxx->eclass_schemes[tree_class]; | ||||||
T8_ASSERT (eclass_scheme != NULL); | ||||||
t8_element_array_t *telements = &tree->elements; | ||||||
/* calculate first and last element on this tree */ | ||||||
t8_locidx_t start = 0; | ||||||
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.
Suggested change
it is not changed afterwards, so we can delete it |
||||||
t8_locidx_t end = eclass_scheme->t8_element_count_leaves_from_root (forest->set_level); | ||||||
t8_debugf ("end: %i\n", end); | ||||||
/* Allocate elements for this processor. */ | ||||||
t8_element_array_init_size (telements, eclass_scheme, end - start); | ||||||
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.
Suggested change
|
||||||
t8_element_t *element = t8_element_array_index_locidx_mutable (telements, 0); | ||||||
eclass_scheme->t8_element_set_linear_id (element, forest->set_level, start); | ||||||
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.
Suggested change
|
||||||
count_elements++; | ||||||
for (t8_locidx_t et = start + 1; et < end; et++, count_elements++) { | ||||||
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.
Suggested change
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. et is not a good name for a variable |
||||||
t8_element_t *element_succ = t8_element_array_index_locidx_mutable (telements, et - start); | ||||||
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.
Suggested change
|
||||||
T8_ASSERT (eclass_scheme->t8_element_level (element) == forest->set_level); | ||||||
eclass_scheme->t8_element_successor (element, element_succ); | ||||||
element = element_succ; | ||||||
} | ||||||
t8_debugf ("count_elements in loop:%li\n", count_elements); | ||||||
} | ||||||
t8_debugf ("count_elements:%li\n", count_elements); | ||||||
} | ||||||
forest->local_num_elements = count_elements; | ||||||
/* TODO: if no tree has pyramid type we can optimize this to global_num_elements = global_num_trees * 2^(dim*level) */ | ||||||
t8_forest_comm_global_num_elements (forest); | ||||||
/* TODO: figure out global_first_position, global_first_quadrant without comm */ | ||||||
} | ||||||
|
||||||
/* Create the elements on this process given a uniform partition of the coarse mesh. */ | ||||||
void | ||||||
t8_forest_populate (t8_forest_t forest) | ||||||
{ | ||||||
t8_gloidx_t child_in_tree_begin; | ||||||
t8_gloidx_t child_in_tree_end; | ||||||
t8_locidx_t count_elements; | ||||||
t8_locidx_t num_tree_elements; | ||||||
t8_locidx_t num_local_trees; | ||||||
t8_gloidx_t jt, first_ctree; | ||||||
t8_gloidx_t start, end, et; | ||||||
t8_tree_t tree; | ||||||
t8_element_t *element, *element_succ; | ||||||
t8_element_array_t *telements; | ||||||
t8_eclass_t tree_class; | ||||||
t8_eclass_scheme_c *eclass_scheme; | ||||||
t8_gloidx_t cmesh_first_tree, cmesh_last_tree; | ||||||
int is_empty; | ||||||
|
||||||
SC_CHECK_ABORT (forest->set_level <= forest->maxlevel, "Given refinement level exceeds the maximum.\n"); | ||||||
/* TODO: create trees and quadrants according to uniform refinement */ | ||||||
t8_cmesh_uniform_bounds (forest->cmesh, forest->set_level, forest->scheme_cxx, &forest->first_local_tree, | ||||||
&child_in_tree_begin, &forest->last_local_tree, &child_in_tree_end, NULL); | ||||||
|
||||||
/* True if the forest has no elements */ | ||||||
is_empty = forest->first_local_tree > forest->last_local_tree | ||||||
|| (forest->first_local_tree == forest->last_local_tree && child_in_tree_begin >= child_in_tree_end); | ||||||
t8_gloidx_t cmesh_first_tree = t8_cmesh_get_first_treeid (forest->cmesh); | ||||||
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.
Suggested change
|
||||||
t8_gloidx_t cmesh_last_tree = cmesh_first_tree + t8_cmesh_get_num_local_trees (forest->cmesh) - 1; | ||||||
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.
Suggested change
|
||||||
t8_gloidx_t | ||||||
child_in_tree_begin; /** does not get filled when the cmesh does not contain any shared elements between processes */ | ||||||
t8_gloidx_t child_in_tree_end; /** see above*/ | ||||||
|
||||||
cmesh_first_tree = t8_cmesh_get_first_treeid (forest->cmesh); | ||||||
cmesh_last_tree = cmesh_first_tree + t8_cmesh_get_num_local_trees (forest->cmesh) - 1; | ||||||
if (forest->set_initial_partition_according_to_cmesh) { | ||||||
SC_CHECK_ABORT (!forest->cmesh->first_tree_shared, "Cmesh needs to be partitioned without shared elements for a " | ||||||
"forest that is partitioned in the same way as the cmesh \n"); | ||||||
forest->first_local_tree = cmesh_first_tree; | ||||||
forest->last_local_tree = cmesh_last_tree; | ||||||
} | ||||||
else { | ||||||
t8_cmesh_uniform_bounds (forest->cmesh, forest->set_level, forest->scheme_cxx, &forest->first_local_tree, | ||||||
&child_in_tree_begin, &forest->last_local_tree, &child_in_tree_end, NULL); | ||||||
} | ||||||
|
||||||
if (!is_empty) { | ||||||
/* True if the forest has no elements */ | ||||||
int is_empty | ||||||
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.
Suggested change
|
||||||
= forest->first_local_tree > forest->last_local_tree | ||||||
|| (!forest->set_initial_partition_according_to_cmesh && forest->first_local_tree == forest->last_local_tree | ||||||
&& child_in_tree_begin >= child_in_tree_end); | ||||||
|
||||||
if (!is_empty && !forest->set_initial_partition_according_to_cmesh) { | ||||||
SC_CHECK_ABORT (forest->first_local_tree >= cmesh_first_tree && forest->last_local_tree <= cmesh_last_tree, | ||||||
"cmesh partition does not match the planned forest partition"); | ||||||
"cmesh partition does not match the planned uniform equally distributed forest partition"); | ||||||
} | ||||||
|
||||||
forest->global_num_elements = forest->local_num_elements = 0; | ||||||
/* create only the non-empty tree objects */ | ||||||
if (is_empty) { | ||||||
forest->local_num_elements = 0; | ||||||
/* This processor is empty | ||||||
* we still set the tree array to store 0 as the number of trees here */ | ||||||
forest->trees = sc_array_new (sizeof (t8_tree_struct_t)); | ||||||
count_elements = 0; | ||||||
/* Set the first local tree larger than the last local tree to | ||||||
* indicate empty forest */ | ||||||
* indicate empty forest, this is sometimes used instead of the more accurate check that local_num_element = 0. TODO: check that line can be removed */ | ||||||
forest->first_local_tree = forest->last_local_tree + 1; | ||||||
} | ||||||
else { | ||||||
/* for each tree, allocate elements */ | ||||||
num_local_trees = forest->last_local_tree - forest->first_local_tree + 1; | ||||||
t8_locidx_t num_local_trees = forest->last_local_tree - forest->first_local_tree + 1; | ||||||
forest->trees = sc_array_new_count (sizeof (t8_tree_struct_t), num_local_trees); | ||||||
first_ctree = t8_cmesh_get_first_treeid (forest->cmesh); | ||||||
for (jt = forest->first_local_tree, count_elements = 0; jt <= forest->last_local_tree; jt++) { | ||||||
tree = (t8_tree_t) t8_sc_array_index_locidx (forest->trees, jt - forest->first_local_tree); | ||||||
tree_class = tree->eclass = t8_cmesh_get_tree_class (forest->cmesh, jt - first_ctree); | ||||||
t8_gloidx_t first_ctree = t8_cmesh_get_first_treeid (forest->cmesh); | ||||||
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.
Suggested change
|
||||||
t8_locidx_t count_elements = 0; | ||||||
for (t8_gloidx_t jt = forest->first_local_tree; jt <= forest->last_local_tree; jt++) { | ||||||
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. jt is not a good name for a variable. |
||||||
t8_tree_t tree = (t8_tree_t) t8_sc_array_index_locidx (forest->trees, jt - forest->first_local_tree); | ||||||
t8_eclass_t tree_class = tree->eclass = t8_cmesh_get_tree_class (forest->cmesh, jt - first_ctree); | ||||||
tree->elements_offset = count_elements; | ||||||
eclass_scheme = forest->scheme_cxx->eclass_schemes[tree_class]; | ||||||
t8_eclass_scheme_c *eclass_scheme = forest->scheme_cxx->eclass_schemes[tree_class]; | ||||||
T8_ASSERT (eclass_scheme != NULL); | ||||||
telements = &tree->elements; | ||||||
t8_element_array_t *telements = &tree->elements; | ||||||
/* calculate first and last element on this tree */ | ||||||
start = (jt == forest->first_local_tree) ? child_in_tree_begin : 0; | ||||||
end = (jt == forest->last_local_tree) ? child_in_tree_end | ||||||
: eclass_scheme->t8_element_count_leaves_from_root (forest->set_level); | ||||||
t8_locidx_t start, end, num_tree_elements; | ||||||
if (forest->set_initial_partition_according_to_cmesh) { | ||||||
start = 0; | ||||||
end = eclass_scheme->t8_element_count_leaves_from_root (forest->set_level); | ||||||
} | ||||||
else { | ||||||
start = (jt == forest->first_local_tree) ? child_in_tree_begin : 0; | ||||||
end = (jt == forest->last_local_tree) ? child_in_tree_end | ||||||
: eclass_scheme->t8_element_count_leaves_from_root (forest->set_level); | ||||||
} | ||||||
num_tree_elements = end - start; | ||||||
t8_debugf ("num_tree_elements: %i \n", num_tree_elements); | ||||||
T8_ASSERT (num_tree_elements > 0); | ||||||
/* Allocate elements for this processor. */ | ||||||
t8_element_array_init_size (telements, eclass_scheme, num_tree_elements); | ||||||
element = t8_element_array_index_locidx_mutable (telements, 0); | ||||||
t8_element_t *element = t8_element_array_index_locidx_mutable (telements, 0); | ||||||
eclass_scheme->t8_element_set_linear_id (element, forest->set_level, start); | ||||||
count_elements++; | ||||||
for (et = start + 1; et < end; et++, count_elements++) { | ||||||
element_succ = t8_element_array_index_locidx_mutable (telements, et - start); | ||||||
for (t8_locidx_t et = start + 1; et < end; et++, count_elements++) { | ||||||
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. Please change the name of the variable. |
||||||
t8_element_t *element_succ = t8_element_array_index_locidx_mutable (telements, et - start); | ||||||
T8_ASSERT (eclass_scheme->t8_element_level (element) == forest->set_level); | ||||||
eclass_scheme->t8_element_successor (element, element_succ); | ||||||
/* TODO: process elements here */ | ||||||
element = element_succ; | ||||||
} | ||||||
} | ||||||
forest->local_num_elements = count_elements; | ||||||
} | ||||||
forest->local_num_elements = count_elements; | ||||||
/* TODO: if no tree has pyramid type we can optimize this to global_num_elements = global_num_trees * 2^(dim*level) */ | ||||||
t8_forest_comm_global_num_elements (forest); | ||||||
/* TODO: figure out global_first_position, global_first_quadrant without comm */ | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,6 +213,9 @@ t8_forest_set_scheme (t8_forest_t forest, t8_scheme_cxx_t *scheme); | |
void | ||
t8_forest_set_level (t8_forest_t forest, int level); | ||
|
||
void | ||
t8_forest_set_uniform_partition_from_cmesh (t8_forest_t forest, t8_cmesh_t cmesh, sc_MPI_Comm comm); | ||
|
||
/** Set a forest as source for copying on committing. | ||
* By default, the forest takes ownership of the source \b from such that it will | ||
* be destroyed on calling \ref t8_forest_commit. To keep ownership of \b | ||
|
@@ -840,6 +843,10 @@ t8_forest_t | |
t8_forest_new_uniform (t8_cmesh_t cmesh, t8_scheme_cxx_t *scheme, const int level, const int do_face_ghost, | ||
sc_MPI_Comm comm); | ||
|
||
t8_forest_t | ||
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. Please add documentation |
||
t8_forest_new_uniform_with_cmesh_partition (t8_cmesh_t cmesh, t8_scheme_cxx_t *scheme, const int level, | ||
const int do_face_ghost, sc_MPI_Comm comm); | ||
|
||
/** Build a adapted forest from another forest. | ||
* \param [in] forest_from The forest to refine | ||
* \param [in] adapt_fn Adapt function to use | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,9 @@ t8_forest_compute_desc (t8_forest_t forest); | |
void | ||
t8_forest_populate (t8_forest_t forest); | ||
|
||
void | ||
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. Please add documentation |
||
t8_forest_populate_according_to_cmesh (t8_forest_t forest); | ||
|
||
/** Return the eclass scheme of a given element class associated to a forest. | ||
* This function does not check whether the given forest is committed, use with | ||
* caution and only if you are sure that the eclass_scheme was set. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: investigate further, because it looks like the second argument is not even used in
t8_forest_populate_irregular