/*1This file is part of t8code.2t8code is a C library to manage a collection (a forest) of multiple3connected adaptive space-trees of general element classes in parallel.45Copyright (C) 2024 the developers67t8code is free software; you can redistribute it and/or modify8it under the terms of the GNU General Public License as published by9the Free Software Foundation; either version 2 of the License, or10(at your option) any later version.1112t8code is distributed in the hope that it will be useful,13but WITHOUT ANY WARRANTY; without even the implied warranty of14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15GNU General Public License for more details.1617You should have received a copy of the GNU General Public License18along with t8code; if not, write to the Free Software Foundation, Inc.,1951 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.20*/2122/** \file t8_scheme.h23* This file defines the C interface of the t8_scheme class. For more information24* refer to the C++ interface in \ref t8_scheme.hxx.25*/2627#ifndef T8_SCHEME_H28#define T8_SCHEME_H2930#include <t8.h>31#include <t8_element.h>3233/** The scheme holds implementations for one or more element classes.34* Opaque pointer for C interface.35* Detailed documentation at \ref t8_scheme.36*/37typedef struct t8_scheme t8_scheme_c;3839T8_EXTERN_C_BEGIN ();4041/** Increase the reference counter of a scheme.42* \param [in,out] scheme On input, this scheme must be alive, that is,43* exist with positive reference count.44*/45void46t8_scheme_ref (t8_scheme_c *scheme);4748/** Decrease the reference counter of a scheme.49* If the counter reaches zero, this scheme is destroyed.50* \param [in,out] pscheme On input, the scheme pointed to must exist51* with positive reference count. If the52* reference count reaches zero, the scheme is53* destroyed and this pointer set to NULL.54* Otherwise, the pointer is not changed and55* the scheme is not modified in other ways.56*/57void58t8_scheme_unref (t8_scheme_c **pscheme);5960/** Return the size of any element of a given class.61* \return The size of an element of class \b ts.62* We provide a default implementation of this routine that should suffice63* for most use cases.64*/65size_t66t8_element_get_element_size (const t8_scheme_c *scheme, const t8_eclass_t tree_class);6768/** Returns true, if there is one element in the tree, that does not refine into 2^dim children.69* Returns false otherwise.70*/71int72t8_element_refines_irregular (const t8_scheme_c *scheme, const t8_eclass_t tree_class);7374/** Return the maximum allowed level for any element of a given class.75* \param [in] scheme The scheme of the forest.76* \param [in] tree_class The eclass of tree the elements are part of.77* \return The maximum allowed level for elements of class \b ts.78*/79int80t8_element_get_maxlevel (const t8_scheme_c *scheme, const t8_eclass_t tree_class);8182/** Return the level of an element.83* \param [in] scheme The scheme of the forest.84* \param [in] tree_class The eclass of tree the elements are part of.85* \param [in] element The element.86* \return The level of \a element.87*/88int89t8_element_get_level (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);9091/** Copy all entries of \b source to \b dest. \b dest must be an existing92* element. No memory is allocated by this function.93* \param [in] scheme Implementation of a class scheme.94* \param [in] tree_class The eclass of the current tree.95* \param [in] source The element whose entries will be copied to \b dest.96* \param [in,out] dest This element's entries will be overwritten with the97* entries of \b source.98* \note \a source and \a dest may point to the same element.99*/100void101t8_element_copy (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *source,102t8_element_t *dest);103104/** Compare two elements with respect to the scheme.105* \param [in] scheme The scheme of the forest.106* \param [in] tree_class The eclass of tree the elements are part of.107* \param [in] elem1 The first element.108* \param [in] elem2 The second element.109* \return negative if elem1 < elem2, zero if elem1 equals elem2110* and positive if elem1 > elem2.111* If elem2 is a copy of elem1 then the elements are equal.112*/113int114t8_element_compare (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *elem1,115const t8_element_t *elem2);116117/** Check if two elements are equal.118* \param [in] scheme The scheme of the forest.119* \param [in] tree_class The eclass of tree the elements are part of.120* \param [in] elem1 The first element.121* \param [in] elem2 The second element.122* \return 1 if the elements are equal, 0 if they are not equal123*/124int125t8_element_is_equal (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *elem1,126const t8_element_t *elem2);127128/**129* Indicates if an element is refinable. Possible reasons for being not refinable could be130* that the element has reached its max level.131* \param [in] scheme The scheme of the forest.132* \param [in] tree_class The eclass of tree the elements are part of.133* \param [in] element The element to check.134* \return 1 if the element is refinable, 0 otherwise.135*/136int137element_is_refinable (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);138139/**140* Compute the parent of a given element \b element and store it in \b parent.141* \b parent needs to be an existing element. No memory is allocated by this function.142* \b element and \b parent can point to the same element, then the entries of143* \b element are overwritten by the ones of its parent.144* \param [in] scheme The scheme of the forest.145* \param [in] tree_class The eclass of tree the elements are part of.146* \param [in] element The element whose parent will be computed.147* \param [in,out] parent This element's entries will be overwritten by those148* of \b element's parent.149* The storage for this element must exist150* and match the element class of the parent.151*/152void153t8_element_get_parent (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,154t8_element_t *parent);155156/** Compute the number of siblings of an element. That is the number of157* Children of its parent.158* \param [in] scheme The scheme of the forest.159* \param [in] tree_class The eclass of tree the elements are part of.160* \param [in] element The element.161* \return The number of siblings of \a element.162* Note that this number is >= 1, since we count the element itself as a sibling.163*/164int165t8_element_get_num_siblings (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);166167/** Compute a specific sibling of a given element \b element and store it in \b sibling.168* \b sibling needs to be an existing element. No memory is allocated by this function.169* \b element and \b sibling can point to the same element, then the entries of170* \b element are overwritten by the ones of its i-th sibling.171* \param [in] scheme The scheme of the forest.172* \param [in] tree_class The eclass of tree the elements are part of.173* \param [in] elem The element whose sibling will be computed.174* \param [in] sibid The id of the sibling computed.175* \param [in,out] sibling This element's entries will be overwritten by those176* of \b element's sibid-th sibling.177* The storage for this element must exist178* and match the element class of the sibling.179*/180void181t8_element_get_sibling (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *elem,182const int sibid, t8_element_t *sibling);183184/** Compute the number of corners of an element.185* \param [in] scheme The scheme of the forest.186* \param [in] tree_class The eclass of tree the elements are part of.187* \param [in] element The element.188* \return The number of corners of \a element.189*/190int191t8_element_get_num_corners (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);192193/** Compute the number of faces of an element.194* \param [in] scheme The scheme of the forest.195* \param [in] tree_class The eclass of tree the elements are part of.196* \param [in] element The element.197* \return The number of faces of \a element.198*/199int200t8_element_get_num_faces (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);201202/** Compute the maximum number of faces of a given element and all of its203* descendants.204* \param [in] scheme The scheme of the forest.205* \param [in] tree_class The eclass of tree the elements are part of.206* \param [in] element The element.207* \return The number of faces of \a element.208*/209int210t8_element_get_max_num_faces (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);211212/** Compute the number of children of an element when it is refined.213* \param [in] scheme The scheme of the forest.214* \param [in] tree_class The eclass of tree the elements are part of.215* \param [in] element The element.216* \return The number of children of \a element.217*/218int219t8_element_get_num_children (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);220221/** Return the max number of children of an eclass.222* \param [in] scheme The scheme of the forest.223* \param [in] tree_class The eclass of tree the elements are part of.224* \return The max number of children of \a element.225*/226int227t8_get_max_num_children (const t8_scheme_c *scheme, const t8_eclass_t tree_class);228229/** Compute the number of children of an element's face when the element is refined.230* \param [in] scheme The scheme of the forest.231* \param [in] tree_class The eclass of tree the elements are part of.232* \param [in] element The element.233* \param [in] face A face of \a element.234* \return The number of children of \a face if \a element is to be refined.235*/236int237t8_element_get_num_face_children (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,238const int face);239240/** Return the corner number of an element's face corner.241* Example quad: 2 x --- x 3242* | |243* | | face 1244* 0 x --- x 1245* Thus for face = 1 the output is: corner=0 : 1, corner=1: 3246*247* \param [in] scheme The scheme of the forest.248* \param [in] tree_class The eclass of tree the elements are part of.249* \param [in] element The element.250* \param [in] face A face index for \a element.251* \param [in] corner A corner index for the face 0 <= \a corner < num_face_corners.252* \return The corner number of the \a corner-th vertex of \a face.253*254* The order in which the corners must be given is determined by the eclass of \a element:255* LINE/QUAD/TRIANGLE: No specific order.256* HEX : In Z-order of the face starting with the lowest corner number.257* TET : Starting with the lowest corner number counterclockwise as seen from258* 'outside' of the element.259*/260int261t8_element_get_face_corner (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,262const int face, const int corner);263264/** Compute the face numbers of the faces sharing an element's corner.265* Example quad: 2 x --- x 3266* | |267* | | face 1268* 0 x --- x 1269* face 2270* Thus for corner = 1 the output is: face=0 : 2, face=1: 1271* \param [in] scheme The scheme of the forest.272* \param [in] tree_class The eclass of tree the elements are part of.273* \param [in] element The element.274* \param [in] corner A corner index for the face.275* \param [in] face A face index for \a corner.276* \return The face number of the \a face-th face at \a corner.277*/278int279t8_element_get_corner_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,280const int corner, const int face);281282/** Construct the child element of a given number.283* \param [in] scheme The scheme of the forest.284* \param [in] tree_class The eclass of tree the elements are part of.285* \param [in] element This must be a valid element, bigger than maxlevel.286* \param [in] childid The number of the child to construct.287* \param [in,out] child The storage for this element must exist.288* On output, a valid element.289* It is valid to call this function with element = child.290*/291void292t8_element_get_child (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,293const int childid, t8_element_t *child);294295/** Construct all children of a given element.296* \param [in] scheme The scheme of the forest.297* \param [in] tree_class The eclass of tree the elements are part of.298* \param [in] element This must be a valid element, bigger than maxlevel.299* \param [in] length The length of the output array \a c must match300* the number of children.301* \param [in,out] c The storage for these \a length elements must exist302* and match the element class in the children's ordering.303* On output, all children are valid.304* It is valid to call this function with element = c[0].305* \see t8_element_num_children306*/307void308t8_element_get_children (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,309const int length, t8_element_t *c[]);310311/** Compute the child id of an element.312* \param [in] scheme The scheme of the forest.313* \param [in] tree_class The eclass of tree the elements are part of.314* \param [in] element This must be a valid element.315* \return The child id of element.316*/317int318t8_element_get_child_id (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);319320/** Compute the ancestor id of an element, that is the child id321* at a given level.322* \param [in] scheme The scheme of the forest.323* \param [in] tree_class The eclass of tree the elements are part of.324* \param [in] element This must be a valid element.325* \param [in] level A refinement level. Must satisfy \a level < element.level326* \return The child_id of \a element in regard to its \a level ancestor.327*/328int329t8_element_get_ancestor_id (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,330const int level);331332/** Query whether a given set of elements is a family or not.333* \param [in] scheme The scheme of the forest.334* \param [in] tree_class The eclass of tree the elements are part of.335* \param [in] fam An array of as many elements as an element of class336* \b scheme has children.337* \return Zero if \b fam is not a family, nonzero if it is.338*/339int340t8_elements_are_family (const t8_scheme_c *scheme, const t8_eclass_t tree_class, t8_element_t *const *fam);341342/** Compute the nearest common ancestor of two elements. That is,343* the element with highest level that still has both given elements as344* descendants.345* \param [in] scheme The scheme of the forest.346* \param [in] tree_class The eclass of tree the elements are part of.347* \param [in] elem1 The first of the two input elements.348* \param [in] elem2 The second of the two input elements.349* \param [in,out] nca The storage for this element must exist350* and match the element class of the child.351* On output the unique nearest common ancestor of352* \b elem1 and \b elem2.353*/354void355t8_element_get_nca (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *elem1,356const t8_element_t *elem2, t8_element_t *nca);357358/** Compute the shape of the face of an element.359* \param [in] scheme The scheme of the forest.360* \param [in] tree_class The eclass of tree the elements are part of.361* \param [in] element The element.362* \param [in] face A face of \a element.363* \return The element shape of the face.364* I.e. T8_ECLASS_LINE for quads, T8_ECLASS_TRIANGLE for tets365* and depending on the face number either T8_ECLASS_QUAD or366* T8_ECLASS_TRIANGLE for prisms.367*/368t8_element_shape_t369t8_element_get_face_shape (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,370const int face);371372/** Given an element and a face of the element, compute all children of373* the element that touch the face.374* \param [in] scheme The scheme of the forest.375* \param [in] tree_class The eclass of tree the elements are part of.376* \param [in] element The element.377* \param [in] face A face of \a element.378* \param [in,out] children Allocated elements, in which the children of \a element379* that share a face with \a face are stored.380* They will be stored in order of their linear id.381* \param [in] num_children The number of elements in \a children. Must match382* the number of children that touch \a face.383* \ref t8_scheme::element_get_num_face_children384* \param [in,out] child_indices If not NULL, an array of num_children integers must be given,385* on output its i-th entry is the child_id of the i-th face_child.386* It is valid to call this function with element = children[0].387*/388void389t8_element_get_children_at_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,390const int face, t8_element_t *children[], const int num_children, int *child_indices);391392/** Given a face of an element and a child number of a child of that face, return the face number393* of the child of the element that matches the child face.394* \verbatim395* x ---- x x x x ---- x396* | | | | | | | <-- f397* | | | x | x--x398* | | | | |399* x ---- x x x ---- x400* element face face_child Returns the face number f401* \endverbatim402*403* \param [in] scheme The scheme of the forest.404* \param [in] tree_class The eclass of tree the elements are part of.405* \param [in] element The element.406* \param [in] face Then number of the face.407* \param [in] face_child A number 0 <= \a face_child < num_face_children,408* specifying a child of \a element that shares a face with \a face.409* These children are counted in linear order. This coincides with410* the order of children from a call to \ref t8_scheme::element_get_children_at_face.411* \return The face number of the face of a child of \a element412* that coincides with \a face_child.413*/414int415t8_element_face_get_child_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,416const int face, const int face_child);417418/** Given a face of an element return the face number419* of the parent of the element that matches the element's face. Or return -1 if420* no face of the parent matches the face.421*422* \param [in] scheme The scheme of the forest.423* \param [in] tree_class The eclass of tree the elements are part of.424* \param [in] element The element.425* \param [in] face Then number of the face.426* \return If \a face of \a element is also a face of \a element's parent,427* the face number of this face. Otherwise -1.428* \note For the root element this function always returns \a face.429*/430int431t8_element_face_get_parent_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,432const int face);433434/** Given an element and a face of this element. If the face lies on the435* tree boundary, return the face number of the tree face.436* If not the return value is arbitrary.437* \param [in] scheme The scheme of the forest.438* \param [in] tree_class The eclass of tree the elements are part of.439* \param [in] element The element.440* \param [in] face The index of a face of \a element.441* \return The index of the tree face that \a face is a subface of, if442* \a face is on a tree boundary.443* Any arbitrary integer if \a is not at a tree boundary.444*/445int446t8_element_get_tree_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,447const int face);448449/** Suppose we have two trees that share a common face f.450* Given an element e that is a subface of f in one of the trees451* and given the orientation of the tree connection, construct the face452* element of the respective tree neighbor that logically coincides with e453* but lies in the coordinate system of the neighbor tree.454* \param [in] scheme The scheme of the forest.455* \param [in] tree_class The eclass of tree the elements are part of.456* \param [in] elem1 The face element.457* \param [in,out] elem2 On return the face element \a elem1 with respect458* to the coordinate system of the other tree.459* \param [in] orientation The orientation of the tree-tree connection.460* \see t8_cmesh_set_join461* \param [in] sign Depending on the topological orientation of the two tree faces,462* either 0 (both faces have opposite orientation)463* or 1 (both faces have the same top. orientation).464* \ref t8_eclass_face_orientation465* \param [in] is_smaller_face Flag to declare whether \a elem1 belongs to466* the smaller face. A face f of tree T is smaller than467* f' of T' if either the eclass of T is smaller or if468* the classes are equal and f<f'. The orientation is469* defined in relation to the smaller face.470* \note \a elem1 and \a elem2 may point to the same element.471*/472void473t8_element_transform_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *elem1,474t8_element_t *elem2, const int orientation, const int sign, const int is_smaller_face);475476/** Given a boundary face inside a root tree's face construct477* the element inside the root tree that has the given face as a478* face.479* \param [in] scheme The scheme of the forest.480* \param [in] tree_class The eclass of tree the elements are part of.481* \param [in] face A face element.482* \param [in,out] element An allocated element. The entries will be filled with483* the data of the element that has \a face as a face and484* lies within the root tree.485* \param [in] root_face The index of the face of the root tree in which \a face486* lies.487* \return The face number of the face of \a element that coincides488* with \a face.489*/490int491t8_element_extrude_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *face,492t8_element_t *element, int root_face);493494/** Construct the boundary element at a specific face.495* \param [in] scheme The scheme of the forest.496* \param [in] tree_class The eclass of tree the elements are part of.497* \param [in] element The input element.498* \param [in] face The index of the face of which to construct the499* boundary element.500* \param [in,out] boundary An allocated element of dimension of \a element501* minus 1. The entries will be filled with the entries502* of the face of \a element.503* If \a element is of class T8_ECLASS_VERTEX, then \a boundary must be NULL504* and will not be modified.505*/506void507t8_element_get_boundary_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,508const int face, t8_element_t *boundary);509510/** Construct the first descendant of an element at a given level that touches a given face.511* \param [in] scheme The scheme of the forest.512* \param [in] tree_class The eclass of tree the elements are part of.513* \param [in] element The input element.514* \param [in] face A face of \a element.515* \param [in, out] first_desc An allocated element. This element's data will be516* filled with the data of the first descendant of \a element517* that shares a face with \a face.518* \param [in] level The level, at which the first descendant is constructed519*/520void521t8_element_get_first_descendant_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class,522const t8_element_t *element, const int face, t8_element_t *first_desc,523const int level);524525/** Construct the last descendant of an element at a given level that touches a given face.526* \param [in] scheme The scheme of the forest.527* \param [in] tree_class The eclass of tree the elements are part of.528* \param [in] element The input element.529* \param [in] face A face of \a element.530* \param [in, out] last_desc An allocated element. This element's data will be531* filled with the data of the last descendant of \a element532* that shares a face with \a face.533* \param [in] level The level, at which the last descendant is constructed534*/535void536t8_element_get_last_descendant_face (const t8_scheme_c *scheme, const t8_eclass_t tree_class,537const t8_element_t *element, const int face, t8_element_t *last_desc,538const int level);539540/** Compute whether a given element shares a given face with its root tree.541* \param [in] scheme The scheme of the forest.542* \param [in] tree_class The eclass of tree the elements are part of.543* \param [in] element The input element.544* \param [in] face A face of \a element.545* \return True if \a face is a subface of the element's root element.546*/547int548t8_element_is_root_boundary (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,549const int face);550551/** Construct the face neighbor of a given element if this face neighbor552* is inside the root tree. Return 0 otherwise.553* \param [in] scheme The scheme of the forest.554* \param [in] tree_class The eclass of tree the elements are part of.555* \param [in] element The element to be considered.556* \param [in,out] neigh If the face neighbor of \a element along \a face is inside557* the root tree, this element's data is filled with the558* data of the face neighbor. Otherwise the data can be modified559* arbitrarily.560* \param [in] face The number of the face along which the neighbor should be561* constructed.562* \param [out] neigh_face The number of \a face as viewed from \a neigh.563* An arbitrary value, if the neighbor is not inside the root tree.564* \return True if \a neigh is inside the root tree.565* False if not. In this case \a neigh's data can be arbitrary566* on output.567*/568int569t8_element_get_face_neighbor_inside (const t8_scheme_c *scheme, const t8_eclass_t tree_class,570const t8_element_t *element, t8_element_t *neigh, const int face, int *neigh_face);571572/** Return the shape of an allocated element according its type.573* For example, a child of an element can be an element of a different shape574* and has to be handled differently - according to its shape.575* \param [in] scheme The scheme of the forest.576* \param [in] tree_class The eclass of tree the elements are part of.577* \param [in] element The element to be considered578* \return The shape of the element as an eclass579*/580t8_element_shape_t581t8_element_get_shape (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);582583/** Initialize the entries of an allocated element according to a584* given linear id in a uniform refinement.585* \param [in] scheme The scheme of the forest.586* \param [in] tree_class The eclass of tree the elements are part of.587* \param [in,out] element The element whose entries will be set.588* \param [in] level The level of the uniform refinement to consider.589* \param [in] id The linear id.590* id must fulfil 0 <= id < 'number of leaves in the uniform refinement'591*/592void593t8_element_set_linear_id (const t8_scheme_c *scheme, const t8_eclass_t tree_class, t8_element_t *element,594const int level, const t8_linearidx_t id);595596/** Compute the linear id of a given element in a hypothetical uniform597* refinement of a given level.598* \param [in] scheme The scheme of the forest.599* \param [in] tree_class The eclass of tree the elements are part of.600* \param [in] element The element whose id we compute.601* \param [in] level The level of the uniform refinement to consider.602* \return The linear id of the element.603*/604t8_linearidx_t605t8_element_get_linear_id (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,606const int level);607608/** Compute the first descendant of a given element.609* \param [in] scheme The scheme of the forest.610* \param [in] tree_class The eclass of tree the elements are part of.611* \param [in] element The element whose descendant is computed.612* \param [out] desc The first element in a uniform refinement of \a element613* at level \a level.614* \param [in] level The uniform refinement level at which the descendant is computed.615* \a level must be greater or equal to the level of \a element.616*/617void618t8_element_get_first_descendant (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,619t8_element_t *desc, const int level);620621/** Compute the last descendant of a given element.622* \param [in] scheme The scheme of the forest.623* \param [in] tree_class The eclass of tree the elements are part of.624* \param [in] element The element whose descendant is computed.625* \param [out] desc The last element in a uniform refinement of \a element626* of the maximum possible level.627* \param [in] level The uniform refinement level at which the descendant is computed.628* \a level must be greater or equal to the level of \a element.629*/630void631t8_element_get_last_descendant (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,632t8_element_t *desc, const int level);633634/** Construct the successor in a uniform refinement of a given element.635* \param [in] scheme The scheme of the forest.636* \param [in] tree_class The eclass of tree the elements are part of.637* \param [in] elem1 The element whose successor should be constructed.638* \param [in,out] elem2 The element whose entries will be set.639*/640void641t8_element_get_successor (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *elem1,642t8_element_t *elem2);643644/** Compute the coordinates of a given element vertex inside a reference tree645* that is embedded into [0,1]^d (d = dimension).646* \param [in] scheme The scheme of the forest.647* \param [in] tree_class The eclass of tree the elements are part of.648* \param [in] element The element to be considered.649* \param [in] vertex The id of the vertex whose coordinates shall be computed.650* \param [out] coords An array of at least as many doubles as the element's dimension651* whose entries will be filled with the coordinates of \a vertex.652* \warning coords should be zero-initialized, as only the first d coords will be set, but when used elsewhere653* all coords might be used.654*/655void656t8_element_get_vertex_reference_coords (const t8_scheme_c *scheme, const t8_eclass_t tree_class,657const t8_element_t *element, const int vertex, double coords[]);658659/** Convert points in the reference space of an element to points in the660* reference space of the tree.661* \param [in] scheme The scheme of the forest.662* \param [in] tree_class The eclass of the current tree.663* \param [in] element The element.664* \param [in] ref_coords The coordinates \f$ [0,1]^\mathrm{dim} \f$ of the point665* in the reference space of the element.666* \param [in] num_coords Number of \f$ dim\f$-sized coordinates to evaluate.667* \param [out] out_coords The coordinates of the points in the668* reference space of the tree.669*/670void671t8_element_get_reference_coords (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,672const double *ref_coords, const size_t num_coords, double out_coords[]);673674/** Count how many leaf descendants of a given uniform level an element would produce.675* \param [in] scheme The scheme of the forest.676* \param [in] tree_class The eclass of tree the elements are part of.677* \param [in] element The element to be checked.678* \param [in] level A refinement level.679* \return Suppose \a element is uniformly refined up to level \a level. The return value680* is the resulting number of elements (of the given level).681* If \a level < t8_element_get_level(element), the return value should be 0.682*683* Example: If \a element is a line element that refines into 2 line elements on each level,684* then the return value is max(0, 2^{\a level - level(\a t)}).685* Thus, if \a element's level is 0, and \a level = 3, the return value is 2^3 = 8.686*/687t8_gloidx_t688t8_element_count_leaves (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,689const int level);690691/** Count how many leaf descendants of a given uniform level the root element will produce.692* \param [in] scheme The scheme of the forest.693* \param [in] tree_class The eclass of tree the elements are part of.694* \param [in] level A refinement level.695* \return The value of \ref t8_element_count_leaves if the input element696* is the root (level 0) element.697*698* This is a convenience function, and can be implemented via699* \ref t8_element_count_leaves.700*/701t8_gloidx_t702t8_element_count_leaves_from_root (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const int level);703704#if T8_ENABLE_DEBUG705/** Query whether a given element can be considered as 'valid' and it is706* safe to perform any of the above algorithms on it.707* For example this could mean that all coordinates are in valid ranges708* and other membervariables do have meaningful values.709* \param [in] scheme The scheme of the forest.710* \param [in] tree_class The eclass of tree the elements are part of.711* \param [in] element The element to be checked.712* \return True if \a element is safe to use. False otherwise.713* \note An element that is constructed with \ref t8_element_new714* must pass this test.715* \note An element for which \ref t8_scheme::element_init was called must pass716* this test.717* \note This function is used for debugging to catch certain errors.718* These can for example occur when an element points to a region719* of memory which should not be interpreted as an element.720* \note We recommend to use the assertion T8_ASSERT (t8_element_is_valid (element))721* in the implementation of each of the functions in this file.722*/723int724t8_element_is_valid (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);725726/**727* Print a given element. For a example for a triangle print the coordinates728* and the level of the triangle. This function is only available in the729* debugging configuration.730*731* \param [in] scheme The scheme of the forest.732* \param [in] tree_class The eclass of tree the elements are part of.733* \param [in] element The element to print734*/735void736t8_element_debug_print (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element);737738#endif739/**740* \brief Fill a string with readable information about the element741*742* \param [in] scheme The scheme of the forest.743* \param [in] tree_class The eclass of the current tree.744* \param[in] element The element to translate into human-readable information.745* \param[in, out] debug_string The string to fill.746* \param[in] string_size The length of \a debug_string.747*/748void749t8_element_to_string (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const t8_element_t *element,750char *debug_string, const int string_size);751752/** Allocate memory for an array of elements of a given class and initialize them.753* \param [in] scheme The scheme of the forest.754* \param [in] tree_class The eclass of tree the elements are part of.755* \param [in] length The number of elements to be allocated.756* \param [in,out] elems On input an array of \b length many unallocated element pointers.757* On output all these pointers will point to an allocated and initialized element.758* \note Not every element that is created in t8code will be created by a call759* to this function. However, if an element is not created using \ref t8_element_new,760* then it is guaranteed that \ref t8_scheme::element_init is called on it.761* \note In debugging mode, an element that was created with \ref t8_element_new762* must pass \ref t8_element_is_valid.763* \note If an element was created by \ref t8_element_new then \ref t8_scheme::element_init764* may not be called for it. Thus, \ref t8_element_new should initialize an element765* in the same way as a call to \ref t8_scheme::element_init would.766* \see t8_element_init767* \see element_is_valid768*/769void770t8_element_new (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const int length, t8_element_t **elems);771772/** Initialize an array of allocated elements.773* \param [in] scheme The scheme to use.774* \param [in] tree_class The eclass of the current tree.775* \param [in] length The number of elements to be initialized.776* \param [in,out] elem On input an array of \a length many allocated777* elements.778* \note In debugging mode, an element that was passed to \ref t8_element_init779* must pass \ref t8_element_is_valid.780* \note If an element was created by \ref t8_element_new then \ref t8_element_init781* may not be called for it. Thus, \ref t8_element_init should initialize an element782* in the same way as a call to \ref t8_element_new would.783* \note Every call to \see t8_element_init must be matched by a call to \see t8_element_deinit784* \see t8_element_deinit785* \see t8_element_new786* \see t8_element_is_valid787*/788void789t8_element_init (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const int length, t8_element_t *elem);790791/** Deinitialize an array of allocated elements.792* \param [in] scheme The scheme to use.793* \param [in] tree_class The eclass of the current tree.794* \param [in] length The number of elements to be deinitialized.795* \param [in,out] elems On input an array of \a length many allocated796* and initialized elements, on output an array of797* \a length many allocated, but not initialized elements.798* \note Call this function if you called \ref t8_element_init on the element pointers.799* \see t8_element_init800*/801void802t8_element_deinit (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const int length, t8_element_t *elems);803804/** Deallocate an array of elements.805* \param [in] scheme The scheme of the forest.806* \param [in] tree_class The eclass of tree the elements are part of.807* \param [in] length The number of elements in the array.808* \param [in,out] elems On input an array of \b length many allocated element pointers. On output all these pointers809* will be freed. \b element itself will not be freed by this function.810*/811void812t8_element_destroy (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const int length, t8_element_t **elems);813814/** Fills an element with the root element.815* \param [in] scheme The scheme of the forest.816* \param [in] tree_class The eclass of tree the elements are part of.817* \param [in,out] element The element to be filled with root.818*/819void820t8_element_set_to_root (const t8_scheme_c *scheme, const t8_eclass_t tree_class, t8_element_t *element);821822/** Pack multiple elements into contiguous memory, so they can be sent via MPI.823* \param [in] scheme The scheme of the forest.824* \param [in] tree_class The eclass of tree the elements are part of.825* \param [in] elements Array of elements that are to be packed826* \param [in] count Number of elements to pack827* \param [in,out] send_buffer Buffer in which to pack the elements828* \param [in] buffer_size size of the buffer (in order to check that we don't access out of range)829* \param [in, out] position the position of the first byte that is not already packed830* \param [in] comm MPI Communicator831*/832void833t8_element_MPI_Pack (const t8_scheme_c *scheme, const t8_eclass_t tree_class, t8_element_t **const elements,834const unsigned int count, void *send_buffer, const int buffer_size, int *position,835sc_MPI_Comm comm);836837/** Determine an upper bound for the size of the packed message of \b count elements838* \param [in] scheme The scheme of the forest.839* \param [in] tree_class The eclass of tree the elements are part of.840* \param [in] count Number of elements to pack841* \param [in] comm MPI Communicator842* \param [out] pack_size upper bound on the message size843*/844void845t8_element_MPI_Pack_size (const t8_scheme_c *scheme, const t8_eclass_t tree_class, const unsigned int count,846sc_MPI_Comm comm, int *pack_size);847848/** Unpack multiple elements from contiguous memory that was received via MPI.849* \param [in] scheme The scheme of the forest.850* \param [in] tree_class The eclass of tree the elements are part of.851* \param [in] recvbuf Buffer from which to unpack the elements852* \param [in] buffer_size size of the buffer (in order to check that we don't access out of range)853* \param [in, out] position the position of the first byte that is not already packed854* \param [in] elements Array of initialised elements that is to be filled from the message855* \param [in] count Number of elements to unpack856* \param [in] comm MPI Communicator857*/858void859t8_element_MPI_Unpack (const t8_scheme_c *scheme, const t8_eclass_t tree_class, void *recvbuf, const int buffer_size,860int *position, t8_element_t **elements, const unsigned int count, sc_MPI_Comm comm);861862T8_EXTERN_C_END ();863864#endif /* !T8_SCHEME_H */865866867