4 #include "Grid/grid_sm.hpp"
5 #include "Grid/comb.hpp"
6 #include "util/mathutil.hpp"
8 template<
unsigned int dim,
unsigned int subdim>
class SubHyperCube;
16 template<
unsigned int dim> std::ostream& operator<<(std::ostream& str, const comb<dim> & c)
19 for (
size_t i = 0 ; i < dim-1 ; i++)
53 template<
unsigned int dim>
70 return pow(2,dim-d) * openfpm::math::C(dim,d);
84 for (
size_t i = 0 ; i <= d_t ; i++)
101 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" " << d <<
" must be smaller than " <<
"\n";
107 std::vector<comb<dim>> v;
162 size_t p_stop = pow(2,pos.
getDim());
163 for (
size_t p = 0 ; p < p_stop ; p++)
174 for (
size_t k = 0 ; k < pos.
getDim() ; k++)
177 bool bit = (p >> k) & 0x01;
180 c.
c[pos.
get(k)] = (bit == 0)? 1 : -1;
224 size_t p_stop = pow(2,dim);
225 for (
size_t p = 0 ; p < p_stop ; p++)
236 for (
size_t k = 0 ; k < dim ; k++)
239 bool bit = (p >> k) & 0x01;
242 c.
c[k] = (bit == 0)? 0 : -1;
268 for (
size_t i = 0 ; i < dim ; i++)
271 {
id =
id | (1 << i);}
299 size_t pos_n_zero[dim];
301 for (
size_t i = 0 ; i < dim ; i++)
309 for (
size_t i = 0 ; i < dim ; i++)
313 pos_n_zero[d-pn_zero-1] = i;
322 long int cum_val = 0;
323 for(
long int i = d - 1; i >= 0 ; i--)
326 if (i+1 < (
long int)d)
327 val = pos_n_zero[i] - pos_n_zero[i+1] - 1;
331 for (
long int j = 0 ; j < (
long int)val; j++)
334 if (((
long int)dim)-cum_val-j-1 >= 0 && i > 0 && ((
long int)dim)-cum_val-j >= i)
335 lin_id += openfpm::math::C(dim-cum_val-j-1,i);
340 cum_val += (val + 1);
349 for (
size_t i = 0 ; i < d ; i++)
351 if (c.
c[pos_n_zero[i]] == -1)
352 {
id =
id | (1 << i);}
415 template<
unsigned int dim,
unsigned int subdim>
432 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";
440 std::vector<comb<dim>> vc;
452 std::vector<comb<dim>> vc(v.size());
455 for (
size_t i = 0 ; i < v.size() ; i++)
460 for (
size_t j = 0 ; j < dim ; j++)
465 vc[i].c[j] = v[i].c[sub_j];
static size_t LinPerm(comb< dim > &c)
Linearize the Permitation given by BinPermutationSt.
static size_t getNumberOfElements_R(size_t d)
Get the number of Elements of dimension d.
static std::vector< comb< dim > > getCombinations_R(size_t d)
Position of the element of dimension d in the hyper-cube of dimension dim.
static void BinPermutations(grid_key_dx_r &pos, std::vector< comb< dim >> &v)
Binary permutations.
This represent a sub-hyper-cube of an hyper-cube like a face or an edge of a cube.
Emulate grid_key_dx with runtime dimensionality.
static int positiveFace(int d)
return the combination of the positive face on direction d
static void BinPermutationsSt(std::vector< comb< dim >> &v)
Binary permutations.
mem_id get(size_t i)
get the i index
static bool isPositive(size_t d)
isPositive return if the combination d is a positive or a negative
static size_t LinId(comb< dim > &c)
Linearize the combination.
void zero()
Set all the elements to zero.
This class is a trick to indicate the compiler a specific specialization pattern. ...
static size_t getNumberOfElementsTo_R(size_t d_t)
Get the sum of the number of elements from d to d_t (included)
grid_key_dx_r & get()
Return the actual key.
bool isNext()
Check if there is the next element.
static std::vector< comb< dim > > getCombinations_R(comb< dim > c, int d)
static int negativeFace(int d)
Return the combination of the negative face on direction d.
This class calculate elements of the hyper-cube.
size_t getDim()
Get the dimensionality of the key.
char c[dim]
Array that store the combination.