p4est_wrap_leaf_t * p4est_wrap_leaf_first (p4est_wrap_t * pp, int track_mirrors) { p4est_t *p4est = pp->p4est; p4est_wrap_leaf_t *leaf; p4est_quadrant_t *mirror; if (p4est->local_num_quadrants == 0) { P4EST_ASSERT (p4est->first_local_tree == -1); P4EST_ASSERT (p4est->last_local_tree == -2); return NULL; } /* prepare internal state of the leaf iterator */ leaf = P4EST_ALLOC (p4est_wrap_leaf_t, 1); leaf->pp = pp; leaf->which_tree = p4est->first_local_tree; P4EST_ASSERT (leaf->which_tree >= 0); leaf->tree = p4est_tree_array_index (p4est->trees, leaf->which_tree); leaf->tquadrants = &leaf->tree->quadrants; P4EST_ASSERT (leaf->tquadrants->elem_size > 0); leaf->which_quad = 0; /* initialize mirror tracking if desired */ leaf->nm = leaf->next_mirror_quadrant = -1; if (track_mirrors) { leaf->mirrors = &(p4est_wrap_get_ghost (pp))->mirrors; if (leaf->mirrors->elem_count > 0) { mirror = p4est_quadrant_array_index (leaf->mirrors, 0); leaf->next_mirror_quadrant = (int) mirror->p.piggy3.local_num; P4EST_ASSERT (leaf->next_mirror_quadrant >= 0); P4EST_ASSERT (leaf->next_mirror_quadrant < p4est->local_num_quadrants); } } else { leaf->mirrors = NULL; leaf->is_mirror = 0; } /* complete leaf and mirror information */ return p4est_wrap_leaf_info (leaf); }
int main (int argc, char **argv) { int mpiret; int changed; int loop; #ifdef P4EST_ENABLE_DEBUG int lp = SC_LP_DEFAULT; #else int lp = SC_LP_PRODUCTION; #endif p4est_locidx_t jl; p4est_wrap_leaf_t *leaf; p4est_ghost_t *ghost; p4est_mesh_t *mesh; sc_MPI_Comm mpicomm; p4est_wrap_t *wrap; mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpicomm = sc_MPI_COMM_WORLD; sc_init (mpicomm, 0, 0, NULL, lp); p4est_init (NULL, lp); #ifndef P4_TO_P8 wrap = p4est_wrap_new_rotwrap (mpicomm, 0); #else wrap = p8est_wrap_new_rotwrap (mpicomm, 0); #endif ghost = p4est_wrap_get_ghost (wrap); SC_CHECK_ABORT (ghost != NULL, "Get ghost"); ghost = NULL; mesh = p4est_wrap_get_mesh (wrap); SC_CHECK_ABORT (mesh != NULL, "Get mesh"); mesh = NULL; for (loop = 0; loop < 3; ++loop) { /* mark for refinement */ for (jl = 0, leaf = p4est_wrap_leaf_first (wrap); leaf != NULL; jl++, leaf = p4est_wrap_leaf_next (leaf)) { if (leaf->which_quad % 3 == 0) { p4est_wrap_mark_refine (wrap, leaf->which_tree, leaf->which_quad); } } SC_CHECK_ABORT (jl == wrap->p4est->local_num_quadrants, "Iterator"); changed = wrap_adapt_partition (wrap, 1); SC_CHECK_ABORT (changed, "Wrap refine"); } for (loop = 0; loop < 2; ++loop) { /* mark some elements for coarsening that does not effect anything */ for (jl = 0, leaf = p4est_wrap_leaf_first (wrap); leaf != NULL; jl++, leaf = p4est_wrap_leaf_next (leaf)) { if (leaf->which_quad % 5 == 0) { p4est_wrap_mark_refine (wrap, leaf->which_tree, leaf->which_quad); p4est_wrap_mark_coarsen (wrap, leaf->which_tree, leaf->which_quad); } } SC_CHECK_ABORT (jl == wrap->p4est->local_num_quadrants, "Iterator"); changed = wrap_adapt_partition (wrap, 0); SC_CHECK_ABORT (!changed, "Wrap noop"); } for (loop = 0; loop < 2; ++loop) { /* mark for coarsening */ for (jl = 0, leaf = p4est_wrap_leaf_first (wrap); leaf != NULL; jl++, leaf = p4est_wrap_leaf_next (leaf)) { if ((leaf->which_quad / 13) % 17 != 3) { p4est_wrap_mark_coarsen (wrap, leaf->which_tree, leaf->which_quad); } } SC_CHECK_ABORT (jl == wrap->p4est->local_num_quadrants, "Iterator"); (void) wrap_adapt_partition (wrap, 0); } p4est_wrap_destroy (wrap); sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }