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  * For each tree the data of the tree faces (where F is the number of faces of the tree) looks like this:
70  *
71  * | Treeid1 Treeid2 ... TreeidF | ttf1 ttf2 ... ttfN | 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 ... TreeidF | ttf1 ttf2 ... ttfF | 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, where N is the total number of attributes:
94  * The Attributes do not necessarily need to be sorted in a particular way, as they are
95  * accessed by offsets in the Att_descr.
96  *
97  * | Att00_descr | Att01_descr | ... Att0 A_0_descr| Att10_descr | ... | AttrT A_T | Att0_data | Att2_data | ... AttN_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 Attk_data starting from Attij_descr, where k is the index in the dataarray.
101  * The actual data is put there in the order of the attribute descriptors, but this is not necessitated by the layout.
102  * - package id of the attribute (int)
103  * - key of the attribute (int)
104  * The data type is t8_attribute_info_struct_t
105  *
106  * Attrend_descr only stores the offset of the end of this attributes block
107  * (like an imaginary very last attribute);
108  * using this info the size of each attribute can be computed as the difference
109  * of the sizes of two consecutive attributes.
110  *
111  * padding is a number of nonused bytes to make the size of the descr block
112  * a multiple of four.
113  *
114  * TODO: maybe padding after the last Att_data is useful too
115  * TODO: We may also need padding between the attributes.
116  *
117  */
118 
119 /* allocate a t8_cmesh_tree struct and allocate memory for its entries.
120  * No memory for ctrees or ghosts is allocated here */
121 /* TODO: document */
122 
123 /* Given a tree return the beginning of its attributes block */
124 #define T8_TREE_FIRST_ATT(t) ((char *) (t) + (t)->att_offset)
125 
126 /* Given a tree and an index i return the i-th attribute index of that tree */
127 #define T8_TREE_ATTR_INFO(t, i) \
128  ((t8_attribute_info_struct_t *) ((char *) (t) + (t)->att_offset + (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) + t8_eclass_num_faces[(t)->eclass] * sizeof (t8_locidx_t))
138 
139 /* Given a ghost return the beginning of its attribute block */
140 #define T8_GHOST_FIRST_ATT(g) T8_TREE_FIRST_ATT (g)
141 
142 /* Given a ghost and an index i return the i-th attribute index of that ghost */
143 #define T8_GHOST_ATTR_INFO(g, i) T8_TREE_ATTR_INFO (g, i)
144 
145 /* Given a ghost and an attribute info return the attribute */
146 #define T8_GHOST_ATTR(g, ai) T8_TREE_ATTR (g, ai)
147 
148 /* Given a ghost return its face_neighbor array */
149 #define T8_GHOST_FACE(g) T8_TREE_FACE (g)
150 
151 /* Given a ghost return its tree_to_face array */
152 #define T8_GHOST_TTF(g) (int8_t *) (T8_GHOST_FACE (g) + t8_eclass_num_faces[(g)->eclass] * sizeof (t8_gloidx_t))
153 
156 typedef struct
157 {
161 
174 void
175 t8_cmesh_trees_init (t8_cmesh_trees_t *ptrees, int num_procs, t8_locidx_t num_trees, t8_locidx_t num_ghosts);
176 
183 t8_cmesh_trees_get_part (const t8_cmesh_trees_t trees, const int proc);
184 
185 /* !!! This does only allocate memory for the trees and ghosts
186  * not yet for the face data and the attributes. See below !!!
187  */
204 void
205 t8_cmesh_trees_start_part (t8_cmesh_trees_t trees, int proc, t8_locidx_t lfirst_tree, t8_locidx_t num_trees,
206  t8_locidx_t lfirst_ghost, t8_locidx_t num_ghosts, int alloc);
207 
223 size_t
225 
233 void
235  t8_locidx_t lnum_ghosts);
236 
246 void
247 t8_cmesh_trees_copy_part (t8_cmesh_trees_t trees_dest, int part_dest, t8_cmesh_trees_t trees_src, int part_src);
248 
256 void
257 t8_cmesh_trees_add_tree (t8_cmesh_trees_t trees, t8_locidx_t ltree_id, int proc, t8_eclass_t eclass);
258 
268 void
269 t8_cmesh_trees_add_ghost (t8_cmesh_trees_t trees, t8_locidx_t lghost_index, t8_gloidx_t gtree_id, int proc,
270  t8_eclass_t eclass, t8_locidx_t num_local_trees);
271 
278 void
280 
281 void
282 t8_cmesh_trees_get_part_data (t8_cmesh_trees_t trees, int proc, t8_locidx_t *first_tree, t8_locidx_t *num_trees,
283  t8_locidx_t *first_ghost, t8_locidx_t *num_ghosts);
284 
285 /* TODO: This function returns NULL if the tree is not present.
286  * So far no error checking is done here. */
294 
306 t8_cmesh_trees_get_tree_ext (t8_cmesh_trees_t trees, t8_locidx_t ltree_id, t8_locidx_t **face_neigh, int8_t **ttf);
307 
316 t8_cmesh_trees_get_face_info (t8_cmesh_trees_t trees, t8_locidx_t ltreeid, int face, int8_t *ttf);
317 
323 t8_cmesh_trees_get_face_neighbor (const t8_ctree_t tree, const int face);
324 
333 t8_cmesh_trees_get_face_neighbor_ext (const t8_ctree_t tree, const int face, int8_t *ttf);
334 
343 t8_cmesh_trees_get_ghost_face_neighbor_ext (const t8_cghost_t ghost, const int face, int8_t *ttf);
344 
345 /* TODO: This function returns NULL if the ghost is not present.
346  * So far no error checking is done here. */
354 
366 t8_cmesh_trees_get_ghost_ext (t8_cmesh_trees_t trees, t8_locidx_t lghost_id, t8_gloidx_t **face_neigh, int8_t **ttf);
367 
379 
380 /* TODO: document.
381  * returns the complete size in bytes needed to store all information */
382 size_t
383 t8_cmesh_trees_size (t8_cmesh_trees_t trees);
384 
394 void
395 t8_cmesh_trees_init_attributes (t8_cmesh_trees_t trees, t8_locidx_t ltree_id, size_t num_attributes, size_t attr_bytes);
396 
410 void *
411 t8_cmesh_trees_get_attribute (const t8_cmesh_trees_t trees, const t8_locidx_t ltree_id, const int package_id,
412  const int key, size_t *size, int is_ghost);
413 
418 size_t
420 
425 size_t
427 
428 /* TODO: Currently there is a bug that forces us to give each tree an attribute */
429 /* TODO: this uses char * and cmesh_set_attribute uses void *. Unify! */
430 /* attr_tree_index is index of attr in tree's attribute array.
431  * We assume that the attributes are already sorted! */
432 void
433 t8_cmesh_trees_add_attribute (t8_cmesh_trees_t trees, int proc, t8_stash_attribute_struct_t *attr, t8_locidx_t tree_id,
434  size_t index);
435 
436 void
437 t8_cmesh_trees_add_ghost_attribute (t8_cmesh_trees_t trees, int proc, t8_stash_attribute_struct_t *attr,
438  t8_locidx_t local_ghost_id, size_t index, size_t *attribute_data_offset);
439 
444 size_t
446 
455 int8_t
456 t8_cmesh_tree_to_face_encode (const int dimension, const t8_locidx_t face, const int orientation);
457 
468 void
469 t8_cmesh_tree_to_face_decode (const int dimension, const int8_t tree_to_face, int *face, int *orientation);
470 
471 /* TODO: To fit to the interface a trees struct is given as parameter here,
472  * however we could just take the one associated to the cmesh given.*/
478 void
480 
492 void
493 t8_cmesh_trees_bcast (t8_cmesh_t cmesh_in, int root, sc_MPI_Comm comm);
494 
503 int
505 
506 int
507 t8_cmesh_trees_is_equal (t8_cmesh_t cmesh, t8_cmesh_trees_t trees_a, t8_cmesh_trees_t trees_b);
508 
514 void
516 
517 T8_EXTERN_C_END ();
518 
519 #endif /* !T8_CMESH_PART_TREE_H */
Definition: t8_cmesh_types.h:157
Definition: t8_cmesh_types.h:230
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
Definition: t8_cmesh_types.h:242
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:157
t8_gloidx_t global_id
The global id.
Definition: t8_cmesh_trees.h:158
t8_locidx_t local_id
The local id.
Definition: t8_cmesh_trees.h:159
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: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.
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
size_t t8_cmesh_trees_get_numproc(const t8_cmesh_trees_t trees)
Return the number of parts of a trees structure.
Definition: t8_cmesh_trees.c:792
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
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
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_part_tree_t t8_cmesh_trees_get_part(const t8_cmesh_trees_t trees, const int proc)
Return one part of a specified tree array.
Definition: t8_cmesh_trees.c:60
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_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_get_attribute(const t8_cmesh_trees_t trees, const t8_locidx_t ltree_id, const int package_id, const 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_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.