diff --git a/NEWS.md b/NEWS.md index 54ade4e905..4838e5befc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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). @@ -23,7 +23,7 @@ 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 +
/* 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. */
@@ -31,7 +31,7 @@ for (t8_locidx_t itree = 0; itree < num_local_trees; ++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. */
- const t8_eclass_scheme_c *tscheme = t8_forest_get_eclass_scheme (forest_from, tree_class);
+ const t8_eclass_scheme_c *tscheme = t8_forest_get_eclass_scheme (forest_from, tree_class);
/* 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 */
@@ -39,16 +39,16 @@ 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 */
- const int elem_level = scheme->t8_element_level (elem);
+ const int elem_level = scheme->t8_element_level (elem);
}
}
-```
+
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
+
/* Get the scheme used by this forest. */
-const t8_scheme *scheme = t8_forest_get_scheme(forest);
-/* Loop over each tree in the forest */
+const t8_scheme *scheme = t8_forest_get_scheme(forest);
+/* Loop over each tree in the forest */
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);
@@ -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);
+ const int elem_level = scheme->element_get_level (tree_class, elem);
}
}
-```
+
In summary there are two major changes:
1. Get the scheme outside of loop over the trees