Пример #1
0
/*
 * Purpose of this program is to verify that
 * p8est_find_edge_transform and p8est_find_corner_transform
 * work as expected for several periodic connectivities.
 */
int
main (int argc, char **argv)
{
  p8est_connectivity_t *conn;

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

  conn = p8est_connectivity_new_periodic ();
  test_periodic (conn);
  p8est_connectivity_destroy (conn);

  conn = p8est_connectivity_new_rotwrap ();
  test_rotwrap (conn);
  p8est_connectivity_destroy (conn);

  test_weird ();

  sc_finalize ();

  return 0;
}
Пример #2
0
int
main (int argc, char **argv)
{
  int                 mpiret;
  int                 wrongusage;
  unsigned            crc;
  const char         *usage;
  mpi_context_t       mpi_context, *mpi = &mpi_context;
  p8est_t            *p8est;
  p8est_connectivity_t *connectivity;
  p8est_geometry_t   *geom;
  p8est_refine_t      refine_fn;
  p8est_coarsen_t     coarsen_fn;
  simple_config_t     config;
  const simple_regression_t *r;

  /* initialize MPI and p4est internals */
  mpiret = MPI_Init (&argc, &argv);
  SC_CHECK_MPI (mpiret);
  mpi->mpicomm = MPI_COMM_WORLD;
  mpiret = MPI_Comm_size (mpi->mpicomm, &mpi->mpisize);
  SC_CHECK_MPI (mpiret);
  mpiret = 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"
    "      unit|periodic|rotwrap|twocubes|twowrap|rotcubes|shell|sphere\n"
    "   Level controls the maximum depth of refinement\n";
  wrongusage = 0;
  config = P8EST_CONFIG_NULL;
  if (!wrongusage && argc != 3) {
    wrongusage = 1;
  }
  if (!wrongusage) {
    if (!strcmp (argv[1], "unit")) {
      config = P8EST_CONFIG_UNIT;
    }
    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;
    }
    else {
      wrongusage = 1;
    }
  }
  if (wrongusage) {
    P4EST_GLOBAL_LERROR (usage);
    sc_abort_collective ("Usage error");
  }

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

  /* create connectivity and forest structures */
  geom = NULL;
  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 ();
    refine_fn = refine_sparse_fn;
  }
  else if (config == P8EST_CONFIG_TWOWRAP) {
    connectivity = p8est_connectivity_new_twowrap ();
    refine_fn = refine_sparse_fn;
  }
  else if (config == P8EST_CONFIG_ROTCUBES) {
    connectivity = p8est_connectivity_new_rotcubes ();
  }
  else if (config == P8EST_CONFIG_SHELL) {
    connectivity = p8est_connectivity_new_shell ();
    geom = p8est_geometry_new_shell (1., .55);
  }
  else if (config == P8EST_CONFIG_SPHERE) {
    connectivity = p8est_connectivity_new_sphere ();
    geom = p8est_geometry_new_sphere (1., 0.191728, 0.039856);
  }
  else {
    connectivity = p8est_connectivity_new_unitcube ();
  }
  p8est = p8est_new_ext (mpi->mpicomm, connectivity, 1, 0, 0,
                         sizeof (user_data_t), init_fn, NULL);

#ifdef VTK_OUTPUT
  p8est_vtk_write_file (p8est, geom, "simple3_new");
#endif

  /* refinement and coarsening */
  p8est_refine (p8est, 1, refine_fn, init_fn);
  if (coarsen_fn != NULL) {
    p8est_coarsen (p8est, 1, coarsen_fn, init_fn);
  }
#ifdef VTK_OUTPUT
  p8est_vtk_write_file (p8est, geom, "simple3_refined");
#endif

  /* balance */
  p8est_balance (p8est, P8EST_CONNECT_FULL, init_fn);
#ifdef VTK_OUTPUT
  p8est_vtk_write_file (p8est, geom, "simple3_balanced");
#endif

  crc = p8est_checksum (p8est);

  /* partition */
  p8est_partition (p8est, NULL);
#ifdef VTK_OUTPUT
  p8est_vtk_write_file (p8est, geom, "simple3_partition");
#endif

#ifdef P4EST_DEBUG
  /* rebalance should not change checksum */
  p8est_balance (p8est, P8EST_CONNECT_FULL, init_fn);
  P4EST_ASSERT (p8est_checksum (p8est) == crc);
#endif

  /* print and verify forest checksum */
  P4EST_GLOBAL_STATISTICSF ("Tree checksum 0x%08x\n", crc);
  if (mpi->mpirank == 0) {
    for (r = regression; r->config != P8EST_CONFIG_NULL; ++r) {
      if (r->config != config || r->mpisize != mpi->mpisize
          || r->level != refine_level)
        continue;
      SC_CHECK_ABORT (crc == r->checksum, "Checksum mismatch");
      P4EST_GLOBAL_INFO ("Checksum regression OK\n");
      break;
    }
  }

  /* destroy the p8est and its connectivity structure */
  p8est_destroy (p8est);
  P4EST_FREE (geom);
  p8est_connectivity_destroy (connectivity);

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

  mpiret = MPI_Finalize ();
  SC_CHECK_MPI (mpiret);

  return 0;
}
Пример #3
0
static void
test_weird (void)
{
  const p4est_topidx_t num_edges = 1, num_ett = 2;
  const p4est_topidx_t num_corners = 1, num_ctt = 4;
  int                 i;
  size_t              zz;
  p8est_edge_info_t   ei;
  p8est_edge_transform_t *et;
  p8est_corner_info_t ci;
  p8est_corner_transform_t *ct;
  sc_array_t         *eta, *cta;
  p8est_connectivity_t *conn;

  conn = p8est_connectivity_new (0, 1,
                                 num_edges, num_ett, num_corners, num_ctt);
  for (i = 0; i < 6; ++i) {
    conn->tree_to_tree[i] = 0;
    conn->tree_to_face[i] = (int8_t) i;
  }
  conn->tree_to_face[4] = 5;
  conn->tree_to_face[5] = 4;

  for (i = 0; i < 12; ++i) {
    conn->tree_to_edge[i] = -1;
  }
  conn->tree_to_edge[5] = 0;
  conn->tree_to_edge[7] = 0;
  conn->edge_to_tree[0] = 0;
  conn->edge_to_tree[1] = 0;
  conn->edge_to_edge[0] = 5;
  conn->edge_to_edge[1] = 19;
  conn->ett_offset[0] = 0;

  for (i = 0; i < 8; ++i) {
    conn->tree_to_corner[i] = -1;
  }
  conn->tree_to_corner[0] = 0;
  conn->tree_to_corner[1] = 0;
  conn->tree_to_corner[4] = 0;
  conn->tree_to_corner[5] = 0;
  conn->corner_to_tree[0] = 0;
  conn->corner_to_tree[1] = 0;
  conn->corner_to_tree[2] = 0;
  conn->corner_to_tree[3] = 0;
  conn->corner_to_corner[0] = 0;
  conn->corner_to_corner[1] = 1;
  conn->corner_to_corner[2] = 4;
  conn->corner_to_corner[3] = 5;
  conn->ctt_offset[0] = 0;

  P4EST_ASSERT (p8est_connectivity_is_valid (conn));

  eta = &ei.edge_transforms;
  sc_array_init (eta, sizeof (p8est_edge_transform_t));
  for (i = 0; i < 2; ++i) {
    p8est_find_edge_transform (conn, 0, weird_edges[i][0], &ei);
    SC_CHECK_ABORT ((int) ei.iedge == weird_edges[i][0], "WE ei");
    SC_CHECK_ABORT (eta->elem_count == 1, "WE count A");
    for (zz = 0; zz < eta->elem_count; ++zz) {
      et = p8est_edge_array_index (eta, zz);
      SC_CHECK_ABORT (et->ntree == 0, "WE tree");
      SC_CHECK_ABORT ((int) et->nedge == weird_edges[i][1], "WE edge");
      SC_CHECK_ABORT (et->nflip == 1, "WE flip");
      SC_CHECK_ABORT (et->corners == et->nedge % 4, "WE corners");
      SC_CHECK_ABORT (et->naxis[0] == 1 && et->naxis[1] == 0 &&
                      et->naxis[2] == 2, "WE axis");
    }
  }
  sc_array_reset (eta);

  cta = &ci.corner_transforms;
  sc_array_init (cta, sizeof (p8est_corner_transform_t));
  for (i = 0; i < 8; ++i) {
    p8est_find_corner_transform (conn, 0, i, &ci);
    SC_CHECK_ABORT ((int) ci.icorner == i, "WC ci");
    SC_CHECK_ABORT ((int) cta->elem_count == 2 - (i & 0x02), "WC count");
    for (zz = 0; zz < cta->elem_count; ++zz) {
      ct = p8est_corner_array_index (cta, zz);
      SC_CHECK_ABORT (ct->ntree == 0, "WC tree");
      SC_CHECK_ABORT ((size_t) ct->ncorner == 4 * zz + !(i % 2), "WC corner");
    }
  }
  sc_array_reset (cta);

  p8est_connectivity_destroy (conn);
}
Пример #4
0
int
main (int argc, char **argv)
{
  int                 mpiret, retval;
  int                 mpirank;
  const char         *argbasename;
  char                afilename[BUFSIZ];
  p4est_topidx_t      tnum_flips;
  p8est_tets_t       *ptg;
  p8est_connectivity_t *connectivity;
  p8est_t            *p8est;
  MPI_Comm            mpicomm;

  mpiret = MPI_Init (&argc, &argv);
  SC_CHECK_MPI (mpiret);
  mpicomm = MPI_COMM_WORLD;
  mpiret = MPI_Comm_rank (mpicomm, &mpirank);

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

  if (argc != 2) {
    SC_GLOBAL_LERRORF ("Usage: %s <tetgen file base name>\n", argv[0]);
    sc_abort ();
  }
  argbasename = argv[1];

  /* read tetgen nodes and tetrahedra from files */
  ptg = p8est_tets_read (argbasename);
  SC_CHECK_ABORTF (ptg != NULL, "Failed to read tetgen %s", argbasename);
  P4EST_GLOBAL_STATISTICSF ("Read %d nodes and %d tets %s attributes\n",
                            (int) ptg->nodes->elem_count / 3,
                            (int) ptg->tets->elem_count / 4,
                            ptg->tet_attributes != NULL ? "with" : "without");

  /* flip orientation to right-handed */
  tnum_flips = p8est_tets_make_righthanded (ptg);
  P4EST_GLOBAL_STATISTICSF ("Performed %ld orientation flip(s)\n",
                            (long) tnum_flips);

  /* create a connectivity from the tet mesh and save it */
  connectivity = p8est_connectivity_new_tets (ptg);
  if (mpirank == 0) {
    snprintf (afilename, BUFSIZ, "%s", "read_tetgen.p8c");
    retval = p8est_connectivity_save (afilename, connectivity);
    SC_CHECK_ABORT (retval == 0, "Failed connectivity_save");
  }

  /* create a forest and visualize */
  p8est = p8est_new (mpicomm, connectivity, 0, NULL, NULL);
  snprintf (afilename, BUFSIZ, "%s", "read_tetgen");
  p8est_vtk_write_file (p8est, NULL, afilename);

  /* clean up */
  p8est_destroy (p8est);
  p8est_connectivity_destroy (connectivity);
  p8est_tets_destroy (ptg);

  sc_finalize ();
  mpiret = MPI_Finalize ();
  SC_CHECK_MPI (mpiret);

  return 0;
}