Esempio n. 1
0
/**
 * aran_solver3d_solve:
 * @solver: an #AranSolver3d.
 *
 * Solves the FMM problem for @solver.
 */
void aran_solver3d_solve (AranSolver3d *solver)
{
  g_return_if_fail (solver != NULL);

  /* clear multipole and local developments before the big work */
  vsg_prtree3d_traverse (solver->prtree, G_POST_ORDER,
                         (VsgPRTree3dFunc) clear_func,
                         solver);

  /* gather information in Multipole development */
  vsg_prtree3d_traverse (solver->prtree, G_POST_ORDER,
                         (VsgPRTree3dFunc) up_func,
                         solver);

  /* transmit info from Multipole to Local developments */
  vsg_prtree3d_near_far_traversal (solver->prtree,
                                   (VsgPRTree3dInteractionFunc) far_func,
                                   (VsgPRTree3dInteractionFunc) near_func,
                                   solver);

  /* distribute information through Local developments towards particles */
  vsg_prtree3d_traverse (solver->prtree, G_PRE_ORDER,
                         (VsgPRTree3dFunc) down_func,
                         solver);
}
Esempio n. 2
0
static void _tree_write (VsgPRTree3d *tree, gchar *prefix)
{
  gchar fn[1024];
  FILE *f;
  gint np = vsg_prtree3d_point_count (tree);
  gint nn = 0;
  gint i;

  g_sprintf (fn, "%s%03d.vtp", prefix, rk);
  f = fopen (fn, "w");

  vsg_prtree3d_traverse (tree, G_PRE_ORDER,
                         (VsgPRTree3dFunc) _traverse_count_local_nodes,
                         &nn);

  fprintf (f, "<?xml version=\"1.0\" ?>\n" \
           "<VTKFile type=\"PolyData\" version=\"0.1\">\n" \
           "<PolyData>\n" \
           "<Piece NumberOfPoints=\"%d\" NumberOfVerts=\"%d\" " \
           "NumberOfLines=\"%d\" NumberOfStrips=\"0\" " \
           "NumberOfPolys=\"0\">\n",
           np + 6*nn, np, 3*nn);

  fprintf (f, "<Points>\n");
  fprintf (f, "<DataArray type=\"Float64\" NumberOfComponents=\"3\" " \
           "format=\"ascii\">\n");
  vsg_prtree3d_traverse (tree, G_PRE_ORDER,
                         (VsgPRTree3dFunc) _traverse_fg_write,
                         f);
  vsg_prtree3d_traverse (tree, G_PRE_ORDER,
                         (VsgPRTree3dFunc) _traverse_bg_write,
                         f);
  fprintf (f, "</DataArray>\n</Points>\n");

  fprintf (f, "<Verts>\n");
  fprintf (f, "<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n");
  for (i=0; i<np; i++) fprintf (f, "%d ", i);
  fprintf (f, "\n</DataArray>\n");
  fprintf (f, "<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\" >");
  for (i=0; i<np; i++) fprintf (f, "%d ", i+1);
  fprintf (f, "\n</DataArray>\n</Verts>\n");

  fprintf (f, "<Lines>\n");
  fprintf (f, "<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n");
  for (i=0; i<3*nn; i++) fprintf (f, "%d %d ", np + 2*i, np + 2*i+1);
  fprintf (f, "\n</DataArray>\n");
  fprintf (f, "<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\" >");
  for (i=0; i<3*nn; i++) fprintf (f, "%d ", 2*(i+1));
  fprintf (f, "\n</DataArray>\n</Lines>\n");



  fprintf (f, "\n</Piece>\n");
  fprintf (f, "</PolyData>\n</VTKFile>\n");
  fclose (f);

}
Esempio n. 3
0
static void _check_local_counts (VsgPRTree3d *tree)
{
  gint pcounts[2][64] = {{0}};

  vsg_prtree3d_traverse (tree, G_POST_ORDER,
                         (VsgPRTree3dFunc) _traverse_check_local_counts,
                         pcounts);
}
Esempio n. 4
0
/**
 * aran_solver3d_traverse:
 * @solver: an #AranSolver3d.
 * @func: traverse function.
 * @user_data: pointer to pass to @func.
 *
 * See vsg_prtree3d_traverse() in Vsg API docs.
 */
void aran_solver3d_traverse (AranSolver3d *solver,
                             GTraverseType order,
                             VsgPRTree3dFunc func,
                             gpointer user_data)
{
  g_return_if_fail (solver != NULL);

  vsg_prtree3d_traverse (solver->prtree, order, func, user_data);
}
Esempio n. 5
0
/**
 * aran_solver3d_solve:
 * @solver: an #AranSolver3d.
 *
 * Solves the FMM problem for @solver.
 */
void aran_solver3d_solve (AranSolver3d *solver)
{
  VsgPRTree3dFarInteractionFunc far;
  VsgPRTree3dInteractionFunc near;
  g_return_if_fail (solver != NULL);

  /*set interaction functions from solevr configuration */
  far = (VsgPRTree3dFarInteractionFunc)
    ((solver->m2l != NULL) ? far_func : nop_far_func);

  near = (VsgPRTree3dInteractionFunc)
    ((solver->p2p != NULL) ? near_func : nop_near_func);


  /* clear multipole and local developments before the big work */
  vsg_prtree3d_traverse (solver->prtree, G_POST_ORDER,
                         (VsgPRTree3dFunc) clear_func,
                         solver);

  /* gather information in Multipole development */
  vsg_prtree3d_traverse (solver->prtree, G_POST_ORDER,
                         (VsgPRTree3dFunc) up_func,
                         solver);

#ifdef VSG_HAVE_MPI
  /* gather shared in_counts */
  {
    VsgPRTreeParallelConfig pc;

    vsg_prtree3d_get_parallel (solver->prtree, &pc);
    vsg_prtree3d_shared_nodes_allreduce (solver->prtree,
                                         &pc.node_data.visit_forward);
  }
#endif /* VSG_HAVE_MPI */

  /* transmit info from Multipole to Local developments */
  vsg_prtree3d_near_far_traversal (solver->prtree, far, near, solver);

  /* distribute information through Local developments towards particles */
  vsg_prtree3d_traverse (solver->prtree, G_PRE_ORDER,
                         (VsgPRTree3dFunc) down_func,
                         solver);
}
Esempio n. 6
0
static void _write_regions (VsgPRTree3d *tree, gchar *prefix)
{
  gchar fn[1024];
  FILE *file;

  sprintf (fn, "%s%03d.txt", prefix, rk);
  file = fopen (fn, "w");

  vsg_prtree3d_traverse (tree, G_PRE_ORDER,
                         (VsgPRTree3dFunc) _traverse_rg_dump, file);

}
static void _tree_write (VsgPRTree3d *tree, gchar *prefix)
{
  gchar fn[1024];
  FILE *f;

  g_sprintf (fn, "%s%03d.txt", prefix, rk);
  f = fopen (fn, "w");

  vsg_prtree3d_traverse (tree, G_PRE_ORDER,
                         (VsgPRTree3dFunc) _traverse_fg_write,
                         f);
  fclose (f);

}
Esempio n. 8
0
static void _tree_write (VsgPRTree3d *tree)
{
  gchar fn[1024];
  FILE *f;
  gint np = vsg_prtree3d_point_count (tree);
  gint i;

  g_sprintf (fn, "prtree3parallel-%03d.vtp", rk);
  f = fopen (fn, "w");

  fprintf (f, "<?xml version=\"1.0\" ?>\n" \
           "<VTKFile type=\"PolyData\" version=\"0.1\">\n" \
           "<PolyData>\n" \
           "<Piece NumberOfPoints=\"%d\" NumberOfVerts=\"%d\" " \
           "NumberOfLines=\"0\" NumberOfStrips=\"0\" " \
           "NumberOfPolys=\"0\">\n",
           np, np);

/*   vsg_prtree3d_traverse (tree, G_PRE_ORDER, */
/*                          (VsgPRTree3dFunc) _traverse_bg_write, */
/*                          f); */

  fprintf (f, "<Points>\n");
  fprintf (f, "<DataArray type=\"Float64\" NumberOfComponents=\"3\" " \
           "format=\"ascii\">\n");
  vsg_prtree3d_traverse (tree, G_PRE_ORDER,
                         (VsgPRTree3dFunc) _traverse_fg_write,
                         f);
  fprintf (f, "</DataArray>\n</Points>\n");

  fprintf (f, "<Verts>\n");
  fprintf (f, "<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n");
  for (i=0; i<np; i++) fprintf (f, "%d ", i);
  fprintf (f, "\n</DataArray>\n");
  fprintf (f, "<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\" >");
  for (i=0; i<np; i++) fprintf (f, "%d ", i+1);
  fprintf (f, "\n</DataArray>\n</Verts>\n");
  fprintf (f, "\n</Piece>\n</PolyData>\n</VTKFile>\n");

  fclose (f);

}
Esempio n. 9
0
static gint check_points_number (VsgPRTree3d *tree)
{
  gint ret = 0;
  gint local_points = 0;
  gint total_points = 0;

  vsg_prtree3d_traverse (tree, G_PRE_ORDER,
                         (VsgPRTree3dFunc) _local_points_count, &local_points);

  MPI_Allreduce (&local_points, &total_points, 1, MPI_INT, MPI_SUM,
                 MPI_COMM_WORLD);

  if (total_points != reference_total_points)
    {
      g_printerr ("%d: total points mismatch : ref=%d verif=%d\n",
                  rk, reference_total_points, total_points);

      ret ++;
    }

  return ret;
}
Esempio n. 10
0
gint main (gint argc, gchar ** argv)
{
  gint ret = 0;

  VsgVector3d lb = {-1., -1., -1.};
  VsgVector3d ub = {1., 1., 1.};

  VsgVector3d points[] = {
    {-0.5, -0.5, -.5},
    {0.5, -0.5, -.5},
    {-0.5, 0.5, .5},
    {0.25, 0.25, .5},
    {0.75, 0.75, .5},
    {1.75, 1.75, 1.}, /* exterior point */
    {1.75, 100.75, 1.}, /* another exterior point */
    {1.75, -100.75, 1.}, /* another exterior point */
  };

  const guint n = sizeof (points) / sizeof (VsgVector3d);

  VsgPRTree3d *tree;
  gint i;

  if (argc > 1 && g_ascii_strncasecmp (argv[1], "--version", 9) == 0)
    {
      g_print ("%s\n", PACKAGE_VERSION);
      return 0;
    }

  vsg_init_gdouble ();

  /* create the tree */
  tree =
    vsg_prtree3d_new_full (&lb, &ub,
                           (VsgPoint3dLocFunc) vsg_vector3d_vector3d_locfunc,
                           (VsgPoint3dDistFunc) vsg_vector3d_dist,
                           NULL, 1);

  /* insert some points */
  for (i=0; i<n; i++)
    {
      vsg_prtree3d_insert_point (tree, &points[i]);
    }

  /* do some traversal */
  i=0;
  vsg_prtree3d_traverse (tree, G_PRE_ORDER,
                         (VsgPRTree3dFunc) traverse_point_count, &i);

  /* check the results */
  if (i != n)
    {
      g_printerr ("ERROR: traverse point count %d (should be %d)\n",
                  i, n);

      ret ++;
    }

  /* remove the points */
  for (i=0; i<n; i++)
    {
      vsg_prtree3d_remove_point (tree, &points[i]);
    }

  /* destroy the tree */
  vsg_prtree3d_free (tree);

  return ret;
}
Esempio n. 11
0
gint main (gint argc, gchar ** argv)
{
  gint ret = 0;

  VsgVector3d lb = {-1., -1., -1.};
  VsgVector3d ub = {1., 1., 1.};
  NodeCounter counter = {0, 0};
  const guint m = 100;
  const guint n = 1000;

  Pt points[m*n];

  VsgPRTree3d *tree;
  gint i;

  if (argc > 1 && g_strncasecmp (argv[1], "--version", 9) == 0)
    {
      g_print ("%s\n", PACKAGE_VERSION);
      return 0;
    }

  vsg_init_gdouble ();

  /* create the tree */
  tree = vsg_prtree3d_new (&lb, &ub, NULL);

  vsg_prtree3d_set_node_data (tree, TYPE_NODE_COUNTER, &counter);

  /* create the points */
  create_points (points, m, n);

  /* insert the points into the tree */
  for (i=0; i<m*n; i++)
    {
      vsg_prtree3d_insert_point (tree, &points[i]);
    }

/*    g_printerr ("ok depth = %d size = %d\n", */
/*                vsg_prtree3d_depth (tree), */
/*                vsg_prtree3d_point_count (tree)); */

  /* accumulate the point counts across the tree */
  vsg_prtree3d_traverse (tree, G_POST_ORDER, (VsgPRTree3dFunc) up, NULL);

  /* do some near/far traversal */
  vsg_prtree3d_near_far_traversal (tree, (VsgPRTree3dFarInteractionFunc) far,
                                   (VsgPRTree3dInteractionFunc) near,
                                   &ret);

  /*  distribute back the point counts across the tree */
  vsg_prtree3d_traverse (tree, G_PRE_ORDER, (VsgPRTree3dFunc) down, NULL);

  /* check the results */
  for (i=0; i<m*n; i++)
    {
      if (points[i].count != m*n)
        {
          g_printerr ("ERROR: wrong count on point %d: %d (should be %d).\n",
                      i, points[i].count, n);
          ret ++;
        }
    }

  /* remove the points */
  for (i=0; i<m*n; i++)
    {
      vsg_prtree3d_remove_point (tree, &points[i]);
    }

  /* destroy the tree */
  vsg_prtree3d_free (tree);

  return ret;
}
Esempio n. 12
0
gint main (gint argc, gchar ** argv)
{
  gint ret = 0;

  VsgVector3d lb = {-1., -1., -1.};
  VsgVector3d ub = {1., 1., 1.};

  VsgVector3d *points;
  gint lvl = 1;
  gint n, np;

  VsgPRTree3d *tree;
  gint i, j, k, l;

  if (argc > 1 && g_strncasecmp (argv[1], "--version", 9) == 0)
    {
      g_print ("%s\n", PACKAGE_VERSION);
      return 0;
    }

  if (argc > 1)
    {
      sscanf (argv[1], "%d", &lvl);
    }

  n = 1<<lvl;
  np = n*n*n;

  vsg_init_gdouble ();

  /* create the points */
  points = g_malloc (np * sizeof (VsgVector3d));
  l = 0;
  for (i=0; i<n; i++)
    {
      gdouble x = 2. * ((i+0.5)/n) - 1.;

      for (j=0; j<n; j++)
        {
          gdouble y = 2. * ((j+0.5)/n) - 1.;

          for (k=0; k<n; k++)
            {
              gdouble z = 2. * ((k+0.5)/n) - 1.;

              vsg_vector3d_set (&points[l], x, y, z);
              l ++;
            }
        }
    }

  /* create the tree */
  tree =
    vsg_prtree3d_new_full (&lb, &ub,
                           (VsgPoint3dLocFunc) vsg_vector3d_vector3d_locfunc,
                           (VsgPoint3dDistFunc) vsg_vector3d_dist,
                           NULL, 1);

  /* configure for hilbert curve order traversal */
  vsg_prtree3d_set_children_order (tree, hilbert3_order,
                                   GINT_TO_POINTER (HK3_0_2_1));

  /* insert some points */
  for (i=0; i<np; i++)
    {
      vsg_prtree3d_insert_point (tree, &points[i]);
    }

  /* do some traversal */
  i=0;
  vsg_prtree3d_traverse (tree, G_PRE_ORDER,
                         (VsgPRTree3dFunc) traverse_point_count, &i);

  /* check the results */
  if (i != np)
    {
      g_printerr ("ERROR: traverse point count %d (should be %d)\n",
                  i, n);

      ret ++;
    }

  /* remove the points */
  for (i=0; i<np; i++)
    {
      vsg_prtree3d_remove_point (tree, &points[i]);
    }

  g_free (points);

  /* destroy the tree */
  vsg_prtree3d_free (tree);

  return ret;
}