Skip to content

Commit

Permalink
Merge branch 'feature-template_multilevel' of github.com:DLR-AMR/t8co…
Browse files Browse the repository at this point in the history
…de into feature-template_multilevel
  • Loading branch information
sandro-elsweijer committed Dec 9, 2024
2 parents c710e12 + 7fd1f90 commit d37ac14
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ doxygen/
CMakeCache.txt
CMakeFiles/
version.txt
Testing/

src/stamp-h1
src/t8_config.h
Expand Down
6 changes: 3 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# User Updates for the upcoming t8code v4.0.0

We have just merged another branch into our main branch that introduces a lot of changes. Here, we want to explain what is new, why we decided on this feature, what we intend with the feature in the (near) future and most importantly what do you as a user have to change to be on par with the upcoming t8code v4.0.0
We have just merged another branch into our main branch that introduces a lot of changes. Here, we want to explain what is new, why we decided on this feature, what we intend with the feature in the (near) future and most importantly what do you as a user have to [change](#what-do-you-have-to-change) to be on par with the upcoming t8code v4.0.0

## What is new?
Long story short: We completely changed the element-schemes, the part of t8code that decides how any element in a forest behaves. Before this update was introduced we used a virtual base class defining all functions. For each type of tree shape there was a class inheriting from the base class and implementing all these functions for a specific type of tree shape (vertex, line, triangle, tetrahedra, ...).
We provided you with a default implementation for all standard shapes supported by t8code by bundling them all together in the default scheme.
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 @@ -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);
<code><span stayle="color:red">const t8_eclass_scheme_c *tscheme = t8_forest_get_eclass_scheme (forest_from, tree_class);</span></code>
/* 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 */
Expand Down
48 changes: 24 additions & 24 deletions src/t8_forest/t8_forest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ t8_forest_is_incomplete_family (const t8_forest_t forest, const t8_locidx_t ltre
T8_ASSERT (elements != NULL);
T8_ASSERT (elements_size > 0);

const t8_scheme *tscheme = t8_forest_get_scheme (forest);
T8_ASSERT (tscheme != NULL);
const t8_scheme *scheme = t8_forest_get_scheme (forest);
T8_ASSERT (scheme != NULL);
const t8_eclass_t tree_class = t8_forest_get_tree_class (forest, ltree_id);

/* If current considered element has level 0 there is no coarsening possible */
if (0 == tscheme->element_get_level (tree_class, elements[0])) {
if (0 == scheme->element_get_level (tree_class, elements[0])) {
return 0;
}

Expand All @@ -76,17 +76,17 @@ t8_forest_is_incomplete_family (const t8_forest_t forest, const t8_locidx_t ltre
/* Buffer for elements */
t8_element_t *element_parent_current;
t8_element_t *element_compare;
tscheme->element_new (tree_class, 1, &element_parent_current);
tscheme->element_new (tree_class, 1, &element_compare);
scheme->element_new (tree_class, 1, &element_parent_current);
scheme->element_new (tree_class, 1, &element_compare);

/* We first assume that we have an (in)complete family with the size of array elements.
* In the following we try to disprove this. */
int family_size = elements_size;

/* Get level, child ID and parent of first element of possible family */
const int level_current = tscheme->element_get_level (tree_class, elements[0]);
const int child_id_current = tscheme->element_get_child_id (tree_class, elements[0]);
tscheme->element_get_parent (tree_class, elements[0], element_parent_current);
const int level_current = scheme->element_get_level (tree_class, elements[0]);
const int child_id_current = scheme->element_get_child_id (tree_class, elements[0]);
scheme->element_get_parent (tree_class, elements[0], element_parent_current);

/* Elements of the current family could already be passed, so that
* the element/family currently under consideration can no longer be coarsened.
Expand All @@ -95,35 +95,35 @@ t8_forest_is_incomplete_family (const t8_forest_t forest, const t8_locidx_t ltre
* */
if (child_id_current > 0 && el_considered > 0) {
const t8_element_t *element_temp = t8_forest_get_tree_element (tree, el_considered - 1);
const int level_temp = tscheme->element_get_level (tree_class, element_temp);
const int level_temp = scheme->element_get_level (tree_class, element_temp);
/* Only elements with higher or equal level then level of current considered
* element, can get potentially be overlapped. */
if (level_temp >= level_current) {
/* Compare ancestors */
tscheme->element_get_nca (tree_class, element_parent_current, element_temp, element_compare);
const int level_compare = tscheme->element_get_level (tree_class, element_compare);
scheme->element_get_nca (tree_class, element_parent_current, element_temp, element_compare);
const int level_compare = scheme->element_get_level (tree_class, element_compare);
/* Level_current-1 is level of element_parent_current */
T8_ASSERT (level_compare <= level_current - 1);
if (level_compare == level_current - 1) {
tscheme->element_destroy (tree_class, 1, &element_parent_current);
tscheme->element_destroy (tree_class, 1, &element_compare);
scheme->element_destroy (tree_class, 1, &element_parent_current);
scheme->element_destroy (tree_class, 1, &element_compare);
return 0;
}
}
}

/* Reduce family_size to the number of family members that directly follow each other. */
for (int family_iter = 1; family_iter < family_size; family_iter++) {
const int level = tscheme->element_get_level (tree_class, elements[family_iter]);
const int level = scheme->element_get_level (tree_class, elements[family_iter]);
/* By comparing the levels in advance we may be able to avoid
* the more complex test with the parent element.*/
if (level != level_current) {
family_size = family_iter;
break;
}
tscheme->element_get_parent (tree_class, elements[family_iter], element_compare);
scheme->element_get_parent (tree_class, elements[family_iter], element_compare);
/* If the levels are equal, check if the parents are too. */
if (!tscheme->element_is_equal (tree_class, element_parent_current, element_compare)) {
if (!scheme->element_is_equal (tree_class, element_parent_current, element_compare)) {
family_size = family_iter;
break;
}
Expand All @@ -136,28 +136,28 @@ t8_forest_is_incomplete_family (const t8_forest_t forest, const t8_locidx_t ltre
* family_size in this family) that would be overlapped after coarsening. */
if (family_size < elements_size) {
/* Get level of element after last element of current possible family */
const int level = tscheme->element_get_level (tree_class, elements[family_size]);
const int level = scheme->element_get_level (tree_class, elements[family_size]);
/* Only elements with higher level then level of current element, can get
* potentially be overlapped. */
if (level > level_current) {
/* Compare ancestors */
tscheme->element_get_nca (tree_class, element_parent_current, elements[family_size], element_compare);
const int level_compare = tscheme->element_get_level (tree_class, element_compare);
scheme->element_get_nca (tree_class, element_parent_current, elements[family_size], element_compare);
const int level_compare = scheme->element_get_level (tree_class, element_compare);
T8_ASSERT (level_compare <= level_current - 1);
if (level_compare == level_current - 1) {
tscheme->element_destroy (tree_class, 1, &element_parent_current);
tscheme->element_destroy (tree_class, 1, &element_compare);
scheme->element_destroy (tree_class, 1, &element_parent_current);
scheme->element_destroy (tree_class, 1, &element_compare);
return 0;
}
}
}

/* clean up */
tscheme->element_destroy (tree_class, 1, &element_parent_current);
tscheme->element_destroy (tree_class, 1, &element_compare);
scheme->element_destroy (tree_class, 1, &element_parent_current);
scheme->element_destroy (tree_class, 1, &element_compare);

#if T8_ENABLE_MPI
const int num_siblings = tscheme->element_get_num_siblings (tree_class, elements[0]);
const int num_siblings = scheme->element_get_num_siblings (tree_class, elements[0]);
T8_ASSERT (family_size <= num_siblings);
/* If the first/last element at a process boundary is not the first/last
* element of a possible family, we are not guaranteed to consider all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#ifndef T8_GEOMETRY_ANALYTIC_H
#define T8_GEOMETRY_ANALYTIC_H

#include <t8.h>
#include <t8_cmesh.h>

/**
* Definition of an analytic geometry function.
* This function maps reference coordinates to physical
Expand Down
1 change: 1 addition & 0 deletions src/t8_geometry/t8_geometry_with_vertices.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#ifndef T8_GEOMETRY_WITH_VERTICES_H
#define T8_GEOMETRY_WITH_VERTICES_H

#include <t8.h>
#include <t8_cmesh.h>

T8_EXTERN_C_BEGIN ();
Expand Down
6 changes: 3 additions & 3 deletions src/t8_vtk/t8_vtk_write_ASCII.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ typedef int (*t8_forest_vtk_cell_data_kernel) (t8_forest_t forest, const t8_loci
static t8_locidx_t
t8_forest_num_points (t8_forest_t forest, const int count_ghosts)
{
const t8_scheme *tscheme = t8_forest_get_scheme (forest);
const t8_scheme *scheme = t8_forest_get_scheme (forest);
t8_locidx_t num_points = 0;

for (t8_locidx_t itree = 0; itree < (t8_locidx_t) forest->trees->elem_count; itree++) {
Expand All @@ -93,7 +93,7 @@ t8_forest_num_points (t8_forest_t forest, const int count_ghosts)
const size_t num_elements = t8_element_array_get_count (&tree->elements);
for (t8_locidx_t ielem = 0; ielem < (t8_locidx_t) num_elements; ielem++) {
const t8_element_t *elem = t8_element_array_index_locidx (&tree->elements, ielem);
num_points += tscheme->element_get_num_corners (tree_class, elem);
num_points += scheme->element_get_num_corners (tree_class, elem);
}
}
if (count_ghosts) {
Expand All @@ -107,7 +107,7 @@ t8_forest_num_points (t8_forest_t forest, const int count_ghosts)
const size_t num_elements = t8_forest_ghost_tree_num_elements (forest, itree);
for (t8_locidx_t ielem = 0; ielem < (t8_locidx_t) num_elements; ielem++) {
const t8_element_t *elem = t8_element_array_index_locidx (ghost_elem, ielem);
num_points += tscheme->element_get_num_corners (ghost_class, elem);
num_points += scheme->element_get_num_corners (ghost_class, elem);
}
}
}
Expand Down

0 comments on commit d37ac14

Please sign in to comment.