#ifndef P4_TO_P8
#else
#endif
#include <sc_options.h>
#ifdef P4EST_ENABLE_FILE_DEPRECATED
#ifndef P4_TO_P8
#define P4EST_DATA_FILE_EXT "p4d"
#else
#define P4EST_DATA_FILE_EXT P8EST_DATA_FILE_EXT
#define P8EST_DATA_FILE_EXT "p8d"
#endif
#define STEP3_BLOCK_SIZE (sizeof (step3_ctx_t))
#define STEP3_ENDIAN_CHECK 0x30415062
#endif
static const double step3_invalid = -1.;
#ifdef P4EST_ENABLE_FILE_DEPRECATED
static int step3_checkpoint = 0;
#endif
typedef struct step3_data
{
double u;
double dudt;
}
step3_data_t;
typedef struct step3_ctx
{
double bump_width;
double max_err;
int refine_period;
int repartition_period;
int write_period;
double current_time;
int time_step;
}
step3_ctx_t;
static double
step3_initial_condition (double x[], double du[], step3_ctx_t * ctx)
{
int i;
double *c = ctx->center;
double bump_width = ctx->bump_width;
double arg, retval;
r2 = 0.;
d[i] = x[i] - c[i];
r2 += d[i] * d[i];
}
arg = -(1. / 2.) * r2 / bump_width / bump_width;
retval = exp (arg);
if (du) {
du[i] = -(1. / bump_width / bump_width) * d[i] * retval;
}
}
return retval;
}
static void
{
q->
x + half_length, q->
y + half_length,
#ifdef P4_TO_P8
q->z + half_length,
#endif
xyz);
}
static void
{
step3_data_t *data = (step3_data_t *) q->
p.
user_data;
double midpoint[3];
step3_get_midpoint (
p4est, which_tree, q, midpoint);
data->u = step3_initial_condition (midpoint, data->du, ctx);
}
static double
{
step3_data_t *data = (step3_data_t *) q->
p.
user_data;
int i;
double diff2;
double *du = data->du;
double h =
double vol;
#ifdef P4_TO_P8
vol = h * h * h;
#else
vol = h * h;
#endif
diff2 = 0.;
diff2 += du[i] * du[i] * (1. / 12.) * h * h * vol;
}
return diff2;
}
static int
{
double global_err = ctx->max_err;
double global_err2 = global_err * global_err;
double h =
double vol, err2;
#ifdef P4_TO_P8
vol = h * h * h;
#else
vol = h * h;
#endif
err2 = step3_error_sqr_estimate (q);
if (err2 > global_err2 * vol) {
return 1;
}
else {
return 0;
}
}
static int
{
double global_err = ctx->max_err;
double global_err2 = global_err * global_err;
double h;
step3_data_t parentdata;
double parentmidpoint[3];
double vol, err2;
step3_get_midpoint (
p4est, which_tree, &parent, parentmidpoint);
parentdata.u = step3_initial_condition (parentmidpoint, parentdata.du, ctx);
#ifdef P4_TO_P8
vol = h * h * h;
#else
vol = h * h;
#endif
err2 = step3_error_sqr_estimate (&parent);
if (err2 < global_err2 * vol) {
return 1;
}
else {
return 0;
}
}
static int
{
double global_err = ctx->max_err;
double global_err2 = global_err * global_err;
double h;
step3_data_t *data;
double vol, err2, childerr2;
double parentu;
double diff;
int i;
h =
#ifdef P4_TO_P8
vol = h * h * h;
#else
vol = h * h;
#endif
parentu = 0.;
data = (step3_data_t *) children[i]->p.user_data;
}
err2 = 0.;
childerr2 = step3_error_sqr_estimate (children[i]);
if (childerr2 > global_err2 * vol) {
return 0;
}
err2 += step3_error_sqr_estimate (children[i]);
diff = (parentu - data->u) * (parentu - data->u);
err2 += diff * vol;
}
return 1;
}
else {
return 0;
}
}
static void
int num_outgoing,
{
step3_data_t *parent_data, *child_data;
int i, j;
double h;
double du_old, du_est;
if (num_outgoing > 1) {
parent_data = (step3_data_t *) incoming[0]->p.user_data;
parent_data->u = 0.;
parent_data->du[j] = step3_invalid;
}
child_data = (step3_data_t *) outgoing[i]->p.user_data;
du_old = parent_data->du[j];
du_est = child_data->du[j];
if (du_old == du_old) {
if (du_est * du_old >= 0.) {
if (fabs (du_est) < fabs (du_old)) {
parent_data->du[j] = du_est;
}
}
else {
parent_data->du[j] = 0.;
}
}
else {
parent_data->du[j] = du_est;
}
}
}
}
else {
parent_data = (step3_data_t *) outgoing[0]->p.user_data;
h =
child_data = (step3_data_t *) incoming[i]->p.user_data;
child_data->u = parent_data->u;
child_data->du[j] = parent_data->du[j];
child_data->u +=
(h / 4.) * parent_data->du[j] * ((i & (1 << j)) ? 1. : -1);
}
}
}
}
static void
{
sc_array_t *u_interp = (sc_array_t *) user_data;
step3_data_t *data = (step3_data_t *) q->
p.
user_data;
double h;
double this_u;
double *this_u_ptr;
int i, j;
tree = p4est_tree_array_index (
p4est->
trees, which_tree);
this_u = data->u;
this_u += (h / 2) * data->du[j] * ((i & (1 << j)) ? 1. : -1.);
}
this_u_ptr = (double *) sc_array_index (u_interp, arrayoffset + i);
this_u_ptr[0] = this_u;
}
}
static void
{
char filename[BUFSIZ] = "";
int retval;
sc_array_t *u_interp;
snprintf (filename, BUFSIZ,
P4EST_STRING "_step3_%04d", timestep);
u_interp = sc_array_new_size (
sizeof (
double), numquads *
P4EST_CHILDREN);
(void *) u_interp,
step3_interpolate_solution,
NULL,
#ifdef P4_TO_P8
NULL,
#endif
NULL);
SC_CHECK_ABORT (context != NULL,
1,
0,
0,
0,
context);
SC_CHECK_ABORT (context != NULL,
"solution", u_interp, context);
SC_CHECK_ABORT (context != NULL,
SC_CHECK_ABORT (!retval,
P4EST_STRING "_vtk: Error writing footer");
sc_array_destroy (u_interp);
}
#ifdef P4EST_ENABLE_FILE_DEPRECATED
static void
{
char filename[BUFSIZ] = "";
char user_string[P4EST_FILE_USER_STRING_BYTES] = "";
char quad_data_user_string[P4EST_FILE_USER_STRING_BYTES] =
"";
int errcode;
p4est_file_context_t *fc;
uint32_t check_endianness = STEP3_ENDIAN_CHECK;
sc_array_t block_arr;
snprintf (filename, BUFSIZ,
timestep);
fc = p4est_file_open_create (
p4est, filename,
"Checkpoint file", &errcode);
SC_CHECK_ABORT (fc != NULL
&& errcode == P4EST_FILE_ERR_SUCCESS,
snprintf (user_string, P4EST_FILE_USER_STRING_BYTES, "%s", "Endianness");
sc_array_init_data (&block_arr, &check_endianness, sizeof (uint32_t), 1);
fc =
p4est_file_write_block (fc, sizeof (uint32_t), &block_arr,
user_string, &errcode);
SC_CHECK_ABORT (fc != NULL
&& errcode == P4EST_FILE_ERR_SUCCESS,
P4EST_STRING "_file_write_block: Error writing endianness");
snprintf (user_string, P4EST_FILE_USER_STRING_BYTES, "%s",
"Simulation context");
fc =
p4est_file_write_block (fc, STEP3_BLOCK_SIZE, &block_arr,
user_string, &errcode);
SC_CHECK_ABORT (fc != NULL
&& errcode == P4EST_FILE_ERR_SUCCESS,
"_file_write_block: Error writing simulation context");
snprintf (user_string, P4EST_FILE_USER_STRING_BYTES,
fc =
&errcode);
SC_CHECK_ABORT (fc != NULL
&& errcode == P4EST_FILE_ERR_SUCCESS,
"_file_write_connectivity: Error writing connectivity");
snprintf (user_string, P4EST_FILE_USER_STRING_BYTES,
"Quadrants of time step %04d.", timestep);
snprintf (quad_data_user_string, P4EST_FILE_USER_STRING_BYTES,
"Quadrant data of time step %04d.", timestep);
fc = p4est_file_write_p4est (fc,
p4est,
user_string, quad_data_user_string, &errcode);
SC_CHECK_ABORT (fc != NULL
&& errcode == P4EST_FILE_ERR_SUCCESS,
p4est_file_close (fc, &errcode);
SC_CHECK_ABORT (errcode == P4EST_FILE_ERR_SUCCESS,
}
#endif
static void step3_timestep (
p4est_t *
p4est,
double start_time,
double end_time);
static void step3_run (sc_MPI_Comm mpicomm);
static void
step3_restart (const char *filename, sc_MPI_Comm mpicomm, double time_inc)
{
#ifdef P4EST_ENABLE_FILE_DEPRECATED
int errcode;
char user_string[P4EST_FILE_USER_STRING_BYTES],
quad_string[P4EST_FILE_USER_STRING_BYTES],
quad_data_string[P4EST_FILE_USER_STRING_BYTES];
step3_ctx_t ctx;
p4est_file_context_t *fc;
uint32_t check_endianness = STEP3_ENDIAN_CHECK;
int32_t read_check_endianness;
sc_array_t block_arr;
#endif
if (filename == NULL) {
step3_run (mpicomm);
return;
}
#ifndef P4EST_ENABLE_FILE_DEPRECATED
else {
SC_ABORT_NOT_REACHED ();
}
#else
fc =
p4est_file_open_read_ext (mpicomm, filename, user_string,
&global_num_quadrants, &errcode);
SC_CHECK_ABORT (fc != NULL
&& errcode == P4EST_FILE_ERR_SUCCESS,
sc_array_init_data (&block_arr, &read_check_endianness, sizeof (uint32_t),
1);
fc =
p4est_file_read_block (fc, sizeof (uint32_t), &block_arr,
user_string, &errcode);
SC_CHECK_ABORT (fc != NULL
&& errcode == P4EST_FILE_ERR_SUCCESS,
"_file_read_block: Error reading data endianness");
P4EST_GLOBAL_PRODUCTIONF ("Read data with user string: %s\n", user_string);
SC_CHECK_ABORT (memcmp
(&read_check_endianness, &check_endianness,
sizeof (uint32_t)) == 0, "Wrong endianness");
sc_array_init_data (&block_arr, &ctx, STEP3_BLOCK_SIZE, 1);
fc =
p4est_file_read_block (fc, STEP3_BLOCK_SIZE, &block_arr, user_string,
&errcode);
SC_CHECK_ABORT (fc != NULL
&& errcode == P4EST_FILE_ERR_SUCCESS,
"_file_read_block: Error reading simulation context");
P4EST_GLOBAL_PRODUCTIONF ("Read data with user string: %s\n", user_string);
fc = p4est_file_read_connectivity (fc, &conn, user_string, &errcode);
SC_CHECK_ABORT (fc != NULL
&& errcode == P4EST_FILE_ERR_SUCCESS,
"_file_read_connectivity: Error reading connectivity");
P4EST_ASSERT (conn != NULL);
P4EST_GLOBAL_PRODUCTIONF ("Read data with user string: %s\n", user_string);
fc = p4est_file_read_p4est (fc, conn,
sizeof (step3_data_t),
&loaded_p4est, quad_string, quad_data_string,
&errcode);
SC_CHECK_ABORT (fc != NULL
&& errcode == P4EST_FILE_ERR_SUCCESS,
P4EST_GLOBAL_PRODUCTIONF ("Read quadrants with user string: %s\n",
quad_string);
P4EST_GLOBAL_PRODUCTIONF ("Read quadrant data with user string: %s\n",
quad_data_string);
p4est_file_close (fc, &errcode);
SC_CHECK_ABORT (errcode == P4EST_FILE_ERR_SUCCESS,
step3_timestep (loaded_p4est, ctx.current_time,
ctx.current_time + time_inc);
#endif
}
static void
{
step3_data_t *data = (step3_data_t *) q->
p.
user_data;
data->dudt = 0.;
}
static void
{
int i, j;
step3_data_t *ghost_data = (step3_data_t *) user_data;
step3_data_t *udata;
double vdotn = 0.;
double uavg;
double q;
double h, facearea;
int which_face;
int upwindside;
sc_array_t *sides = &(info->
sides);
P4EST_ASSERT (sides->elem_count == 2);
side[0] = p4est_iter_fside_array_index_int (sides, 0);
side[1] = p4est_iter_fside_array_index_int (sides, 1);
which_face = side[0]->
face;
switch (which_face) {
case 0:
vdotn = -ctx->v[0];
break;
case 1:
vdotn = ctx->v[0];
break;
case 2:
vdotn = -ctx->v[1];
break;
case 3:
vdotn = ctx->v[1];
break;
#ifdef P4_TO_P8
case 4:
vdotn = -ctx->v[2];
break;
case 5:
vdotn = ctx->v[2];
break;
#endif
}
upwindside = vdotn >= 0. ? 0 : 1;
uavg = 0;
if (side[upwindside]->is_hanging) {
if (side[upwindside]->is.hanging.is_ghost[j]) {
udata =
(step3_data_t *) &ghost_data[side[upwindside]->is.hanging.quadid[j]];
}
else {
udata =
(step3_data_t *) side[upwindside]->is.hanging.quad[j]->p.user_data;
}
uavg += udata->u;
}
}
else {
if (side[upwindside]->is.full.is_ghost) {
udata = (step3_data_t *) & ghost_data[side[upwindside]->is.full.quadid];
}
else {
udata = (step3_data_t *) side[upwindside]->is.full.quad->p.user_data;
}
uavg = udata->u;
}
q = vdotn * uavg;
for (i = 0; i < 2; i++) {
if (side[i]->is_hanging) {
h =
#ifndef P4_TO_P8
facearea = h;
#else
facearea = h * h;
#endif
if (!side[i]->is.hanging.is_ghost[j]) {
if (i == upwindside) {
udata->dudt += vdotn * udata->u * facearea * (i ? 1. : -1.);
}
else {
udata->dudt += q * facearea * (i ? 1. : -1.);
}
}
}
}
else {
#ifndef P4_TO_P8
facearea = h;
#else
facearea = h * h;
#endif
if (!side[i]->is.full.is_ghost) {
udata->dudt += q * facearea * (i ? 1. : -1.);
}
}
}
}
static void
{
step3_data_t *data = (step3_data_t *) q->
p.
user_data;
double dt = *((double *) user_data);
double vol;
double h =
#ifdef P4_TO_P8
vol = h * h * h;
#else
vol = h * h;
#endif
data->u += dt * data->dudt / vol;
}
static void
{
step3_data_t *data = (step3_data_t *) q->
p.
user_data;
int j;
data->du[j] = step3_invalid;
}
}
static void
{
int i, j;
sc_array_t *sides = &(info->sides);
step3_data_t *ghost_data = (step3_data_t *) user_data;
step3_data_t *udata;
double uavg[2];
double h[2];
double du_est, du_old;
int which_dir;
P4EST_ASSERT (sides->elem_count == 2);
side[0] = p4est_iter_fside_array_index_int (sides, 0);
side[1] = p4est_iter_fside_array_index_int (sides, 1);
which_dir = side[0]->
face / 2;
for (i = 0; i < 2; i++) {
uavg[i] = 0;
if (side[i]->is_hanging) {
h[i] =
if (side[i]->is.hanging.is_ghost[j]) {
}
else {
udata = (step3_data_t *) side[i]->is.hanging.quad[j]->p.user_data;
}
uavg[i] += udata->u;
}
}
else {
h[i] =
if (side[i]->is.full.is_ghost) {
}
else {
udata = (step3_data_t *) side[i]->is.full.quad->p.user_data;
}
uavg[i] = udata->u;
}
}
du_est = (uavg[1] - uavg[0]) / ((h[0] + h[1]) / 2.);
for (i = 0; i < 2; i++) {
if (side[i]->is_hanging) {
if (!side[i]->is.hanging.is_ghost[j]) {
du_old = udata->du[which_dir];
if (du_old == du_old) {
if (du_est * du_old >= 0.) {
if (fabs (du_est) < fabs (du_old)) {
udata->du[which_dir] = du_est;
}
}
else {
udata->du[which_dir] = 0.;
}
}
else {
udata->du[which_dir] = du_est;
}
}
}
}
else {
if (!side[i]->is.full.is_ghost) {
du_old = udata->du[which_dir];
if (du_old == du_old) {
if (du_est * du_old >= 0.) {
if (fabs (du_est) < fabs (du_old)) {
udata->du[which_dir] = du_est;
}
}
else {
udata->du[which_dir] = 0.;
}
}
else {
udata->du[which_dir] = du_est;
}
}
}
}
}
static void
{
step3_data_t *data = (step3_data_t *) q->
p.
user_data;
double umax = *((double *) user_data);
umax = SC_MAX (data->u, umax);
*((double *) user_data) = umax;
}
static double
{
int max_level, global_max_level;
int mpiret, i;
double min_h, vnorm;
double dt;
max_level = 0;
for (t = flt; t <= llt; t++) {
max_level = SC_MAX (max_level, tree->
maxlevel);
}
mpiret =
sc_MPI_Allreduce (&max_level, &global_max_level, 1, sc_MPI_INT,
SC_CHECK_MPI (mpiret);
min_h =
vnorm = 0;
vnorm += ctx->v[i] * ctx->v[i];
}
vnorm = sqrt (vnorm);
dt = min_h / 2. / vnorm;
return dt;
}
static void
step3_timestep (
p4est_t *
p4est,
double start_time,
double end_time)
{
double t = start_time;
double dt = 0.;
int i;
step3_data_t *ghost_data;
int refine_period = ctx->refine_period;
int repartition_period = ctx->repartition_period;
int write_period = ctx->write_period;
int recursive = 0;
int allowcoarsening = 1;
int callbackorphans = 0;
int mpiret;
double orig_max_err = ctx->max_err;
double umax, global_umax;
ghost_data =
P4EST_ALLOC (step3_data_t, ghost->ghosts.elem_count);
step3_reset_derivatives,
step3_minmod_estimate,
#ifdef P4_TO_P8
NULL,
#endif
NULL);
for (t = start_time, i = ctx->time_step; t < end_time; t += dt, i++) {
P4EST_GLOBAL_PRODUCTIONF ("time %f\n", t);
if (!(i % refine_period)) {
if (i) {
umax = 0.;
step3_compute_max,
NULL,
#ifdef P4_TO_P8
NULL,
#endif
NULL);
mpiret =
sc_MPI_Allreduce (&umax, &global_umax, 1, sc_MPI_DOUBLE, sc_MPI_MAX,
SC_CHECK_MPI (mpiret);
ctx->max_err = orig_max_err * global_umax;
P4EST_GLOBAL_PRODUCTIONF ("u_max %f\n", global_umax);
step3_refine_err_estimate, NULL,
step3_replace_quads);
step3_coarsen_err_estimate, NULL,
step3_replace_quads);
step3_replace_quads);
ghost = NULL;
ghost_data = NULL;
}
dt = step3_get_timestep (
p4est);
}
if (i && !(i % repartition_period)) {
if (ghost) {
ghost = NULL;
ghost_data = NULL;
}
}
if (!(i % write_period)) {
step3_write_solution (
p4est, i);
}
if (!ghost) {
ghost_data =
P4EST_ALLOC (step3_data_t, ghost->ghosts.elem_count);
}
ghost,
(void *) ghost_data,
step3_quad_divergence,
step3_upwind_flux,
#ifdef P4_TO_P8
NULL,
#endif
NULL);
(void *) &dt,
step3_timestep_update,
NULL,
#ifdef P4_TO_P8
NULL,
#endif
NULL);
step3_reset_derivatives,
step3_minmod_estimate,
#ifdef P4_TO_P8
NULL,
#endif
NULL);
}
ctx->time_step = i - 1;
ctx->current_time = t - dt;
#ifdef P4EST_ENABLE_FILE_DEPRECATED
if (step3_checkpoint) {
step3_write_checkpoint (
p4est, i - 1);
}
#endif
}
static void
step3_run (sc_MPI_Comm mpicomm)
{
int recursive, partforcoarsen;
step3_ctx_t ctx;
memset (&ctx, -1, sizeof (ctx));
ctx.bump_width = 0.1;
ctx.max_err = 2.e-2;
ctx.center[0] = 0.5;
ctx.center[1] = 0.5;
#ifdef P4_TO_P8
ctx.center[2] = 0.5;
#endif
#ifndef P4_TO_P8
ctx.v[0] = -0.445868402501118;
ctx.v[1] = -0.895098523991131;
#else
ctx.v[0] = 0.485191768970225;
ctx.v[1] = -0.427996381877778;
ctx.v[2] = 0.762501176669961;
#endif
ctx.refine_period = 2;
ctx.repartition_period = 4;
ctx.write_period = 8;
ctx.time_step = 0;
#ifndef P4_TO_P8
#else
#endif
conn,
0,
4,
1,
sizeof (step3_data_t),
step3_init_initial_condition,
(void *) (&ctx));
recursive = 1;
step3_init_initial_condition);
step3_init_initial_condition);
partforcoarsen = 1;
step3_timestep (
p4est, 0., 0.1);
}
int
main (int argc, char **argv)
{
int mpiret, retval;
int help, usage_error;
sc_MPI_Comm mpicomm;
sc_options_t *opt;
const char *filename;
mpiret = sc_MPI_Init (&argc, &argv);
SC_CHECK_MPI (mpiret);
mpicomm = sc_MPI_COMM_WORLD;
sc_init (mpicomm, 1, 1, NULL, SC_LP_ESSENTIAL);
P4EST_GLOBAL_PRODUCTIONF
("This is the p4est %dD demo example/steps/%s_step3\n",
filename = NULL;
opt = sc_options_new (argv[0]);
sc_options_add_bool (opt, 'H', "help", &help, 0,
"Print the help string and end the program");
#ifdef P4EST_ENABLE_FILE_DEPRECATED
sc_options_add_bool (opt, 'C', "write-checkpoint", &step3_checkpoint, 0,
"Write checkpoint files to disk");
sc_options_add_string (opt, 'L', "load-checkpoint", &filename,
NULL, "Load and start from a checkpoint file");
#endif
usage_error = (retval == -1 || retval < argc);
if (usage_error || help) {
}
else {
step3_restart (filename, mpicomm, 0.1);
}
sc_options_destroy (opt);
sc_finalize ();
mpiret = sc_MPI_Finalize ();
SC_CHECK_MPI (mpiret);
return usage_error ? EXIT_FAILURE : EXIT_SUCCESS;
}
void p4est_refine(p4est_t *p4est, int refine_recursive, p4est_refine_t refine_fn, p4est_init_t init_fn)
Refine a forest.
void p4est_destroy(p4est_t *p4est)
Destroy a p4est.
#define P4EST_QMAXLEVEL
The finest level of the quadtree for representing quadrant corners.
Definition: p4est.h:59
void p4est_partition(p4est_t *p4est, int allow_for_coarsening, p4est_weight_t weight_fn)
Equally partition the forest.
void p4est_balance(p4est_t *p4est, p4est_connect_type_t btype, p4est_init_t init_fn)
2:1 balance the size differences of neighboring elements in a forest.
void p4est_qcoord_to_vertex(p4est_connectivity_t *connectivity, p4est_topidx_t treeid, p4est_qcoord_t x, p4est_qcoord_t y, double vxyz[3])
Transform a quadrant coordinate into the space spanned by tree vertices.
#define P4EST_QUADRANT_LEN(l)
The length of a quadrant of level l.
Definition: p4est.h:65
void p4est_coarsen(p4est_t *p4est, int coarsen_recursive, p4est_coarsen_t coarsen_fn, p4est_init_t init_fn)
Coarsen a forest.
#define P4EST_ROOT_LEN
The length of a side of the root quadrant.
Definition: p4est.h:62
int32_t p4est_qcoord_t
Typedef for quadrant coordinates.
Definition: p4est_base.h:81
#define P4EST_FREE(p)
free an allocated array
Definition: p4est_base.h:210
#define P4EST_ALLOC(t, n)
allocate a t-array with n elements
Definition: p4est_base.h:199
SC_DLL_PUBLIC int p4est_package_id
The package id for p4est within libsc.
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
void p4est_init(sc_log_handler_t log_handler, int log_threshold)
Registers p4est with the SC Library and sets the logging behavior.
int64_t p4est_gloidx_t
Typedef for globally unique indexing of quadrants.
Definition: p4est_base.h:118
Routines for manipulating quadrants (neighbors, parents, children, etc.)
void p4est_quadrant_parent(const p4est_quadrant_t *q, p4est_quadrant_t *r)
Compute the parent of a quadrant.
Parallel messaging and support code.
void p4est_connectivity_destroy(p4est_connectivity_t *connectivity)
Destroy a connectivity structure.
#define P4EST_HALF
The number of children/corners touching one face.
Definition: p4est_connectivity.h:77
#define P4EST_DIM
The spatial dimension.
Definition: p4est_connectivity.h:71
#define P4EST_STRING
p4est identification string
Definition: p4est_connectivity.h:94
#define P4EST_CHILDREN
The number of children of a quadrant, also the number of corners.
Definition: p4est_connectivity.h:75
@ P4EST_CONNECT_FACE
Balance across faces only.
Definition: p4est_connectivity.h:116
@ P4EST_CONNECT_FULL
= CORNER.
Definition: p4est_connectivity.h:119
p4est_connectivity_t * p4est_connectivity_new_periodic(void)
Create a connectivity structure for an all-periodic unit square.
Interface routines with extended capabilities.
void p4est_coarsen_ext(p4est_t *p4est, int coarsen_recursive, int callback_orphans, p4est_coarsen_t coarsen_fn, p4est_init_t init_fn, p4est_replace_t replace_fn)
Coarsen a forest.
void p4est_balance_ext(p4est_t *p4est, p4est_connect_type_t btype, p4est_init_t init_fn, p4est_replace_t replace_fn)
2:1 balance the size differences of neighboring elements in a forest.
void p4est_refine_ext(p4est_t *p4est, int refine_recursive, int maxlevel, p4est_refine_t refine_fn, p4est_init_t init_fn, p4est_replace_t replace_fn)
Refine a forest with a bounded refinement level and a replace option.
p4est_t * p4est_new_ext(sc_MPI_Comm mpicomm, p4est_connectivity_t *connectivity, p4est_locidx_t min_quadrants, int min_level, int fill_uniform, size_t data_size, p4est_init_t init_fn, void *user_pointer)
Create a new forest.
p4est_ghost_t * p4est_ghost_new(p4est_t *p4est, p4est_connect_type_t btype)
Builds the ghost layer.
void p4est_ghost_destroy(p4est_ghost_t *ghost)
Frees all memory used for the ghost layer.
void p4est_ghost_exchange_data(p4est_t *p4est, p4est_ghost_t *ghost, void *ghost_data)
Transfer data for local quadrants that are ghosts to other processors.
Provide functions to serialize/deserialize a forest.
Iteration over mesh topology via callbacks.
void p4est_iterate(p4est_t *p4est, p4est_ghost_t *ghost_layer, void *user_data, p4est_iter_volume_t iter_volume, p4est_iter_face_t iter_face, p4est_iter_corner_t iter_corner)
Execute user supplied callbacks at every volume, face, and corner in the local forest.
Routines for printing a forest and associated fields to VTK format.
p4est_vtk_context_t * p4est_vtk_write_point_dataf(p4est_vtk_context_t *cont, int num_point_scalars, int num_point_vectors,...)
Write VTK point data.
p4est_vtk_context_t * p4est_vtk_write_header(p4est_vtk_context_t *cont)
Write the VTK header.
int p4est_vtk_write_footer(p4est_vtk_context_t *cont)
Write the VTU footer and clean up.
p4est_vtk_context_t * p4est_vtk_context_new(p4est_t *p4est, const char *filename)
The first call to write a VTK file using individual functions.
p4est_vtk_context_t * p4est_vtk_write_cell_dataf(p4est_vtk_context_t *cont, int write_tree, int write_level, int write_rank, int wrap_rank, int num_cell_scalars, int num_cell_vectors,...)
Write VTK cell data.
void p4est_vtk_context_set_scale(p4est_vtk_context_t *cont, double scale)
Modify the context parameter for scaling the quadrants.
struct p4est_vtk_context p4est_vtk_context_t
Opaque context type for writing VTK output with multiple function calls.
Definition: p4est_vtk.h:42
Routines for manipulating quadrants (neighbors, parents, children, etc.)
Parallel messaging and support code.
p8est_connectivity_t * p8est_connectivity_new_periodic(void)
Create a connectivity structure for an all-periodic unit cube.
Interface routines with extended capabilities.
Provide functions to serialize/deserialize a forest.
Iteration over mesh topology via callbacks.
Routines for printing a forest and associated fields to VTK format.
This structure holds the 2D inter-tree connectivity information.
Definition: p4est_connectivity.h:190
Quadrants that neighbor the local domain.
Definition: p4est_ghost.h:46
The information that is available to the user-defined p4est_iter_face_t callback.
Definition: p4est_iterate.h:124
p4est_quadrant_t * quad
the actual quadrant
Definition: p4est_iterate.h:69
p4est_locidx_t quadid
index in tree or ghost array
Definition: p4est_iterate.h:70
p4est_quadrant_t * quad[2]
the actual quadrant
Definition: p4est_iterate.h:79
p4est_locidx_t quadid[2]
index in tree or ghost array
Definition: p4est_iterate.h:80
Information about one side of a face in the forest.
Definition: p4est_iterate.h:94
int8_t face
which quadrant side the face touches
Definition: p4est_iterate.h:96
The information that is available to the user-defined p4est_iter_volume_t callback function.
Definition: p4est_iterate.h:47
p4est_quadrant_t * quad
the quadrant of the callback
Definition: p4est_iterate.h:50
p4est_locidx_t quadid
id in quad's tree array (see p4est_tree_t)
Definition: p4est_iterate.h:51
p4est_topidx_t treeid
the tree containing quad
Definition: p4est_iterate.h:53
The 2D quadrant datatype.
Definition: p4est.h:76
int8_t level
level of refinement
Definition: p4est.h:80
union p4est_quadrant::p4est_quadrant_data p
a union of additional data attached to a quadrant
p4est_qcoord_t y
coordinates
Definition: p4est.h:78
The p4est tree datatype.
Definition: p4est.h:129
int8_t maxlevel
highest local quadrant level
Definition: p4est.h:138
p4est_locidx_t quadrants_offset
cumulative sum over earlier trees on this processor (locals only)
Definition: p4est.h:133
The p4est forest datatype.
Definition: p4est.h:150
p4est_topidx_t first_local_tree
0-based index of first local tree, must be -1 for an empty processor
Definition: p4est.h:161
p4est_connectivity_t * connectivity
connectivity structure, not owned
Definition: p4est.h:177
p4est_locidx_t local_num_quadrants
number of quadrants on all trees on this processor
Definition: p4est.h:167
void * user_pointer
convenience pointer for users, never touched by p4est
Definition: p4est.h:157
sc_array_t * trees
array of all trees
Definition: p4est.h:178
sc_MPI_Comm mpicomm
MPI communicator.
Definition: p4est.h:151
p4est_topidx_t last_local_tree
0-based index of last local tree, must be -2 for an empty processor
Definition: p4est.h:164
p4est_iter_face_side_hanging_t hanging
if is_hanging, use is.hanging to access per-quadrant data
Definition: p4est_iterate.h:106
p4est_iter_face_side_full_t full
if !is_hanging, use is.full to access per-quadrant data
Definition: p4est_iterate.h:103
void * user_data
never changed by p4est
Definition: p4est.h:94