4#include "Grid/grid_sm.hpp"
5#include "Grid/comb.hpp"
6#include "util/mathutil.hpp"
8template<
unsigned int dim,
unsigned int subdim>
class SubHyperCube;
16template<
unsigned int dim> std::ostream& operator<<(std::ostream& str,
const comb<dim> & c)
19 for (
size_t i = 0 ; i < dim-1 ; i++)
56template<
unsigned int dim>
73 return pow(2,dim-d) * openfpm::math::C(dim,d);
87 for (
size_t i = 0 ; i <= d_t ; i++)
104 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" " << d <<
" must be smaller than " <<
"\n";
110 std::vector<comb<dim>> v;
155 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" " << d <<
" must be smaller than " <<
"\n";
162 for (
size_t i = 0 ; i < dim ; i++)
164 if (bc[i] == PERIODIC)
174 std::vector<comb<dim>> v;
189 for (
size_t i = 0 ; i < key.
getDim() ; i++)
234 size_t p_stop = pow(2,pos.
getDim());
235 for (
size_t p = 0 ; p < p_stop ; p++)
246 for (
size_t k = 0 ; k < pos.
getDim() ; k++)
249 bool bit = (p >> k) & 0x01;
252 c.
c[pos.
get(k)] = (bit == 0)? 1 : -1;
295 size_t p_stop = pow(2,dim);
296 for (
size_t p = 0 ; p < p_stop ; p++)
307 for (
size_t k = 0 ; k < dim ; k++)
310 bool bit = (p >> k) & 0x01;
313 c.
c[k] = (bit == 0)? 0 : -1;
341 for (
size_t i = 0 ; i < dim ; i++)
344 {
id =
id | (1 << i);}
372 size_t pos_n_zero[dim];
374 for (
size_t i = 0 ; i < dim ; i++)
382 for (
size_t i = 0 ; i < dim ; i++)
386 pos_n_zero[d-pn_zero-1] = i;
395 long int cum_val = 0;
396 for(
long int i = d - 1; i >= 0 ; i--)
399 if (i+1 < (
long int)d)
402 val = pos_n_zero[i] - pos_n_zero[i+1] - 1;
410 for (
long int j = 0 ; j < (
long int)val; j++)
414 if (((
long int)dim)-cum_val-j-1 >= 0 && i > 0 && ((
long int)dim)-cum_val-j >= i)
415 lin_id += openfpm::math::C(dim-cum_val-j-1,i);
420 cum_val += (val + 1);
429 for (
size_t i = 0 ; i < d ; i++)
431 if (c.
c[pos_n_zero[i]] == -1)
432 {
id =
id | (1 << i);}
497template<
unsigned int dim,
unsigned int subdim>
514 std::cerr <<
"Error SubHyperCube: " << __FILE__ <<
" " << __LINE__ <<
" the hyper-cube selected must have dimensionality bigger than the dimensionality of the requested combinations, or the number of zero in c must me bigger than d" <<
"\n";
522 std::vector<comb<dim>> vc;
534 std::vector<comb<dim>> vc(v.size());
537 for (
size_t i = 0 ; i < v.size() ; i++)
542 for (
size_t j = 0 ; j < dim ; j++)
547 vc[i].c[j] = v[i].c[sub_j];
This class calculate elements of the hyper-cube.
static std::vector< comb< dim > > getCombinations_R(size_t d)
static size_t getNumberOfElementsTo_R(size_t d_t)
Get the sum of the number of elements from d to d_t (included)
static void BinPermutationsSt(std::vector< comb< dim > > &v)
Binary permutations.
static int negativeFace(int d)
Return the combination of the negative face on direction d.
static void BinPermutations(grid_key_dx_r &pos, std::vector< comb< dim > > &v)
Binary permutations.
static size_t LinPerm(comb< dim > &c)
Linearize the permutation given by BinPermutationSt.
static size_t getNumberOfElements_R(size_t d)
Get the number of Elements of dimension d.
static size_t LinId(comb< dim > &c)
Linearize the combination.
static int positiveFace(int d)
return the combination of the positive face on direction d
static bool isPositive(size_t d)
isPositive return if the combination d is a positive or a negative
static std::vector< comb< dim > > getCombinations_R_bc(size_t d, const size_t(&bc)[dim])
bool isNext()
Check if there is the next element.
grid_key_dx_r & get()
Return the actual key.
This represent a sub-hyper-cube of an hyper-cube like a face or an edge of a cube.
static std::vector< comb< dim > > getCombinations_R(comb< dim > c, int d)
Emulate grid_key_dx with runtime dimensionality.
void set_d(size_t i, mem_id id)
Set the i index.
mem_id get(size_t i)
get the i index
size_t getDim()
Get the dimensionality of the key.
Position of the element of dimension d in the hyper-cube of dimension dim.
void zero()
Set all the elements to zero.
signed char c[dim]
Array that store the combination.