Exemplo n.º 1
0
Arquivo: mesh2.c Projeto: holke/p4est
static void
hack_test (mpi_context_t * mpi, p4est_connectivity_t * connectivity)
{
  int                 i;
  int8_t              cc;
  p4est_topidx_t      tt;
  p4est_locidx_t      lnq, lng, lnc, lnco;
  p4est_locidx_t      li, qtc;
  p4est_locidx_t      co0, co1, coi, cq;
  p4est_t            *p4est;
  p4est_ghost_t      *ghost;
  p4est_mesh_t       *mesh;

  p4est = p4est_new_ext (mpi->mpicomm, connectivity, 0,
                         refine_level, 1, 0, NULL, NULL);
  p4est_vtk_write_file (p4est, NULL, "mesh_hack");

  ghost = p4est_ghost_new (p4est, P4EST_CONNECT_FULL);
  mesh = p4est_mesh_new_ext (p4est, ghost, 1, 1, P4EST_CONNECT_FULL);

  lnq = mesh->local_num_quadrants;
  lng = mesh->ghost_num_quadrants;
  lnco = lnq + lng;
  lnc = mesh->local_num_corners;
  P4EST_LDEBUGF ("Local quads %lld corners %lld array %lld\n",
                 (long long) lnq, (long long) lnc,
                 (long long) mesh->corner_offset->elem_count);
  for (li = 0; li < lnq; ++li) {
    tt = mesh->quad_to_tree[li];
    if (tt >= 2) {
      /* break; */
    }
    for (i = 0; i < P4EST_CHILDREN; ++i) {
      qtc = mesh->quad_to_corner[P4EST_CHILDREN * li + i];
      if (qtc >= lnco) {
        P4EST_LDEBUGF ("Quad %lld tree %lld Corner %d is %lld\n",
                       (long long) li, (long long) tt, i, (long long) qtc);
        if (qtc >= lnco) {
          qtc -= lnco;
          co0 = *(p4est_locidx_t *) sc_array_index (mesh->corner_offset, qtc);
          co1 =
            *(p4est_locidx_t *) sc_array_index (mesh->corner_offset, qtc + 1);
          for (coi = co0; coi < co1; ++coi) {
            cq = *(p4est_locidx_t *) sc_array_index (mesh->corner_quad, coi);
            cc = *(int8_t *) sc_array_index (mesh->corner_corner, coi);
            P4EST_LDEBUGF ("   Part %d quad %lld corner %d\n",
                           (int) (coi - co0), (long long) cq, (int) cc);
          }
        }
      }
    }
  }

  p4est_mesh_destroy (mesh);
  p4est_ghost_destroy (ghost);
  p4est_destroy (p4est);
}
Exemplo n.º 2
0
static int
search_callback (p4est_t * p4est, p4est_topidx_t which_tree,
                 p4est_quadrant_t * quadrant, p4est_locidx_t local_num,
                 void *point)
{
  test_point_t       *p = (test_point_t *) point;
  int                 is_leaf;
  int                 is_match;

  is_leaf = local_num >= 0;
  P4EST_ASSERT (!is_leaf || local_num < p4est->local_num_quadrants);
  P4EST_ASSERT (point != NULL);

  P4EST_LDEBUGF ("Tree %lld quadrant %s level %d %d child %d leaf %d\n",
                 (long long) which_tree, p->name,
                 (int) p->quad.level, (int) quadrant->level,
                 p4est_quadrant_child_id (quadrant), is_leaf);

  if (which_tree != p->quad.p.piggy3.which_tree) {
    return 0;
  }

  if (quadrant->level < p->quad.level) {
    is_match = p4est_quadrant_is_ancestor (quadrant, &p->quad);
    P4EST_LDEBUGF ("Ancestor for quadrant %s is %d\n", p->name, is_match);
  }
  else {
    is_match = !p4est_quadrant_compare (quadrant, &p->quad);
    P4EST_LDEBUGF ("Tree %lld same size quadrant %s match %d\n",
                   (long long) which_tree, p->name, is_match);
  }

  if (is_match && is_leaf) {
    p4est_locidx_t      num = -1;

    if (quadrant->level < p->quad.level) {
      num = p->quad.p.piggy3.local_num = -1;
    }
    else {
      P4EST_ASSERT (local_num >= 0);
      num = p->quad.p.piggy3.local_num = local_num;
    }
    P4EST_INFOF ("Matched quadrant %s at %lld\n", p->name, (long long) num);
    p4est_quadrant_print (SC_LP_INFO, quadrant);
    p4est_quadrant_print (SC_LP_INFO, &p->quad);
    ++found_count;
  }

  return is_match;
}
Exemplo n.º 3
0
static void
p4est_build_verify_5 (p4est_t * p4est)
{
  test_build_t       *tb;

  tb = (test_build_t *) p4est->user_pointer;

  P4EST_LDEBUGF ("T5 added %d dup %d\n", tb->init_add, tb->init_default);
}
Exemplo n.º 4
0
int
main (int argc, char **argv)
{
  sc_MPI_Comm         mpicomm;
  int                 mpiret, retval;
  int                 level;
  const char         *filename;
  p4est_connectivity_t *conn;
  sc_options_t       *opt;

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

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

  opt = sc_options_new (argv[0]);
  sc_options_add_int (opt, 'l', "level", &level, 0,
                      "Upfront refinement level");
  retval = sc_options_parse (p4est_package_id, SC_LP_ERROR, opt, argc, argv);
  if (retval == -1 || retval + 1 != argc) {
    sc_options_print_usage (p4est_package_id, SC_LP_PRODUCTION, opt, NULL);
    sc_abort_collective ("Usage error");
  }
  filename = argv[retval];
  P4EST_LDEBUGF ("Loading %s\n", filename);
  conn = p4est_connectivity_load (filename, NULL);

  run_load (mpicomm, conn, level);

  p4est_connectivity_destroy (conn);
  sc_options_destroy (opt);

  sc_finalize ();

  mpiret = sc_MPI_Finalize ();
  SC_CHECK_MPI (mpiret);

  return 0;
}
Exemplo n.º 5
0
int
main (int argc, char **argv)
{
  int                 my_face, target_face, orientation;
  int                 face_ref, face_perm;
  int                 low[2], high[2], swap;
  int                 i, reverse;
  int                 ft[9], gt[9];
  int                *my_axis = &ft[0];
  int                *target_axis = &ft[3];
  int                *edge_reverse = &ft[6];

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

  for (my_face = 0; my_face < 2 * P4EST_DIM; ++my_face) {
    for (target_face = 0; target_face < 2 * P4EST_DIM; ++target_face) {
      for (orientation = 0; orientation < 4; ++orientation) {

        /* find if my edges 0 and 2 are parallel to the x, y, or z-axis */
        my_axis[0] = p8est_face_edges[my_face][0] / 4;
        my_axis[1] = p8est_face_edges[my_face][2] / 4;
        target_axis[0] = target_axis[1] = -1;
        edge_reverse[0] = edge_reverse[1] = 0;

        /* find matching target vertices */
        face_ref = p8est_face_permutation_refs[my_face][target_face];
        face_perm = p8est_face_permutation_sets[face_ref][orientation];
        low[0] = low[1] =
          p8est_face_corners[target_face][p8est_face_permutations[face_perm]
                                          [0]];
        high[0] =
          p8est_face_corners[target_face][p8est_face_permutations[face_perm]
                                          [1]];
        high[1] =
          p8est_face_corners[target_face][p8est_face_permutations[face_perm]
                                          [2]];
        if (low[0] > high[0]) {
          swap = low[0];
          low[0] = high[0];
          high[0] = swap;
          edge_reverse[0] = 1;
        }
        if (low[1] > high[1]) {
          swap = low[1];
          low[1] = high[1];
          high[1] = swap;
          edge_reverse[1] = 1;
        }

        /* find matching target edges */
        for (i = 0; i < 12; ++i) {
          if (low[0] == p8est_edge_corners[i][0] &&
              high[0] == p8est_edge_corners[i][1]) {
            P4EST_ASSERT (target_axis[0] == -1);
            target_axis[0] = i / 4;
#ifndef P4EST_ENABLE_DEBUG
            if (target_axis[1] >= 0)
              break;
#endif
          }
          else if (low[1] == p8est_edge_corners[i][0] &&
                   high[1] == p8est_edge_corners[i][1]) {
            P4EST_ASSERT (target_axis[1] == -1);
            target_axis[1] = i / 4;
#ifndef P4EST_ENABLE_DEBUG
            if (target_axis[0] >= 0)
              break;
#endif
          }
        }

        /* find what axis is normal to the faces */
        my_axis[2] = my_face / 2;
        target_axis[2] = target_face / 2;
        edge_reverse[2] = 2 * (my_face % 2) + target_face % 2;

#ifdef P4EST_ENABLE_DEBUG
        for (i = 0; i < 3; ++i) {
          P4EST_ASSERT (0 <= my_axis[i] && my_axis[i] < 3);
          P4EST_ASSERT (0 <= target_axis[i] && target_axis[i] < 3);
        }
        P4EST_ASSERT (my_axis[0] != my_axis[1] &&
                      my_axis[0] != my_axis[2] && my_axis[1] != my_axis[2]);
        P4EST_ASSERT (target_axis[0] != target_axis[1] &&
                      target_axis[0] != target_axis[2] &&
                      target_axis[1] != target_axis[2]);
#endif

        /* output the results */
        P4EST_LDEBUGF
          ("Results for %d %d %d are %d %d %d %d %d %d %d %d %d\n",
           my_face, target_face, orientation, ft[0], ft[1], ft[2],
           ft[3], ft[4], ft[5], ft[6], ft[7], ft[8]);

        /* compute the transformation code in a faster way and compare */
        gt[0] = my_face < 2 ? 1 : 0;
        gt[1] = my_face < 4 ? 2 : 1;
        gt[2] = my_face / 2;
        reverse =
          p8est_face_permutation_refs[0][my_face] ^
          p8est_face_permutation_refs[0][target_face] ^
          (orientation == 0 || orientation == 3);
        gt[3 + reverse] = target_face < 2 ? 1 : 0;
        gt[3 + !reverse] = target_face < 4 ? 2 : 1;
        gt[5] = target_face / 2;
        reverse = p8est_face_permutation_refs[my_face][target_face] == 1;
        gt[6 + reverse] = orientation % 2;
        gt[6 + !reverse] = orientation / 2;
        gt[8] = 2 * (my_face % 2) + target_face % 2;

        /* ensure that both computations yield the same result */
        SC_CHECK_ABORT (!memcmp (ft, gt, 9 * sizeof (int)), "Mismatch");
      }
    }
  }

  sc_finalize ();

  return 0;
}