Skip to content

Commit

Permalink
Proposal for highlighting the changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Davknapp committed Dec 9, 2024
1 parent 7fd1f90 commit d2df1df
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ We provided you with a default implementation for all standard shapes supported
If you wanted to use an element function you needed the scheme and the eclass of the tree the element belongs to to call the proper function.

### CRTP instead of a virtual base class
We left this approach and now use a [CRTP](https://www.fluentcpp.com/2017/05/16/what-the-crtp-brings-to-code/) approach instead. That way we can get rid of the virtual base class and hopefully by avoiding virtual function calls and now with the opportunity to inline functions we can optimize the code further.
We left this approach and now use a [CRTP](https://www.fluentcpp.com/2017/05/16/what-the-crtp-brings-to-code/) approach instead. That way we can get rid of the virtual base class and hopefully by avoiding virtual function calls and now with the opportunity to inline functions we can optimize the code further.

### The scheme builder
Furthermore, we now provide a scheme builder instead of only the default scheme with our default implementation (don't worry, the default implementation is still there and untouched, t8code will still behave in the way that you know it).
Expand All @@ -23,32 +23,32 @@ We also aim to let you be more creative with the scheme builder. We see applicat

## What do you have to change?
A typical situation where you need the element schemes is when you loop over all trees and all elements in each tree to call a function on each element:
```cpp
<pre><code>
/* Loop over each tree in the forest */
for (t8_locidx_t itree = 0; itree < num_local_trees; ++itree){
/* Get the tree with local id itree. */
const t8_tree_t tree = t8_forest_get_tree (forest, itree);
/* Get the eclass of the tree. */
const t8_eclass_t tree_class = t8_forest_get_tree_class (forest, itree);
/* Get the scheme of of this eclass. */
<code><span stayle="color:red">const t8_eclass_scheme_c *tscheme = t8_forest_get_eclass_scheme (forest_from, tree_class);</span></code>
<font color="red">const t8_eclass_scheme_c *tscheme = t8_forest_get_eclass_scheme (forest_from, tree_class);</font>
/* Get the number of elements in the tree itree. */
const t8_locidx_t num_elems = t8_forest_get_tree_num_elements (forest, itree);
/* Loop over all elements */
for (t8locidx_t ielem = 0; ielem < num_elems; ++ielem){
/* Get the element with tree-local-id ielem */
const t8_element_t *elem = t8_forest_get_element_in_tree (forest, itree, ielem);
/* Call a function on that element */
const int elem_level = scheme->t8_element_level (elem);
<font color="orange">const int elem_level = scheme->t8_element_level (elem);</font>
}
}
```
</code></pre>

Instead of getting the tree specific scheme we only need to get the schemes used by this forest in total. Additionally (such that the scheme knows which implementation to use) we add the class of the tree to the call of the element function:
```cpp
<pre><code>
/* Get the scheme used by this forest. */
const t8_scheme *scheme = t8_forest_get_scheme(forest);
/* Loop over each tree in the forest */
<font color="greenyellow">const t8_scheme *scheme = t8_forest_get_scheme(forest);
/* Loop over each tree in the forest */</font>
for (t8_locidx_t itree = 0; itree < num_local_trees; ++itree){
/* Get the number of elements in the tree itree */
const t8_locidx_t num_elems = t8_forest_get_tree_num_elements (forest, itree);
Expand All @@ -59,10 +59,10 @@ for (t8_locidx_t itree = 0; itree < num_local_trees; ++itree){
/* Get the element with tree-local-id ielem */
const t8_element_t *elem = t8_forest_get_element_in_tree (forest, itree, ielem);
/* Call a function on that element */
elem_level = scheme->element_get_level (tree_class, elem);
<font color="orange"> const int elem_level = scheme->element_get_level (tree_class, elem);</font>
}
}
```
</code></pre>

In summary there are two major changes:
1. Get the scheme outside of loop over the trees
Expand Down

0 comments on commit d2df1df

Please sign in to comment.