示例#1
0
int
main (int argc, char **argv)
{
  sc_MPI_Comm         mpicomm;
  int                 mpiret;
  int                 size, rank;

  mpiret = sc_MPI_Init (&argc, &argv);
  SC_CHECK_MPI (mpiret);
  mpicomm = sc_MPI_COMM_WORLD;
  mpiret = sc_MPI_Comm_size (mpicomm, &size);
  SC_CHECK_MPI (mpiret);
  mpiret = sc_MPI_Comm_rank (mpicomm, &rank);
  SC_CHECK_MPI (mpiret);

  sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT);
  p4est_init (NULL, SC_LP_DEFAULT);

  (void) check_backward_compatibility ();
  check_int_types ();

#ifndef P4_TO_P8
  check_all (mpicomm, p4est_connectivity_new_unitsquare (),
             "test_unitsquare", 0xef45243bU, 0xbc5d0907U);
  check_all (mpicomm, p4est_connectivity_new_rotwrap (),
             "test_rotwrap2", 0x266d2739U, 0x29a31248U);
  check_all (mpicomm, p4est_connectivity_new_corner (),
             "test_corner", 0x9dad92ccU, 0x937b27afU);
  check_all (mpicomm, p4est_connectivity_new_moebius (),
             "test_moebius", 0xbbc10f7fU, 0x09b6319eU);
  check_all (mpicomm, p4est_connectivity_new_star (),
             "test_star", 0xfb28233fU, 0x8e8a32b3);
#else
  check_all (mpicomm, p8est_connectivity_new_unitcube (),
             "test_unitcube", 0x2574801fU, 0x312559a7U);
  check_all (mpicomm, p8est_connectivity_new_periodic (),
             "test_periodic3", 0xdc7e8a93U, 0x0787ca2dU);
  check_all (mpicomm, p8est_connectivity_new_rotwrap (),
             "test_rotwrap", 0xa675888dU, 0x626cbe90U);
  check_all (mpicomm, p8est_connectivity_new_twocubes (),
             "test_twocubes", 0x7188978aU, 0x4124bcabU);
  check_all (mpicomm, p8est_connectivity_new_twowrap (),
             "test_twowrap", 0x8e3f994cU, 0x9dd49e94);
  check_all (mpicomm, p8est_connectivity_new_rotcubes (),
             "test_rotcubes", 0xc0e1b235U, 0x974af07a);
  check_all (mpicomm, p8est_connectivity_new_shell (),
             "test_shell", 0x558723a2U, 0x4dedf35eU);
  check_all (mpicomm,
             p8est_connectivity_new_brick (2, 3, 4, 0, 0, 1),
             "test_brick", 0x82174e14U, 0x211da6c5);
#endif

  /* clean up and exit */
  sc_finalize ();

  mpiret = sc_MPI_Finalize ();
  SC_CHECK_MPI (mpiret);

  return 0;
}
示例#2
0
int
main (int argc, char *argv[])
{
  int                 mpiret;

  /* initialize MPI and p4est internals */
  mpiret = sc_MPI_Init (&argc, &argv);
  SC_CHECK_MPI (mpiret);
  sc_init (sc_MPI_COMM_WORLD, 1, 1, NULL, SC_LP_DEFAULT);
  p4est_init (NULL, SC_LP_DEFAULT);

#ifndef P4_TO_P8
  test_reduce (p4est_connectivity_new_unitsquare (), "unitsquare");
  test_reduce (p4est_connectivity_new_periodic (), "periodic");
  test_reduce (p4est_connectivity_new_rotwrap (), "rotwrap");
  test_reduce (p4est_connectivity_new_corner (), "corner");
  test_reduce (p4est_connectivity_new_pillow (), "pillow");
  test_reduce (p4est_connectivity_new_moebius (), "moebius");
  test_reduce (p4est_connectivity_new_star (), "star");
  test_reduce (p4est_connectivity_new_cubed (), "cubed");
  test_reduce (p4est_connectivity_new_disk (), "disk");
  test_reduce (p4est_connectivity_new_brick (3, 2, 0, 0), "brick00");
  test_reduce (p4est_connectivity_new_brick (3, 2, 0, 1), "brick01");
  test_reduce (p4est_connectivity_new_brick (3, 2, 1, 0), "brick10");
  test_reduce (p4est_connectivity_new_brick (3, 2, 1, 1), "brick11");
#else
  test_reduce (p8est_connectivity_new_unitcube (), "unitcube");
  test_reduce (p8est_connectivity_new_periodic (), "periodic");
  test_reduce (p8est_connectivity_new_rotwrap (), "rotwrap");
  test_reduce (p8est_connectivity_new_twocubes (), "twocubes");
  test_reduce (p8est_connectivity_new_twowrap (), "twowrap");
  test_reduce (p8est_connectivity_new_rotcubes (), "rotcubes");
  test_reduce (p8est_connectivity_new_brick (4, 3, 2, 0, 0, 0), "brick000");
  test_reduce (p8est_connectivity_new_brick (4, 3, 2, 0, 0, 1), "brick001");
  test_reduce (p8est_connectivity_new_brick (4, 3, 2, 0, 1, 0), "brick010");
  test_reduce (p8est_connectivity_new_brick (4, 3, 2, 0, 1, 1), "brick011");
  test_reduce (p8est_connectivity_new_brick (4, 3, 2, 1, 0, 0), "brick100");
  test_reduce (p8est_connectivity_new_brick (4, 3, 2, 1, 0, 1), "brick101");
  test_reduce (p8est_connectivity_new_brick (4, 3, 2, 1, 1, 1), "brick111");
#endif
  /* clean up and exit */
  sc_finalize ();

  mpiret = sc_MPI_Finalize ();
  SC_CHECK_MPI (mpiret);
  return 0;
}
示例#3
0
int
main (int argc, char **argv)
{
  int                 mpiret;

  mpiret = sc_MPI_Init (&argc, &argv);
  SC_CHECK_MPI (mpiret);

  sc_init (sc_MPI_COMM_WORLD, 1, 1, NULL, SC_LP_DEFAULT);
  p4est_init (NULL, SC_LP_DEFAULT);

#ifndef P4_TO_P8
  test_complete (p4est_connectivity_new_unitsquare (), "unitsquare", 1);
  test_complete (p4est_connectivity_new_periodic (), "2D periodic", 0);
  test_complete (p4est_connectivity_new_rotwrap (), "rotwrap", 0);
  test_complete (p4est_connectivity_new_corner (), "corner", 1);
  test_complete (p4est_connectivity_new_moebius (), "moebius", 1);
  test_complete (p4est_connectivity_new_star (), "star", 1);
  test_complete (p4est_connectivity_new_brick (3, 18, 0, 1),
                 "2D periodic brick", 0);
  test_complete (p4est_connectivity_new_brick (3, 18, 0, 0), "2D brick", 1);
#else
  test_complete (p8est_connectivity_new_unitcube (), "unitcube", 1);
  test_complete (p8est_connectivity_new_periodic (), "3D periodic", 0);
  test_complete (p8est_connectivity_new_rotwrap (), "rotwrap", 0);
  test_complete (p8est_connectivity_new_twowrap (), "twowrap", 1);
  test_complete (p8est_connectivity_new_twocubes (), "twocubes", 1);
  test_complete (p8est_connectivity_new_rotcubes (), "rotcubes", 1);
  test_complete (p8est_connectivity_new_brick (3, 2, 8, 1, 0, 1),
                 "3D periodic brick", 0);
  test_complete (p8est_connectivity_new_brick (3, 2, 8, 0, 0, 0),
                 "3D brick", 1);
#endif

  sc_finalize ();

  mpiret = sc_MPI_Finalize ();
  SC_CHECK_MPI (mpiret);

  return 0;
}
示例#4
0
int
main (int argc, char **argv)
{
  int                 mpirank, mpisize;
  int                 mpiret;
  sc_MPI_Comm         mpicomm;
  p4est_t            *p4est;
  p4est_connectivity_t *connectivity;

  mpiret = sc_MPI_Init (&argc, &argv);
  SC_CHECK_MPI (mpiret);
  mpicomm = sc_MPI_COMM_WORLD;
  mpiret = sc_MPI_Comm_size (mpicomm, &mpisize);
  SC_CHECK_MPI (mpiret);
  mpiret = sc_MPI_Comm_rank (mpicomm, &mpirank);
  SC_CHECK_MPI (mpiret);

  sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT);
  p4est_init (NULL, SC_LP_DEFAULT);

  /* create connectivity and forest structures */
#ifdef P4_TO_P8
  connectivity = p8est_connectivity_new_rotcubes ();
#else
  connectivity = p4est_connectivity_new_star ();
#endif
  p4est = p4est_new_ext (mpicomm, connectivity, 15, 0, 0, 1, NULL, NULL);
  p4est_refine_ext (p4est, 1, P4EST_QMAXLEVEL, refine_fn, NULL, replace_fn);
  p4est_coarsen_ext (p4est, 1, 0, coarsen_fn, NULL, replace_fn);
  p4est_balance_ext (p4est, P4EST_CONNECT_FULL, NULL, replace_fn);

  p4est_destroy (p4est);
  p4est_connectivity_destroy (connectivity);
  sc_finalize ();

  mpiret = sc_MPI_Finalize ();
  SC_CHECK_MPI (mpiret);

  return 0;
}
示例#5
0
int
main (int argc, char **argv)
{
  sc_MPI_Comm         mpicomm;
  int                 mpiret;
  int                 mpisize, mpirank;
  unsigned            crc;
#ifndef P4_TO_P8
  size_t              kz;
  int8_t              l;
  p4est_quadrant_t   *q;
  p4est_tree_t        stree, *tree = &stree;
#endif
  p4est_t            *p4est;
  p4est_connectivity_t *connectivity;

  /* initialize MPI */
  mpiret = sc_MPI_Init (&argc, &argv);
  SC_CHECK_MPI (mpiret);
  mpicomm = sc_MPI_COMM_WORLD;
  mpiret = sc_MPI_Comm_size (mpicomm, &mpisize);
  SC_CHECK_MPI (mpiret);
  mpiret = sc_MPI_Comm_rank (mpicomm, &mpirank);
  SC_CHECK_MPI (mpiret);

  sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT);
  p4est_init (NULL, SC_LP_DEFAULT);

#ifndef P4_TO_P8
  connectivity = p4est_connectivity_new_star ();
#else
  connectivity = p8est_connectivity_new_rotcubes ();
#endif
  p4est = p4est_new_ext (mpicomm, connectivity, 0, 0, 0, 4, NULL, NULL);

#ifndef P4_TO_P8
  /* build empty tree */
  sc_array_init (&tree->quadrants, sizeof (p4est_quadrant_t));
  for (l = 0; l <= P4EST_MAXLEVEL; ++l) {
    tree->quadrants_per_level[l] = 0;
  }
  tree->maxlevel = 0;

  /* insert two quadrants */
  sc_array_resize (&tree->quadrants, 4);
  q = p4est_quadrant_array_index (&tree->quadrants, 0);
  p4est_quadrant_set_morton (q, 3, 13);
  q = p4est_quadrant_array_index (&tree->quadrants, 1);
  p4est_quadrant_set_morton (q, 1, 1);
  q = p4est_quadrant_array_index (&tree->quadrants, 2);
  p4est_quadrant_set_morton (q, 1, 2);
  q = p4est_quadrant_array_index (&tree->quadrants, 3);
  p4est_quadrant_set_morton (q, 1, 3);
  for (kz = 0; kz < tree->quadrants.elem_count; ++kz) {
    q = p4est_quadrant_array_index (&tree->quadrants, kz);
    q->p.user_data = sc_mempool_alloc (p4est->user_data_pool);
    ++tree->quadrants_per_level[q->level];
    tree->maxlevel = (int8_t) SC_MAX (tree->maxlevel, q->level);
  }

  /* balance the tree, print and destroy */
#if 0
  p4est_balance_subtree (p4est, P4EST_CONNECT_FULL, 0, NULL);
  p4est_tree_print (SC_LP_INFO, tree);
#endif
  for (kz = 0; kz < tree->quadrants.elem_count; ++kz) {
    q = p4est_quadrant_array_index (&tree->quadrants, kz);
    sc_mempool_free (p4est->user_data_pool, q->p.user_data);
  }
  sc_array_reset (&tree->quadrants);
#endif /* !P4_TO_P8 */

  /* check reset data function */
  p4est_reset_data (p4est, 0, init_fn, NULL);
  p4est_reset_data (p4est, 0, NULL, NULL);

  /* refine and balance the forest */
  SC_CHECK_ABORT (p4est_is_balanced (p4est, P4EST_CONNECT_FULL), "Balance 1");
  p4est_refine (p4est, 1, refine_fn, NULL);
  SC_CHECK_ABORT (!p4est_is_balanced (p4est, P4EST_CONNECT_FULL),
                  "Balance 2");
  p4est_balance (p4est, P4EST_CONNECT_FULL, NULL);
  SC_CHECK_ABORT (p4est_is_balanced (p4est, P4EST_CONNECT_FULL), "Balance 3");

  /* check reset data function */
  p4est_reset_data (p4est, 17, NULL, NULL);
  p4est_reset_data (p4est, 8, init_fn, NULL);

  /* checksum and partition */
  crc = p4est_checksum (p4est);
  p4est_partition (p4est, 0, NULL);
  SC_CHECK_ABORT (p4est_checksum (p4est) == crc, "Partition");
  SC_CHECK_ABORT (p4est_is_balanced (p4est, P4EST_CONNECT_FULL), "Balance 4");

  /* check reset data function */
  p4est_reset_data (p4est, 3, NULL, NULL);
  p4est_reset_data (p4est, 3, NULL, NULL);

  /* checksum and rebalance */
  crc = p4est_checksum (p4est);
  p4est_balance (p4est, P4EST_CONNECT_FULL, NULL);
  SC_CHECK_ABORT (p4est_checksum (p4est) == crc, "Rebalance");

  /* clean up and exit */
  P4EST_ASSERT (p4est->user_data_pool->elem_count ==
                (size_t) p4est->local_num_quadrants);
  p4est_destroy (p4est);
  p4est_connectivity_destroy (connectivity);

  sc_finalize ();

  mpiret = sc_MPI_Finalize ();
  SC_CHECK_MPI (mpiret);

  return 0;
}
示例#6
0
int
main (int argc, char **argv)
{
  int                 mpiret;
  sc_MPI_Comm         mpicomm;
  p4est_t            *p4est;
  p4est_connectivity_t *connectivity;
  p4est_locidx_t      save_local_count;
  p4est_geometry_t   *geom;

  mpiret = sc_MPI_Init (&argc, &argv);
  SC_CHECK_MPI (mpiret);
  mpicomm = sc_MPI_COMM_WORLD;

  sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT);
  p4est_init (NULL, SC_LP_DEFAULT);

  /* create connectivity and forest structures */
#ifdef P4_TO_P8
  connectivity = p8est_connectivity_new_rotcubes ();
  geom = NULL;
#else
  connectivity = p4est_connectivity_new_star ();
  geom = p4est_geometry_new_connectivity (connectivity);
#endif
  p4est = p4est_new_ext (mpicomm, connectivity, 15, 0, 0, 0, NULL, NULL);

  save_local_count = p4est->local_num_quadrants;
  refine_callback_count = 0;
  p4est_refine_ext (p4est, 0, 2, test_refine, NULL, NULL);
  SC_CHECK_ABORT (refine_callback_count == save_local_count, "Refine count");

  refine_callback_count = 0;
  p4est_refine (p4est, 1, test_refine, NULL);
  p4est_balance (p4est, P4EST_CONNECT_FULL, NULL);

  coarsen_all = 1;
  p4est_coarsen_both (p4est, 0, test_coarsen, NULL);
  coarsen_all = 0;
  p4est_coarsen_both (p4est, 1, test_coarsen, NULL);
  p4est_balance (p4est, P4EST_CONNECT_FULL, NULL);
  coarsen_all = 1;

  p4est_coarsen_both (p4est, 1, test_coarsen, NULL);
  p4est_vtk_write_file (p4est, geom, P4EST_STRING "_endcoarsen");

  if (p4est->mpisize == 1) {
    SC_CHECK_ABORT (p4est->global_num_quadrants ==
                    (p4est_gloidx_t) connectivity->num_trees, "Coarsen all");
  }

  p4est_destroy (p4est);
  if (geom != NULL) {
    p4est_geometry_destroy (geom);
  }
  p4est_connectivity_destroy (connectivity);
  sc_finalize ();

  mpiret = sc_MPI_Finalize ();
  SC_CHECK_MPI (mpiret);

  return 0;
}
示例#7
0
int
main (int argc, char **argv)
{
  sc_MPI_Comm         mpicomm;
  int                 mpiret;
  int                 size, rank;
  unsigned            crcF, crcC;
  p4est_connectivity_t *connectivity;
  p4est_t            *p4est;
  p4est_t            *p4estF, *p4estC;
#ifdef P4_TO_P8
  unsigned            crcE;
  p4est_t            *p4estE;
#endif

  /* initialize */
  mpiret = sc_MPI_Init (&argc, &argv);
  SC_CHECK_MPI (mpiret);
  mpicomm = sc_MPI_COMM_WORLD;
  mpiret = sc_MPI_Comm_size (mpicomm, &size);
  SC_CHECK_MPI (mpiret);
  mpiret = sc_MPI_Comm_rank (mpicomm, &rank);
  SC_CHECK_MPI (mpiret);

  sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT);
  p4est_init (NULL, SC_LP_DEFAULT);

  /* create forest and refine */
#ifndef P4_TO_P8
  connectivity = p4est_connectivity_new_star ();
#else
  connectivity = p8est_connectivity_new_rotcubes ();
#endif
  p4est = p4est_new_ext (mpicomm, connectivity, 0, 0, 0, 0, NULL, NULL);
  p4est_refine (p4est, 1, refine_fn, NULL);

  /* test face balance */
  p4estF = p4est_copy (p4est, 0);
#ifndef P4_TO_P8
  p4est_balance (p4estF, P4EST_CONNECT_FACE, NULL);
#else
  p4est_balance (p4estF, P8EST_CONNECT_FACE, NULL);
#endif
  crcF = p4est_checksum (p4estF);
  P4EST_GLOBAL_INFOF ("Face balance with %lld quadrants and crc 0x%08x\n",
                      (long long) p4estF->global_num_quadrants, crcF);

#ifdef P4_TO_P8
  /* test edge balance */
  p4estE = p4est_copy (p4est, 1);
  p4est_balance (p4estF, P8EST_CONNECT_EDGE, NULL);
  p4est_balance (p4estE, P8EST_CONNECT_EDGE, NULL);
  crcE = p4est_checksum (p4estE);
  SC_CHECK_ABORT (crcE == p4est_checksum (p4estF), "mismatch A");
  P4EST_GLOBAL_INFOF ("Edge balance with %lld quadrants and crc 0x%08x\n",
                      (long long) p4estE->global_num_quadrants, crcE);
#endif

  /* test corner balance */
  p4estC = p4est_copy (p4est, 1);
#ifndef P4_TO_P8
  p4est_balance (p4estF, P4EST_CONNECT_CORNER, NULL);
  p4est_balance (p4estC, P4EST_CONNECT_CORNER, NULL);
#else
  p4est_balance (p4estF, P8EST_CONNECT_CORNER, NULL);
  p4est_balance (p4estC, P8EST_CONNECT_CORNER, NULL);
#endif
  crcC = p4est_checksum (p4estC);
  SC_CHECK_ABORT (crcC == p4est_checksum (p4estF), "mismatch B");
  P4EST_GLOBAL_INFOF ("Corner balance with %lld quadrants and crc 0x%08x\n",
                      (long long) p4estC->global_num_quadrants, crcC);

  /* destroy forests and connectivity */
  p4est_destroy (p4est);
  p4est_destroy (p4estF);
#ifdef P4_TO_P8
  p4est_destroy (p4estE);
#endif
  p4est_destroy (p4estC);
  p4est_connectivity_destroy (connectivity);

  /* clean up and exit */
  sc_finalize ();

  mpiret = sc_MPI_Finalize ();
  SC_CHECK_MPI (mpiret);

  return 0;
}
示例#8
0
int
main (int argc, char **argv)
{
  int                 rank;
  int                 mpiret;
  sc_MPI_Comm         mpicomm;
  p4est_t            *p4est;
  p4est_connectivity_t *connectivity;

  mpiret = sc_MPI_Init (&argc, &argv);
  SC_CHECK_MPI (mpiret);
  mpicomm = sc_MPI_COMM_WORLD;
  mpiret = sc_MPI_Comm_rank (mpicomm, &rank);
  SC_CHECK_MPI (mpiret);

  sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT);
  p4est_init (NULL, SC_LP_DEFAULT);

  /* create connectivity and forest structures */
  connectivity = p4est_connectivity_new_star ();
  p4est = p4est_new_ext (mpicomm, connectivity, 15, 0, 0,
                         sizeof (user_data_t), init_fn, NULL);

  /* refine to make the number of elements interesting */
  p4est_refine (p4est, 1, refine_fn, init_fn);

  /* balance the forest */
  p4est_balance (p4est, P4EST_CONNECT_FULL, init_fn);

  /* do a uniform partition, include the weight function for testing */
  p4est_partition (p4est, 0, weight_one);

  p4est_check_local_order (p4est, connectivity);

  /* do a weighted partition with many zero weights */
  weight_counter = 0;
  weight_index = (rank == 1) ? 1342 : 0;
  p4est_partition (p4est, 0, weight_once);

  p4est_check_local_order (p4est, connectivity);

  /* clean up */
  p4est_destroy (p4est);
  p4est_connectivity_destroy (connectivity);

  /* create connectivity and forest structures */
  connectivity = p4est_connectivity_new_periodic ();
  p4est = p4est_new_ext (mpicomm, connectivity, 15, 0, 0,
                         sizeof (user_data_t), init_fn, NULL);

  /* refine to make the number of elements interesting */
  p4est_refine (p4est, 1, refine_fn, init_fn);

  /* balance the forest */
  p4est_balance (p4est, P4EST_CONNECT_FULL, init_fn);

  /* do a uniform partition, include the weight function for testing */
  p4est_partition (p4est, 0, weight_one);

  p4est_check_local_order (p4est, connectivity);

  /* clean up and exit */
  p4est_destroy (p4est);
  p4est_connectivity_destroy (connectivity);
  sc_finalize ();

  mpiret = sc_MPI_Finalize ();
  SC_CHECK_MPI (mpiret);

  return 0;
}
示例#9
0
int
main (int argc, char **argv)
{
  sc_MPI_Comm         mpicomm;
  int                 mpiret;
  int                 found_total;
  p4est_locidx_t      jt, Al, Bl;
  p4est_locidx_t      local_count;
  p4est_connectivity_t *conn;
  p4est_quadrant_t   *A, *B;
  p4est_geometry_t   *geom;
  p4est_t            *p4est;
  sc_array_t         *points;
  test_point_t       *p;
  const char         *vtkname;

  /* Initialize MPI */
  mpiret = sc_MPI_Init (&argc, &argv);
  SC_CHECK_MPI (mpiret);
  mpicomm = sc_MPI_COMM_WORLD;

  /* Initialize packages */
  sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT);
  p4est_init (NULL, SC_LP_DEFAULT);

  /* Create forest */
#ifndef P4_TO_P8
  conn = p4est_connectivity_new_star ();
  geom = NULL;
  vtkname = "test_search2";
#else
  conn = p8est_connectivity_new_sphere ();
  geom = p8est_geometry_new_sphere (conn, 1., 0.191728, 0.039856);
  vtkname = "test_search3";
#endif
  p4est = p4est_new_ext (mpicomm, conn, 0, 0, 0, 0, NULL, &local_count);
  p4est_refine (p4est, 1, refine_fn, NULL);
  p4est_partition (p4est, 0, NULL);
  p4est_vtk_write_file (p4est, geom, vtkname);

  /* The following code should really be in a separate function. */

  /* Prepare a point search -- fix size so the memory is not relocated */
  points = sc_array_new_size (sizeof (test_point_t), 2);

  /* A */
  p = (test_point_t *) sc_array_index (points, 0);
  p->name = "A";
  A = &p->quad;
  P4EST_QUADRANT_INIT (A);
  p4est_quadrant_set_morton (A, 3, 23);
  A->p.piggy3.which_tree = 0;
  A->p.piggy3.local_num = -1;
  Al = -1;

  /* B */
  p = (test_point_t *) sc_array_index (points, 1);
  p->name = "B";
  B = &p->quad;
  P4EST_QUADRANT_INIT (B);
  p4est_quadrant_set_morton (B, 2, 13);
  B->p.piggy3.which_tree = conn->num_trees / 2;
  B->p.piggy3.local_num = -1;
  Bl = -1;

  /* Find quadrant numbers if existing */
  for (jt = p4est->first_local_tree; jt <= p4est->last_local_tree; ++jt) {
    size_t              zz;
    p4est_tree_t       *tree = p4est_tree_array_index (p4est->trees, jt);
    p4est_quadrant_t   *quad;
    sc_array_t         *tquadrants = &tree->quadrants;

    for (zz = 0; zz < tquadrants->elem_count; ++zz) {
      quad = p4est_quadrant_array_index (tquadrants, zz);
      if (A->p.piggy3.which_tree == jt && !p4est_quadrant_compare (quad, A)) {
        Al = tree->quadrants_offset + (p4est_locidx_t) zz;
        P4EST_VERBOSEF ("Searching for A at %lld\n", (long long) Al);
      }
      if (B->p.piggy3.which_tree == jt && !p4est_quadrant_compare (quad, B)) {
        Bl = tree->quadrants_offset + (p4est_locidx_t) zz;
        P4EST_VERBOSEF ("Searching for B at %lld\n", (long long) Bl);
      }
    }
  }

  /* Go */
  found_count = 0;
  p4est_search_local (p4est, 0, NULL, search_callback, points);
  mpiret = sc_MPI_Allreduce (&found_count, &found_total,
                             1, sc_MPI_INT, sc_MPI_SUM, mpicomm);
  SC_CHECK_MPI (mpiret);
  SC_CHECK_ABORT (found_total == (int) points->elem_count, "Point search");
  SC_CHECK_ABORT (A->p.piggy3.local_num == Al, "Search A");
  SC_CHECK_ABORT (B->p.piggy3.local_num == Bl, "Search B");

  /* Use another search to count local quadrants */
  local_count = 0;
  p4est_search_local (p4est, 0, count_callback, NULL, NULL);
  SC_CHECK_ABORT (local_count == p4est->local_num_quadrants, "Count search");

  /* Clear memory */
  sc_array_destroy (points);
  p4est_destroy (p4est);
  if (geom != NULL) {
    p4est_geometry_destroy (geom);
  }
  p4est_connectivity_destroy (conn);

  /* Test the build_local function and friends */
  test_build_local (mpicomm);

  /* Finalize */
  sc_finalize ();
  mpiret = sc_MPI_Finalize ();
  SC_CHECK_MPI (mpiret);

  return 0;
}
示例#10
0
文件: mesh2.c 项目: holke/p4est
int
main (int argc, char **argv)
{
  int                 mpiret;
  int                 wrongusage;
  const char         *usage;
  mpi_context_t       mpi_context, *mpi = &mpi_context;
  p4est_connectivity_t *connectivity;
  simple_config_t     config;

  /* initialize MPI and p4est internals */
  mpiret = sc_MPI_Init (&argc, &argv);
  SC_CHECK_MPI (mpiret);
  mpi->mpicomm = sc_MPI_COMM_WORLD;
  mpiret = sc_MPI_Comm_size (mpi->mpicomm, &mpi->mpisize);
  SC_CHECK_MPI (mpiret);
  mpiret = sc_MPI_Comm_rank (mpi->mpicomm, &mpi->mpirank);
  SC_CHECK_MPI (mpiret);

  sc_init (mpi->mpicomm, 1, 1, NULL, SC_LP_DEFAULT);
  p4est_init (NULL, SC_LP_DEFAULT);

  /* process command line arguments */
  usage =
    "Arguments: <configuration> <level>\n   Configuration can be any of\n"
#ifndef P4_TO_P8
    "      unit|three|moebius|star|periodic|rotwrap|cubed|disk\n"
#else
    "      unit|periodic|rotwrap|twocubes|twowrap|rotcubes|shell|sphere\n"
#endif
    "   Level controls the maximum depth of refinement\n";
  wrongusage = 0;
  config = P4EST_CONFIG_NULL;
  if (!wrongusage && argc != 3) {
    wrongusage = 1;
  }
  if (!wrongusage) {
    if (!strcmp (argv[1], "unit")) {
#ifndef P4_TO_P8
      config = P4EST_CONFIG_UNIT;
#else
      config = P8EST_CONFIG_UNIT;
#endif
    }
#ifndef P4_TO_P8
    else if (!strcmp (argv[1], "three")) {
      config = P4EST_CONFIG_THREE;
    }
    else if (!strcmp (argv[1], "moebius")) {
      config = P4EST_CONFIG_MOEBIUS;
    }
    else if (!strcmp (argv[1], "star")) {
      config = P4EST_CONFIG_STAR;
    }
    else if (!strcmp (argv[1], "periodic")) {
      config = P4EST_CONFIG_PERIODIC;
    }
    else if (!strcmp (argv[1], "rotwrap")) {
      config = P4EST_CONFIG_ROTWRAP;
    }
    else if (!strcmp (argv[1], "cubed")) {
      config = P4EST_CONFIG_CUBED;
    }
    else if (!strcmp (argv[1], "disk")) {
      config = P4EST_CONFIG_DISK;
    }
#else
    else if (!strcmp (argv[1], "periodic")) {
      config = P8EST_CONFIG_PERIODIC;
    }
    else if (!strcmp (argv[1], "rotwrap")) {
      config = P8EST_CONFIG_ROTWRAP;
    }
    else if (!strcmp (argv[1], "twocubes")) {
      config = P8EST_CONFIG_TWOCUBES;
    }
    else if (!strcmp (argv[1], "twowrap")) {
      config = P8EST_CONFIG_TWOWRAP;
    }
    else if (!strcmp (argv[1], "rotcubes")) {
      config = P8EST_CONFIG_ROTCUBES;
    }
    else if (!strcmp (argv[1], "shell")) {
      config = P8EST_CONFIG_SHELL;
    }
    else if (!strcmp (argv[1], "sphere")) {
      config = P8EST_CONFIG_SPHERE;
    }
#endif
    else {
      wrongusage = 1;
    }
  }
  if (wrongusage) {
    P4EST_GLOBAL_LERROR (usage);
    sc_abort_collective ("Usage error");
  }

  /* assign variables based on configuration */
  refine_level = atoi (argv[2]);

  /* create connectivity and forest structures */
  if (0) {
  }
#ifndef P4_TO_P8
  else if (config == P4EST_CONFIG_THREE) {
    connectivity = p4est_connectivity_new_corner ();
  }
  else if (config == P4EST_CONFIG_MOEBIUS) {
    connectivity = p4est_connectivity_new_moebius ();
  }
  else if (config == P4EST_CONFIG_STAR) {
    connectivity = p4est_connectivity_new_star ();
  }
  else if (config == P4EST_CONFIG_PERIODIC) {
    connectivity = p4est_connectivity_new_periodic ();
  }
  else if (config == P4EST_CONFIG_ROTWRAP) {
    connectivity = p4est_connectivity_new_rotwrap ();
  }
  else if (config == P4EST_CONFIG_CUBED) {
    connectivity = p4est_connectivity_new_cubed ();
  }
  else if (config == P4EST_CONFIG_DISK) {
    connectivity = p4est_connectivity_new_disk ();
  }
#else
  else if (config == P8EST_CONFIG_PERIODIC) {
    connectivity = p8est_connectivity_new_periodic ();
  }
  else if (config == P8EST_CONFIG_ROTWRAP) {
    connectivity = p8est_connectivity_new_rotwrap ();
  }
  else if (config == P8EST_CONFIG_TWOCUBES) {
    connectivity = p8est_connectivity_new_twocubes ();
  }
  else if (config == P8EST_CONFIG_TWOWRAP) {
    connectivity = p8est_connectivity_new_twowrap ();
  }
  else if (config == P8EST_CONFIG_ROTCUBES) {
    connectivity = p8est_connectivity_new_rotcubes ();
  }
  else if (config == P8EST_CONFIG_SHELL) {
    connectivity = p8est_connectivity_new_shell ();
  }
  else if (config == P8EST_CONFIG_SPHERE) {
    connectivity = p8est_connectivity_new_sphere ();
  }
#endif
  else {
#ifndef P4_TO_P8
    connectivity = p4est_connectivity_new_unitsquare ();
#else
    connectivity = p8est_connectivity_new_unitcube ();
#endif
  }

#if 0
  /* hack test */
  hack_test (mpi, connectivity);
#else
  /* run mesh tests */
  mesh_run (mpi, connectivity, 1, 0, 1, P4EST_CONNECT_FULL);
  mesh_run (mpi, connectivity, 0, 1, 0, P4EST_CONNECT_FULL);
  mesh_run (mpi, connectivity, 0, 0, 0, P4EST_CONNECT_FACE);
  mesh_run (mpi, connectivity, 1, 1, 1, P4EST_CONNECT_FACE);
#endif

  /* clean up and exit */
  p4est_connectivity_destroy (connectivity);
  sc_finalize ();

  mpiret = sc_MPI_Finalize ();
  SC_CHECK_MPI (mpiret);

  return 0;
}
示例#11
0
int
main (int argc, char **argv)
{
  sc_MPI_Comm         mpicomm;
  int                 mpiret;
  int                 mpirank;
  int                 first_arg;
  const char         *prefix;
  p4est_connectivity_t *connectivity;
  sc_options_t       *opt;

  /* initialize MPI */
  mpiret = sc_MPI_Init (&argc, &argv);
  SC_CHECK_MPI (mpiret);
  mpicomm = sc_MPI_COMM_WORLD;
  mpiret = sc_MPI_Comm_rank (mpicomm, &mpirank);
  SC_CHECK_MPI (mpiret);

  /* initialize libsc and p4est */
  sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT);
  p4est_init (NULL, SC_LP_DEFAULT);

  /* handle command line options */
  opt = sc_options_new (argv[0]);
  sc_options_add_int (opt, 'l', "level", &refine_level,
                      default_refine_level, "Refinement level");
  sc_options_add_string (opt, 'o', "oprefix", &prefix,
                         P4EST_STRING, "Output prefix");
  first_arg = sc_options_parse (p4est_package_id, SC_LP_INFO,
                                opt, argc, argv);
  SC_CHECK_ABORT (first_arg >= 0, "Option error");

  /* create connectivity */
#ifndef P4_TO_P8
  connectivity = p4est_connectivity_new_star ();
#else
  connectivity = p8est_connectivity_new_rotcubes ();
#endif

  /* test with vertex information */
  test_loadsave (connectivity, prefix, mpicomm, mpirank);

  /* test without vertex information */
  connectivity->num_vertices = 0;
  P4EST_FREE (connectivity->vertices);
  connectivity->vertices = NULL;
  P4EST_FREE (connectivity->tree_to_vertex);
  connectivity->tree_to_vertex = NULL;
  p4est_connectivity_set_attr (connectivity, 1);
  memset (connectivity->tree_to_attr, 0,
          connectivity->num_trees * sizeof (int8_t));
  test_loadsave (connectivity, prefix, mpicomm, mpirank);

  /* clean up and exit */
  p4est_connectivity_destroy (connectivity);
  sc_options_destroy (opt);
  sc_finalize ();

  mpiret = sc_MPI_Finalize ();
  SC_CHECK_MPI (mpiret);

  return 0;
}