t8  UNKNOWN
t8code is a C library to manage a forest of adaptive space-trees of general element classes in parallel.
t8_forest_general.h
Go to the documentation of this file.
1 /*
2  This file is part of t8code.
3  t8code is a C library to manage a collection (a forest) of multiple
4  connected adaptive space-trees of general element classes in parallel.
5 
6  Copyright (C) 2015 the developers
7 
8  t8code is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  t8code is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with t8code; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22 
27 /* TODO: begin documenting this file: make doxygen 2>&1 | grep t8_forest */
28 
29 #ifndef T8_FOREST_GENERAL_H
30 #define T8_FOREST_GENERAL_H
31 
32 #include <t8_cmesh.h>
33 #include <t8_element.h>
34 #include <t8_data/t8_containers.h>
35 
37 typedef struct t8_forest *t8_forest_t;
38 typedef struct t8_tree *t8_tree_t;
39 
42 typedef enum {
48 
53 typedef void (*t8_generic_function_pointer) (void);
54 T8_EXTERN_C_BEGIN ();
55 
86 typedef void (*t8_forest_replace_t) (t8_forest_t forest_old, t8_forest_t forest_new, t8_locidx_t which_tree,
87  t8_eclass_scheme_c *ts, const int refine, const int num_outgoing,
88  const t8_locidx_t first_outgoing, const int num_incoming,
89  const t8_locidx_t first_incoming);
90 
112 /* TODO: Do we really need the forest argument? Since the forest is not committed yet it
113  * seems dangerous to expose to the user. */
114 typedef int (*t8_forest_adapt_t) (t8_forest_t forest, t8_forest_t forest_from, t8_locidx_t which_tree,
115  t8_locidx_t lelement_id, t8_eclass_scheme_c *ts, const int is_family,
116  const int num_elements, t8_element_t *elements[]);
117 
129 void
130 t8_forest_init (t8_forest_t *pforest);
131 
140 int
142 
151 int
153 
161 int
163 
174 int
175 t8_forest_is_equal (t8_forest_t forest_a, t8_forest_t forest_b);
176 
187 void
188 t8_forest_set_cmesh (t8_forest_t forest, t8_cmesh_t cmesh, sc_MPI_Comm comm);
189 
200 void
202 
213 void
214 t8_forest_set_level (t8_forest_t forest, int level);
215 
229 void
230 t8_forest_set_copy (t8_forest_t forest, const t8_forest_t from);
231 
254 /* TODO: make recursive flag to int specifying the number of recursions? */
255 void
256 t8_forest_set_adapt (t8_forest_t forest, const t8_forest_t set_from, t8_forest_adapt_t adapt_fn, int recursive);
257 
265 void
266 t8_forest_set_user_data (t8_forest_t forest, void *data);
267 
274 void *
275 t8_forest_get_user_data (const t8_forest_t forest);
276 
287 void
289 
298 
319 void
320 t8_forest_set_partition (t8_forest_t forest, const t8_forest_t set_from, int set_for_coarsening);
321 
345 void
346 t8_forest_set_balance (t8_forest_t forest, const t8_forest_t set_from, int no_repartition);
347 
356 void
357 t8_forest_set_ghost (t8_forest_t forest, int do_ghost, t8_ghost_type_t ghost_type);
358 
367 void
368 t8_forest_set_ghost_ext (t8_forest_t forest, int do_ghost, t8_ghost_type_t ghost_type, int ghost_version);
369 
370 /* TODO: use assertions and document that the forest_set (..., from) and
371  * set_load are mutually exclusive. */
372 void
373 t8_forest_set_load (t8_forest_t forest, const char *filename);
374 
379 void
381 
387 void
389 
401 int
402 t8_forest_get_maxlevel (const t8_forest_t forest);
403 
411 
419 
429 
437 t8_forest_get_eclass (const t8_forest_t forest, const t8_locidx_t ltreeid);
438 
449 t8_forest_get_local_id (const t8_forest_t forest, const t8_gloidx_t gtreeid);
450 
464 t8_forest_get_local_or_ghost_id (const t8_forest_t forest, const t8_gloidx_t gtreeid);
465 
476 
487 
495 
518 void
520  t8_element_t **pneighbor_leaves[], int face, int *dual_faces[], int *num_neighbors,
521  t8_locidx_t **pelement_indices, t8_eclass_scheme_c **pneigh_scheme,
522  int forest_is_balanced);
523 
524 void
525 t8_forest_leaf_face_neighbors_ext (t8_forest_t forest, t8_locidx_t ltreeid, const t8_element_t *leaf,
526  t8_element_t **pneighbor_leaves[], int face, int *dual_faces[], int *num_neighbors,
527  t8_locidx_t **pelement_indices, t8_eclass_scheme_c **pneigh_scheme,
528  int forest_is_balanced, t8_gloidx_t *gneigh_tree);
529 
540 /* TODO: In \ref t8_forest_ghost_cxx we already implemented a begin and end function
541  * that allow for overlapping communication and computation. We will make them
542  * available in this interface in the future. */
543 void
544 t8_forest_ghost_exchange_data (t8_forest_t forest, sc_array_t *element_data);
545 
547 void
549 
559 void
560 t8_forest_partition_cmesh (t8_forest_t forest, sc_MPI_Comm comm, int set_profiling);
561 
567 sc_MPI_Comm
568 t8_forest_get_mpicomm (const t8_forest_t forest);
569 
576 
583 
590 
597 
607 t8_forest_global_tree_id (const t8_forest_t forest, const t8_locidx_t ltreeid);
608 
615 t8_tree_t
616 t8_forest_get_tree (const t8_forest_t forest, const t8_locidx_t ltree_id);
617 
624 double *
626 
634 t8_forest_tree_get_leaves (const t8_forest_t forest, const t8_locidx_t ltree_id);
635 
642 
652 t8_element_t *
653 t8_forest_get_element (t8_forest_t forest, t8_locidx_t lelement_id, t8_locidx_t *ltreeid);
654 
663 const t8_element_t *
664 t8_forest_get_element_in_tree (t8_forest_t forest, t8_locidx_t ltreeid, t8_locidx_t leid_in_tree);
665 
673 
683 t8_forest_get_tree_element_offset (const t8_forest_t forest, const t8_locidx_t ltreeid);
684 
691 
698 t8_forest_get_tree_class (const t8_forest_t forest, const t8_locidx_t ltreeid);
699 
709 
716 t8_forest_get_scheme (const t8_forest_t forest);
717 
727 
738 t8_forest_element_neighbor_eclass (t8_forest_t forest, t8_locidx_t ltreeid, const t8_element_t *elem, int face);
739 
758  t8_eclass_scheme_c *neigh_scheme, int face, int *neigh_face);
759 
760 /* TODO: implement */
761 void
762 t8_forest_iterate (t8_forest_t forest);
763 
782 void
784  const double *points, int num_points, int *is_inside, const double tolerance);
785 
786 /* TODO: if set level and partition/adapt/balance all give NULL, then
787  * refine uniformly and partition/adapt/balance the unfiform forest. */
800 t8_forest_new_uniform (t8_cmesh_t cmesh, t8_scheme_cxx_t *scheme, const int level, const int do_face_ghost,
801  sc_MPI_Comm comm);
802 
814 /* TODO: make user_data const. */
816 t8_forest_new_adapt (t8_forest_t forest_from, t8_forest_adapt_t adapt_fn, int recursive, int do_face_ghost,
817  void *user_data);
818 
823 void
824 t8_forest_ref (t8_forest_t forest);
825 
837 void
838 t8_forest_unref (t8_forest_t *pforest);
839 
840 T8_EXTERN_C_END ();
841 
842 #endif /* !T8_FOREST_GENERAL_H */
This structure holds the connectivity data of the coarse mesh.
Definition: t8_cmesh_types.h:88
This structure holds the data of a local tree including the information about face neighbors.
Definition: t8_cmesh_types.h:189
This struct holds virtual functions for a particular element class.
Definition: t8_element_cxx.hxx:41
The t8_element_array_t is an array to store t8_element_t * of a given eclass_scheme implementation.
Definition: t8_containers.h:42
This structure is private to the implementation.
Definition: t8_forest_types.h:69
The scheme holds implementations for one or more element classes.
Definition: t8_element.h:51
The t8 tree datatype.
Definition: t8_forest_types.h:143
t8_eclass_t eclass
The element class of this tree.
Definition: t8_forest_types.h:145
t8_element_array_t elements
locally stored elements
Definition: t8_forest_types.h:144
int64_t t8_gloidx_t
A type for global indexing that holds really big numbers.
Definition: t8.h:100
int32_t t8_locidx_t
A type for processor-local indexing.
Definition: t8.h:89
We define the coarse mesh of trees in this file.
We define the t8_element_array that stores elements of a given eclass scheme.
enum t8_eclass t8_eclass_t
This enumeration contains all possible element classes.
This file defines basic operations on an element in a refinement tree.
struct t8_element t8_element_t
Opaque structure for a generic element, only used as pointer.
Definition: t8_element.h:42
void t8_forest_set_partition(t8_forest_t forest, const t8_forest_t set_from, int set_for_coarsening)
Set a source forest to be partitioned during commit.
Definition: t8_forest.c:167
t8_eclass_scheme_c * t8_forest_get_eclass_scheme(t8_forest_t forest, t8_eclass_t eclass)
Return the eclass scheme of a given element class associated to a forest.
Definition: t8_forest.c:1018
t8_forest_t t8_forest_new_uniform(t8_cmesh_t cmesh, t8_scheme_cxx_t *scheme, const int level, const int do_face_ghost, sc_MPI_Comm comm)
Build a uniformly refined forest on a coarse mesh.
Definition: t8_forest.c:1408
int t8_forest_no_overlap(t8_forest_t forest)
Check whether the forest has local overlapping elements.
Definition: t8_forest_cxx.cxx:261
t8_ctree_t t8_forest_get_coarse_tree(t8_forest_t forest, t8_locidx_t ltreeid)
Given the local id of a tree in a forest, return the coarse tree of the cmesh that corresponds to thi...
Definition: t8_forest.c:1152
t8_eclass_t t8_forest_get_eclass(const t8_forest_t forest, const t8_locidx_t ltreeid)
Return the element class of a forest local tree.
Definition: t8_forest.c:1038
double * t8_forest_get_tree_vertices(t8_forest_t forest, t8_locidx_t ltreeid)
Return a pointer to the vertex coordinates of a tree.
Definition: t8_forest.c:834
t8_locidx_t t8_forest_cmesh_ltreeid_to_ltreeid(t8_forest_t forest, t8_locidx_t lctreeid)
Given the local id of a tree in the coarse mesh of a forest, compute the tree's local id in the fores...
Definition: t8_forest.c:1120
void t8_forest_commit(t8_forest_t forest)
After allocating and adding properties to a forest, commit the changes.
Definition: t8_forest.c:416
t8_locidx_t t8_forest_get_num_ghost_trees(const t8_forest_t forest)
Return the number of ghost trees of a given forest.
Definition: t8_forest.c:770
void * t8_forest_get_user_data(const t8_forest_t forest)
Return the user data pointer associated with a forest.
Definition: t8_forest.c:289
t8_gloidx_t t8_forest_get_first_local_element_id(t8_forest_t forest)
Compute the global index of the first local element of a forest.
Definition: t8_forest.c:998
sc_MPI_Comm t8_forest_get_mpicomm(const t8_forest_t forest)
Return the mpi communicator associated to a forest.
Definition: t8_forest.c:755
t8_gloidx_t t8_forest_get_global_num_elements(const t8_forest_t forest)
Return the number of global elements in the forest.
Definition: t8_forest.c:686
t8_locidx_t t8_forest_ltreeid_to_cmesh_ltreeid(t8_forest_t forest, t8_locidx_t ltreeid)
Given the local id of a tree in a forest, compute the tree's local id in the associated cmesh.
Definition: t8_forest.c:1089
t8_locidx_t t8_forest_get_tree_element_offset(const t8_forest_t forest, const t8_locidx_t ltreeid)
Return the element offset of a local tree, that is the number of elements in all trees with smaller l...
Definition: t8_forest.c:952
t8_locidx_t t8_forest_get_num_ghosts(const t8_forest_t forest)
Return the number of ghost elements of a forest.
Definition: t8_forest.c:694
void t8_forest_set_balance(t8_forest_t forest, const t8_forest_t set_from, int no_repartition)
Set a source forest to be balanced during commit.
Definition: t8_forest.c:193
void t8_forest_leaf_face_neighbors(t8_forest_t forest, t8_locidx_t ltreeid, const t8_element_t *leaf, t8_element_t **pneighbor_leaves[], int face, int *dual_faces[], int *num_neighbors, t8_locidx_t **pelement_indices, t8_eclass_scheme_c **pneigh_scheme, int forest_is_balanced)
Compute the leaf face neighbors of a forest.
Definition: t8_forest_cxx.cxx:1928
void t8_forest_element_points_inside(t8_forest_t forest, t8_locidx_t ltreeid, const t8_element_t *element, const double *points, int num_points, int *is_inside, const double tolerance)
Query whether a batch of points lies inside an element.
Definition: t8_forest_cxx.cxx:1089
void t8_forest_set_ghost_ext(t8_forest_t forest, int do_ghost, t8_ghost_type_t ghost_type, int ghost_version)
Like t8_forest_set_ghost but with the additional options to change the ghost algorithm.
Definition: t8_forest.c:222
t8_gloidx_t t8_forest_get_num_global_trees(const t8_forest_t forest)
Return the number of global trees of a given forest.
Definition: t8_forest.c:796
const t8_element_t * t8_forest_get_element_in_tree(t8_forest_t forest, t8_locidx_t ltreeid, t8_locidx_t leid_in_tree)
Return an element of a local tree in a forest.
Definition: t8_forest.c:941
t8_ghost_type_t
This type controls, which neighbors count as ghost elements.
Definition: t8_forest_general.h:42
@ T8_GHOST_VERTICES
Consider all vertex (codimension 3) and edge and face neighbors.
Definition: t8_forest_general.h:46
@ T8_GHOST_FACES
Consider all face (codimension 1) neighbors.
Definition: t8_forest_general.h:44
@ T8_GHOST_NONE
Do not create ghost layer.
Definition: t8_forest_general.h:43
@ T8_GHOST_EDGES
Consider all edge (codimension 2) and face neighbors.
Definition: t8_forest_general.h:45
void t8_forest_set_adapt(t8_forest_t forest, const t8_forest_t set_from, t8_forest_adapt_t adapt_fn, int recursive)
Set a source forest with an adapt function to be adapted on committing.
Definition: t8_forest.c:251
void(* t8_generic_function_pointer)(void)
This typedef is needed as a helper construct to properly be able to define a function that returns a ...
Definition: t8_forest_general.h:53
t8_element_t * t8_forest_get_element(t8_forest_t forest, t8_locidx_t lelement_id, t8_locidx_t *ltreeid)
Return an element of the forest.
Definition: t8_forest.c:881
void t8_forest_set_copy(t8_forest_t forest, const t8_forest_t from)
Set a forest as source for copying on committing.
Definition: t8_forest.c:143
t8_locidx_t t8_forest_get_local_num_elements(const t8_forest_t forest)
Return the number of process local elements in the forest.
Definition: t8_forest.c:678
void t8_forest_set_user_data(t8_forest_t forest, void *data)
Set the user data of a forest.
Definition: t8_forest.c:282
int t8_forest_get_maxlevel(const t8_forest_t forest)
Return the maximum allowed refinement level for any element in a forest.
Definition: t8_forest_cxx.cxx:201
void t8_forest_init(t8_forest_t *pforest)
Create a new forest with reference count one.
Definition: t8_forest.c:40
void t8_forest_ref(t8_forest_t forest)
Increase the reference counter of a forest.
Definition: t8_forest.c:1545
struct t8_forest * t8_forest_t
Opaque pointer to a forest implementation.
Definition: t8_forest_general.h:37
int t8_forest_is_initialized(t8_forest_t forest)
Check whether a forest is not NULL, initialized and not committed.
Definition: t8_forest.c:66
t8_element_array_t * t8_forest_tree_get_leaves(const t8_forest_t forest, const t8_locidx_t ltree_id)
Return the array of leaf elements of a local tree in a forest.
Definition: t8_forest.c:840
t8_locidx_t t8_forest_get_tree_num_elements(t8_forest_t forest, t8_locidx_t ltreeid)
Return the number of elements of a tree.
Definition: t8_forest.c:972
void t8_forest_unref(t8_forest_t *pforest)
Decrease the reference counter of a forest.
Definition: t8_forest.c:1552
void t8_forest_set_scheme(t8_forest_t forest, t8_scheme_cxx_t *scheme)
Set the element scheme associated to a forest.
Definition: t8_forest.c:117
t8_eclass_t t8_forest_get_tree_class(const t8_forest_t forest, const t8_locidx_t ltreeid)
Return the eclass of a tree in a forest.
Definition: t8_forest.c:981
void t8_forest_set_user_function(t8_forest_t forest, t8_generic_function_pointer function)
Set the user function pointer of a forest.
Definition: t8_forest.c:295
t8_locidx_t t8_forest_get_num_local_trees(const t8_forest_t forest)
Return the number of local trees of a given forest.
Definition: t8_forest.c:781
void t8_forest_set_level(t8_forest_t forest, int level)
Set the initial refinement level to be used when forest is committed.
Definition: t8_forest.c:131
t8_generic_function_pointer t8_forest_get_user_function(const t8_forest_t forest)
Return the user function pointer associated with a forest.
Definition: t8_forest.c:302
t8_tree_t t8_forest_get_tree(const t8_forest_t forest, const t8_locidx_t ltree_id)
Return a pointer to a tree in a forest.
Definition: t8_forest.c:826
int t8_forest_is_committed(t8_forest_t forest)
Check whether a forest is not NULL, initialized and committed.
Definition: t8_forest.c:72
void t8_forest_set_cmesh(t8_forest_t forest, t8_cmesh_t cmesh, sc_MPI_Comm comm)
Set the cmesh associated to a forest.
Definition: t8_forest.c:94
t8_locidx_t t8_forest_get_tree_element_count(t8_tree_t tree)
Return the number of elements of a tree.
Definition: t8_forest.c:960
void t8_forest_partition_cmesh(t8_forest_t forest, sc_MPI_Comm comm, int set_profiling)
Change the cmesh associated to a forest to a partitioned cmesh that is partitioned according to the t...
Definition: t8_forest.c:729
t8_locidx_t t8_forest_get_local_or_ghost_id(const t8_forest_t forest, const t8_gloidx_t gtreeid)
Given a global tree id compute the forest local id of this tree.
Definition: t8_forest.c:1065
t8_gloidx_t t8_forest_get_first_local_tree_id(const t8_forest_t forest)
Return the global id of the first local tree of a forest.
Definition: t8_forest.c:762
t8_forest_t t8_forest_new_adapt(t8_forest_t forest_from, t8_forest_adapt_t adapt_fn, int recursive, int do_face_ghost, void *user_data)
Build a adapted forest from another forest.
Definition: t8_forest.c:1435
t8_locidx_t t8_forest_get_local_id(const t8_forest_t forest, const t8_gloidx_t gtreeid)
Given a global tree id compute the forest local id of this tree.
Definition: t8_forest.c:1045
void t8_forest_set_ghost(t8_forest_t forest, int do_ghost, t8_ghost_type_t ghost_type)
Enable or disable the creation of a layer of ghost elements.
Definition: t8_forest.c:244
void(* t8_forest_replace_t)(t8_forest_t forest_old, t8_forest_t forest_new, t8_locidx_t which_tree, t8_eclass_scheme_c *ts, const int refine, const int num_outgoing, const t8_locidx_t first_outgoing, const int num_incoming, const t8_locidx_t first_incoming)
Callback function prototype to replace one set of elements with another.
Definition: t8_forest_general.h:86
t8_cmesh_t t8_forest_get_cmesh(t8_forest_t forest)
Return a cmesh associated to a forest.
Definition: t8_forest.c:849
void t8_forest_comm_global_num_elements(t8_forest_t forest)
Compute the global number of elements in a forest as the sum of the local element counts.
Definition: t8_forest.c:309
void t8_forest_ghost_print(t8_forest_t forest)
Print the ghost structure of a forest.
Definition: t8_forest_ghost.cxx:1802
void t8_forest_ghost_exchange_data(t8_forest_t forest, sc_array_t *element_data)
Exchange ghost information of user defined element data.
Definition: t8_forest_ghost.cxx:1770
t8_scheme_cxx_t * t8_forest_get_scheme(const t8_forest_t forest)
Return the element scheme associated to a forest.
Definition: t8_forest.c:1009
t8_eclass_t t8_forest_element_neighbor_eclass(t8_forest_t forest, t8_locidx_t ltreeid, const t8_element_t *elem, int face)
Return the eclass of the tree in which a face neighbor of a given element lies.
Definition: t8_forest_cxx.cxx:1471
int t8_forest_is_equal(t8_forest_t forest_a, t8_forest_t forest_b)
Check whether two committed forests have the same local elements.
Definition: t8_forest_cxx.cxx:318
int(* t8_forest_adapt_t)(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[])
Callback function prototype to decide for refining and coarsening.
Definition: t8_forest_general.h:114
t8_gloidx_t t8_forest_element_face_neighbor(t8_forest_t forest, t8_locidx_t ltreeid, const t8_element_t *elem, t8_element_t *neigh, t8_eclass_scheme_c *neigh_scheme, int face, int *neigh_face)
Construct the face neighbor of an element, possibly across tree boundaries.
Definition: t8_forest_cxx.cxx:1514
t8_gloidx_t t8_forest_global_tree_id(const t8_forest_t forest, const t8_locidx_t ltreeid)
Return the global id of a local tree or a ghost tree.
Definition: t8_forest.c:804