#ifndef dg_pack_H #define dg_pack_H /* Cell blocks (packs) in multi-dimensional dyadic grids */ /* Last edited on 2014-05-15 20:49:03 by stolfilocal */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include /* CELL PACKS A /cell pack/ is an array {\X} of cells in a given layer {r} of {G*}, defined by a position vector {pos[0..d-1]} in that layer and a /pack size vector/ {psz[0..d-1]} of positive integers. In the procedures below, a pack is usually specified by its size vector {psz} and the cell identifier {idb} of the cell whose position is {pos}. Let {gsz[0..d-1]} be the size of layer {r} along each axis. A cell {C'} of layer {r} belongs to the pack {\X} if and only if its position vector {pos'} satisfies {pos'[i] = pos[i] + e[i] (mod gsz[i])} for every {i}, where each {e[i]} is some integer in the range {0..psz[i]-1}. The vector {e} is the /relative position/ of {C'} within the pack. DUPLICATE ENTRIES A cell pack is defined as an array, so it has exactly {N = psz[0]*ˇˇpsz[d-1]} entries. This is true even when {psz[i] > gsz[i]} for some {i}. In this case the pack wraps around and overlap itself, and includes some cells two or more times, with different relative position vectors {e}. PACK SLOT INDICES Each entry of the cell pack is identified by a /slot index/ {pkx} in {0..N-1}, which is related to its relative position vector {e[0..d-1]} and the pack sizes {psz[0..d-1]} by the function {ix_pos_by_col}. The lower cell of the pack has relative position {e = (0,..0)} and slot index {0}. The cell with relative position {e[i] = psz[i]-1} for all {i} is the /upper cell/ of the pack, and has slot index {N-1}. */ typedef uint64_t dg_pack_slot_index_t; /* Identifies a cell slot in the pack of some locus {E}. */ #define dg_NOT_SLOT ((dg_pack_slot_index_t)-1) /* The {dg_pack_slot_index_t} of a cell that is not in the pack. */ uint64_t dg_pack_slot_count(dg_dim_t d, dg_grid_size_t psz[]); /* Returns the number of slots in a cell pack with sinze {psz[i]} along each axis {i}, namely {PROD { psz[i] : i \in 0..d-1 }}. */ void dg_pack_cells ( dg_dim_t d, dg_cell_id_t idb, dg_grid_size_t psz[], dg_cell_id_t id[] ); /* Returns in {id[0..N-1]} the identifiers of all cells in the pack whose lower cell is {idb} and whose size along axis {i} is {psz[i]}, for {i} in {0..d-1}; where {N = dg_pack_slot_count(d,psz)}. */ dg_pack_slot_index_t dg_pack_find_cell ( dg_dim_t d, dg_cell_id_t id, dg_cell_id_t idb, dg_grid_size_t psz[] ); /* Returns the slot index {pkx} of cell with identifier {id} in the cell pack whose lower cell has identifier {idb} and whose size vector is {psz[0..d-1]}. If {id} occurs multiple times in the pack, returns the first occurrence. If {id} is not part of the pack, returns {dg_NOT_SLOT} */ bool_t dg_pack_intersects_cell ( dg_dim_t d, dg_cell_id_t id, dg_cell_id_t idb, dg_grid_size_t psz[] ); /* Returns TRUE if cell {id} intersects some cell of the pack with lower cell {idb} and size {psz[0..d-1]}. */ void dg_pack_box_root_relative ( dg_dim_t d, dg_cell_id_t idb, dg_grid_size_t psz[], interval_t IDB[] ); /* Stores in {B[0..d-1]} the lower and upper coordinates of the box of {R^d} that corresponds to the cell pack with lower cell {idb} and size vector {psz[0..d-1]}. The lower endpoints will be in the range {[0_1)}; the upper endpoint will be strictly greater. Due to the toroidal geometry, the upper endpoint {HI(B[i])} will be 1 or more whenever the position of {idb} along axis {i} is {gsz[i]-psz[i]} or more, where {gsz[i]} is the grid's size along that axis. */ #endif