t8  UNKNOWN
t8code is a C library to manage a forest of adaptive space-trees of general element classes in parallel.
t8_cmesh_trees.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 
28 #ifndef T8_CMESH_PART_TREE_H
29 #define T8_CMESH_PART_TREE_H
30 
31 #include <t8.h>
32 #include <t8_cmesh.h>
33 #include "t8_cmesh_types.h"
34 
35 T8_EXTERN_C_BEGIN ();
36 
37 /* Interface for the data layout of the coarse trees.
38  *
39  * The layout is the same for replicated and partitioned meshes.
40  * Each process stores a meta array of data arrays. In the replicated case this meta
41  * array has only one entry whereas in the partitioned case there is one data array for
42  * each processor from which local trees were received in the last partition step
43  * (and only one meta array if the cmesh arose from a partitioned commit).
44  *
45  * Each dara arrays stores the local trees, the ghosts, face neighbor information
46  * of the ghosts, face neihbor information of the trees and the attributes of the trees.
47  * Furthermore we store for each tree and for each ghost to which data array they belong to.
48  * So the data looks like:
49  *
50  * TODO: would be more logical to switch Ghost and Tree faces
51  *
52  * M_0: | Trees | Ghosts | Ghost faces | Tree faces | Tree attributes | Ghost attributes
53  * M_1: | Trees | Ghosts | Ghost faces | Tree faces | Tree attributes | Ghost attributes
54  * . . . . . .
55  * M_n: | Trees | Ghosts | Ghost faces | Tree faces | Tree attributes | Ghost attributes
56  *
57  * tree_to_proc: | 0 | 0 | 1 | ... | n | these are just random examples here
58  * ghost_to_proc: | 0 | 1 | 2 | ... | n |
59  *
60  *
61  * Each tree T stores an offset to its Tree faces, such that (char*)&T + offset is
62  * a pointer to the faces array.
63  * The same holds for the ghost.
64  * Also each tree stores the number of attributes and an offset relative to itself
65  * to the first attribute entry of that tree.
66  *
67  * Tree faces:
68  *
69  * The data of Tree faces looks for each tree:
70  *
71  * | Treeid1 Treeid2 ... | ttf1 ttf2 ... | padding |
72  *
73  * Where padding is a number of unused bytes that makes the whole block a multiple
74  * of 4 Bytes.
75  * Treeid is a t8_locidx_t storing the local tree id for local tree neighbors and
76  * the local ghost id + num_local_trees for ghost neighbors.
77  * For the encoding of ttf (tree to face) see \ref t8_ctree_struct_t, ttf entries are int8_t
78  * and the offset of ttf1 can be calculated from the Tree faces offset and the
79  * class of the tree.
80  *
81  * Ghost faces:
82  *
83  * | Treeid1 Treeid2 ... | ttf1 ttf2 ... | padding |
84  *
85  * Where padding is a number of unused bytes that makes the whole block a multiple
86  * of sizeof (void*) Bytes.
87  * Treeidj is a t8_gloidx_t storing the global tree id for all neighbors.
88  * For the encoding of ttf (tree to face) see \ref t8_ctree_struct_t, ttf entries are int8_t
89  * and the offset of ttf1 can be calculated from the Tree faces offset and the
90  * class of the tree.
91  * Tree attributes:
92  *
93  * The data of Tree attributes looks like:
94  *
95  * TODO: This description seems incomplete. Why is it not Attij_data?
96  *
97  * | Att00_descr | Att01_descr | ... | Att10_descr | ... | Attrend_descr | Att1_data | Att2_data | ... |
98  * TODO: maybe insert padding here ||
99  * Where Attij_descr is a descriptor of the j-th attribute data of tree i storing
100  * - an offset to Atti_data starting from Atti0_descr
101  * - package id of the attribute (int)
102  * - key of the attribute (int)
103  * The data type is t8_attribute_info_struct_t
104  *
105  * Attrend_descr only stores the offset of the end of this attributes block
106  * (like an imaginary very last attribute);
107  * using this info the size of each attribute can be computed as the difference
108  * of the sizes of two consecutive attributes.
109  *
110  * padding is a number of nonused bytes to make the size of the descr block
111  * a multiple of four.
112  *
113  * TODO: maybe padding after the last Att_data is useful too
114  * TODO: We may also need padding between the attributes.
115  *
116  */
117 
118 /* allocate a t8_cmesh_tree struct and allocate memory for its entries.
119  * No memory for ctrees or ghosts is allocated here */
120 /* TODO: document */
121 
122 /* Given a tree return the beginning of its attributes block */
123 #define T8_TREE_FIRST_ATT(t) ((char *) (t) + (t)->att_offset)
124 
125 /* Given a tree and an index i return the i-th attribute index of that tree */
126 #define T8_TREE_ATTR_INFO(t, i) \
127  ((t8_attribute_info_struct_t *) ((char *) (t) + (t)->att_offset + (i) * sizeof (t8_attribute_info_struct_t)))
128 
129 /* Given a tree and an attribute info return the attribute */
130 #define T8_TREE_ATTR(t, ai) (T8_TREE_FIRST_ATT (t) + (ai)->attribute_offset)
131 
132 /* Given a tree return its face_neighbor array */
133 #define T8_TREE_FACE(t) ((char *) (t) + (t)->neigh_offset)
134 
135 /* Given a tree return irs tree_to_face array */
136 #define T8_TREE_TTF(t) (T8_TREE_FACE (t) + t8_eclass_num_faces[(t)->eclass] * sizeof (t8_locidx_t))
137 
138 /* Given a ghost return the beginning of its attribute block */
139 #define T8_GHOST_FIRST_ATT(g) T8_TREE_FIRST_ATT (g)
140 
141 /* Given a ghost and an index i return the i-th attribute index of that ghost */
142 #define T8_GHOST_ATTR_INFO(g, i) T8_TREE_ATTR_INFO (g, i)
143 
144 /* Given a ghost and an attribute info return the attribute */
145 #define T8_GHOST_ATTR(g, ai) T8_TREE_ATTR (g, ai)
146 
147 /* Given a ghost return its face_neighbor array */
148 #define T8_GHOST_FACE(g) T8_TREE_FACE (g)
149 
150 /* Given a ghost return its tree_to_face array */
151 #define T8_GHOST_TTF(g) (int8_t *) (T8_GHOST_FACE (g) + t8_eclass_num_faces[(g)->eclass] * sizeof (t8_gloidx_t))
152 
155 typedef struct
156 {
160 
173 void
174 t8_cmesh_trees_init (t8_cmesh_trees_t *ptrees, int num_procs, t8_locidx_t num_trees, t8_locidx_t num_ghosts);
175 
182 t8_cmesh_trees_get_part (t8_cmesh_trees_t trees, int proc);
183 
184 /* !!! This does only allocate memory for the trees and ghosts
185  * not yet for the face data and the attributes. See below !!!
186  */
203 void
204 t8_cmesh_trees_start_part (t8_cmesh_trees_t trees, int proc, t8_locidx_t lfirst_tree, t8_locidx_t num_trees,
205  t8_locidx_t lfirst_ghost, t8_locidx_t num_ghosts, int alloc);
206 
222 size_t
224 
232 void
234  t8_locidx_t lnum_ghosts);
235 
245 void
246 t8_cmesh_trees_copy_part (t8_cmesh_trees_t trees_dest, int part_dest, t8_cmesh_trees_t trees_src, int part_src);
247 
255 void
256 t8_cmesh_trees_add_tree (t8_cmesh_trees_t trees, t8_locidx_t ltree_id, int proc, t8_eclass_t eclass);
257 
267 void
268 t8_cmesh_trees_add_ghost (t8_cmesh_trees_t trees, t8_locidx_t lghost_index, t8_gloidx_t gtree_id, int proc,
269  t8_eclass_t eclass, t8_locidx_t num_local_trees);
270 
277 void
279 
280 void
281 t8_cmesh_trees_get_part_data (t8_cmesh_trees_t trees, int proc, t8_locidx_t *first_tree, t8_locidx_t *num_trees,
282  t8_locidx_t *first_ghost, t8_locidx_t *num_ghosts);
283 
284 /* TODO: This function returns NULL if the tree is not present.
285  * So far no error checking is done here. */
293 
305 t8_cmesh_trees_get_tree_ext (t8_cmesh_trees_t trees, t8_locidx_t ltree_id, t8_locidx_t **face_neigh, int8_t **ttf);
306 
315 t8_cmesh_trees_get_face_info (t8_cmesh_trees_t trees, t8_locidx_t ltreeid, int face, int8_t *ttf);
316 
322 t8_cmesh_trees_get_face_neighbor (const t8_ctree_t tree, const int face);
323 
332 t8_cmesh_trees_get_face_neighbor_ext (const t8_ctree_t tree, const int face, int8_t *ttf);
333 
342 t8_cmesh_trees_get_ghost_face_neighbor_ext (const t8_cghost_t ghost, const int face, int8_t *ttf);
343 
344 /* TODO: This function returns NULL if the ghost is not present.
345  * So far no error checking is done here. */
353 
365 t8_cmesh_trees_get_ghost_ext (t8_cmesh_trees_t trees, t8_locidx_t lghost_id, t8_gloidx_t **face_neigh, int8_t **ttf);
366 
378 
379 /* TODO: document.
380  * returns the complete size in bytes needed to store all information */
381 size_t
382 t8_cmesh_trees_size (t8_cmesh_trees_t trees);
383 
393 void
394 t8_cmesh_trees_init_attributes (t8_cmesh_trees_t trees, t8_locidx_t ltree_id, size_t num_attributes, size_t attr_bytes);
395 
409 void *
410 t8_cmesh_trees_get_attribute (t8_cmesh_trees_t trees, t8_locidx_t ltree_id, int package_id, int key, size_t *size,
411  int is_ghost);
412 
417 size_t
419 
424 size_t
426 
427 /* TODO: Currently there is a bug that forces us to give each tree an attribute */
428 /* TODO: this uses char * and cmesh_set_attribute uses void *. Unify! */
429 /* attr_tree_index is index of attr in tree's attribute array.
430  * We assume that the attributes are already sorted! */
431 void
432 t8_cmesh_trees_add_attribute (t8_cmesh_trees_t trees, int proc, t8_stash_attribute_struct_t *attr, t8_locidx_t tree_id,
433  size_t index);
434 
435 void
436 t8_cmesh_trees_add_ghost_attribute (t8_cmesh_trees_t trees, int proc, t8_stash_attribute_struct_t *attr,
437  t8_locidx_t local_ghost_id, size_t index, size_t *attribute_data_offset);
438 
443 size_t
445 
454 int8_t
455 t8_cmesh_tree_to_face_encode (const int dimension, const t8_locidx_t face, const int orientation);
456 
467 void
468 t8_cmesh_tree_to_face_decode (const int dimension, const int8_t tree_to_face, int *face, int *orientation);
469 
470 /* TODO: To fit to the interface a trees struct is given as parameter here,
471  * however we could just take the one associated to the cmesh given.*/
477 void
479 
491 void
492 t8_cmesh_trees_bcast (t8_cmesh_t cmesh_in, int root, sc_MPI_Comm comm);
493 
502 int
504 
505 int
506 t8_cmesh_trees_is_equal (t8_cmesh_t cmesh, t8_cmesh_trees_t trees_a, t8_cmesh_trees_t trees_b);
507 
513 void
515 
516 T8_EXTERN_C_END ();
517 
518 #endif /* !T8_CMESH_PART_TREE_H */
Definition: t8_cmesh_types.h:161
Definition: t8_cmesh_types.h:234
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:193
Definition: t8_cmesh_types.h:246
The attribute information that is stored before a cmesh is committed.
Definition: t8_cmesh_stash.h:63
This struct is an entry of the trees global_id to local_id hash table for ghost trees.
Definition: t8_cmesh_trees.h:156
t8_gloidx_t global_id
The global id.
Definition: t8_cmesh_trees.h:157
t8_locidx_t local_id
The local id.
Definition: t8_cmesh_trees.h:158
This is the administrative header file for t8code.
int64_t t8_gloidx_t
A type for global indexing that holds really big numbers.
Definition: t8.h:98
int32_t t8_locidx_t
A type for processor-local indexing.
Definition: t8.h:87
We define the coarse mesh of trees in this file.
t8_ctree_t t8_cmesh_trees_get_tree_ext(t8_cmesh_trees_t trees, t8_locidx_t ltree_id, t8_locidx_t **face_neigh, int8_t **ttf)
Return a pointer to a specific tree in a trees struct plus pointers to its face_neighbor and tree_to_...
Definition: t8_cmesh_trees.c:473
void t8_cmesh_trees_add_tree(t8_cmesh_trees_t trees, t8_locidx_t ltree_id, int proc, t8_eclass_t eclass)
Add a tree to a trees structure.
Definition: t8_cmesh_trees.c:88
void t8_cmesh_trees_copy_toproc(t8_cmesh_trees_t trees_dest, t8_cmesh_trees_t trees_src, t8_locidx_t lnum_trees, t8_locidx_t lnum_ghosts)
Copy the tree_to_proc and ghost_to_proc arrays of one tree structure to another one.
Definition: t8_cmesh_trees.c:596
t8_cghost_t t8_cmesh_trees_get_ghost(t8_cmesh_trees_t trees, t8_locidx_t lghost)
Return a pointer to a specific ghost in a trees struct.
Definition: t8_cmesh_trees.c:530
size_t t8_cmesh_trees_attribute_size(t8_ctree_t tree)
Return the total size of all attributes stored at a specified tree.
Definition: t8_cmesh_trees.c:381
void t8_cmesh_trees_set_all_boundary(t8_cmesh_t cmesh, t8_cmesh_trees_t trees)
Set all neighbor fields of all local trees and ghosts to boundary.
Definition: t8_cmesh_trees.c:329
void t8_cmesh_trees_add_ghost(t8_cmesh_trees_t trees, t8_locidx_t lghost_index, t8_gloidx_t gtree_id, int proc, t8_eclass_t eclass, t8_locidx_t num_local_trees)
Add a ghost to a trees structure.
Definition: t8_cmesh_trees.c:109
t8_part_tree_t t8_cmesh_trees_get_part(t8_cmesh_trees_t trees, int proc)
Return one part of a specified tree array.
Definition: t8_cmesh_trees.c:60
void t8_cmesh_trees_copy_part(t8_cmesh_trees_t trees_dest, int part_dest, t8_cmesh_trees_t trees_src, int part_src)
Copy the trees array from one part to another.
Definition: t8_cmesh_trees.c:447
t8_gloidx_t t8_cmesh_trees_get_ghost_face_neighbor_ext(const t8_cghost_t ghost, const int face, int8_t *ttf)
Given a coarse ghost and a face number, return the local id of the neighbor tree together with its tr...
Definition: t8_cmesh_trees.c:512
size_t t8_cmesh_trees_get_numproc(t8_cmesh_trees_t trees)
Return the number of parts of a trees structure.
Definition: t8_cmesh_trees.c:792
t8_locidx_t t8_cmesh_trees_get_face_neighbor_ext(const t8_ctree_t tree, const int face, int8_t *ttf)
Given a coarse tree and a face number, return the local id of the neighbor tree together with its tre...
Definition: t8_cmesh_trees.c:487
t8_locidx_t t8_cmesh_trees_get_ghost_local_id(t8_cmesh_trees_t trees, t8_gloidx_t global_id)
Given the global tree id of a ghost tree in a trees structure, return its local ghost id.
Definition: t8_cmesh_trees.c:557
void t8_cmesh_trees_init(t8_cmesh_trees_t *ptrees, int num_procs, t8_locidx_t num_trees, t8_locidx_t num_ghosts)
Initialize a trees structure and allocate its parts.
Definition: t8_cmesh_trees.c:67
int8_t t8_cmesh_tree_to_face_encode(const int dimension, const t8_locidx_t face, const int orientation)
Compute the tree-to-face information given a face and orientation value of a face connection.
Definition: t8_cmesh_trees.c:806
void t8_cmesh_trees_print(t8_cmesh_t cmesh, t8_cmesh_trees_t trees)
Print the trees,ghosts and their neighbors in ASCII format t stdout.
Definition: t8_cmesh_trees.c:842
void * t8_cmesh_trees_get_attribute(t8_cmesh_trees_t trees, t8_locidx_t ltree_id, int package_id, int key, size_t *size, int is_ghost)
Return an attribute that is stored at a tree.
Definition: t8_cmesh_trees.c:728
void t8_cmesh_trees_bcast(t8_cmesh_t cmesh_in, int root, sc_MPI_Comm comm)
Broadcast an existing valid trees structure from a root rank to all other ranks.
Definition: t8_cmesh_trees.c:911
t8_cghost_t t8_cmesh_trees_get_ghost_ext(t8_cmesh_trees_t trees, t8_locidx_t lghost_id, t8_gloidx_t **face_neigh, int8_t **ttf)
Return a pointer to a specific ghost in a trees struct plus pointers to its face_neighbor and tree_to...
Definition: t8_cmesh_trees.c:542
void t8_cmesh_trees_destroy(t8_cmesh_trees_t *trees)
Free all memory allocated with a trees structure.
Definition: t8_cmesh_trees.c:1175
void t8_cmesh_tree_to_face_decode(const int dimension, const int8_t tree_to_face, int *face, int *orientation)
Given a tree-to-face value, get its encoded face number and orientation.
Definition: t8_cmesh_trees.c:830
t8_ctree_t t8_cmesh_trees_get_tree(t8_cmesh_trees_t trees, t8_locidx_t ltree)
Return a pointer to a specific tree in a trees struct.
Definition: t8_cmesh_trees.c:461
void t8_cmesh_trees_init_attributes(t8_cmesh_trees_t trees, t8_locidx_t ltree_id, size_t num_attributes, size_t attr_bytes)
For one tree in a trees structure set the number of attributes and temporarily store the total size o...
Definition: t8_cmesh_trees.c:604
size_t t8_cmesh_trees_ghost_attribute_size(t8_cghost_t ghost)
Return the total size of all attributes stored at a specified ghost.
Definition: t8_cmesh_trees.c:396
t8_locidx_t t8_cmesh_trees_get_face_neighbor(const t8_ctree_t tree, const int face)
Given a coarse tree and a face number, return the local id of the neighbor tree.
Definition: t8_cmesh_trees.c:505
void t8_cmesh_trees_start_part(t8_cmesh_trees_t trees, int proc, t8_locidx_t lfirst_tree, t8_locidx_t num_trees, t8_locidx_t lfirst_ghost, t8_locidx_t num_ghosts, int alloc)
Allocate the first_tree array of a given tree_part in a tree struct with a given number of trees and ...
Definition: t8_cmesh_trees.c:185
size_t t8_cmesh_trees_finish_part(t8_cmesh_trees_t trees, int proc)
After all classes of trees and ghosts have been set and after the number of tree attributes was set a...
Definition: t8_cmesh_trees.c:220
t8_locidx_t t8_cmesh_trees_get_face_info(t8_cmesh_trees_t trees, t8_locidx_t ltreeid, int face, int8_t *ttf)
Return the face neighbor of a tree at a given face and return the tree_to_face info.
int t8_cmesh_trees_is_face_consistent(t8_cmesh_t cmesh, t8_cmesh_trees_t trees)
Check whether the face connection of a trees structure are consistent.
Definition: t8_cmesh_trees.c:991
We define here the datatypes needed for internal cmesh routines.
enum t8_eclass t8_eclass_t
This enumeration contains all possible element classes.