Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DLR-AMR
GitHub Repository: DLR-AMR/t8code
Path: blob/main/src/t8_schemes/t8_scheme.h
903 views
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) 2024 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
23
/** \file t8_scheme.h
24
* This file defines the C interface of the t8_scheme class. For more information
25
* refer to the C++ interface in \ref t8_scheme.hxx.
26
*/
27
28
#ifndef T8_SCHEME_H
29
#define T8_SCHEME_H
30
31
#include <t8.h>
32
#include <t8_element.h>
33
34
/** The scheme holds implementations for one or more element classes.
35
* Opaque pointer for C interface.
36
* Detailed documentation at \ref t8_scheme.
37
*/
38
typedef struct t8_scheme t8_scheme_c;
39
40
T8_EXTERN_C_BEGIN ();
41
42
/** Increase the reference counter of a scheme.
43
* \param [in,out] scheme On input, this scheme must be alive, that is,
44
* exist with positive reference count.
45
*/
46
void
47
t8_scheme_ref (t8_scheme_c *scheme);
48
49
/** Decrease the reference counter of a scheme.
50
* If the counter reaches zero, this scheme is destroyed.
51
* \param [in,out] pscheme On input, the scheme pointed to must exist
52
* with positive reference count. If the
53
* reference count reaches zero, the scheme is
54
* destroyed and this pointer set to NULL.
55
* Otherwise, the pointer is not changed and
56
* the scheme is not modified in other ways.
57
*/
58
void
59
t8_scheme_unref (t8_scheme_c **pscheme);
60
61
/** Return the size of any element of a given class.
62
* \return The size of an element of class \b ts.
63
* We provide a default implementation of this routine that should suffice
64
* for most use cases.
65
*/
66
size_t
67
t8_element_get_element_size (const t8_scheme_c *scheme, const t8_eclass_t tree_class);
68
69
/** Returns true, if there is one element in the tree, that does not refine into 2^dim children.
70
* Returns false otherwise.
71
*/
72
int
73
t8_element_refines_irregular (const t8_scheme_c *scheme, const t8_eclass_t tree_class);
74
75
/** Return the maximum allowed level for any element of a given class.
76
* \param [in] scheme The scheme of the forest.
77
* \param [in] tree_class The eclass of tree the elements are part of.
78
* \return The maximum allowed level for elements of class \b ts.
79
*/
80
int
81
t8_element_get_maxlevel (const t8_scheme_c *scheme, const t8_eclass_t tree_class);
82
83
/** Return the level of an element.
84
* \param [in] scheme The scheme of the forest.
85
* \param [in] tree_class The eclass of tree the elements are part of.
86
* \param [in] element The element.
87
* \return The level of \a element.
88
*/
89
int
90
t8_element_get_level (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);
91
92
/** Copy all entries of \b source to \b dest. \b dest must be an existing
93
* element. No memory is allocated by this function.
94
* \param [in] scheme Implementation of a class scheme.
95
* \param [in] tree_class The eclass of the current tree.
96
* \param [in] source The element whose entries will be copied to \b dest.
97
* \param [in,out] dest This element's entries will be overwritten with the
98
* entries of \b source.
99
* \note \a source and \a dest may point to the same element.
100
*/
101
void
102
t8_element_copy (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *source,
103
t8_element_t *dest);
104
105
/** Compare two elements with respect to the scheme.
106
* \param [in] scheme The scheme of the forest.
107
* \param [in] tree_class The eclass of tree the elements are part of.
108
* \param [in] elem1 The first element.
109
* \param [in] elem2 The second element.
110
* \return negative if elem1 < elem2, zero if elem1 equals elem2
111
* and positive if elem1 > elem2.
112
* If elem2 is a copy of elem1 then the elements are equal.
113
*/
114
int
115
t8_element_compare (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *elem1,
116
const t8_element_t *elem2);
117
118
/** Check if two elements are equal.
119
* \param [in] scheme The scheme of the forest.
120
* \param [in] tree_class The eclass of tree the elements are part of.
121
* \param [in] elem1 The first element.
122
* \param [in] elem2 The second element.
123
* \return 1 if the elements are equal, 0 if they are not equal
124
*/
125
int
126
t8_element_is_equal (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *elem1,
127
const t8_element_t *elem2);
128
129
/**
130
* Indicates if an element is refinable. Possible reasons for being not refinable could be
131
* that the element has reached its max level.
132
* \param [in] scheme The scheme of the forest.
133
* \param [in] tree_class The eclass of tree the elements are part of.
134
* \param [in] element The element to check.
135
* \return 1 if the element is refinable, 0 otherwise.
136
*/
137
int
138
element_is_refinable (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);
139
140
/**
141
* Compute the parent of a given element \b element and store it in \b parent.
142
* \b parent needs to be an existing element. No memory is allocated by this function.
143
* \b element and \b parent can point to the same element, then the entries of
144
* \b element are overwritten by the ones of its parent.
145
* \param [in] scheme The scheme of the forest.
146
* \param [in] tree_class The eclass of tree the elements are part of.
147
* \param [in] element The element whose parent will be computed.
148
* \param [in,out] parent This element's entries will be overwritten by those
149
* of \b element's parent.
150
* The storage for this element must exist
151
* and match the element class of the parent.
152
*/
153
void
154
t8_element_get_parent (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
155
t8_element_t *parent);
156
157
/** Compute the number of siblings of an element. That is the number of
158
* Children of its parent.
159
* \param [in] scheme The scheme of the forest.
160
* \param [in] tree_class The eclass of tree the elements are part of.
161
* \param [in] element The element.
162
* \return The number of siblings of \a element.
163
* Note that this number is >= 1, since we count the element itself as a sibling.
164
*/
165
int
166
t8_element_get_num_siblings (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);
167
168
/** Compute a specific sibling of a given element \b element and store it in \b sibling.
169
* \b sibling needs to be an existing element. No memory is allocated by this function.
170
* \b element and \b sibling can point to the same element, then the entries of
171
* \b element are overwritten by the ones of its i-th sibling.
172
* \param [in] scheme The scheme of the forest.
173
* \param [in] tree_class The eclass of tree the elements are part of.
174
* \param [in] elem The element whose sibling will be computed.
175
* \param [in] sibid The id of the sibling computed.
176
* \param [in,out] sibling This element's entries will be overwritten by those
177
* of \b element's sibid-th sibling.
178
* The storage for this element must exist
179
* and match the element class of the sibling.
180
*/
181
void
182
t8_element_get_sibling (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *elem,
183
const int sibid, t8_element_t *sibling);
184
185
/** Compute the number of corners of an element.
186
* \param [in] scheme The scheme of the forest.
187
* \param [in] tree_class The eclass of tree the elements are part of.
188
* \param [in] element The element.
189
* \return The number of corners of \a element.
190
*/
191
int
192
t8_element_get_num_corners (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);
193
194
/** Compute the number of faces of an element.
195
* \param [in] scheme The scheme of the forest.
196
* \param [in] tree_class The eclass of tree the elements are part of.
197
* \param [in] element The element.
198
* \return The number of faces of \a element.
199
*/
200
int
201
t8_element_get_num_faces (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);
202
203
/** Compute the maximum number of faces of a given element and all of its
204
* descendants.
205
* \param [in] scheme The scheme of the forest.
206
* \param [in] tree_class The eclass of tree the elements are part of.
207
* \param [in] element The element.
208
* \return The number of faces of \a element.
209
*/
210
int
211
t8_element_get_max_num_faces (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);
212
213
/** Compute the number of children of an element when it is refined.
214
* \param [in] scheme The scheme of the forest.
215
* \param [in] tree_class The eclass of tree the elements are part of.
216
* \param [in] element The element.
217
* \return The number of children of \a element.
218
*/
219
int
220
t8_element_get_num_children (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);
221
222
/** Return the max number of children of an eclass.
223
* \param [in] scheme The scheme of the forest.
224
* \param [in] tree_class The eclass of tree the elements are part of.
225
* \return The max number of children of \a element.
226
*/
227
int
228
t8_get_max_num_children (const t8_scheme_c *scheme, const t8_eclass_t tree_class);
229
230
/** Compute the number of children of an element's face when the element is refined.
231
* \param [in] scheme The scheme of the forest.
232
* \param [in] tree_class The eclass of tree the elements are part of.
233
* \param [in] element The element.
234
* \param [in] face A face of \a element.
235
* \return The number of children of \a face if \a element is to be refined.
236
*/
237
int
238
t8_element_get_num_face_children (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
239
const int face);
240
241
/** Return the corner number of an element's face corner.
242
* Example quad: 2 x --- x 3
243
* | |
244
* | | face 1
245
* 0 x --- x 1
246
* Thus for face = 1 the output is: corner=0 : 1, corner=1: 3
247
*
248
* \param [in] scheme The scheme of the forest.
249
* \param [in] tree_class The eclass of tree the elements are part of.
250
* \param [in] element The element.
251
* \param [in] face A face index for \a element.
252
* \param [in] corner A corner index for the face 0 <= \a corner < num_face_corners.
253
* \return The corner number of the \a corner-th vertex of \a face.
254
*
255
* The order in which the corners must be given is determined by the eclass of \a element:
256
* LINE/QUAD/TRIANGLE: No specific order.
257
* HEX : In Z-order of the face starting with the lowest corner number.
258
* TET : Starting with the lowest corner number counterclockwise as seen from
259
* 'outside' of the element.
260
*/
261
int
262
t8_element_get_face_corner (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
263
const int face, const int corner);
264
265
/** Compute the face numbers of the faces sharing an element's corner.
266
* Example quad: 2 x --- x 3
267
* | |
268
* | | face 1
269
* 0 x --- x 1
270
* face 2
271
* Thus for corner = 1 the output is: face=0 : 2, face=1: 1
272
* \param [in] scheme The scheme of the forest.
273
* \param [in] tree_class The eclass of tree the elements are part of.
274
* \param [in] element The element.
275
* \param [in] corner A corner index for the face.
276
* \param [in] face A face index for \a corner.
277
* \return The face number of the \a face-th face at \a corner.
278
*/
279
int
280
t8_element_get_corner_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
281
const int corner, const int face);
282
283
/** Construct the child element of a given number.
284
* \param [in] scheme The scheme of the forest.
285
* \param [in] tree_class The eclass of tree the elements are part of.
286
* \param [in] element This must be a valid element, bigger than maxlevel.
287
* \param [in] childid The number of the child to construct.
288
* \param [in,out] child The storage for this element must exist.
289
* On output, a valid element.
290
* It is valid to call this function with element = child.
291
*/
292
void
293
t8_element_get_child (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
294
const int childid, t8_element_t *child);
295
296
/** Construct all children of a given element.
297
* \param [in] scheme The scheme of the forest.
298
* \param [in] tree_class The eclass of tree the elements are part of.
299
* \param [in] element This must be a valid element, bigger than maxlevel.
300
* \param [in] length The length of the output array \a c must match
301
* the number of children.
302
* \param [in,out] c The storage for these \a length elements must exist
303
* and match the element class in the children's ordering.
304
* On output, all children are valid.
305
* It is valid to call this function with element = c[0].
306
* \see t8_element_num_children
307
*/
308
void
309
t8_element_get_children (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
310
const int length, t8_element_t *c[]);
311
312
/** Compute the child id of an element.
313
* \param [in] scheme The scheme of the forest.
314
* \param [in] tree_class The eclass of tree the elements are part of.
315
* \param [in] element This must be a valid element.
316
* \return The child id of element.
317
*/
318
int
319
t8_element_get_child_id (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);
320
321
/** Compute the ancestor id of an element, that is the child id
322
* at a given level.
323
* \param [in] scheme The scheme of the forest.
324
* \param [in] tree_class The eclass of tree the elements are part of.
325
* \param [in] element This must be a valid element.
326
* \param [in] level A refinement level. Must satisfy \a level < element.level
327
* \return The child_id of \a element in regard to its \a level ancestor.
328
*/
329
int
330
t8_element_get_ancestor_id (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
331
const int level);
332
333
/** Query whether a given set of elements is a family or not.
334
* \param [in] scheme The scheme of the forest.
335
* \param [in] tree_class The eclass of tree the elements are part of.
336
* \param [in] fam An array of as many elements as an element of class
337
* \b scheme has children.
338
* \return Zero if \b fam is not a family, nonzero if it is.
339
*/
340
int
341
t8_elements_are_family (const t8_scheme_c *scheme, const t8_eclass_t tree_class, t8_element_t *const *fam);
342
343
/** Compute the nearest common ancestor of two elements. That is,
344
* the element with highest level that still has both given elements as
345
* descendants.
346
* \param [in] scheme The scheme of the forest.
347
* \param [in] tree_class The eclass of tree the elements are part of.
348
* \param [in] elem1 The first of the two input elements.
349
* \param [in] elem2 The second of the two input elements.
350
* \param [in,out] nca The storage for this element must exist
351
* and match the element class of the child.
352
* On output the unique nearest common ancestor of
353
* \b elem1 and \b elem2.
354
*/
355
void
356
t8_element_get_nca (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *elem1,
357
const t8_element_t *elem2, t8_element_t *nca);
358
359
/** Compute the shape of the face of an element.
360
* \param [in] scheme The scheme of the forest.
361
* \param [in] tree_class The eclass of tree the elements are part of.
362
* \param [in] element The element.
363
* \param [in] face A face of \a element.
364
* \return The element shape of the face.
365
* I.e. T8_ECLASS_LINE for quads, T8_ECLASS_TRIANGLE for tets
366
* and depending on the face number either T8_ECLASS_QUAD or
367
* T8_ECLASS_TRIANGLE for prisms.
368
*/
369
t8_element_shape_t
370
t8_element_get_face_shape (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
371
const int face);
372
373
/** Given an element and a face of the element, compute all children of
374
* the element that touch the face.
375
* \param [in] scheme The scheme of the forest.
376
* \param [in] tree_class The eclass of tree the elements are part of.
377
* \param [in] element The element.
378
* \param [in] face A face of \a element.
379
* \param [in,out] children Allocated elements, in which the children of \a element
380
* that share a face with \a face are stored.
381
* They will be stored in order of their linear id.
382
* \param [in] num_children The number of elements in \a children. Must match
383
* the number of children that touch \a face.
384
* \ref t8_scheme::element_get_num_face_children
385
* \param [in,out] child_indices If not NULL, an array of num_children integers must be given,
386
* on output its i-th entry is the child_id of the i-th face_child.
387
* It is valid to call this function with element = children[0].
388
*/
389
void
390
t8_element_get_children_at_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
391
const int face, t8_element_t *children[], const int num_children, int *child_indices);
392
393
/** Given a face of an element and a child number of a child of that face, return the face number
394
* of the child of the element that matches the child face.
395
* \verbatim
396
* x ---- x x x x ---- x
397
* | | | | | | | <-- f
398
* | | | x | x--x
399
* | | | | |
400
* x ---- x x x ---- x
401
* element face face_child Returns the face number f
402
* \endverbatim
403
*
404
* \param [in] scheme The scheme of the forest.
405
* \param [in] tree_class The eclass of tree the elements are part of.
406
* \param [in] element The element.
407
* \param [in] face Then number of the face.
408
* \param [in] face_child A number 0 <= \a face_child < num_face_children,
409
* specifying a child of \a element that shares a face with \a face.
410
* These children are counted in linear order. This coincides with
411
* the order of children from a call to \ref t8_scheme::element_get_children_at_face.
412
* \return The face number of the face of a child of \a element
413
* that coincides with \a face_child.
414
*/
415
int
416
t8_element_face_get_child_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
417
const int face, const int face_child);
418
419
/** Given a face of an element return the face number
420
* of the parent of the element that matches the element's face. Or return -1 if
421
* no face of the parent matches the face.
422
*
423
* \param [in] scheme The scheme of the forest.
424
* \param [in] tree_class The eclass of tree the elements are part of.
425
* \param [in] element The element.
426
* \param [in] face Then number of the face.
427
* \return If \a face of \a element is also a face of \a element's parent,
428
* the face number of this face. Otherwise -1.
429
* \note For the root element this function always returns \a face.
430
*/
431
int
432
t8_element_face_get_parent_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
433
const int face);
434
435
/** Given an element and a face of this element. If the face lies on the
436
* tree boundary, return the face number of the tree face.
437
* If not the return value is arbitrary.
438
* \param [in] scheme The scheme of the forest.
439
* \param [in] tree_class The eclass of tree the elements are part of.
440
* \param [in] element The element.
441
* \param [in] face The index of a face of \a element.
442
* \return The index of the tree face that \a face is a subface of, if
443
* \a face is on a tree boundary.
444
* Any arbitrary integer if \a is not at a tree boundary.
445
*/
446
int
447
t8_element_get_tree_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
448
const int face);
449
450
/** Suppose we have two trees that share a common face f.
451
* Given an element e that is a subface of f in one of the trees
452
* and given the orientation of the tree connection, construct the face
453
* element of the respective tree neighbor that logically coincides with e
454
* but lies in the coordinate system of the neighbor tree.
455
* \param [in] scheme The scheme of the forest.
456
* \param [in] tree_class The eclass of tree the elements are part of.
457
* \param [in] elem1 The face element.
458
* \param [in,out] elem2 On return the face element \a elem1 with respect
459
* to the coordinate system of the other tree.
460
* \param [in] orientation The orientation of the tree-tree connection.
461
* \see t8_cmesh_set_join
462
* \param [in] sign Depending on the topological orientation of the two tree faces,
463
* either 0 (both faces have opposite orientation)
464
* or 1 (both faces have the same top. orientation).
465
* \ref t8_eclass_face_orientation
466
* \param [in] is_smaller_face Flag to declare whether \a elem1 belongs to
467
* the smaller face. A face f of tree T is smaller than
468
* f' of T' if either the eclass of T is smaller or if
469
* the classes are equal and f<f'. The orientation is
470
* defined in relation to the smaller face.
471
* \note \a elem1 and \a elem2 may point to the same element.
472
*/
473
void
474
t8_element_transform_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *elem1,
475
t8_element_t *elem2, const int orientation, const int sign, const int is_smaller_face);
476
477
/** Given a boundary face inside a root tree's face construct
478
* the element inside the root tree that has the given face as a
479
* face.
480
* \param [in] scheme The scheme of the forest.
481
* \param [in] tree_class The eclass of tree the elements are part of.
482
* \param [in] face A face element.
483
* \param [in,out] element An allocated element. The entries will be filled with
484
* the data of the element that has \a face as a face and
485
* lies within the root tree.
486
* \param [in] root_face The index of the face of the root tree in which \a face
487
* lies.
488
* \return The face number of the face of \a element that coincides
489
* with \a face.
490
*/
491
int
492
t8_element_extrude_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *face,
493
t8_element_t *element, int root_face);
494
495
/** Construct the boundary element at a specific face.
496
* \param [in] scheme The scheme of the forest.
497
* \param [in] tree_class The eclass of tree the elements are part of.
498
* \param [in] element The input element.
499
* \param [in] face The index of the face of which to construct the
500
* boundary element.
501
* \param [in,out] boundary An allocated element of dimension of \a element
502
* minus 1. The entries will be filled with the entries
503
* of the face of \a element.
504
* If \a element is of class T8_ECLASS_VERTEX, then \a boundary must be NULL
505
* and will not be modified.
506
*/
507
void
508
t8_element_get_boundary_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
509
const int face, t8_element_t *boundary);
510
511
/** Construct the first descendant of an element at a given level that touches a given face.
512
* \param [in] scheme The scheme of the forest.
513
* \param [in] tree_class The eclass of tree the elements are part of.
514
* \param [in] element The input element.
515
* \param [in] face A face of \a element.
516
* \param [in, out] first_desc An allocated element. This element's data will be
517
* filled with the data of the first descendant of \a element
518
* that shares a face with \a face.
519
* \param [in] level The level, at which the first descendant is constructed
520
*/
521
void
522
t8_element_get_first_descendant_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class,
523
const t8_element_t *element, const int face, t8_element_t *first_desc,
524
const int level);
525
526
/** Construct the last descendant of an element at a given level that touches a given face.
527
* \param [in] scheme The scheme of the forest.
528
* \param [in] tree_class The eclass of tree the elements are part of.
529
* \param [in] element The input element.
530
* \param [in] face A face of \a element.
531
* \param [in, out] last_desc An allocated element. This element's data will be
532
* filled with the data of the last descendant of \a element
533
* that shares a face with \a face.
534
* \param [in] level The level, at which the last descendant is constructed
535
*/
536
void
537
t8_element_get_last_descendant_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class,
538
const t8_element_t *element, const int face, t8_element_t *last_desc,
539
const int level);
540
541
/** Compute whether a given element shares a given face with its root tree.
542
* \param [in] scheme The scheme of the forest.
543
* \param [in] tree_class The eclass of tree the elements are part of.
544
* \param [in] element The input element.
545
* \param [in] face A face of \a element.
546
* \return True if \a face is a subface of the element's root element.
547
*/
548
int
549
t8_element_is_root_boundary (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
550
const int face);
551
552
/** Construct the face neighbor of a given element if this face neighbor
553
* is inside the root tree. Return 0 otherwise.
554
* \param [in] scheme The scheme of the forest.
555
* \param [in] tree_class The eclass of tree the elements are part of.
556
* \param [in] element The element to be considered.
557
* \param [in,out] neigh If the face neighbor of \a element along \a face is inside
558
* the root tree, this element's data is filled with the
559
* data of the face neighbor. Otherwise the data can be modified
560
* arbitrarily.
561
* \param [in] face The number of the face along which the neighbor should be
562
* constructed.
563
* \param [out] neigh_face The number of \a face as viewed from \a neigh.
564
* An arbitrary value, if the neighbor is not inside the root tree.
565
* \return True if \a neigh is inside the root tree.
566
* False if not. In this case \a neigh's data can be arbitrary
567
* on output.
568
*/
569
int
570
t8_element_get_face_neighbor_inside (const t8_scheme_c *scheme, const t8_eclass_t tree_class,
571
const t8_element_t *element, t8_element_t *neigh, const int face, int *neigh_face);
572
573
/** Return the shape of an allocated element according its type.
574
* For example, a child of an element can be an element of a different shape
575
* and has to be handled differently - according to its shape.
576
* \param [in] scheme The scheme of the forest.
577
* \param [in] tree_class The eclass of tree the elements are part of.
578
* \param [in] element The element to be considered
579
* \return The shape of the element as an eclass
580
*/
581
t8_element_shape_t
582
t8_element_get_shape (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);
583
584
/** Initialize the entries of an allocated element according to a
585
* given linear id in a uniform refinement.
586
* \param [in] scheme The scheme of the forest.
587
* \param [in] tree_class The eclass of tree the elements are part of.
588
* \param [in,out] element The element whose entries will be set.
589
* \param [in] level The level of the uniform refinement to consider.
590
* \param [in] id The linear id.
591
* id must fulfil 0 <= id < 'number of leaves in the uniform refinement'
592
*/
593
void
594
t8_element_set_linear_id (const t8_scheme_c *scheme, const t8_eclass_t tree_class, t8_element_t *element,
595
const int level, const t8_linearidx_t id);
596
597
/** Compute the linear id of a given element in a hypothetical uniform
598
* refinement of a given level.
599
* \param [in] scheme The scheme of the forest.
600
* \param [in] tree_class The eclass of tree the elements are part of.
601
* \param [in] element The element whose id we compute.
602
* \param [in] level The level of the uniform refinement to consider.
603
* \return The linear id of the element.
604
*/
605
t8_linearidx_t
606
t8_element_get_linear_id (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
607
const int level);
608
609
/** Compute the first descendant of a given element.
610
* \param [in] scheme The scheme of the forest.
611
* \param [in] tree_class The eclass of tree the elements are part of.
612
* \param [in] element The element whose descendant is computed.
613
* \param [out] desc The first element in a uniform refinement of \a element
614
* at level \a level.
615
* \param [in] level The uniform refinement level at which the descendant is computed.
616
* \a level must be greater or equal to the level of \a element.
617
*/
618
void
619
t8_element_get_first_descendant (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
620
t8_element_t *desc, const int level);
621
622
/** Compute the last descendant of a given element.
623
* \param [in] scheme The scheme of the forest.
624
* \param [in] tree_class The eclass of tree the elements are part of.
625
* \param [in] element The element whose descendant is computed.
626
* \param [out] desc The last element in a uniform refinement of \a element
627
* of the maximum possible level.
628
* \param [in] level The uniform refinement level at which the descendant is computed.
629
* \a level must be greater or equal to the level of \a element.
630
*/
631
void
632
t8_element_get_last_descendant (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
633
t8_element_t *desc, const int level);
634
635
/** Construct the successor in a uniform refinement of a given element.
636
* \param [in] scheme The scheme of the forest.
637
* \param [in] tree_class The eclass of tree the elements are part of.
638
* \param [in] elem1 The element whose successor should be constructed.
639
* \param [in,out] elem2 The element whose entries will be set.
640
*/
641
void
642
t8_element_get_successor (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *elem1,
643
t8_element_t *elem2);
644
645
/** Compute the coordinates of a given element vertex inside a reference tree
646
* that is embedded into [0,1]^d (d = dimension).
647
* \param [in] scheme The scheme of the forest.
648
* \param [in] tree_class The eclass of tree the elements are part of.
649
* \param [in] element The element to be considered.
650
* \param [in] vertex The id of the vertex whose coordinates shall be computed.
651
* \param [out] coords An array of at least as many doubles as the element's dimension
652
* whose entries will be filled with the coordinates of \a vertex.
653
* \warning coords should be zero-initialized, as only the first d coords will be set, but when used elsewhere
654
* all coords might be used.
655
*/
656
void
657
t8_element_get_vertex_reference_coords (const t8_scheme_c *scheme, const t8_eclass_t tree_class,
658
const t8_element_t *element, const int vertex, double coords[]);
659
660
/** Convert points in the reference space of an element to points in the
661
* reference space of the tree.
662
* \param [in] scheme The scheme of the forest.
663
* \param [in] tree_class The eclass of the current tree.
664
* \param [in] element The element.
665
* \param [in] ref_coords The coordinates \f$ [0,1]^\mathrm{dim} \f$ of the point
666
* in the reference space of the element.
667
* \param [in] num_coords Number of \f$ dim\f$-sized coordinates to evaluate.
668
* \param [out] out_coords The coordinates of the points in the
669
* reference space of the tree.
670
*/
671
void
672
t8_element_get_reference_coords (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
673
const double *ref_coords, const size_t num_coords, double out_coords[]);
674
675
/** Count how many leaf descendants of a given uniform level an element would produce.
676
* \param [in] scheme The scheme of the forest.
677
* \param [in] tree_class The eclass of tree the elements are part of.
678
* \param [in] element The element to be checked.
679
* \param [in] level A refinement level.
680
* \return Suppose \a element is uniformly refined up to level \a level. The return value
681
* is the resulting number of elements (of the given level).
682
* If \a level < t8_element_get_level(element), the return value should be 0.
683
*
684
* Example: If \a element is a line element that refines into 2 line elements on each level,
685
* then the return value is max(0, 2^{\a level - level(\a t)}).
686
* Thus, if \a element's level is 0, and \a level = 3, the return value is 2^3 = 8.
687
*/
688
t8_gloidx_t
689
t8_element_count_leaves (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
690
const int level);
691
692
/** Count how many leaf descendants of a given uniform level the root element will produce.
693
* \param [in] scheme The scheme of the forest.
694
* \param [in] tree_class The eclass of tree the elements are part of.
695
* \param [in] level A refinement level.
696
* \return The value of \ref t8_element_count_leaves if the input element
697
* is the root (level 0) element.
698
*
699
* This is a convenience function, and can be implemented via
700
* \ref t8_element_count_leaves.
701
*/
702
t8_gloidx_t
703
t8_element_count_leaves_from_root (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const int level);
704
705
#if T8_ENABLE_DEBUG
706
/** Query whether a given element can be considered as 'valid' and it is
707
* safe to perform any of the above algorithms on it.
708
* For example this could mean that all coordinates are in valid ranges
709
* and other membervariables do have meaningful values.
710
* \param [in] scheme The scheme of the forest.
711
* \param [in] tree_class The eclass of tree the elements are part of.
712
* \param [in] element The element to be checked.
713
* \return True if \a element is safe to use. False otherwise.
714
* \note An element that is constructed with \ref t8_element_new
715
* must pass this test.
716
* \note An element for which \ref t8_scheme::element_init was called must pass
717
* this test.
718
* \note This function is used for debugging to catch certain errors.
719
* These can for example occur when an element points to a region
720
* of memory which should not be interpreted as an element.
721
* \note We recommend to use the assertion T8_ASSERT (t8_element_is_valid (element))
722
* in the implementation of each of the functions in this file.
723
*/
724
int
725
t8_element_is_valid (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);
726
727
/**
728
* Print a given element. For a example for a triangle print the coordinates
729
* and the level of the triangle. This function is only available in the
730
* debugging configuration.
731
*
732
* \param [in] scheme The scheme of the forest.
733
* \param [in] tree_class The eclass of tree the elements are part of.
734
* \param [in] element The element to print
735
*/
736
void
737
t8_element_debug_print (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);
738
739
#endif
740
/**
741
* \brief Fill a string with readable information about the element
742
*
743
* \param [in] scheme The scheme of the forest.
744
* \param [in] tree_class The eclass of the current tree.
745
* \param[in] element The element to translate into human-readable information.
746
* \param[in, out] debug_string The string to fill.
747
* \param[in] string_size The length of \a debug_string.
748
*/
749
void
750
t8_element_to_string (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,
751
char *debug_string, const int string_size);
752
753
/** Allocate memory for an array of elements of a given class and initialize them.
754
* \param [in] scheme The scheme of the forest.
755
* \param [in] tree_class The eclass of tree the elements are part of.
756
* \param [in] length The number of elements to be allocated.
757
* \param [in,out] elems On input an array of \b length many unallocated element pointers.
758
* On output all these pointers will point to an allocated and initialized element.
759
* \note Not every element that is created in t8code will be created by a call
760
* to this function. However, if an element is not created using \ref t8_element_new,
761
* then it is guaranteed that \ref t8_scheme::element_init is called on it.
762
* \note In debugging mode, an element that was created with \ref t8_element_new
763
* must pass \ref t8_element_is_valid.
764
* \note If an element was created by \ref t8_element_new then \ref t8_scheme::element_init
765
* may not be called for it. Thus, \ref t8_element_new should initialize an element
766
* in the same way as a call to \ref t8_scheme::element_init would.
767
* \see t8_element_init
768
* \see element_is_valid
769
*/
770
void
771
t8_element_new (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const int length, t8_element_t **elems);
772
773
/** Initialize an array of allocated elements.
774
* \param [in] scheme The scheme to use.
775
* \param [in] tree_class The eclass of the current tree.
776
* \param [in] length The number of elements to be initialized.
777
* \param [in,out] elem On input an array of \a length many allocated
778
* elements.
779
* \note In debugging mode, an element that was passed to \ref t8_element_init
780
* must pass \ref t8_element_is_valid.
781
* \note If an element was created by \ref t8_element_new then \ref t8_element_init
782
* may not be called for it. Thus, \ref t8_element_init should initialize an element
783
* in the same way as a call to \ref t8_element_new would.
784
* \note Every call to \see t8_element_init must be matched by a call to \see t8_element_deinit
785
* \see t8_element_deinit
786
* \see t8_element_new
787
* \see t8_element_is_valid
788
*/
789
void
790
t8_element_init (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const int length, t8_element_t *elem);
791
792
/** Deinitialize an array of allocated elements.
793
* \param [in] scheme The scheme to use.
794
* \param [in] tree_class The eclass of the current tree.
795
* \param [in] length The number of elements to be deinitialized.
796
* \param [in,out] elems On input an array of \a length many allocated
797
* and initialized elements, on output an array of
798
* \a length many allocated, but not initialized elements.
799
* \note Call this function if you called \ref t8_element_init on the element pointers.
800
* \see t8_element_init
801
*/
802
void
803
t8_element_deinit (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const int length, t8_element_t *elems);
804
805
/** Deallocate an array of elements.
806
* \param [in] scheme The scheme of the forest.
807
* \param [in] tree_class The eclass of tree the elements are part of.
808
* \param [in] length The number of elements in the array.
809
* \param [in,out] elems On input an array of \b length many allocated element pointers. On output all these pointers
810
* will be freed. \b element itself will not be freed by this function.
811
*/
812
void
813
t8_element_destroy (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const int length, t8_element_t **elems);
814
815
/** Fills an element with the root element.
816
* \param [in] scheme The scheme of the forest.
817
* \param [in] tree_class The eclass of tree the elements are part of.
818
* \param [in,out] element The element to be filled with root.
819
*/
820
void
821
t8_element_set_to_root (const t8_scheme_c *scheme, const t8_eclass_t tree_class, t8_element_t *element);
822
823
/** Pack multiple elements into contiguous memory, so they can be sent via MPI.
824
* \param [in] scheme The scheme of the forest.
825
* \param [in] tree_class The eclass of tree the elements are part of.
826
* \param [in] elements Array of elements that are to be packed
827
* \param [in] count Number of elements to pack
828
* \param [in,out] send_buffer Buffer in which to pack the elements
829
* \param [in] buffer_size size of the buffer (in order to check that we don't access out of range)
830
* \param [in, out] position the position of the first byte that is not already packed
831
* \param [in] comm MPI Communicator
832
*/
833
void
834
t8_element_MPI_Pack (const t8_scheme_c *scheme, const t8_eclass_t tree_class, t8_element_t **const elements,
835
const unsigned int count, void *send_buffer, const int buffer_size, int *position,
836
sc_MPI_Comm comm);
837
838
/** Determine an upper bound for the size of the packed message of \b count elements
839
* \param [in] scheme The scheme of the forest.
840
* \param [in] tree_class The eclass of tree the elements are part of.
841
* \param [in] count Number of elements to pack
842
* \param [in] comm MPI Communicator
843
* \param [out] pack_size upper bound on the message size
844
*/
845
void
846
t8_element_MPI_Pack_size (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const unsigned int count,
847
sc_MPI_Comm comm, int *pack_size);
848
849
/** Unpack multiple elements from contiguous memory that was received via MPI.
850
* \param [in] scheme The scheme of the forest.
851
* \param [in] tree_class The eclass of tree the elements are part of.
852
* \param [in] recvbuf Buffer from which to unpack the elements
853
* \param [in] buffer_size size of the buffer (in order to check that we don't access out of range)
854
* \param [in, out] position the position of the first byte that is not already packed
855
* \param [in] elements Array of initialised elements that is to be filled from the message
856
* \param [in] count Number of elements to unpack
857
* \param [in] comm MPI Communicator
858
*/
859
void
860
t8_element_MPI_Unpack (const t8_scheme_c *scheme, const t8_eclass_t tree_class, void *recvbuf, const int buffer_size,
861
int *position, t8_element_t **elements, const unsigned int count, sc_MPI_Comm comm);
862
863
T8_EXTERN_C_END ();
864
865
#endif /* !T8_SCHEME_H */
866
867