Skip to content
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: Subelements 3D transition scheme #1063

Draft
wants to merge 61 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
c829a8c
Added transition scheme files and transition forest files
Apr 17, 2024
3d8fe61
Added functions is_subelement and transition_refine_identifier
Apr 17, 2024
588173c
Merge branch 'DLR-AMR:main' into feature_subelement_3D_merge_main_2.0
Tabea-leistikow Apr 17, 2024
5efb2fd
Adjusting t8_forest_adapt() for transitioning
Apr 23, 2024
3b20e8f
Add t8_forest_supports_transitioning
Apr 24, 2024
c8887e2
Add function forest_untransition()
Apr 25, 2024
a237cbb
Added two example files, basic_hex and _global_hex
May 7, 2024
a4ba651
Add const keyword + forest_transition functions such as set_transition
May 7, 2024
0f7ff6c
small adjustments (like additional MPI functions and const keyword)
May 7, 2024
9209aef
Fixed typos
May 7, 2024
1cc4970
Fixed typos
May 7, 2024
49625bd
Corrected warnings
May 7, 2024
17fb727
Added gtest folder schemes_transition, gtest plus small corrections
May 13, 2024
ac5a3e9
Added descendant and equal test + correction in t8_element_equal func…
May 14, 2024
1a16a92
Added test face_descendant + correction in scheme
May 14, 2024
faeddb1
Added more test for t8_schemes_transition
May 14, 2024
95df1df
Added t8_forest_commit test for transitioned forest
May 21, 2024
7bc5d00
Added test file for forest commit + corrections in t8_element_new + _…
May 22, 2024
b3b06f3
Completed gtest_forest_commit
May 22, 2024
2205e80
Corrected typo
May 22, 2024
824415c
Merge branch 'main' into feature_subelement_3D_merge_main_2.0
May 22, 2024
ba38293
Added vertex function + reference_coords
May 27, 2024
5ddc71a
Adjustment in test file t8_forest_transition
May 27, 2024
0b9fd5b
Added reference_coords function
Jun 4, 2024
3936e50
Added forest example
Jun 4, 2024
d6eaff7
Added new example to test t8_forest_untransition
Jun 5, 2024
74b5cd7
added example file for multiple trees
Jun 11, 2024
c035cb5
Better documentaion in t8_forest_transition.h
Jun 12, 2024
1fe0f32
Little clean-up + documentation
Jun 12, 2024
4d3f6b3
clang-format
Jun 12, 2024
b9fab89
corrected typo
Jun 12, 2024
8f7ae08
Little clean-up
Jun 12, 2024
c8e79b3
Added LFN example + functions. example does not work yet
Jun 13, 2024
b1a1191
Typos + corrected bug, LFN works
Jun 13, 2024
89c3d69
corrected typo leafs->leaves
Jun 13, 2024
4331133
clang-format
Jun 13, 2024
6c12197
corrected typo
Jun 13, 2024
44eb4e3
clang-format
Jun 13, 2024
a87e46f
Merge branch 'main' into feature_subelement_3D_merge_main_2.0
jmark Jul 8, 2024
1624806
Use more const pointers according to new changes in main
holke Jul 12, 2024
58f5806
t8_element_reference_coords for 2D transition scheme
holke Jul 22, 2024
fcd2090
Rename forest_cxx.cxx to forest.cxx to prepare merge
holke Jul 22, 2024
4601a6d
Merge remote-tracking branch 'origin/main' into feature_subelement_3D…
holke Jul 22, 2024
88eafc3
fix merge gone wrong
holke Jul 22, 2024
c33bbf3
finish merge - adapt to new file names
holke Jul 22, 2024
f2527dd
Update CMakelists
holke Jul 22, 2024
e5c0720
update changed header file names
holke Jul 23, 2024
b5a5dc4
fix memory bug because of wrong element size computation
holke Jul 24, 2024
2680045
extend t8_element_reference_coords for multiple coordinates
holke Jul 24, 2024
a1e3919
fix coordinate computation - ref_coords always 3 dim
holke Aug 5, 2024
c698527
fix transition quad init
holke Aug 5, 2024
15bd1b2
fix transition hex last desc
holke Aug 5, 2024
6f0c735
clean up transition hex
holke Aug 5, 2024
51b6c2b
indent
holke Aug 5, 2024
c097d71
Introduce int typedef for coordinates of quad subelements
holke Aug 6, 2024
2006556
Fix interpolation. Use real coordinates not barycentric
holke Aug 6, 2024
a3fc59f
Fix is_leaf check for subelements
holke Aug 6, 2024
7520dc3
add TODO comment in test
holke Aug 6, 2024
66e9a30
Merge remote-tracking branch 'origin/main' into feature_subelement_3D…
holke Aug 6, 2024
8508747
Merge branch 'feature-element_is_leaf' into feature_subelement_3D_mer…
holke Aug 6, 2024
d61176d
Fix subelement pyramid coordinate computation
holke Aug 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ DISTCLEANFILES += \
# non-recursive build
include src/Makefile.am
include src/t8_schemes/t8_default/Makefile.am
include src/t8_schemes/t8_transition/Makefile.am
include test/Makefile.am
include example/Makefile.am
include tutorials/Makefile.am
Expand Down
4 changes: 3 additions & 1 deletion example/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ include example/geometry/Makefile.am
include example/common/Makefile.am
include example/version/Makefile.am

include example/remove/Makefile.am
include example/remove/Makefile.am

include example/transition/Makefile.am
16 changes: 16 additions & 0 deletions example/transition/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file is part of t8code
# Non-recursive Makefile.am in example/transition
# Included from toplevel directory

bin_PROGRAMS += \
example/transition/t8_transition_global_hex \
example/transition/t8_transition_basic_hex \
example/transition/t8_transition_forest \
example/transition/t8_transition_multiple_trees_hex \
example/transition/t8_transition_LFN_hex

example_transition_t8_transition_global_hex_SOURCES = example/transition/t8_transition_global_hex.cxx
example_transition_t8_transition_basic_hex_SOURCES = example/transition/t8_transition_basic_hex.cxx
example_transition_t8_transition_forest_SOURCES = example/transition/t8_transition_forest.cxx
example_transition_t8_transition_multiple_trees_hex_SOURCES = example/transition/t8_transition_multiple_trees_hex.cxx
example_transition_t8_transition_LFN_hex_SOURCES = example/transition/t8_transition_LFN_hex.cxx
243 changes: 243 additions & 0 deletions example/transition/t8_transition_LFN_hex.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
/*
This file is part of t8code.
t8code is a C library to manage a collection (a forest) of multiple
connected adaptive space-trees of general element types in parallel.

Copyright (C) 2015 the developers

t8code is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

t8code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with t8code; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/* Description:
* This is the example file for refinement with transitioning. In this testcase, we are able to
* (i) refine a mesh according to some refinement criterion and use transition cells to make the mesh conformal
* (ii) use multiple adaptation steps in which the refinement criterion changes (e.g. the geometry)
* (iii) decide, whether we want to check the LFN function for each mesh
* (iv) decide, whether we want to get statistics printed out, regarding # of elements in the meshes and runtime infos of the several functions or other debugging information
*/

/* to switch between the default quad scheme and the transition implementation */
#include "t8_eclass.h"
#include "t8_forest/t8_forest_types.h"

#include "t8_forest/t8_forest_general.h"
#include <cstring>
#include <t8_schemes/t8_transition/t8_transition_conformal_hex/t8_transition_conformal_hex_cxx.hxx>
#include <t8_schemes/t8_transition/t8_transition_cxx.hxx>
#include <t8_schemes/t8_default/t8_default_cxx.hxx>
#include <t8_forest/t8_forest_io.h> // to write vtk
#include <t8_vec.h>
#include <example/common/t8_example_common.h>
#include <t8_cmesh/t8_cmesh_examples.h> /* for cmesh initialization via for example t8_cmesh_new_hypercube */
#include <t8_cmesh_vtk_writer.h>
#include <sc/src/sc_containers.h>

/* In this example, the left side of a unit cube with initial level 2 is refined to construct an adapted and transitioned forest. */

/* Refinement criterion: All elements with x-coordinate smaller than 0.5 are being refined. All other elements remain unchanged. */
int
t8_adapt_callback (t8_forest_t forest, t8_forest_t forest_from, t8_locidx_t which_tree, t8_locidx_t lelement_id,
t8_eclass_scheme_c *ts, const int is_family, const int num_elements, t8_element_t *elements[])
{
int child_id = ts->t8_element_child_id (elements[0]);
if (child_id == 1) {
return 1;
}
return 0;
}

/* adapt, balance, transition and partition a given forest in one step */
static t8_forest_t
t8_test_forest_commit_abpt (t8_forest_t forest)
{
t8_forest_t forest_ada_bal_tra_par;

/* Adapt, balance and partition the uniform forest */
t8_forest_init (&forest_ada_bal_tra_par);
t8_forest_set_adapt (forest_ada_bal_tra_par, forest, t8_adapt_callback, 0);
t8_forest_set_balance (forest_ada_bal_tra_par, NULL, 0);
t8_forest_set_transition (forest_ada_bal_tra_par, NULL, 0);
t8_forest_set_partition (forest_ada_bal_tra_par, NULL, 0);
t8_forest_commit (forest_ada_bal_tra_par);

return forest_ada_bal_tra_par;
}

/* Compute neighbors of all elements in all trees at all faces */
void
t8_LFN_test (t8_forest_t forest_adapt)
{
t8_debugf ("~~~~~~~~~~ Into the LFN test function. ~~~~~~~~~~\n");

/* Collecting data of the adapted forest */
const t8_element_t *current_element;
t8_tree_t current_tree;
t8_locidx_t forest_is_balanced = 1;
t8_element_t **neighbor_leaves;
t8_locidx_t *element_indices;
t8_eclass_scheme_c *neigh_scheme;
t8_eclass_t eclass;
t8_eclass_scheme_c *ts;

int *dual_faces;
int num_neighbors;
int face_id;
int local_num_trees
= t8_forest_get_num_local_trees (forest_adapt); /* get the number of trees, this process knows about */
int current_tree_num_elements;
int subelement_count = 0;
int LFN_call_count = 0;
int tree_count;
int elem_count;
int neighbor_count;

for (tree_count = 0; tree_count < local_num_trees; ++tree_count) {
eclass = t8_forest_get_tree_class (forest_adapt, tree_count);
ts = t8_forest_get_eclass_scheme (forest_adapt, eclass);

/* get the number of elements in the current tree */
current_tree = t8_forest_get_tree (forest_adapt, tree_count);
current_tree_num_elements = t8_forest_get_tree_element_count (current_tree);

for (elem_count = 0; elem_count < current_tree_num_elements; ++elem_count) {

/* determining the current element according to the given tree id and element id within the tree */
current_element = t8_forest_get_element_in_tree (forest_adapt, tree_count, elem_count);

if (ts->t8_element_is_subelement (current_element)) {
subelement_count++;
}

/* print current element */
#if T8_ENABLE_DEBUG
t8_productionf ("\n\n________________"
"\nCurrent element: local elem index of this process: %i of %i (without ghosts)\n",
elem_count, t8_forest_get_local_num_elements (forest_adapt));
ts->t8_element_debug_print (current_element);
#endif

for (face_id = 0; face_id < ts->t8_element_num_faces (current_element); ++face_id) {
LFN_call_count++;
t8_forest_leaf_face_neighbors (forest_adapt, tree_count, current_element, &neighbor_leaves, face_id,
&dual_faces, &num_neighbors, &element_indices, &neigh_scheme,
forest_is_balanced);
/* free memory if neighbors exist */
if (num_neighbors > 0) {

/* print all neighbor elements */
for (neighbor_count = 0; neighbor_count < num_neighbors; neighbor_count++) {
#if T8_ENABLE_DEBUG
t8_productionf ("\n_________"
"\nNeighbor: %i of %i at face %i: (dual face: %i | local index %i of %i (with ghosts) | "
"ghost, if >= %i):\n",
neighbor_count + 1, num_neighbors, face_id, dual_faces[neighbor_count],
element_indices[neighbor_count],
t8_forest_get_local_num_elements (forest_adapt) + t8_forest_get_num_ghosts (forest_adapt),
t8_forest_get_local_num_elements (forest_adapt) - 1);
ts->t8_element_debug_print (neighbor_leaves[neighbor_count]);
#endif
}

neigh_scheme->t8_element_destroy (num_neighbors, neighbor_leaves);

T8_FREE (element_indices);
T8_FREE (neighbor_leaves);
T8_FREE (dual_faces);
}
else {
#if T8_ENABLE_DEBUG
/* no neighbor in this case */
t8_productionf ("\n_________"
"\nNeighbor: at face %i: There is no neighbor (domain boundary).\n",
face_id);
#endif
}
} /* end of face loop */
} /* end of element loop */
} /* end of tree loop */

T8_ASSERT (subelement_count == t8_forest_get_local_num_subelements (forest_adapt));

t8_debugf ("~~~~~~~~~~ The LFN test function finished successful ~~~~~~~~~~\n");
} /* end of t8_LFN_test */

/* Initializing, adapting balancing and transitioning a forest */
static void
t8_transition_global (void)
{
/* At the moment, subelements are only implemented for hexes and quads */
t8_eclass_t eclass
= T8_ECLASS_HEX; /* depending on the include file, this will be the transitioned or default hex implementation */
t8_forest_t forest;
t8_forest_t forest_adapt;
t8_cmesh_t cmesh;
char filename[BUFSIZ];

/* refinement setting */
int level = 2; /* initial uniform refinement level */

t8_locidx_t polygons_x = 2;
t8_locidx_t polygons_y = 1;
t8_locidx_t polygons_z = 1;

const double boundary[24] = { 0, 0, 0, 2, 0, 0, 0, 1, 0, 2, 1, 0, 0, 0, 1, 2, 0, 1, 0, 1, 1, 2, 1, 1 };

t8_scheme_cxx_t *scheme = t8_scheme_new_transition_hex_cxx ();

/* construct a multiple tree hex cmesh */
// cmesh = t8_cmesh_new_hypercube_pad (eclass, sc_MPI_COMM_WORLD, boundary, polygons_x, polygons_y, polygons_z, 0);

cmesh = t8_cmesh_new_hypercube (eclass, sc_MPI_COMM_WORLD, 0, 0, 0);
/* Create a uniformly refined forest */
forest = t8_forest_new_uniform (cmesh, scheme, level, 0, sc_MPI_COMM_WORLD);

t8_forest_write_vtk (forest, "forest_global_hex");

for (int adaptation_count = 1; adaptation_count <= 1; ++adaptation_count) {

forest_adapt = t8_test_forest_commit_abpt (forest);

t8_LFN_test (forest_adapt);

t8_debugf ("---------------ROUND %i ---------------------------\n\n", adaptation_count);

forest = forest_adapt;
}
t8_forest_write_vtk (forest, "transition_global_hex");

t8_forest_unref (&forest_adapt);

} /* end of t8_transition_global */

int
main (int argc, char **argv)
{
int mpiret;

mpiret = sc_MPI_Init (&argc, &argv);
SC_CHECK_MPI (mpiret);

sc_init (sc_MPI_COMM_WORLD, 1, 1, NULL, SC_LP_DEFAULT);
t8_init (SC_LP_DEFAULT);

t8_transition_global ();

sc_finalize ();
mpiret = sc_MPI_Finalize ();

SC_CHECK_MPI (mpiret);

return 0;
}
Loading
Loading