t8  1.2.0
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 wheras 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 arised 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) ((t8_attribute_info_struct_t *) \
127  ((char*)(t) + (t)->att_offset + \
128  (i) * sizeof (t8_attribute_info_struct_t)))
129 
130 /* Given a tree and an attribute info return the attribute */
131 #define T8_TREE_ATTR(t,ai) (T8_TREE_FIRST_ATT(t) + (ai)->attribute_offset)
132 
133 /* Given a tree return its face_neighbor array */
134 #define T8_TREE_FACE(t) ((char *) (t) + (t)->neigh_offset)
135 
136 /* Given a tree return irs tree_to_face array */
137 #define T8_TREE_TTF(t) (T8_TREE_FACE(t) + \
138  t8_eclass_num_faces[(t)->eclass] * sizeof(t8_locidx_t))
139 
140 /* Given a ghost return the beginning of its attribute block */
141 #define T8_GHOST_FIRST_ATT(g) T8_TREE_FIRST_ATT (g)
142 
143 /* Given a ghost and an index i return the i-th attribute index of that ghost */
144 #define T8_GHOST_ATTR_INFO(g,i) T8_TREE_ATTR_INFO (g, i)
145 
146 /* Given a ghost and an attribute info return the attribute */
147 #define T8_GHOST_ATTR(g,ai) T8_TREE_ATTR(g,ai)
148 
149 /* Given a ghost return its face_neighbor array */
150 #define T8_GHOST_FACE(g) T8_TREE_FACE(g)
151 
152 /* Given a ghost return its tree_to_face array */
153 #define T8_GHOST_TTF(g) (int8_t *) (T8_GHOST_FACE(g) + \
154  t8_eclass_num_faces[(g)->eclass] * sizeof(t8_gloidx_t))
155 
158 typedef struct
159 {
163 
177  int num_procs, t8_locidx_t num_trees,
178  t8_locidx_t num_ghosts);
179 
186  int proc);
187 
188 /* !!! This does only allocate memory for the trees and ghosts
189  * not yet for the face data and the attributes. See below !!!
190  */
208  int proc,
209  t8_locidx_t lfirst_tree,
210  t8_locidx_t num_trees,
211  t8_locidx_t lfirst_ghost,
212  t8_locidx_t num_ghosts,
213  int alloc);
214 
231  int proc);
232 
241  t8_cmesh_trees_t trees_src,
242  t8_locidx_t lnum_trees,
243  t8_locidx_t lnum_ghosts);
244 
255  int part_dest,
256  t8_cmesh_trees_t trees_src,
257  int part_src);
258 
267  t8_locidx_t ltree_id, int proc,
268  t8_eclass_t eclass);
269 
280  t8_locidx_t lghost_index,
281  t8_gloidx_t gtree_id, int proc,
282  t8_eclass_t eclass,
283  t8_locidx_t num_local_trees);
284 
292  t8_cmesh_trees_t trees);
293 
294 void t8_cmesh_trees_get_part_data (t8_cmesh_trees_t trees,
295  int proc,
296  t8_locidx_t *first_tree,
297  t8_locidx_t *num_trees,
298  t8_locidx_t *first_ghost,
299  t8_locidx_t *num_ghosts);
300 
301 /* TODO: This function returns NULL if the tree is not present.
302  * So far no error checking is done here. */
309  t8_locidx_t ltree);
310 
322  t8_locidx_t ltree_id,
323  t8_locidx_t **face_neigh,
324  int8_t **ttf);
325 
334  t8_locidx_t ltreeid,
335  int face, int8_t *ttf);
336 
342  const int face);
343 
352  tree,
353  const int face,
354  int8_t *ttf);
355 
365  ghost,
366  const int
367  face,
368  int8_t *ttf);
369 
370 /* TODO: This function returns NULL if the ghost is not present.
371  * So far no error checking is done here. */
378  t8_locidx_t lghost);
379 
391  t8_locidx_t lghost_id,
392  t8_gloidx_t **face_neigh,
393  int8_t **ttf);
394 
405  t8_gloidx_t global_id);
406 
407 /* TODO: document.
408  * returns the complete size in bytes needed to store all information */
409 size_t t8_cmesh_trees_size (t8_cmesh_trees_t trees);
410 
421  t8_locidx_t ltree_id,
422  size_t num_attributes,
423  size_t attr_bytes);
424 
439  t8_locidx_t ltree_id,
440  int package_id, int key,
441  size_t *size, int is_ghost);
442 
448 
454 
455 /* TODO: Currently there is a bug that forces us to give each tree an attribute */
456 /* TODO: this uses char * and cmesh_set_attribute uses void *. Unify! */
457 /* attr_tree_index is index of attr in tree's attribute array.
458  * We assume that the attributes are already sorted! */
459 void t8_cmesh_trees_add_attribute (t8_cmesh_trees_t trees,
460  int proc,
462  *attr, t8_locidx_t tree_id,
463  size_t index);
464 
470 
479 int8_t t8_cmesh_tree_to_face_encode (const int dimension,
480  const t8_locidx_t face,
481  const int orientation);
482 
493 void t8_cmesh_tree_to_face_decode (const int dimension,
494  const int8_t tree_to_face,
495  int *face,
496  int *orientation);
497 
498 /* TODO: To fit to the interface a trees struct is given as parameter here,
499  * however we could just take the one associated to the cmesh given.*/
505 void t8_cmesh_trees_print (t8_cmesh_t cmesh,
506  t8_cmesh_trees_t trees);
507 
519 void t8_cmesh_trees_bcast (t8_cmesh_t cmesh_in, int root,
520  sc_MPI_Comm comm);
521 
532  trees);
533 
534 int t8_cmesh_trees_is_equal (t8_cmesh_t cmesh,
535  t8_cmesh_trees_t trees_a,
536  t8_cmesh_trees_t trees_b);
537 
544 
545 T8_EXTERN_C_END ();
546 
547 #endif /* !T8_CMESH_PART_TREE_H */
Definition: t8_cmesh_types.h:156
Definition: t8_cmesh_types.h:231
This structure holds the connectivity data of the coarse mesh.
Definition: t8_cmesh_types.h:83
This structure holds the data of a local tree including the information about face neighbors.
Definition: t8_cmesh_types.h:189
Definition: t8_cmesh_types.h:244
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:159
t8_gloidx_t global_id
The global id.
Definition: t8_cmesh_trees.h:160
t8_locidx_t local_id
The local id.
Definition: t8_cmesh_trees.h:161
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:105
int32_t t8_locidx_t
A type for processor-local indexing.
Definition: t8.h:94
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:480
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:95
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:610
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:540
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:383
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:326
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:117
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:61
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:453
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:521
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:787
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:495
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:569
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:68
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:801
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:840
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:716
void t8_cmesh_trees_bcast(t8_cmesh_t cmesh_in, int root, sc_MPI_Comm comm)
Brodcast an existing valid trees structure from a root rank to all other ranks.
Definition: t8_cmesh_trees.c:918
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:553
void t8_cmesh_trees_destroy(t8_cmesh_trees_t *trees)
Free all memory allocated with a trees structure.
Definition: t8_cmesh_trees.c:1211
void 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:237
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:827
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:468
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:621
int t8_cmesh_trees_is_face_consistend(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:1002
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:398
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:514
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:198
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 neigbor of a tree at a given face and return the tree_to_face info.
We define here the datatypes needed for internal cmesh routines.
enum t8_eclass t8_eclass_t
This enumeration contains all possible element classes.