Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DLR-AMR
GitHub Repository: DLR-AMR/t8code
Path: blob/main/src/t8_cmesh/t8_cmesh_internal/t8_cmesh_stash.h
921 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) 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
23
/** \file t8_cmesh_stash.h
24
* We define the data structures and routines for temporary storage before commit
25
*/
26
27
#ifndef T8_CMESH_STASH_H
28
#define T8_CMESH_STASH_H
29
30
#include <t8.h>
31
#include <t8_eclass.h>
32
33
/**
34
* Opaque pointer to a stash data structure.
35
*/
36
typedef struct t8_stash *t8_stash_t;
37
38
/* TODO: could store class information in an offset array instead of
39
* for each single tree. Especially for non-hybrid meshes this
40
* would massively reduce our memory footprint */
41
42
/** The eclass information that is stored before a cmesh is committed.
43
*/
44
typedef struct t8_stash_class
45
{
46
t8_gloidx_t id; /**< The global tree id */
47
t8_eclass_t eclass; /**< The eclass of that tree */
48
} t8_stash_class_struct_t;
49
50
/** The face-connection information that is stored before a cmesh is committed.
51
*/
52
typedef struct t8_stash_joinface
53
{
54
t8_gloidx_t id1; /**< The global tree id of the first tree in the connection. */
55
t8_gloidx_t id2; /**< The global tree id of the second tree. We ensure id1<=id2. */
56
int face1; /**< The face number of the first of the connected faces. */
57
int face2; /**< The face number of the second face. */
58
int orientation; /**< The orientation of the face connection. \see t8_cmesh_types.h. */
59
} t8_stash_joinface_struct_t;
60
61
/** The attribute information that is stored before a cmesh is committed.
62
* The pair (package_id, key) serves as a lookup key to identify the
63
* data.
64
*/
65
typedef struct t8_stash_attribute
66
{
67
t8_gloidx_t id; /**< The global tree id */
68
size_t attr_size; /**< The size (in bytes) of this attribute */
69
void *attr_data; /**< Array of \a size bytes storing the attributes data. */
70
int is_owned; /**< True if the data was copied, false if the data is still owned by user. */
71
int package_id; /**< The id of the package that set this attribute. */
72
int key; /**< The key used by the package to identify this attribute. */
73
} t8_stash_attribute_struct_t;
74
75
/** The stash data structure is used to store information about the cmesh
76
* before it is committed. In particular we store the eclasses of the trees,
77
* the face-connections and the tree attributes.
78
* Using the stash structure allows us to have a very flexible interface. When constructing a new mesh, the
79
* user can specify all these mesh entities in arbitrary order.
80
* As soon as the cmesh is committed the information is copied from the stash
81
* to the cmesh in an order mannered.
82
*/
83
typedef struct t8_stash
84
{
85
sc_array_t classes; /**< Stores the eclasses of the trees. \see t8_stash_class */
86
sc_array_t joinfaces; /**< Stores the face-connections. \see t8_stash_joinface */
87
sc_array_t attributes; /**< Stores the attributes. \see t8_stash_attribute */
88
} t8_stash_struct_t;
89
90
T8_EXTERN_C_BEGIN ();
91
92
/** Initialize a stash data structure.
93
* \param [in,out] pstash A pointer to the stash to be initialized.
94
*/
95
void
96
t8_stash_init (t8_stash_t *pstash);
97
98
/** Free all memory associated in a stash structure.
99
* \param [in,out] pstash A pointer to the stash to be destroyed.
100
* The pointer is set to NULL after the function call.
101
*/
102
void
103
t8_stash_destroy (t8_stash_t *pstash);
104
105
/** Set the eclass of a tree.
106
* \param [in, out] stash The stash to be updated.
107
* \param [in] id The global id of the tree whose eclass should be set.
108
* \param [in] eclass The eclass of tree with id \a id.
109
*/
110
void
111
t8_stash_add_class (t8_stash_t stash, t8_gloidx_t id, t8_eclass_t eclass);
112
113
/** Add a face connection to a stash.
114
* \param [in, out] stash The stash to be updated.
115
* \param [in] gid1 The global id of the first tree.
116
* \param [in] gid2 The global id of the second tree,
117
* \param [in] face1 The face number of the face of the first tree.
118
* \param [in] face2 The face number of the face of the second tree.
119
* \param [in] orientation The orientation of the faces to each other.
120
*/
121
void
122
t8_stash_add_facejoin (t8_stash_t stash, t8_gloidx_t gid1, t8_gloidx_t gid2, int face1, int face2, int orientation);
123
124
/** Sort the entries in the class array by the order given in
125
* the enum definition of t8_eclass.
126
* \param [in,out] stash The stash whose class array is sorted.
127
*/
128
void
129
t8_stash_class_sort (t8_stash_t stash);
130
131
/** Search for an entry with a given tree index in the class-stash.
132
* The stash must be sorted beforehand.
133
* \param [in] stash The stash to be searched for.
134
* \param [in] tree_id The global tree id.
135
* \return The index of an element in the classes array
136
* of \a stash corresponding to \a tree_id.
137
* -1 if not found.
138
*/
139
ssize_t
140
t8_stash_class_bsearch (t8_stash_t stash, t8_gloidx_t tree_id);
141
142
/** Sort then entries in the facejoin array in order of the first treeid.
143
* \param [in,out] stash The stash whose facejoin array is sorted.
144
*/
145
void
146
t8_stash_joinface_sort (t8_stash_t stash);
147
148
/** Add an attribute to a tree.
149
* \param [in] stash The stash structure to be modified.
150
* \param [in] id The global index of the tree to which the attribute is added.
151
* \param [in] package_id The unique id of the current package.
152
* \param [in] key An integer value used to identify this attribute.
153
* \param [in] size The size (in bytes) of the attribute.
154
* \param [in] attr Points to \a size bytes of memory that should be stored as the attribute.
155
* \param [in] copy If true the attribute data is copied from \a attr to an internal storage.
156
* If false only the pointer \a attr is stored and the data is only copied
157
* if the cmesh is committed. (More memory efficient).
158
*/
159
void
160
t8_stash_add_attribute (t8_stash_t stash, t8_gloidx_t id, int package_id, int key, size_t size, void *const attr,
161
int copy);
162
163
/** Return the size (in bytes) of an attribute in the stash.
164
* \param [in] stash The stash to be considered.
165
* \param [in] index The index of the attribute in the attribute array of \a stash.
166
* \return The size in bytes of the attribute.
167
*/
168
size_t
169
t8_stash_get_attribute_size (t8_stash_t stash, size_t index);
170
171
/** Return the pointer to an attribute in the stash.
172
* \param [in] stash The stash to be considered.
173
* \param [in] index The index of the attribute in the attribute array of \a stash.
174
* \return A void pointer to the memory region where the attribute is stored.
175
*/
176
void *
177
t8_stash_get_attribute (t8_stash_t stash, size_t index);
178
179
/** Return the id of the tree a given attribute belongs to.
180
* \param [in] stash The stash to be considered.
181
* \param [in] index The index of the attribute in the attribute array of \a stash.
182
* \return The tree id.
183
*/
184
t8_gloidx_t
185
t8_stash_get_attribute_tree_id (t8_stash_t stash, size_t index);
186
187
/** Return the key of a given attribute.
188
* \param [in] stash The stash to be considered.
189
* \param [in] index The index of the attribute in the attribute array of \a stash.
190
* \return The attribute's key.
191
*/
192
int
193
t8_stash_get_attribute_key (t8_stash_t stash, size_t index);
194
195
/** Return the package_id of a given attribute.
196
* \param [in] stash The stash to be considered.
197
* \param [in] index The index of the attribute in the attribute array of \a stash.
198
* \return The attribute's package_id.
199
*/
200
int
201
t8_stash_get_attribute_id (t8_stash_t stash, size_t index);
202
203
/** Return true if an attribute in the stash is owned by the stash, that is,
204
* it was copied in the call to \a t8_stash_add_attribute.
205
* Returns false if the attribute is not owned by the stash.
206
* \param [in] stash The stash to be considered.
207
* \param [in] index The index of the attribute in the attribute array of \a stash.
208
* \return True of false.
209
*/
210
int
211
t8_stash_attribute_is_owned (t8_stash_t stash, size_t index);
212
213
/** Sort the attributes array of a stash in the order
214
* (treeid, packageid, key) *
215
* \param [in,out] stash The stash to be considered.
216
*/
217
void
218
t8_stash_attribute_sort (t8_stash_t stash);
219
220
/** Broadcast a stash on the root process to all processes in a communicator.
221
* The number of entries in the classes, joinfaces and attributes arrays must
222
* be known on the receiving processes before calling this function.
223
* \param [in,out] stash On root the stash that is to be broadcasted.
224
* On the other process an initialized stash. Its entries will
225
* get overwritten by the entries in the root stash.
226
* \param [in] root The mpirank of the root process.
227
* \param [in] comm The mpi communicator which is used for broadcast.
228
* \param [in] elem_counts An array with three entries giving the number of
229
* elements in the classes, joinfaces and attributes arrays.
230
*/
231
t8_stash_t
232
t8_stash_bcast (t8_stash_t stash, int root, sc_MPI_Comm comm, const size_t elem_counts[3]);
233
234
/* TODO: specify equivalence relation. is a different order of data allowed? */
235
/** Check two stashes for equal content and return true if so.
236
* \param [in] stash_a The first stash to be considered.
237
* \param [in] stash_b The first stash to be considered.
238
* \return True if both stashes hold copies of the same data.
239
* False otherwise.
240
*/
241
int
242
t8_stash_is_equal (t8_stash_t stash_a, t8_stash_t stash_b);
243
244
T8_EXTERN_C_END ();
245
246
#endif /* !T8_CMESH_STASH_H */
247
248