t8  UNKNOWN
t8code is a C library to manage a forest of adaptive space-trees of general element classes in parallel.
t8_cmesh.h
Go to the documentation of this file.
1 /*
2  This file is part of t8code.
3  t8code is a C library to manage a collection (a forest) of multiple
4  connected adaptive space-trees of general element classes in parallel.
5 
6  Copyright (C) 2015 the developers
7 
8  t8code is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  t8code is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with t8code; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22 
27 #ifndef T8_CMESH_H
28 #define T8_CMESH_H
29 
30 #include <t8.h>
31 #include <t8_data/t8_shmem.h>
32 #include <t8_cmesh/t8_cmesh_save.h>
33 #include <t8_element.h>
34 
35 /* Forward pointer reference to hidden cmesh implementation.
36  * This reference needs to be known by t8_geometry, hence we
37  * put it before the include. */
38 typedef struct t8_cmesh *t8_cmesh_t;
39 
41 
42 /* TODO: If including eclass were just for the cmesh_new routines, we should
43  * move them into a different file.
44  * However, when specifying the parent-child order in cmesh_reorder,
45  * we might keep the eclass interface for virtual functions.
46  * Actually, we need eclass in the type definition in cmesh.c.
47  * So we might as well use tree-related virtual functions there too.
48  */
49 #include <t8_eclass.h>
50 
51 /* TODO: make it legal to call cmesh_set functions multiple times,
52  * just overwrite the previous setting if no inconsistency can occur.
53  * edit: This should be achieved now.
54  */
55 
56 /* Forward pointer references to hidden implementations of
57  * tree and ghost tree. */
58 typedef struct t8_ctree *t8_ctree_t;
59 typedef struct t8_cghost *t8_cghost_t;
60 
61 T8_EXTERN_C_BEGIN ();
62 
69 void
70 t8_cmesh_init (t8_cmesh_t *pcmesh);
71 
80 int
82 
91 int
93 
94 #ifdef T8_ENABLE_DEBUG
103 int
105 #endif
106 
120 /* TODO: write a test for this function */
121 int
122 t8_cmesh_tree_vertices_negative_volume (t8_eclass_t eclass, double *vertices, int num_vertices);
123 
124 /* TODO: Currently it is not possible to destroy set_from before
125  * cmesh is destroyed. */
139 void
140 t8_cmesh_set_derive (t8_cmesh_t cmesh, t8_cmesh_t set_from);
141 
151 t8_cmesh_alloc_offsets (int mpisize, sc_MPI_Comm comm);
152 
183 void
184 t8_cmesh_set_partition_range (t8_cmesh_t cmesh, int set_face_knowledge, t8_gloidx_t first_local_tree,
185  t8_gloidx_t last_local_tree);
186 
198 void
200 
211 void
212 t8_cmesh_set_partition_uniform (t8_cmesh_t cmesh, int element_level, t8_scheme_cxx_t *ts);
213 
217 /* If level = 0 then no refinement is performed */
218 void
219 t8_cmesh_set_refine (t8_cmesh_t cmesh, int level, t8_scheme_cxx_t *scheme);
220 
230 void
231 t8_cmesh_set_dimension (t8_cmesh_t cmesh, int dim);
232 
240 void
241 t8_cmesh_set_tree_class (t8_cmesh_t cmesh, t8_gloidx_t gtree_id, t8_eclass_t tree_class);
242 
266 void
267 t8_cmesh_set_attribute (t8_cmesh_t cmesh, t8_gloidx_t gtree_id, int package_id, int key, void *data, size_t data_size,
268  int data_persists);
269 
281 void
282 t8_cmesh_set_attribute_string (t8_cmesh_t cmesh, t8_gloidx_t gtree_id, int package_id, int key, const char *string);
283 
295 void
296 t8_cmesh_set_join (t8_cmesh_t cmesh, t8_gloidx_t gtree1, t8_gloidx_t gtree2, int face1, int face2, int orientation);
297 
308 void
309 t8_cmesh_set_profiling (t8_cmesh_t cmesh, int set_profiling);
310 
311 /* returns true if cmesh_a equals cmesh_b */
312 /* TODO: document
313  * collective or serial */
323 int
324 t8_cmesh_is_equal (t8_cmesh_t cmesh_a, t8_cmesh_t cmesh_b);
325 
330 int
332 
352 t8_cmesh_bcast (t8_cmesh_t cmesh_in, int root, sc_MPI_Comm comm);
353 
354 #ifdef T8_WITH_METIS
355 /* TODO: document this. */
356 /* TODO: think about making this a pre-commit set_reorder function. */
357 void
358 t8_cmesh_reorder (t8_cmesh_t cmesh, sc_MPI_Comm comm);
359 
360 /* TODO: think about a sensible interface for a parmetis reordering. */
361 #endif
362 
363 /* TODO: comment */
364 /* If no geometry is registered and cmesh is modified from another cmesh then
365  * the other cmesh's geometries are used.
366  * \note If you need to use \ref t8_cmesh_bcast, then all geometries must be
367  * registered \a after the bcast operation, not before.
368  */
369 void
370 t8_cmesh_register_geometry (t8_cmesh_t cmesh, const t8_geometry_c *geometry);
371 
378 void
379 t8_cmesh_set_tree_geometry (t8_cmesh_t cmesh, t8_gloidx_t gtreeid, const char *geom_name);
380 
387 void
388 t8_cmesh_commit (t8_cmesh_t cmesh, sc_MPI_Comm comm);
389 
390 /* TODO: Document */
391 /* Currently, it is only legal to save cmeshes that use the linear geometry. */
392 int
393 t8_cmesh_save (t8_cmesh_t cmesh, const char *fileprefix);
394 
395 /* TODO: Document */
397 t8_cmesh_load (const char *filename, sc_MPI_Comm comm);
398 
399 /* TODO: Document */
400 /* procs_per_node is only relevant in mode==JUQUEEN.
401  * num_files = 1 => replicated cmesh is constructed */
403 t8_cmesh_load_and_distribute (const char *fileprefix, int num_files, sc_MPI_Comm comm, t8_load_mode_t mode,
404  int procs_per_node);
405 
415 int
416 t8_cmesh_comm_is_valid (t8_cmesh_t cmesh, sc_MPI_Comm comm);
417 
424 int
426 
434 
443 
452 
461 
462 /* TODO: Comment */
463 const t8_geometry_c *
464 t8_cmesh_get_tree_geometry (t8_cmesh_t cmesh, t8_gloidx_t gtreeid);
465 
473 int
474 t8_cmesh_treeid_is_local_tree (const t8_cmesh_t cmesh, const t8_locidx_t ltreeid);
475 
483 int
484 t8_cmesh_treeid_is_ghost (const t8_cmesh_t cmesh, const t8_locidx_t ltreeid);
485 
495 t8_cmesh_ltreeid_to_ghostid (const t8_cmesh_t cmesh, const t8_locidx_t ltreeid);
496 
497 /* TODO: Replace this iterator with a new one that does not need the
498  * treeid to be part of the ctree struct */
499 /* TODO: should this and the next function be part of the interface? */
508 
509 /* TODO: should this function behave like first_tree if tree argument is NULL? */
521 
532 t8_cmesh_get_tree (t8_cmesh_t cmesh, t8_locidx_t ltree_id);
533 
544 
553 int
554 t8_cmesh_tree_face_is_boundary (t8_cmesh_t cmesh, t8_locidx_t ltree_id, int face);
555 
566 
577 
591 t8_cmesh_get_local_id (t8_cmesh_t cmesh, t8_gloidx_t global_id);
592 
608 t8_cmesh_get_face_neighbor (const t8_cmesh_t cmesh, const t8_locidx_t ltreeid, const int face, int *dual_face,
609  int *orientation);
610 
617 void
619 
626 double *
628 
640 void *
641 t8_cmesh_get_attribute (t8_cmesh_t cmesh, int package_id, int key, t8_locidx_t ltree_id);
642 
653 
654 /* TODO: remove get_ when there is no risk of confusion? Convention?
655  * Update: use get throughout for access functions that do not change the object.
656  * */
657 
671 void
672 t8_cmesh_uniform_bounds (t8_cmesh_t cmesh, int level, t8_scheme_cxx_t *ts, t8_gloidx_t *first_local_tree,
673  t8_gloidx_t *child_in_tree_begin, t8_gloidx_t *last_local_tree, t8_gloidx_t *child_in_tree_end,
674  int8_t *first_tree_shared);
675 
680 void
681 t8_cmesh_ref (t8_cmesh_t cmesh);
682 
695 void
696 t8_cmesh_unref (t8_cmesh_t *pcmesh);
697 
706 void
707 t8_cmesh_destroy (t8_cmesh_t *pcmesh);
708 
709 /* Functions for constructing complete and committed cmeshes */
710 
712 t8_cmesh_new_testhybrid (sc_MPI_Comm comm);
713 
722 void
723 t8_cmesh_coords_axb (const double *coords_in, double *coords_out, int num_vertices, double alpha, const double b[3]);
724 
732 void
733 t8_cmesh_translate_coordinates (const double *coords_in, double *coords_out, int num_vertices, double translate[3]);
734 
736 void
737 t8_cmesh_new_translate_vertices_to_attributes (const t8_locidx_t *tvertices, const double *vertices,
738  double *attr_vertices, const int num_vertices);
739 
748 void
749 t8_cmesh_debug_print_trees (const t8_cmesh_t cmesh, sc_MPI_Comm comm);
750 T8_EXTERN_C_END ();
751 
752 #endif /* !T8_CMESH_H */
Definition: t8_cmesh_types.h:161
t8_eclass_t eclass
The eclass of this ghost.
Definition: t8_cmesh_types.h:163
This structure holds the connectivity data of the coarse mesh.
Definition: t8_cmesh_types.h:88
This structure holds the data of a local tree including the information about face neighbors.
Definition: t8_cmesh_types.h:193
Definition: t8_geometry_base.hxx:37
The scheme holds implementations for one or more element classes.
Definition: t8_element.h:51
Shared memory array structure.
Definition: t8_shmem.c:35
This is the administrative header file for t8code.
int64_t t8_gloidx_t
A type for global indexing that holds really big numbers.
Definition: t8.h:98
int32_t t8_locidx_t
A type for processor-local indexing.
Definition: t8.h:87
t8_locidx_t t8_cmesh_get_local_id(t8_cmesh_t cmesh, t8_gloidx_t global_id)
Return the local id of a give global tree.
Definition: t8_cmesh.c:1010
void t8_cmesh_init(t8_cmesh_t *pcmesh)
Create a new cmesh with reference count one.
Definition: t8_cmesh.c:142
void t8_cmesh_set_attribute_string(t8_cmesh_t cmesh, t8_gloidx_t gtree_id, int package_id, int key, const char *string)
Store a string as an attribute at a tree in a cmesh.
Definition: t8_cmesh.c:364
void t8_cmesh_set_profiling(t8_cmesh_t cmesh, int set_profiling)
Enable or disable profiling for a cmesh.
Definition: t8_cmesh.c:590
int t8_cmesh_treeid_is_ghost(const t8_cmesh_t cmesh, const t8_locidx_t ltreeid)
Query whether a given t8_locidx_t belongs to a ghost of a cmesh.
Definition: t8_cmesh.c:298
t8_ctree_t t8_cmesh_get_tree(t8_cmesh_t cmesh, t8_locidx_t ltree_id)
Return a pointer to a given local tree.
Definition: t8_cmesh.c:319
double * t8_cmesh_get_tree_vertices(t8_cmesh_t cmesh, t8_locidx_t ltreeid)
Return a pointer to the vertex coordinates of a tree.
Definition: t8_cmesh.c:376
void t8_cmesh_debug_print_trees(const t8_cmesh_t cmesh, sc_MPI_Comm comm)
Definition: t8_cmesh.c:1308
void t8_cmesh_unref(t8_cmesh_t *pcmesh)
Decrease the reference counter of a cmesh.
Definition: t8_cmesh.c:1215
int t8_cmesh_is_initialized(t8_cmesh_t cmesh)
Check whether a cmesh is not NULL, initialized and not committed.
Definition: t8_cmesh.c:43
t8_eclass_t t8_cmesh_get_ghost_class(t8_cmesh_t cmesh, t8_locidx_t lghost_id)
Return the eclass of a given local ghost.
Definition: t8_cmesh.c:985
void t8_cmesh_new_translate_vertices_to_attributes(const t8_locidx_t *tvertices, const double *vertices, double *attr_vertices, const int num_vertices)
TODO: Add proper documentation.
Definition: t8_cmesh.c:1254
void t8_cmesh_set_partition_range(t8_cmesh_t cmesh, int set_face_knowledge, t8_gloidx_t first_local_tree, t8_gloidx_t last_local_tree)
Declare if the cmesh is understood as a partitioned cmesh and specify the processor local tree range.
Definition: t8_cmesh.c:202
void t8_cmesh_print_profile(t8_cmesh_t cmesh)
Print the collected statistics from a cmesh profile.
Definition: t8_cmesh.c:1118
t8_shmem_array_t t8_cmesh_get_partition_table(t8_cmesh_t cmesh)
Return the shared memory array storing the partition table of a partitioned cmesh.
Definition: t8_cmesh.c:400
void t8_cmesh_set_tree_geometry(t8_cmesh_t cmesh, t8_gloidx_t gtreeid, const char *geom_name)
Set the geometry for a tree, thus specify which geometry to use for this tree.
Definition: t8_cmesh_geometry.cxx:48
int t8_cmesh_is_partitioned(t8_cmesh_t cmesh)
Query whether a committed cmesh is partitioned or replicated.
Definition: t8_cmesh.c:902
t8_locidx_t t8_cmesh_get_num_ghosts(t8_cmesh_t cmesh)
Return the number of ghost trees of a cmesh.
Definition: t8_cmesh.c:928
t8_locidx_t t8_cmesh_get_num_local_trees(t8_cmesh_t cmesh)
Return the number of local trees of a cmesh.
Definition: t8_cmesh.c:919
t8_cmesh_t t8_cmesh_bcast(t8_cmesh_t cmesh_in, int root, sc_MPI_Comm comm)
Broadcast a cmesh structure that exists only on one process to all processes in the cmesh's communica...
Definition: t8_cmesh.c:665
void t8_cmesh_set_join(t8_cmesh_t cmesh, t8_gloidx_t gtree1, t8_gloidx_t gtree2, int face1, int face2, int orientation)
Insert a face-connection between two trees in a cmesh.
Definition: t8_cmesh.c:559
void t8_cmesh_set_refine(t8_cmesh_t cmesh, int level, t8_scheme_cxx_t *scheme)
Refine the cmesh to a given level.
Definition: t8_cmesh.c:273
void t8_cmesh_translate_coordinates(const double *coords_in, double *coords_out, int num_vertices, double translate[3])
Compute y = x + translate on an array of doubles, interpreting each 3 as one vector x.
Definition: t8_cmesh.c:1235
t8_ctree_t t8_cmesh_get_next_tree(t8_cmesh_t cmesh, t8_ctree_t tree)
Given a local tree in a cmesh return a pointer to the next local tree.
Definition: t8_cmesh.c:344
t8_gloidx_t t8_cmesh_get_global_id(t8_cmesh_t cmesh, t8_locidx_t local_id)
Return the global id of a given local tree or ghost.
Definition: t8_cmesh.c:998
t8_ctree_t t8_cmesh_get_first_tree(t8_cmesh_t cmesh)
Return a pointer to the first local tree in a cmesh.
Definition: t8_cmesh.c:331
void t8_cmesh_coords_axb(const double *coords_in, double *coords_out, int num_vertices, double alpha, const double b[3])
Compute y = ax + b on an array of doubles, interpreting each 3 as one vector x.
Definition: t8_cmesh.c:1268
t8_shmem_array_t t8_cmesh_alloc_offsets(int mpisize, sc_MPI_Comm comm)
Allocate a shared memory array to store the tree offsets of a cmesh.
Definition: t8_cmesh.c:186
void t8_cmesh_ref(t8_cmesh_t cmesh)
Increase the reference counter of a cmesh.
Definition: t8_cmesh.c:1208
t8_locidx_t t8_cmesh_ltreeid_to_ghostid(const t8_cmesh_t cmesh, const t8_locidx_t ltreeid)
Given a local tree id that belongs to a ghost, return the index of the ghost.
Definition: t8_cmesh.c:308
int t8_cmesh_tree_face_is_boundary(t8_cmesh_t cmesh, t8_locidx_t ltree_id, int face)
Query whether a face of a local tree or ghost is at the domain boundary.
Definition: t8_cmesh.c:937
int t8_cmesh_is_committed(t8_cmesh_t cmesh)
Check whether a cmesh is not NULL, initialized and committed.
Definition: t8_cmesh.c:87
t8_locidx_t t8_cmesh_get_face_neighbor(const t8_cmesh_t cmesh, const t8_locidx_t ltreeid, const int face, int *dual_face, int *orientation)
Given a local tree id and a face number, get information about the face neighbor tree.
Definition: t8_cmesh.c:1048
t8_gloidx_t t8_cmesh_get_first_treeid(t8_cmesh_t cmesh)
Return the global index of the first local tree of a cmesh.
Definition: t8_cmesh.c:284
int t8_cmesh_tree_vertices_negative_volume(t8_eclass_t eclass, double *vertices, int num_vertices)
Given a set of vertex coordinates for a tree of a given eclass.
Definition: t8_cmesh.c:455
void t8_cmesh_commit(t8_cmesh_t cmesh, sc_MPI_Comm comm)
After allocating and adding properties to a cmesh, finish its construction.
Definition: t8_cmesh_commit.c:580
int t8_cmesh_no_negative_volume(t8_cmesh_t cmesh)
After a cmesh is committed, check whether all trees in a cmesh do have positive volume.
Definition: t8_cmesh.c:519
void t8_cmesh_destroy(t8_cmesh_t *pcmesh)
Verify that a coarse mesh has only one reference left and destroy it.
Definition: t8_cmesh.c:1227
t8_gloidx_t t8_cmesh_get_num_trees(t8_cmesh_t cmesh)
Return the global number of trees in a cmesh.
Definition: t8_cmesh.c:910
t8_eclass_t t8_cmesh_get_tree_class(t8_cmesh_t cmesh, t8_locidx_t ltree_id)
Return the eclass of a given local tree.
Definition: t8_cmesh.c:973
void t8_cmesh_uniform_bounds(t8_cmesh_t cmesh, int level, t8_scheme_cxx_t *ts, t8_gloidx_t *first_local_tree, t8_gloidx_t *child_in_tree_begin, t8_gloidx_t *last_local_tree, t8_gloidx_t *child_in_tree_end, int8_t *first_tree_shared)
Calculate the section of a uniform forest for the current rank.
Definition: t8_cmesh_cxx.cxx:35
void t8_cmesh_set_dimension(t8_cmesh_t cmesh, int dim)
Set the dimension of a cmesh.
Definition: t8_cmesh.c:413
void t8_cmesh_set_tree_class(t8_cmesh_t cmesh, t8_gloidx_t gtree_id, t8_eclass_t tree_class)
Set the class of a tree in the cmesh.
Definition: t8_cmesh.c:422
int t8_cmesh_is_empty(t8_cmesh_t cmesh)
Check whether a cmesh is empty on all processes.
Definition: t8_cmesh.c:659
int t8_cmesh_treeid_is_local_tree(const t8_cmesh_t cmesh, const t8_locidx_t ltreeid)
Query whether a given t8_locidx_t belongs to a local tree of a cmesh.
Definition: t8_cmesh.c:290
int t8_cmesh_comm_is_valid(t8_cmesh_t cmesh, sc_MPI_Comm comm)
Check whether a given MPI communicator assigns the same rank and mpisize as stored in a cmesh.
Definition: t8_cmesh.c:127
void * t8_cmesh_get_attribute(t8_cmesh_t cmesh, int package_id, int key, t8_locidx_t ltree_id)
Return the attribute pointer of a tree.
Definition: t8_cmesh.c:385
void t8_cmesh_set_partition_uniform(t8_cmesh_t cmesh, int element_level, t8_scheme_cxx_t *ts)
Declare if the cmesh is understood as a partitioned cmesh where the partition table is derived from a...
Definition: t8_cmesh.c:252
void t8_cmesh_set_derive(t8_cmesh_t cmesh, t8_cmesh_t set_from)
This function sets a cmesh to be derived from.
Definition: t8_cmesh.c:169
void t8_cmesh_set_partition_offsets(t8_cmesh_t cmesh, t8_shmem_array_t tree_offsets)
Declare if the cmesh is understood as a partitioned cmesh and specify the first local tree for each p...
Definition: t8_cmesh.c:231
int t8_cmesh_is_equal(t8_cmesh_t cmesh_a, t8_cmesh_t cmesh_b)
Check whether two given cmeshes carry the same information.
Definition: t8_cmesh.c:607
void t8_cmesh_set_attribute(t8_cmesh_t cmesh, t8_gloidx_t gtree_id, int package_id, int key, void *data, size_t data_size, int data_persists)
Store an attribute at a tree in a cmesh.
Definition: t8_cmesh.c:354
We define routines to save and load a cmesh to/from the file system.
enum t8_load_mode t8_load_mode_t
This enumeration contains all modes in which we can open a saved cmesh.
We define all possible element classes that occur in hybrid meshes.
enum t8_eclass t8_eclass_t
This enumeration contains all possible element classes.
This file defines basic operations on an element in a refinement tree.
Typedef for the t8_geometry class in order to be usable as a pointer from .c files.
We define basic shared memory routines.