-
Notifications
You must be signed in to change notification settings - Fork 54
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
Feature vertex ghosts #1353
base: main
Are you sure you want to change the base?
Feature vertex ghosts #1353
Changes from all commits
2949bd6
9a1c1d1
d6d69df
5d85bb5
4218bec
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 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -546,6 +546,60 @@ class t8_default_scheme_quad: public t8_default_scheme_common<t8_default_scheme_ | |||||||||||||
void | ||||||||||||||
element_get_anchor (const t8_element_t *elem, int anchor[3]) const; | ||||||||||||||
|
||||||||||||||
inline int | ||||||||||||||
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
|
||||||||||||||
element_max_num_vertex_neighbors () const | ||||||||||||||
{ | ||||||||||||||
return 4; | ||||||||||||||
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 avoid magic numbers. |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
inline void | ||||||||||||||
element_vertex_neighbors (const t8_element_t *element, const int vertex, int *num_neighbors, t8_element_t **neighbors, | ||||||||||||||
int *neigh_ivertices) const | ||||||||||||||
{ | ||||||||||||||
p4est_quadrant_t *elem = (p4est_quadrant_t *) element; | ||||||||||||||
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
|
||||||||||||||
p4est_qcoord_t len = P4EST_QUADRANT_LEN (elem->level); | ||||||||||||||
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
|
||||||||||||||
*num_neighbors = 0; | ||||||||||||||
const int dim = 2; | ||||||||||||||
for (int icube = 0; icube < (1 << dim); icube++) { | ||||||||||||||
Comment on lines
+562
to
+563
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
And maybe don't use 4 directly, because it is a magic number again. |
||||||||||||||
int idim = 0; | ||||||||||||||
p4est_qcoord_t shift = (vertex & 1 << idim) + (icube & 1 << idim); | ||||||||||||||
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
|
||||||||||||||
shift >>= idim; | ||||||||||||||
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
No need to shift |
||||||||||||||
shift -= 1; | ||||||||||||||
shift *= len; | ||||||||||||||
((p4est_quadrant_t *) neighbors[*num_neighbors])->x = elem->x + shift; | ||||||||||||||
idim = 1; | ||||||||||||||
shift = (vertex & 1 << idim) + (icube & 1 << idim); | ||||||||||||||
shift >>= idim; | ||||||||||||||
Comment on lines
+570
to
+572
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
|
||||||||||||||
shift -= 1; | ||||||||||||||
shift *= len; | ||||||||||||||
((p4est_quadrant_t *) neighbors[*num_neighbors])->y = elem->y + shift; | ||||||||||||||
|
||||||||||||||
((p4est_quadrant_t *) neighbors[*num_neighbors])->level = elem->level; | ||||||||||||||
|
||||||||||||||
const int neigh_cube_vertex = (1 << dim) - 1 - icube; | ||||||||||||||
neigh_ivertices[*num_neighbors] = neigh_cube_vertex; | ||||||||||||||
if (element_is_equal (element, neighbors[*num_neighbors]) | ||||||||||||||
|| ((p4est_quadrant_t *) neighbors[*num_neighbors])->x < 0 | ||||||||||||||
|| ((p4est_quadrant_t *) neighbors[*num_neighbors])->x >= P4EST_ROOT_LEN | ||||||||||||||
|| ((p4est_quadrant_t *) neighbors[*num_neighbors])->y < 0 | ||||||||||||||
|| ((p4est_quadrant_t *) neighbors[*num_neighbors])->y >= P4EST_ROOT_LEN) { | ||||||||||||||
continue; | ||||||||||||||
} | ||||||||||||||
++(*num_neighbors); | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
inline void | ||||||||||||||
element_corner_descendant (const t8_element_t *element, int vertex, int level, t8_element_t *descendant) const | ||||||||||||||
{ | ||||||||||||||
p4est_quadrant_t *elem = (p4est_quadrant_t *) element; | ||||||||||||||
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
|
||||||||||||||
p4est_quadrant_t *desc = (p4est_quadrant_t *) descendant; | ||||||||||||||
p4est_qcoord_t coord_offset = P4EST_QUADRANT_LEN (elem->level) - P4EST_QUADRANT_LEN (level); | ||||||||||||||
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
|
||||||||||||||
desc->x = elem->x + coord_offset * ((vertex & 1 << 0) >> 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
|
||||||||||||||
desc->y = elem->y + coord_offset * ((vertex & 1 << 1) >> 1); | ||||||||||||||
desc->level = level; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** Compute the integer coordinates of a given element vertex. | ||||||||||||||
* The default scheme implements the Morton type SFCs. In these SFCs the | ||||||||||||||
* elements are positioned in a cube [0,1]^(dL) with dimension d (=0,1,2,3) and | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -837,6 +837,33 @@ class t8_scheme { | |
eclass_schemes[tree_class]); | ||
}; | ||
|
||
inline int | ||
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 document this function. |
||
element_max_num_vertex_neighbors (const t8_eclass_t tree_class) const | ||
{ | ||
return std::visit ([&] (auto &&scheme) { return scheme.element_max_num_vertex_neighbors (); }, | ||
eclass_schemes[tree_class]); | ||
} | ||
|
||
inline 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 document this function. |
||
element_vertex_neighbors (const t8_eclass_t tree_class, const t8_element_t *element, const int vertex, | ||
int *num_neighbors, t8_element_t **neighbors, int *neigh_ivertices) const | ||
{ | ||
return std::visit ( | ||
[&] (auto &&scheme) { | ||
return scheme.element_vertex_neighbors (element, vertex, num_neighbors, neighbors, neigh_ivertices); | ||
}, | ||
eclass_schemes[tree_class]); | ||
} | ||
|
||
inline 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 document this function. |
||
element_corner_descendant (const t8_eclass_t tree_class, const t8_element_t *element, int vertex, int level, | ||
t8_element_t *descendant) const | ||
{ | ||
return std::visit ( | ||
[&] (auto &&scheme) { return scheme.element_corner_descendant (element, vertex, level, descendant); }, | ||
eclass_schemes[tree_class]); | ||
} | ||
|
||
/** Compute the coordinates of a given element vertex inside a reference tree | ||
* that is embedded into [0,1]^d (d = dimension). | ||
* \param [in] tree_class The eclass of the current tree. | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -149,40 +149,19 @@ t8_step4_partition_ghost (t8_forest_t forest) | |||||||
* We currently support ghost mode T8_GHOST_FACES that creates face neighbor ghost elements | ||||||||
* and will in future also support other modes for edge/vertex neighbor ghost elements. | ||||||||
*/ | ||||||||
t8_forest_set_ghost (new_forest, 1, T8_GHOST_FACES); | ||||||||
t8_forest_set_ghost (new_forest, 1, T8_GHOST_VERTICES); | ||||||||
/* Commit the forest, this step will perform the partitioning and ghost layer creation. */ | ||||||||
t8_forest_commit (new_forest); | ||||||||
|
||||||||
return new_forest; | ||||||||
} | ||||||||
|
||||||||
/* In this function we adapt a forest as in step3 and balance it. | ||||||||
* In our main program the input forest is already adapted and then the resulting twice adapted forest will be unbalanced. | ||||||||
*/ | ||||||||
static t8_forest_t | ||||||||
t8_step4_balance (t8_forest_t forest) | ||||||||
int | ||||||||
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. why is balance removed? 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. Because the changes in the tutorial were not meant to be reviewed or merged, rather to test stuff out locally. This feature is not tested at all, and I see that as a bigger priority than fixing tutorials |
||||||||
t8_refine_first_child (t8_forest_t forest, t8_forest_t forest_from, t8_locidx_t which_tree, t8_eclass_t tree_class, | ||||||||
t8_locidx_t lelement_id, const t8_scheme *scheme, const int is_family, const int num_elements, | ||||||||
t8_element_t *elements[]) | ||||||||
{ | ||||||||
t8_forest_t balanced_forest; | ||||||||
/* Adapt the input forest. */ | ||||||||
t8_forest_t unbalanced_forest = t8_step3_adapt_forest (forest); | ||||||||
|
||||||||
/* Output to vtk. */ | ||||||||
t8_forest_write_vtk (unbalanced_forest, "t8_step4_unbalanced_forest"); | ||||||||
t8_global_productionf (" [step4] Wrote unbalanced forest to vtu files: %s*\n", "t8_step4_unbalanced_forest"); | ||||||||
|
||||||||
/* Initialize new forest. */ | ||||||||
t8_forest_init (&balanced_forest); | ||||||||
/* Specify that this forest should result from balancing unbalanced_forest. | ||||||||
* The last argument is the flag 'no_repartition'. | ||||||||
* Since balancing will refine elements, the load-balance will be broken afterwards. | ||||||||
* Setting this flag to false (no_repartition = false -> yes repartition) will repartition | ||||||||
* the forest after balance, such that every process has the same number of elements afterwards. | ||||||||
*/ | ||||||||
t8_forest_set_balance (balanced_forest, unbalanced_forest, 0); | ||||||||
/* Commit the forest. */ | ||||||||
t8_forest_commit (balanced_forest); | ||||||||
|
||||||||
return balanced_forest; | ||||||||
return !scheme->element_get_child_id (tree_class, elements[0]); | ||||||||
} | ||||||||
|
||||||||
int | ||||||||
|
@@ -196,7 +175,6 @@ t8_step4_main (int argc, char **argv) | |||||||
const char *prefix_uniform = "t8_step4_uniform_forest"; | ||||||||
const char *prefix_adapt = "t8_step4_adapted_forest"; | ||||||||
const char *prefix_partition_ghost = "t8_step4_partitioned_ghost_forest"; | ||||||||
const char *prefix_balance = "t8_step4_balanced_forest"; | ||||||||
/* The uniform refinement level of the forest. */ | ||||||||
const int level = 3; | ||||||||
|
||||||||
|
@@ -208,7 +186,7 @@ t8_step4_main (int argc, char **argv) | |||||||
/* Initialize the sc library, has to happen before we initialize t8code. */ | ||||||||
sc_init (sc_MPI_COMM_WORLD, 1, 1, NULL, SC_LP_ESSENTIAL); | ||||||||
/* Initialize t8code with log level SC_LP_PRODUCTION. See sc.h for more info on the log levels. */ | ||||||||
t8_init (SC_LP_PRODUCTION); | ||||||||
t8_init (SC_LP_DEBUG); | ||||||||
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 it back to SC_LP_PRODUCTION |
||||||||
|
||||||||
/* Print a message on the root process. */ | ||||||||
t8_global_productionf (" [step4] \n"); | ||||||||
|
@@ -230,7 +208,7 @@ t8_step4_main (int argc, char **argv) | |||||||
t8_global_productionf (" [step4] Creating an adapted forest as in step3.\n"); | ||||||||
t8_global_productionf (" [step4] \n"); | ||||||||
/* Build a cube cmesh with tet, hex, and prism trees. */ | ||||||||
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 udpate this commen.t |
||||||||
cmesh = t8_cmesh_new_hypercube_hybrid (comm, 0, 0); | ||||||||
cmesh = t8_cmesh_new_hypercube (T8_ECLASS_QUAD, comm, 0, 0, 0); | ||||||||
t8_global_productionf (" [step4] Created coarse mesh.\n"); | ||||||||
forest = t8_forest_new_uniform (cmesh, t8_scheme_new_default (), level, 0, comm); | ||||||||
|
||||||||
|
@@ -242,15 +220,13 @@ t8_step4_main (int argc, char **argv) | |||||||
t8_global_productionf (" [step4] Wrote uniform level %i forest to vtu files: %s*\n", level, prefix_uniform); | ||||||||
|
||||||||
/* | ||||||||
* Adapt the forest. | ||||||||
* Adapt. | ||||||||
*/ | ||||||||
|
||||||||
/* Adapt the forest. We can reuse the forest variable, since the new adapted | ||||||||
* forest will take ownership of the old forest and destroy it. | ||||||||
* Note that the adapted forest is a new forest, though. */ | ||||||||
forest = t8_step3_adapt_forest (forest); | ||||||||
forest = t8_forest_new_adapt (forest, t8_refine_first_child, 0, 0, NULL); | ||||||||
forest = t8_forest_new_adapt (forest, t8_refine_first_child, 0, 0, NULL); | ||||||||
Comment on lines
+226
to
+227
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
|
||||||||
|
||||||||
/* Print information of our new forest. */ | ||||||||
/* Print information of the forest. */ | ||||||||
t8_step3_print_forest_information (forest); | ||||||||
|
||||||||
/* Write forest to vtu files. */ | ||||||||
|
@@ -270,20 +246,6 @@ t8_step4_main (int argc, char **argv) | |||||||
/* Write forest to vtu files. */ | ||||||||
t8_forest_write_vtk_ext (forest, prefix_partition_ghost, 1, 1, 1, 1, 1, 0, 1, 0, NULL); | ||||||||
|
||||||||
/* | ||||||||
* Balance | ||||||||
*/ | ||||||||
|
||||||||
t8_global_productionf (" [step4] \n"); | ||||||||
t8_global_productionf (" [step4] Creating an unbalanced forest and balancing it.\n"); | ||||||||
t8_global_productionf (" [step4] \n"); | ||||||||
forest = t8_step4_balance (forest); | ||||||||
t8_global_productionf (" [step4] Balanced forest.\n"); | ||||||||
t8_step3_print_forest_information (forest); | ||||||||
/* Write forest to vtu files. */ | ||||||||
t8_forest_write_vtk (forest, prefix_balance); | ||||||||
t8_global_productionf (" [step4] Wrote balanced forest to vtu files: %s*\n", prefix_balance); | ||||||||
|
||||||||
/* | ||||||||
* clean-up | ||||||||
*/ | ||||||||
|
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.
Please update the error-message, too.