cburstedde / p4est

The "p4est" forest-of-octrees library

Home Page:www.p4est.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

p4est_iterate

stichou opened this issue · comments

It's me again ...
I am trying to figure out how the function p4est_iterate works and how we can use it to fill data to a given output array (the aim is to pass then the output array to p4est_vtk_write_cell_data).
What I am trying to do is to simply take a quantity stored in my quadrant user_data (here rho) and store all values in the array density_array.
Here is my code step by step:

  1. Array creation
numquads = p4est->local_num_quadrants;
npoints= P4EST_CHILDREN;
array_size = numquads * npoints;
density_array = sc_array_new_size (sizeof (double), array_size);
  1. Then I use the p4est_iterate function for visiting each cell and populate density_array :
p4est_iterate(p4est, NULL, (double *) density_array, fill_solution , NULL, NULL);
  1. Inspired by p4est_step.3 I created a callback function fill_solution but from the examples I do not understand how the user_data stored in the quadrant is supposed to be transferred to output.
static void
fill_solution (p4est_iter_volume_info_t * info, void *user_data)
{
  sc_array_t         *output = (sc_array_t *) user_data; //array to be filled
  p4est_quadrant_t   *q = info->quad;                         //quadrant
  data_t             *data = (data_t *) q->p.user_data;     //data stored in quadrant
  // This is the data I want to store 
  //data->rho
}
  • If I well understood, output is a pointer to the array where I want to store my data but how the function fill_solution is supposed to know the location where I want to store data->rho ?
  • Can you give me a hint for storing my data in density_array, please ?
  • I plan next to do mathematical operations between quantities stored in different quadrants. I suppose that I can either work with p4est_iterate or directly with arrays where I would have first stored my data. In terms of performance and data management I suppose that using p4est_iterate is the best choice, isn't it ?

Thank you for your help,
Steven

P-S; 1. I have to admit that the notion of callback function is a little bit obscure to me.
2. It is the 3rd time I use the "project issues" for questions rather than for reporting bugs etc. If you have a dedicated forum, or another communication channel, for usage questions as mines please let me know.

Thanks for your post. If you want to write VTK cell data, you need one value per cell. Only for point data, which lives at the quadrant corners, you will need P4EST_CHILDREN many values.

The user data is what you like it to be. You can set it to any number of bytes, which can be done by defining a struct with your per-quadrant variables and pass sizeof this struct as the number of user data bytes. The p4est_iterate volume callback gives you each quadrant in order, where you can cast the user data pointer to a pointer to your struct type. The index of the array to write the data to, however, is not directly passed to you. You may either (a) keep a context counter that you increment at the end of the volume callback, or (b) construct the process-local index of the quadrant by indexing into the tree array and adding the tree's cumulative index to the quadid.