p4est  2.8.7
p4est is a software library for parallel adaptive mesh refinement.
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
p6est.h
Go to the documentation of this file.
1 /*
2  This file is part of p4est.
3  p4est is a C library to manage a collection (a forest) of multiple
4  connected adaptive quadtrees or octrees in parallel.
5 
6  Copyright (C) 2010 The University of Texas System
7  Additional copyright (C) 2011 individual authors
8  Written by Carsten Burstedde, Lucas C. Wilcox, and Tobin Isaac
9 
10  p4est is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14 
15  p4est is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with p4est; if not, write to the Free Software Foundation, Inc.,
22  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 */
24 
25 #ifndef P6EST_H
26 #define P6EST_H
27 
53 /* 2+1D refinement is based on the 2D p4est datatypes */
54 #include <p4est.h>
55 /* We need p8est_connect_type_t typedef from p8est_connectivity */
56 #include <p8est_connectivity.h>
57 
58 SC_EXTERN_C_BEGIN;
59 
64 typedef struct p6est_connectivity
65 {
69  double *top_vertices;
73  double height[3];
76 }
78 
93  double *top_vertices,
94  double height[3]);
95 
98 
106  p4est_topidx_t which_tree,
107  double vertices[24]);
108 
119  connectivity,
120  p4est_topidx_t treeid,
121  p4est_qcoord_t x,
122  p4est_qcoord_t y,
123  p4est_qcoord_t z, double vxyz[3]);
124 
128 typedef struct p2est_quadrant
129 {
131  int8_t level,
133  int16_t pad16;
135  {
136  void *user_data;
137  long user_long;
138  int user_int;
140  struct
141  {
143  int owner_rank;
144  }
146  struct
147  {
149  p4est_topidx_t from_tree;
150  }
151  piggy2;
153  struct
154  {
156  p4est_locidx_t local_num;
157  }
158  piggy3;
160  }
161  p;
162 }
164 
166 typedef struct p6est
167 {
168  sc_MPI_Comm mpicomm;
169  int mpisize,
173  size_t data_size;
175  void *user_pointer;
182  sc_array_t *layers;
184  sc_mempool_t *user_data_pool;
185  /* WARNING: This is NULL if data size
186  * equals zero. */
187  sc_mempool_t *layer_pool;
192 }
194 
203 typedef void (*p6est_init_t) (p6est_t * p6est,
204  p4est_topidx_t which_tree,
205  p4est_quadrant_t * column,
206  p2est_quadrant_t * layer);
207 
236 typedef void (*p6est_replace_t) (p6est_t * p6est,
237  p4est_topidx_t which_tree,
238  int num_outcolumns,
239  int num_outlayers,
240  p4est_quadrant_t * outcolumns[],
241  p2est_quadrant_t * outlayers[],
242  int num_incolumns,
243  int num_inlayers,
244  p4est_quadrant_t * incolumns[],
245  p2est_quadrant_t * inlayers[]);
246 
252  p4est_topidx_t which_tree,
253  p4est_quadrant_t * column);
254 
260  p4est_topidx_t which_tree,
261  p4est_quadrant_t * column,
262  p2est_quadrant_t * layer);
263 
269  p4est_topidx_t which_tree,
270  p4est_quadrant_t * columns[]);
271 
277  p4est_topidx_t which_tree,
278  p4est_quadrant_t * column,
279  p2est_quadrant_t * layers[]);
280 
285 typedef int (*p6est_weight_t) (p6est_t * p6est,
286  p4est_topidx_t which_tree,
287  p4est_quadrant_t * column,
288  p2est_quadrant_t * layer);
289 
290 extern void *P2EST_DATA_UNINITIALIZED;
291 
293 #define P2EST_QUADRANT_INIT(q) \
294  ((void) memset ((q), -1, sizeof (p2est_quadrant_t)))
295 
317 p6est_t *p6est_new (sc_MPI_Comm mpicomm,
318  p6est_connectivity_t * connectivity,
319  size_t data_size,
320  p6est_init_t init_fn, void *user_pointer);
321 
341  double *top_vertices,
342  double height[3], int min_zlevel,
343  size_t data_size,
344  p6est_init_t init_fn,
345  void *user_pointer);
346 
352 
362 p6est_t *p6est_copy (p6est_t * input, int copy_data);
363 
376 void p6est_reset_data (p6est_t * p6est, size_t data_size,
377  p6est_init_t init_fn,
378  void *user_pointer);
379 
399  int refine_recursive,
400  p6est_refine_column_t refine_fn,
401  p6est_init_t init_fn);
402 
422  int refine_recursive,
423  p6est_refine_layer_t refine_fn,
424  p6est_init_t init_fn);
425 
436  int coarsen_recursive,
437  p6est_coarsen_column_t coarsen_fn,
438  p6est_init_t init_fn);
439 
450  int coarsen_recursive,
451  p6est_coarsen_layer_t coarsen_fn,
452  p6est_init_t init_fn);
453 
462  p8est_connect_type_t btype,
463  p6est_init_t init_fn);
464 
465 typedef enum
466 {
467  P6EST_COMM_PARTITION = 1,
468  P6EST_COMM_GHOST,
469  P6EST_COMM_BALANCE
470 }
471 p6est_comm_tag_t;
472 
487  p6est_weight_t weight_fn);
488 void p6est_partition_correct (p6est_t * p6est,
490  num_layers_in_proc);
491 void p6est_partition_to_p4est_partition (p6est_t * p6est,
493  num_layers_in_proc,
495  num_columns_in_proc);
496 void p4est_partition_to_p6est_partition (p6est_t * p6est,
498  num_columns_in_proc,
500  num_layers_in_proc);
501 
502 p4est_gloidx_t p6est_partition_for_coarsening (p6est_t * p6est,
504  num_layers_in_proc);
505 p4est_gloidx_t p6est_partition_given (p6est_t * p6est,
507  num_layers_in_proc);
508 
514 
526 void p6est_save (const char *filename, p6est_t * p6est,
527  int save_data);
528 
547 p6est_t *p6est_load (const char *filename, sc_MPI_Comm mpicomm,
548  size_t data_size, int load_data,
549  void *user_pointer,
550  p6est_connectivity_t ** connectivity);
551 
553 /*@unused@*/
554 static inline p2est_quadrant_t *
555 p2est_quadrant_array_index (sc_array_t * array, size_t it)
556 {
557  P4EST_ASSERT (array->elem_size == sizeof (p2est_quadrant_t));
558  P4EST_ASSERT (it < array->elem_count);
559 
560  return (p2est_quadrant_t *) (array->array + sizeof (p2est_quadrant_t) * it);
561 }
562 
564 /*@unused@*/
565 static inline p2est_quadrant_t *
566 p2est_quadrant_array_push (sc_array_t * array)
567 {
568  p2est_quadrant_t *q;
569 
570  P4EST_ASSERT (array->elem_size == sizeof (p2est_quadrant_t));
571 
572  q = (p2est_quadrant_t *) sc_array_push (array);
574  return q;
575 }
576 
578 /*@unused@*/
579 static inline p2est_quadrant_t *
580 p2est_quadrant_mempool_alloc (sc_mempool_t * mempool)
581 {
582  P4EST_ASSERT (mempool->elem_size == sizeof (p2est_quadrant_t));
583 
584  return (p2est_quadrant_t *) sc_mempool_alloc (mempool);
585 }
586 
588 /*@unused@*/
589 static inline p2est_quadrant_t *
590 p2est_quadrant_list_pop (sc_list_t * list)
591 {
592  return (p2est_quadrant_t *) sc_list_pop (list);
593 }
594 
595 #define P6EST_COLUMN_GET_RANGE(q,f,l) \
596  do { \
597  *(f) = (size_t) (q)->p.piggy3.local_num; \
598  *(l) = *(f) + (size_t) (q)->p.piggy3.which_tree; \
599  } while (0);
600 
601 #define P6EST_COLUMN_SET_RANGE(q,f,l) \
602  do { \
603  (q)->p.piggy3.local_num = (p4est_locidx_t) (f); \
604  (q)->p.piggy3.which_tree = (p4est_topidx_t) ((l) - (f)); \
605  } while (0);
606 
607 /*@unused@*/
608 static inline void
609 p6est_layer_init_data (p6est_t * p6est, p4est_topidx_t which_tree,
610  p4est_quadrant_t * column,
611  p2est_quadrant_t * layer, p6est_init_t init_fn)
612 {
613  if (p6est->data_size > 0) {
614  layer->p.user_data = sc_mempool_alloc (p6est->user_data_pool);
615  }
616  else {
617  layer->p.user_data = NULL;
618  }
619  if (init_fn != NULL) {
620  init_fn (p6est, which_tree, column, layer);
621  }
622 }
623 
624 /*@unused@*/
625 static inline void
626 p6est_layer_free_data (p6est_t * p6est, p2est_quadrant_t * layer)
627 {
628  if (p6est->data_size > 0) {
629  sc_mempool_free (p6est->user_data_pool, layer->p.user_data);
630  }
631  layer->p.user_data = NULL;
632 }
633 
634 void p6est_compress_columns (p6est_t * p6est);
635 void p6est_update_offsets (p6est_t * p6est);
636 
637 SC_EXTERN_C_END;
638 
639 #endif /* !P6EST_H */
The top-level 2D p4est interface.
int32_t p4est_qcoord_t
Typedef for quadrant coordinates.
Definition: p4est_base.h:81
int32_t p4est_topidx_t
Typedef for counting topological entities (trees, tree vertices).
Definition: p4est_base.h:93
int32_t p4est_locidx_t
Typedef for processor-local indexing of quadrants and nodes.
Definition: p4est_base.h:106
int64_t p4est_gloidx_t
Typedef for globally unique indexing of quadrants.
Definition: p4est_base.h:118
int(* p6est_refine_column_t)(p6est_t *p6est, p4est_topidx_t which_tree, p4est_quadrant_t *column)
Callback function prototype to decide whether to horizontally refine a column, i.e....
Definition: p6est.h:251
void(* p6est_init_t)(p6est_t *p6est, p4est_topidx_t which_tree, p4est_quadrant_t *column, p2est_quadrant_t *layer)
Callback function prototype to initialize the layers's user data.
Definition: p6est.h:203
void p6est_balance(p6est_t *p6est, p8est_connect_type_t btype, p6est_init_t init_fn)
Balance a forest.
struct p6est_connectivity p6est_connectivity_t
This structure holds the 2D+1D inter-tree connectivity information.
p6est_t * p6est_load(const char *filename, sc_MPI_Comm mpicomm, size_t data_size, int load_data, void *user_pointer, p6est_connectivity_t **connectivity)
Load the complete connectivity/p6est structure from disk.
void p6est_connectivity_destroy(p6est_connectivity_t *conn)
Destroy a p6est_connectivity structure.
struct p2est_quadrant p2est_quadrant_t
A 1D quadrant datatype: this is used to encode a "layer" of a column in the 2D+1D AMR scheme.
p4est_gloidx_t p6est_partition(p6est_t *p6est, p6est_weight_t weight_fn)
Equally partition the forest.
void p6est_tree_get_vertices(p6est_connectivity_t *conn, p4est_topidx_t which_tree, double vertices[24])
Get the vertices of the corners of a tree.
struct p6est p6est_t
The p6est forest datatype.
void p6est_destroy(p6est_t *p6est)
Destroy a p6est.
void p6est_refine_layers(p6est_t *p6est, int refine_recursive, p6est_refine_layer_t refine_fn, p6est_init_t init_fn)
Refine the layers within the columns of a sheet.
void p6est_save(const char *filename, p6est_t *p6est, int save_data)
Save the complete connectivity/p6est data to disk.
int(* p6est_weight_t)(p6est_t *p6est, p4est_topidx_t which_tree, p4est_quadrant_t *column, p2est_quadrant_t *layer)
Callback function prototype to calculate weights for partitioning.
Definition: p6est.h:285
p6est_connectivity_t * p6est_connectivity_new(p4est_connectivity_t *conn4, double *top_vertices, double height[3])
Create a p6est_connectivity_t from a p4est_connectivity_t.
void p6est_coarsen_columns(p6est_t *p6est, int coarsen_recursive, p6est_coarsen_column_t coarsen_fn, p6est_init_t init_fn)
Coarsen the columns of a sheet.
int(* p6est_coarsen_column_t)(p6est_t *p6est, p4est_topidx_t which_tree, p4est_quadrant_t *columns[])
Callback function prototype to decide for horizontal coarsening.
Definition: p6est.h:268
void(* p6est_replace_t)(p6est_t *p6est, p4est_topidx_t which_tree, int num_outcolumns, int num_outlayers, p4est_quadrant_t *outcolumns[], p2est_quadrant_t *outlayers[], int num_incolumns, int num_inlayers, p4est_quadrant_t *incolumns[], p2est_quadrant_t *inlayers[])
Callback function prototype to transfer information from outgoing layers to incoming layers.
Definition: p6est.h:236
p6est_t * p6est_copy(p6est_t *input, int copy_data)
Make a deep copy of a p6est.
p6est_t * p6est_new(sc_MPI_Comm mpicomm, p6est_connectivity_t *connectivity, size_t data_size, p6est_init_t init_fn, void *user_pointer)
Create a new forest.
unsigned p6est_checksum(p6est_t *p6est)
Compute the checksum for a forest.
void p6est_coarsen_layers(p6est_t *p6est, int coarsen_recursive, p6est_coarsen_layer_t coarsen_fn, p6est_init_t init_fn)
Coarsen the layers of a sheet.
void p6est_reset_data(p6est_t *p6est, size_t data_size, p6est_init_t init_fn, void *user_pointer)
Reset user pointer and element data.
void p6est_refine_columns(p6est_t *p6est, int refine_recursive, p6est_refine_column_t refine_fn, p6est_init_t init_fn)
Refine the columns of a sheet.
int(* p6est_refine_layer_t)(p6est_t *p6est, p4est_topidx_t which_tree, p4est_quadrant_t *column, p2est_quadrant_t *layer)
Callback function prototype to decide whether to vertically refine a layer.
Definition: p6est.h:259
int(* p6est_coarsen_layer_t)(p6est_t *p6est, p4est_topidx_t which_tree, p4est_quadrant_t *column, p2est_quadrant_t *layers[])
Callback function prototype to decide for vertical coarsening.
Definition: p6est.h:276
#define P2EST_QUADRANT_INIT(q)
set statically allocated quadrant to defined values
Definition: p6est.h:293
p6est_t * p6est_new_from_p4est(p4est_t *p4est, double *top_vertices, double height[3], int min_zlevel, size_t data_size, p6est_init_t init_fn, void *user_pointer)
Create a new forest from an already created p4est that represents columns.
void p6est_qcoord_to_vertex(p6est_connectivity_t *connectivity, p4est_topidx_t treeid, p4est_qcoord_t x, p4est_qcoord_t y, p4est_qcoord_t z, double vxyz[3])
Transform a quadrant coordinate into the space spanned by tree vertices.
The connectivity defines the coarse topology of the forest.
p8est_connect_type_t
Characterize a type of adjacency.
Definition: p8est_connectivity.h:120
A 1D quadrant datatype: this is used to encode a "layer" of a column in the 2D+1D AMR scheme.
Definition: p6est.h:129
int8_t level
level of refinement
Definition: p6est.h:131
union p2est_quadrant::p6est_quadrant_data p
a union of additional data attached to a layer
int16_t pad16
padding
Definition: p6est.h:133
int8_t pad8
padding
Definition: p6est.h:132
p4est_qcoord_t z
vertical coordinate
Definition: p6est.h:130
This structure holds the 2D inter-tree connectivity information.
Definition: p4est_connectivity.h:190
The 2D quadrant datatype.
Definition: p4est.h:76
The p4est forest datatype.
Definition: p4est.h:150
This structure holds the 2D+1D inter-tree connectivity information.
Definition: p6est.h:65
p4est_connectivity_t * conn4
the 2D connecitvity; owned; vertices interpreted as the vertices of the bottom of the sheet
Definition: p6est.h:66
double * top_vertices
if NULL, uniform vertical profile, otherwise the vertices of the top of the sheet: should be the same...
Definition: p6est.h:69
double height[3]
if top_vertices == NULL, this gives the offset from the bottom of the sheet to the top
Definition: p6est.h:73
The p6est forest datatype.
Definition: p6est.h:167
void * user_pointer
convenience pointer for users, never touched by p4est
Definition: p6est.h:175
sc_MPI_Comm mpicomm
MPI communicator.
Definition: p6est.h:168
sc_mempool_t * user_data_pool
memory allocator for user data
Definition: p6est.h:184
int mpirank
this process's MPI rank
Definition: p6est.h:170
p4est_t * columns
2D description of column layout built from connectivity.
Definition: p6est.h:178
p6est_connectivity_t * connectivity
topology of sheet, not owned.
Definition: p6est.h:177
size_t data_size
size of per-quadrant p.user_data (see p2est_quadrant_t::p2est_quadrant_data::user_data)
Definition: p6est.h:173
int mpisize
number of MPI processes
Definition: p6est.h:169
p4est_gloidx_t * global_first_layer
first global quadrant index for each process and 1 beyond
Definition: p6est.h:189
p4est_qcoord_t root_len
height of the domain
Definition: p6est.h:191
int mpicomm_owned
whether this communicator is owned by the forest
Definition: p6est.h:171
sc_mempool_t * layer_pool
memory allocator for temporary layers
Definition: p6est.h:187
sc_array_t * layers
single array that stores p2est_quadrant_t layers within columns
Definition: p6est.h:182
p4est_topidx_t which_tree
the tree containing the quadrant
Definition: p6est.h:139
struct p2est_quadrant::p6est_quadrant_data::@12 piggy3
of ghost layers, store the tree and index in the owner's numbering
struct p2est_quadrant::p6est_quadrant_data::@11 piggy2
of transformed layers, store the original tree and the target tree
void * user_data
never changed by p4est
Definition: p6est.h:136
long user_long
never changed by p4est
Definition: p6est.h:137
int user_int
never changed by p4est
Definition: p6est.h:138
struct p2est_quadrant::p6est_quadrant_data::@10 piggy1
of ghost layer, store the tree and owner rank