-
Notifications
You must be signed in to change notification settings - Fork 70
Feature: add neighbor subface helper #2216
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
base: main
Are you sure you want to change the base?
Changes from all commits
8760dcf
7908780
2e89aef
fda9f6b
e265561
beb432b
5e29523
a7f955d
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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1885,6 +1885,39 @@ t8_forest_leaf_face_neighbors (t8_forest_t forest, t8_locidx_t ltreeid, const t8 | |||||||||||||||||||
| pelement_indices, pneigh_eclass, forest_is_balanced, NULL, NULL); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| int | ||||||||||||||||||||
| t8_forest_leaf_neighbor_subface (t8_forest_t forest, t8_locidx_t ltreeid, const t8_element_t *leaf, int face, | ||||||||||||||||||||
| t8_eclass_t neighbor_tree_class, const t8_element_t *neighbor_leaf, int neighbor_face) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| t8_scheme const *scheme = t8_forest_get_scheme (forest); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| t8_element_t *target = nullptr; | ||||||||||||||||||||
| scheme->element_new (neighbor_tree_class, 1, &target); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| int dummy; // Can't pass a nullptr to t8_forest_element_face_neighbor below (see #2214) | ||||||||||||||||||||
| t8_forest_element_face_neighbor (forest, ltreeid, leaf, target, neighbor_tree_class, face, &dummy); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| int const num_children = scheme->element_get_num_face_children (neighbor_tree_class, neighbor_leaf, neighbor_face); | ||||||||||||||||||||
|
Collaborator
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
Contributor
Author
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. I can see why you'd want the variable name to be a little bit more explicit, but isn't the comment just paraphrasing what
Collaborator
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.
I guess I have a fundamentally different philosophy here, but that is definitely not a problem at all! :-) Because it is in fact just my personal preference and not part of any t8code coding guidelines. So if you feel like some of the comments I suggested are too much, don't worry and feel free not to add them 👍 In case you are interested, my philosphy is more that reading the doxygen header of a function along with the inline code comments should already give an idea about what the code does -- and how it does it, meaning the structure of the algorithm. For example, the line code comments I suggested alone would read which, I'd argue, already gives you a rough but useful outline of the function without reading one single line of code. (And as for the added work of writing the comments, I am certain the time is neglible compared to the time saved for future readers -- after all, while writing the code we know what we're doing anyway!) So regarding your quote here
this would be my answer, that is, paraphrasing the code in a language made for humans to understand, not compilers 😉 |
||||||||||||||||||||
|
|
||||||||||||||||||||
| std::array<t8_element_t *, 4> children; // assumes a 2:1 balanced forest | ||||||||||||||||||||
| scheme->element_new (neighbor_tree_class, 4, children.begin ()); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| scheme->element_get_children_at_face (neighbor_tree_class, neighbor_leaf, neighbor_face, children.begin (), | ||||||||||||||||||||
| num_children, nullptr); | ||||||||||||||||||||
|
Comment on lines
+1902
to
+1906
Collaborator
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. It may well be that I missed something here, but shouldn't we use
Suggested change
Contributor
Author
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. There are two reasons for why we can't use
Maybe there is a properly named global constant which could be used instead of this magic number?
Collaborator
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. Whoops, the integral constant expression point is in fact quite obvious here, sorry for missing that. How about defining a new constant to or and using it here? Then it should also be clear where the number 4 comes from. |
||||||||||||||||||||
|
|
||||||||||||||||||||
|
Collaborator
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
Contributor
Author
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. I guess this is meant to be a comment. However, after re-reading with fresh eyes this piece of code, I think this is just a
Collaborator
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. Ah, of course this should be a comment not C++ code 😬
Collaborator
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. Good idea, |
||||||||||||||||||||
| int result = -1; | ||||||||||||||||||||
| for (int i_child = 0; i_child < num_children; ++i_child) { | ||||||||||||||||||||
| if (scheme->element_compare (neighbor_tree_class, target, children[i_child]) == 0) { | ||||||||||||||||||||
|
Comment on lines
+1909
to
+1910
Collaborator
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
Contributor
Author
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. I'll make the adequate changes here when the previous comments are settled. |
||||||||||||||||||||
| result = i_child; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| T8_ASSERT(result != -1); // make sure the face was found | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
Collaborator
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
Contributor
Author
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. I think the "free memory" part is quite self evident here, but the "return sub-face ID" part is indeed not clear with the current state of the code. However maybe this just means that
Collaborator
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. Maybe
dutkalex marked this conversation as resolved.
|
||||||||||||||||||||
| scheme->element_destroy (neighbor_tree_class, 4, children.begin ()); | ||||||||||||||||||||
| scheme->element_destroy (neighbor_tree_class, 1, &target); | ||||||||||||||||||||
| return result; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| void | ||||||||||||||||||||
| t8_forest_print_all_leaf_neighbors (t8_forest_t forest) | ||||||||||||||||||||
| { | ||||||||||||||||||||
|
|
||||||||||||||||||||
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.
Maybe we can find a more expressive name than
target? e.g.Or maybe we can even find something better?
sub_neighbor?Uh oh!
There was an error while loading. Please reload this page.
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 are only two hard things in computer science: cache invalidation and naming things." 😉
I see your point, and I guess since I could not come up with a better name at the time and went for the rather undescriptive but concise option. I feel like
virtual_face_neighboris more descriptive thansub_neighbor, but it looses the "it's what we're looking for" idea. It seems hard to find a (reasonably sized) name which encodes unambiguously all this information. Maybe this means a small comment is necessary to clarify exactly what this is... What do you think?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.
Love the quote!😄
I think a comment is a good idea anyway (as I said, I will basically never say "no" to code comments 🙈 )
We all do not love long variable names, but what's the harm of using maybe
target_virtual_neighboror eventarget_virtual_face_neighbor-- after all, this isn't some old Fortran code with 72 characters per line 😉With a comment, however, I also don't mind sticking to
targetif that's what you prefer.