Ejemplo n.º 1
0
str_grid_cell_filler_t* str_grid_cell_filler_new(str_grid_t* grid)
{
  str_grid_cell_filler_t* filler = polymec_malloc(sizeof(str_grid_cell_filler_t));
  filler->grid = grid;
  str_grid_get_extents(grid, &filler->nx, &filler->ny, &filler->nz);
  filler->patch_fillers = int_ptr_unordered_map_new();
  filler->tokens = int_ptr_unordered_map_new();
  return filler;
}
Ejemplo n.º 2
0
str_grid_edge_data_t* str_grid_edge_data_with_buffer(str_grid_t* grid, 
                                                     int num_components,
                                                     void* buffer)
{
  ASSERT(num_components > 0);

  // Allocate storage.
  int num_patches = 3 * str_grid_num_patches(grid);
  size_t patches_size = sizeof(str_grid_patch_t*) * num_patches;
  size_t edge_data_size = sizeof(str_grid_edge_data_t) + patches_size;
  str_grid_edge_data_t* edge_data = polymec_malloc(edge_data_size);
  edge_data->grid = grid;
  edge_data->nc = num_components;

  str_grid_get_extents(grid, &edge_data->nx, &edge_data->ny, &edge_data->nz);
  edge_data->x_patches = int_ptr_unordered_map_new();
  edge_data->y_patches = int_ptr_unordered_map_new();
  edge_data->z_patches = int_ptr_unordered_map_new();
  edge_data->patch_offsets = polymec_malloc(sizeof(int) * (3*num_patches+1));
  edge_data->buffer = NULL;

  // Now populate the patches for x-, y-, and z-edges.
  int px, py, pz;
  str_grid_get_patch_size(grid, &px, &py, &pz);
  edge_data->patch_lx = 1.0 / edge_data->nx;
  edge_data->patch_ly = 1.0 / edge_data->ny;
  edge_data->patch_lz = 1.0 / edge_data->nz;
  int pos = 0, i, j, k;
  while (str_grid_next_patch(grid, &pos, &i, &j, &k))
  {
    int index = patch_index(edge_data, i, j, k);

    int_ptr_unordered_map_insert_with_v_dtor(edge_data->x_patches, index, 
                                             str_grid_patch_with_buffer(px+1, py, pz, num_components, 0, NULL),
                                             DTOR(str_grid_patch_free));

    int_ptr_unordered_map_insert_with_v_dtor(edge_data->y_patches, index, 
                                             str_grid_patch_with_buffer(px, py+1, pz, num_components, 0, NULL),
                                             DTOR(str_grid_patch_free));

    int_ptr_unordered_map_insert_with_v_dtor(edge_data->z_patches, index, 
                                             str_grid_patch_with_buffer(px, py, pz+1, num_components, 0, NULL),
                                             DTOR(str_grid_patch_free));
  }
  count_edges(edge_data);

  // Set the buffer.
  str_grid_edge_data_set_buffer(edge_data, buffer, false);

  return edge_data;
}
Ejemplo n.º 3
0
void define_units_system(int units_system_name)
{
  if (units_systems == NULL)
    units_systems = int_ptr_unordered_map_new();
  if (int_ptr_unordered_map_contains(units_systems, units_system_name))
    polymec_error("define_units_system: units system %d is already defined.", units_system_name);
  int_ptr_unordered_map_insert_with_v_dtor(units_systems, 
                                           units_system_name, 
                                           int_real_unordered_map_new(),
                                           DTOR(int_real_unordered_map_free));
}
Ejemplo n.º 4
0
str_grid_node_data_t* str_grid_node_data_with_buffer(str_grid_t* grid, 
                                                     int num_components, 
                                                     void* buffer)
{
  ASSERT(num_components > 0);

  // Allocate storage.
  int num_patches = str_grid_num_patches(grid);
  size_t patches_size = sizeof(str_grid_patch_t*) * num_patches;
  size_t node_data_size = sizeof(str_grid_node_data_t) + patches_size;
  str_grid_node_data_t* node_data = polymec_malloc(node_data_size);
  node_data->grid = grid;
  node_data->nc = num_components;

  str_grid_get_extents(grid, &node_data->nx, &node_data->ny, &node_data->nz);
  node_data->patches = int_ptr_unordered_map_new();
  node_data->patch_offsets = polymec_malloc(sizeof(int) * (num_patches+1));
  node_data->buffer = NULL;

  // Now populate the patches (with NULL buffers).
  int px, py, pz;
  str_grid_get_patch_size(grid, &px, &py, &pz);
  node_data->patch_lx = 1.0 / node_data->nx;
  node_data->patch_ly = 1.0 / node_data->ny;
  node_data->patch_lz = 1.0 / node_data->nz;
  int pos = 0, i, j, k, l = 0;
  while (str_grid_next_patch(grid, &pos, &i, &j, &k))
  {
    int index = patch_index(node_data, i, j, k);
    int_ptr_unordered_map_insert_with_v_dtor(node_data->patches, index, 
      str_grid_patch_with_buffer(px+1, py+1, pz+1, num_components, 0, NULL),
      DTOR(str_grid_patch_free));
    ++l;
  }

  count_nodes(node_data);

  // Set the buffer.
  str_grid_node_data_set_buffer(node_data, buffer, false);

  return node_data;
}
Ejemplo n.º 5
0
amr_grid_t* amr_grid_new(MPI_Comm comm,
                         int nx, int ny, int nz, 
                         int px, int py, int pz, 
                         bool periodic_in_x, 
                         bool periodic_in_y, 
                         bool periodic_in_z)
{
  ASSERT(nx > 0);
  ASSERT(ny > 0);
  ASSERT(nz > 0);
  ASSERT(px > 0);
  ASSERT(py > 0);
  ASSERT(pz > 0);

  amr_grid_t* grid = polymec_malloc(sizeof(amr_grid_t));
  grid->nx = nx;
  grid->ny = ny;
  grid->nz = nz;
  grid->px = px;
  grid->py = py;
  grid->pz = pz;
  grid->x_periodic = periodic_in_x;
  grid->y_periodic = periodic_in_y;
  grid->z_periodic = periodic_in_z;
  grid->num_local_patches = 0;
  grid->local_patch_indices = NULL;
  grid->patch_types = polymec_malloc(sizeof(patch_type_t) * nx * ny * nz);
  grid->remote_owners = polymec_malloc(sizeof(int) * nx * ny * nz);
  grid->comm = comm;
  for (int i = 0; i < nx * ny * nz; ++i)
  {
    grid->patch_types[i] = NO_PATCH;
    grid->remote_owners[i] = -1;
  }

  grid->ref_ratio = 0;
  grid->coarser = NULL;
  grid->coarse_interpolator = NULL;
  grid->finer = NULL;
  grid->fine_interpolator = NULL;

  for (int n = 0; n < 6; ++n)
  {
    grid->neighbors[n] = NULL;
    grid->neighbor_interpolators[n] = NULL;
  }

  grid->finalized = false;
  grid->cell_ex = NULL;
  grid->x_face_ex = NULL;
  grid->y_face_ex = NULL;
  grid->z_face_ex = NULL;
  grid->x_edge_ex = NULL;
  grid->y_edge_ex = NULL;
  grid->z_edge_ex = NULL;
  grid->node_ex = NULL;

  for (int centering = 0; centering < 8; ++centering)
    grid->local_buffers[centering] = ptr_array_new();
  grid->pending_data = int_ptr_unordered_map_new();

  return grid;
}