8 #ifndef FD_EXPRESSIONS_HPP_ 9 #define FD_EXPRESSIONS_HPP_ 14 constexpr
int NORM_EXPRESSION = 0;
15 constexpr
int STAG_EXPRESSION = 1;
16 constexpr
int GRID_COMP = 2;
18 template <
typename exp1,
typename exp2,
typename impl>
25 template<
unsigned int i>
28 template<
unsigned int prp,
typename base_type,
typename gtype>
31 if (c_where[i] != c_o1[i])
33 int sign = (c_where[i] > c_o1[i])?1:-1;
36 long int x0 = k.getKeyRef().get(i);
38 k.getKeyRef().set_d(i, x0 + sign);
40 k.getKeyRef().set_d(i, x0);
52 template<
unsigned int prp,
typename base_type,
typename gtype>
55 if (c_where[0] != c_o1[0])
57 int sign = (c_where[0] > c_o1[0])?1:-1;
59 inte_out += g.template getProp<prp>(k);
61 long int x0 = k.getKeyRef().get(0);
63 k.getKeyRef().set_d(0, x0 + sign);
64 inte_out += g.template getProp<prp>(k);
65 k.getKeyRef().set_d(0, x0);
70 inte_out += g.template getProp<prp>(k);
76 template<
typename base_type>
79 typedef base_type type;
81 template<
unsigned int prp,
typename gtype>
94 template<
unsigned int prp,
typename gtype>
97 return g.template getProp<prp>(k);
100 template<
unsigned int prp,
typename gtype>
103 return g.template getProp<prp>(k);
108 template<
unsigned int i>
111 template<
unsigned int prp,
typename base_type,
typename gtype>
114 if (c_where[i] != c_o1[i])
117 long int x0 = k.getKeyRef().get(i);
119 int sign = (c_where[i] > c_o1[i])?1:-1;
121 k.getKeyRef().set_d(i, x0 + sign);
123 k.getKeyRef().set_d(i, x0);
135 template<
unsigned int prp,
typename base_type,
typename gtype>
138 if (c_where[0] != c_o1[0])
140 int sign = (c_where[0] > c_o1[0])?1:-1;
142 inte_out += g.template getProp<prp>(k)[comp];
144 long int x0 = k.getKeyRef().get(0);
146 k.getKeyRef().set_d(0, x0 + sign);
147 inte_out += g.template getProp<prp>(k)[comp];
148 k.getKeyRef().set_d(0, x0);
153 inte_out += g.template getProp<prp>(k)[comp];
159 template<
typename base_type,
unsigned int N1>
162 typedef base_type type;
164 template<
unsigned int prp,
typename gtype>
175 {inte = g.template getProp<prp>(k)[comp];}
180 template<
unsigned int prp,
typename gtype>
183 return g.template getProp<prp>(k)[comp];
186 template<
unsigned int prp,
typename gtype>
189 return g.template getProp<prp>(k)[comp];
193 template<
typename base_type,
unsigned int N1>
196 typedef base_type type;
198 template<
unsigned int prp,
typename gtype>
209 {inte = g.template getProp<prp>(k)[comp];}
214 template<
unsigned int prp,
typename gtype>
217 return g.template getProp<prp>(k)[comp];
220 template<
unsigned int prp,
typename gtype>
223 return g.template getProp<prp>(k)[comp];
227 template<
unsigned int i>
230 template<
typename Sys_eqs,
typename gmap_type,
typename unordered_map_type ,
typename gtype>
231 static void value_nz(
const gmap_type & g_map,
232 unordered_map_type & cols,
237 typename Sys_eqs::stype coeff,
242 if (c_where[i] != c_o1[i])
244 int sign = (c_where[i] > c_o1[i])?1:-1;
264 template<
typename Sys_eqs,
typename gmap_type,
typename unordered_map_type ,
typename gtype>
265 static void value_nz(
const gmap_type & g_map,
266 unordered_map_type & cols,
271 typename Sys_eqs::stype coeff,
276 if (c_where[0] != c_o1[0])
278 int sign = (c_where[0] > c_o1[0])?1:-1;
280 cols[g_map.template getProp<0>(key)*Sys_eqs::nvar + var_id + comp] += coeff / c;
285 cols[g_map.template getProp<0>(key)*Sys_eqs::nvar + var_id + comp] += coeff / c;
290 cols[g_map.template getProp<0>(key)*Sys_eqs::nvar + var_id + comp] += coeff;
295 template<
unsigned int prp,
typename gr
id,
unsigned int impl>
305 template<
unsigned int prp,
typename gr
id>
311 typedef typename boost::mpl::at<typename grid::value_type::type,boost::mpl::int_<prp>>::type type_proc;
319 static const unsigned int prop = prp;
323 void setVarId(
int var_id)
325 this->var_id = var_id;
405 auto it = g.getDomainIterator();
411 g.template getProp<prp>(key) = g_exp.value(key,s_pos);
433 auto it = g.getDomainIterator();
439 g.template getProp<prp>(key) = g_exp.value(key,s_pos);
456 auto it = g.getDomainIterator();
465 g.template getProp<prp>(key) = d;
474 template<
typename Sys_eqs,
typename gmap_type,
typename unordered_map_type>
475 inline void value_nz(
const gmap_type & g_map,
478 typename Sys_eqs::stype (& spacing )[Sys_eqs::dims],
479 unordered_map_type & cols,
480 typename Sys_eqs::stype coeff,
484 cols[g_map.template getProp<0>(key)*Sys_eqs::nvar + var_id + comp] += coeff;
487 inline grid_dist_expression_op<grid_dist_expression<prp,grid,NORM_EXPRESSION>,boost::mpl::int_<1>,g_comp> operator[](
int comp)
493 grid_dist_expression_op<grid_dist_expression<prp,grid,NORM_EXPRESSION>,boost::mpl::int_<1>,g_comp> v_exp(*
this,comp_n,var_id);
503 return this->value(key,c_where);
511 template<
unsigned int prp,
typename gr
id>
517 typedef typename boost::mpl::at<typename grid::value_type::type,boost::mpl::int_<prp>>::type type_proc;
525 static const unsigned int prop = prp;
529 void setVarId(
int var_id)
531 this->var_id = var_id;
609 auto it = g.getDomainIterator();
617 g.template getProp<prp>(key) = g_exp.value(key,s_pos);
636 auto it = g.getDomainIterator();
644 g.template getProp<prp>(key) = g_exp.value(key,s_pos);
661 auto it = g.getDomainIterator();
667 g.template getProp<prp>(key) = d;
675 template<
typename Sys_eqs,
typename gmap_type,
typename unordered_map_type>
676 inline void value_nz(
const gmap_type & g_map,
679 typename Sys_eqs::stype (& spacing )[Sys_eqs::dims],
680 unordered_map_type & cols,
681 typename Sys_eqs::stype coeff,
690 for (
int i = 0 ; i < grid::dims ; i++)
692 if (c_where[i] != c_o1[i])
696 grid_dist_expression_value_impl_vnz<Sys_eqs::dims-1>::template value_nz<Sys_eqs>(g_map,cols,g,key,c_where,c_o1,coeff,c,comp,var_id);
700 inline grid_dist_expression_op<grid_dist_expression<prp,grid,STAG_EXPRESSION>,boost::mpl::int_<1>,g_comp> operator[](
int comp)
706 grid_dist_expression_op<grid_dist_expression<prp,grid,STAG_EXPRESSION>,boost::mpl::int_<1>,g_comp> v_exp(*
this,comp_n,var_id);
718 template<
unsigned int dim>
759 template<
unsigned int dim>
800 template<
unsigned int dim,
unsigned int impl>
841 template <
typename exp1,
typename exp2>
852 typedef typename exp1::gtype gtype;
879 typename std::remove_reference<decltype(o1.value(key,c_where))>::type val;
881 return o1.value(key,c_where) + o2.value(key,c_where);
908 template<
typename Sys_eqs,
typename gmap_type,
typename unordered_map_type>
909 inline void value_nz(
const gmap_type & g_map,
912 typename Sys_eqs::stype (& spacing )[Sys_eqs::dims],
913 unordered_map_type & cols,
914 typename Sys_eqs::stype coeff,
918 o1.template value_nz<Sys_eqs>(g_map,key,gs,spacing,cols,coeff,comp,c_where);
919 o2.template value_nz<Sys_eqs>(g_map,key,gs,spacing,cols,coeff,comp,c_where);
926 template <
typename exp1,
typename exp2>
937 typedef typename exp1::gtype gtype;
964 typename std::remove_reference<decltype(o1.value(key,c_where))>::type val;
966 return o1.value(key,c_where) - o2.value(key,c_where);
993 template<
typename Sys_eqs,
typename gmap_type,
typename unordered_map_type>
994 inline void value_nz(
const gmap_type & g_map,
997 typename Sys_eqs::stype (& spacing )[Sys_eqs::dims],
998 unordered_map_type & cols,
999 typename Sys_eqs::stype coeff,
1003 o1.template value_nz<Sys_eqs>(g_map,key,gs,spacing,cols,coeff,comp,c_where);
1004 o2.template value_nz<Sys_eqs>(g_map,key,gs,spacing,cols,-coeff,comp,c_where);
1010 template <
typename exp1>
1018 typedef typename exp1::gtype gtype;
1044 typename std::remove_reference<decltype(o1.value(key,c_where))>::type val;
1046 return -o1.value(key,c_where);
1058 return o1.getGrid();
1070 return o1.getGrid();
1073 template<
typename Sys_eqs,
typename gmap_type,
typename unordered_map_type>
1074 inline void value_nz(
const gmap_type & g_map,
1077 typename Sys_eqs::stype (& spacing )[Sys_eqs::dims],
1078 unordered_map_type & cols,
1079 typename Sys_eqs::stype coeff,
1083 o1.template value_nz<Sys_eqs>(g_map,key,gs,spacing,cols,-coeff,comp,c_where);
1089 template <
typename exp1,
typename exp2>
1100 typedef typename exp2::gtype gtype;
1127 typename std::remove_reference<decltype(o1.value(key,c_where))>::type val;
1129 return o1.value(key,c_where) * o2.value(key,c_where);
1141 return o1.getGrid();
1153 return o1.getGrid();
1156 template<
typename Sys_eqs,
typename gmap_type,
typename unordered_map_type>
1157 inline void value_nz(
const gmap_type & g_map,
1160 typename Sys_eqs::stype (& spacing )[Sys_eqs::dims],
1161 unordered_map_type & cols,
1162 typename Sys_eqs::stype coeff,
1166 typename Sys_eqs::stype coeff_tmp = o1.value(key,c_where) * coeff;
1168 o2.template value_nz<Sys_eqs>(g_map,key,gs,spacing,cols,coeff_tmp,comp,c_where);
1179 template <
typename gr
id_type,
unsigned int prp>
1185 return v.template getProp<prp>(k);
1189 template<
unsigned int,
bool is_val
id>
1192 template<
typename exp_type>
1195 return o1.value(key,c_where);
1198 template<
typename exp_type>
1201 return o1.value_ref(key,c_where);
1204 template<
unsigned int prop,
typename exp_type,
typename gr
id_type>
1210 template<
unsigned int prop,
typename gr
id_type>
1220 template<
typename exp_type>
1226 template<
unsigned int prop,
typename exp_type,
typename gr
id_type>
1231 template<
unsigned int prop,
typename gr
id_type>
1240 template<
typename exp_type>
1243 return o1.value(key,c_where,comp[0]);
1246 template<
typename exp_type>
1249 return o1.value_ref(key,c_where,comp[0]);
1252 template<
unsigned int prop,
typename exp_type,
typename gr
id_type>
1258 template<
unsigned int prop,
typename gr
id_type>
1268 template<
typename exp_type>
1271 return o1.value(key)[comp[0]][comp[1]];
1274 template<
unsigned int prop,
typename exp_type,
typename gr
id_type>
1280 template<
unsigned int prop,
typename gr
id_type>
1291 template <
typename exp1,
int n>
1301 void setVarId(
int var_id)
1303 this->var_id = var_id;
1310 typedef std::false_type is_ker;
1312 typedef typename exp1::gtype gtype;
1315 static const unsigned int prop = exp1::prop;
1320 :o1(o1),var_id(var_id)
1322 for (
int i = 0 ; i < n ; i++)
1323 {this->comp[i] = comp[i];}
1335 return o1.getGrid();
1347 return o1.getGrid();
1357 typedef typename boost::mpl::at<typename gtype::value_type::type,boost::mpl::int_<exp1::prop>>::type
property_act;
1401 return this->value(key,c_where);
1404 template<
typename Sys_eqs,
typename gmap_type,
typename unordered_map_type>
1405 inline void value_nz(
const gmap_type & g_map,
1408 typename Sys_eqs::stype (& spacing )[Sys_eqs::dims],
1409 unordered_map_type & cols,
1410 typename Sys_eqs::stype coeff,
1418 std::cout << __FILE__ <<
":" << __LINE__ <<
" Error it only work for tensore of rank 1 ... like vectors " << std::endl;
1423 o1.template value_nz<Sys_eqs>(g_map,key,gs,spacing,cols,coeff,comp_ + var_id + comp[0],c_where);
1426 inline grid_dist_expression_op<exp1,boost::mpl::int_<2>,g_comp> operator[](
int comp_)
1430 for (
int i = 0 ; i < n ; i++)
1431 {comp_n[i] = comp[i];}
1434 grid_dist_expression_op<exp1,boost::mpl::int_<2>,g_comp> v_exp(o1,comp_n,var_id);
1444 return this->value(key,c_where);
1459 auto & g = getGrid();
1461 auto it = g.getDomainIterator();
1465 auto key = it.get();
1486 auto & g = getGrid();
1488 auto it = g.getDomainIterator();
1495 auto key = it.get();
1514 auto & v = getGrid();
1516 auto it = v.getDomainIterator();
1520 auto key = it.get();
1544 template <
unsigned int prp,
typename gr
id>
inline grid_dist_expression<prp,grid,NORM_EXPRESSION> getV(
grid & g)
1546 grid_dist_expression<prp,grid,NORM_EXPRESSION> exp_g(g);
1557 template <
unsigned int prp,
typename gr
id>
inline grid_dist_expression<prp,grid,STAG_EXPRESSION> getV_stag(
grid & g)
1559 grid_dist_expression<prp,grid,STAG_EXPRESSION> exp_g(g);
1574 template<
unsigned int p1,
unsigned int p2,
typename g1,
typename g2,
unsigned int impl_p1,
unsigned int impl_p2>
1591 template<
typename exp1 ,
typename exp2,
typename op1,
unsigned int prp1,
typename g1,
unsigned int impl_p1>
1608 template<
typename exp1 ,
typename exp2,
typename op1,
unsigned int prp1,
typename g1,
unsigned int impl_p1>
1625 template<
typename exp1 ,
typename exp2,
typename op1,
typename exp3 ,
typename exp4,
typename op2>
1642 template<
unsigned int prp1 ,
typename g1,
unsigned int impl_p1>
1659 template<
unsigned int prp1 ,
typename g1,
unsigned int impl_p1>
1676 template<
typename exp1 ,
typename exp2,
typename op1>
1693 template<
unsigned int p1,
unsigned int p2,
typename g1,
typename g2,
unsigned int impl_p1,
unsigned int impl_p2>
1710 template<
typename exp1 ,
typename exp2,
typename op1,
unsigned int prp1,
typename g1,
unsigned int impl_p1>
1727 template<
typename exp1 ,
typename exp2,
typename op1,
unsigned int prp1,
typename g1,
unsigned int impl_p1>
1743 template<
typename exp1 ,
typename exp2_,
typename op1>
1752 template<
unsigned int prp1 ,
typename g1,
unsigned int impl_p1>
1770 template<
typename exp1 ,
typename exp2,
typename op1,
typename exp3 ,
typename exp4,
typename op2>
1787 template<
unsigned int prp1 ,
typename g1,
unsigned int impl_p1>
1804 template<
unsigned int prp1 ,
typename g1,
unsigned int impl_p1>
1821 template<
typename exp1 ,
typename exp2,
typename op1>
1838 template<
unsigned int p2,
typename g2,
unsigned int impl_p2>
1855 template<
unsigned int p2,
typename g2,
unsigned int impl_p2>
1872 template<
unsigned int p1,
typename v1,
unsigned int p2,
typename v2,
unsigned int impl_p1,
unsigned int impl_p2>
1889 template<
unsigned int p1,
typename v1,
typename exp1,
typename exp2,
typename op1,
unsigned int impl_p1>
1906 template<
unsigned int p1,
typename v1,
typename exp1,
typename exp2,
typename op1,
unsigned int impl_p1>
1923 template<
typename exp1,
typename exp2,
typename op1,
typename exp3 ,
typename exp4,
typename op2>
1940 template<
typename exp1 ,
typename exp2,
typename op1>
1957 template<
typename exp1 ,
typename exp2,
typename op1>
grid_dist_expression(const double &d)
constructor from a constant expression
double value(const grid_dist_key_dx< dim > &k, comb< dim > &c_where) const
Evaluate the expression.
void init() const
initialize the expression tree
auto value(grid_dist_key_dx< gtype::dims > &key, comb< gtype::dims > &c_where) const -> typename std::remove_reference< decltype(o1.value(key, c_where))>::type
Evaluate the expression.
const gtype & getGrid() const
Return the grid on which is acting.
base_key & getKeyRef()
Get the reference key.
grid_dist_expression(grid &g)
constructor for an external grid
float vtype
type of object the structure return then evaluated
Position of the element of dimension d in the hyper-cube of dimension dim.
grid_dist_expression(const float &d)
constrictor from constant value
void init() const
This function must be called before value.
const exp1 o1
expression 1
auto value(grid_dist_key_dx< gtype::dims > &key, comb< gtype::dims > &c_where) const -> decltype(get_grid_dist_expression_op< n, n==rank_gen< property_act >::type::value >::get(o1, key, c_where, comp))
Return the result of the expression.
auto value(grid_dist_key_dx< gtype::dims > &key, comb< gtype::dims > &c_where) const -> typename std::remove_reference< decltype(o1.value(key, c_where))>::type
Evaluate the expression.
gtype & operator=(const grid_dist_expression< prp2, gtype, impl > &v_exp)
Fill the vector property with the evaluated expression.
const exp2 o2
expression 1
auto value_ref(grid_dist_key_dx< gtype::dims > &key, comb< gtype::dims > &c_where) const -> decltype(get_grid_dist_expression_op< n, n==rank_gen< property_act >::type::value >::get_ref(o1, key, c_where, comp))
Return the result of the expression.
auto value(grid_dist_key_dx< gtype::dims > &key, comb< gtype::dims > &c_where) const -> typename std::remove_reference< decltype(o1.value(key, c_where))>::type
Evaluate the expression.
gtype & getGrid()
Return the grid on which is acting.
void init() const
This function must be called before value.
Grid key for a distributed grid.
double d
constant parameter
This class implement the point shape in an N-dimensional space.
float value(const grid_dist_key_dx< dim > &k) const
Evaluate the expression.
grid & operator=(double d)
Fill the grid property with the double.
grid & operator=(const grid_dist_expression_op< exp1, exp2, op > &g_exp)
Fill the grid property with the evaluated expression.
grid gtype
The type of the internal grid.
grid_dist_expression(const double &d)
constructor from a constant expression
gtype & getGrid()
Return the grid on which is acting.
gtype & getGrid()
Return the vector on which is acting.
const exp1 o1
expression 1
gtype & operator=(double d)
Fill the vector property with the double.
double value(const grid_dist_key_dx< dim > &k, comb< dim > &c_where) const
Evaluate the expression.
gtype & getGrid()
Return the grid on which is acting.
auto value_ref(const grid_dist_key_dx< grid::dims > &k, comb< grid::dims > &c_where, int comp=0) const -> decltype(grid_dist_expression_value_impl< type_proc >::template value_ref< prp >(g, k, comp))
Evaluate the expression.
const exp2 o2
expression 1
gtype & getGrid()
Return the grid on which is acting.
const gtype & getGrid() const
Return the vector on which is acting.
grid & getGrid()
Return the grid on which is acting.
auto value_ref(const grid_dist_key_dx< grid::dims > &k, comb< grid::dims > &c_where, int comp=0) const -> decltype(grid_dist_expression_value_impl< type_proc >::template value_ref< prp >(g, k, comp))
Evaluate the expression.
grid_dist_expression_op(const exp1 &o1, const exp2 &o2)
Costruct a FD expression out of two expressions.
const grid & getGrid() const
Return the grid on which is acting.
const exp1 o1
expression 1
const grid & getGrid() const
Return the grid on which is acting.
const exp2 o2
expression 1
This is a distributed grid.
grid gtype
The type of the internal grid.
const gtype & getGrid() const
Return the grid on which is acting.
__device__ static __host__ auto value(grid_type &v, const grid_dist_key_dx< grid_type::dims > &k) -> decltype(v.template getProp< prp >(k))
return the value (position or property) of the particle k in the vector v
auto value(grid_dist_key_dx< grid::dims > &k, comb< grid::dims > &c_where, int comp=0) const -> decltype(grid_dist_expression_value_impl< type_proc >::template inte< prp >(g, k, c_where, c_where, comp))
Evaluate the expression.
void init() const
This function must be called before value.
grid & operator=(const grid_dist_expression< prp2, grid, STAG_EXPRESSION > &g_exp)
Fill the grid property with the evaluated expression.
void mone()
Set all the elements to -1.
double d
constant parameter
grid_dist_expression_op(const exp1 &o1, const exp2 &o2)
Costruct a FD expression out of two expressions.
auto get(grid_dist_key_dx< gtype::dims > &key, comb< gtype::dims > &c_where) const -> decltype(value(key, c_where))
Return the result of the expression.
void zero()
Set all the elements to zero.
void init() const
This function must be called before value.
grid & getGrid()
Return the grid on which is acting.
grid_dist_expression_op(const exp1 &o1, const exp2 &o2)
Costruct a FD expression out of two expressions.
grid_dist_expression_op(const exp1 &o1, int(&comp)[n], int var_id)
constructor from an expresssion
const gtype & getGrid() const
Return the grid on which is acting.
grid & operator=(double d)
Fill the grid property with the double.
boost::mpl::at< typename gtype::value_type::type, boost::mpl::int_< exp1::prop > >::type property_act
property on which this view is acting
auto value(const grid_dist_key_dx< grid::dims > &k, comb< grid::dims > &c_where, int comp=0) const -> decltype(grid_dist_expression_value_impl< type_proc >::template value_n< prp >(g, k, comp))
Evaluate the expression.
void init() const
This function must be called before value.
grid & operator=(const grid_dist_expression_op< exp1, exp2, op > &g_exp)
Fill the grid property with the evaluated expression.
grid_dist_expression(grid &g)
constructor for an external grid
const gtype & getGrid() const
Return the grid on which is acting.
selector for position or properties left side expression
auto value(grid_dist_key_dx< gtype::dims > &key, comb< gtype::dims > &c_where) const -> typename std::remove_reference< decltype(o1.value(key, c_where))>::type
Evaluate the expression.
like std::rank but it also work for openfpm structures like Point where it return 1
grid_dist_expression_op(const exp1 &o1)
Costruct a FD expression out of two expressions.
gtype & operator=(const grid_dist_expression_op< exp1_, exp2_, op > &v_exp)
Fill the vector property with the evaluated expression.
void init() const
This function must be called before value.
grid & operator=(const grid_dist_expression< prp2, grid, NORM_EXPRESSION > &g_exp)
Fill the grid property with the evaluated expression.
void init() const
This function must be called before value.
void init() const
This function must be called before value.
const exp1 o1
expression 1
void init() const
This function must be called before value.