OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
vector_dist_operators_apply_kernel.hpp
1 /*
2  * vector_dist_operators_apply_kernel.hpp
3  *
4  * Created on: Jun 19, 2016
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_NUMERICS_SRC_OPERATORS_VECTOR_VECTOR_DIST_OPERATORS_APPLY_KERNEL_HPP_
9 #define OPENFPM_NUMERICS_SRC_OPERATORS_VECTOR_VECTOR_DIST_OPERATORS_APPLY_KERNEL_HPP_
10 
12 
13 #define DEFINE_INTERACTION_3D(name) struct name \
14 {\
15 \
16  Point<3,double> value(const Point<3,double> & xp, const Point<3,double> xq)\
17  {
18 
19 #define END_INTERACTION }\
20  };
21 
28 template<typename ObjType, typename Sfinae = void>
29 struct is_expression: std::false_type {};
30 
31 template<typename ObjType>
32 struct is_expression<ObjType, typename Void<typename ObjType::is_expression>::type> : std::true_type
33 {};
34 
36 template<typename exp, bool is_exp = is_expression<exp>::value>
38 {
40  typedef typename exp::return_type rtype;
41 };
42 
44 template<typename exp>
45 struct apply_kernel_rtype<exp,false>
46 {
48  typedef exp rtype;
49 };
50 
51 
56 template<typename rtype>
57 struct set_zero
58 {
60  __device__ __host__ static rtype create()
61  {
62  return 0.0;
63  }
64 };
65 
67 template<unsigned int dim, typename T>
68 struct set_zero<Point<dim,T>>
69 {
71  __device__ __host__ static Point<dim,T> create()
72  {
73  Point<dim,T> ret;
74 
75  ret.zero();
76  return ret;
77  }
78 };
79 
80 constexpr int NN_index_sort = 1;
81 constexpr int NN_index_unsort = 0;
82 
83 template<unsigned int impl>
84 struct NN_index
85 {
86  template<typename NN_type>
87  __device__ __host__ static auto get(NN_type & NN) -> decltype(NN.get())
88  {
89  return NN.get();
90  }
91 };
92 
93 template<>
94 struct NN_index<NN_index_sort>
95 {
96  template<typename NN_type>
97  __device__ __host__ static auto get(NN_type & NN) -> decltype(NN.get_sort())
98  {
99  return NN.get_sort();
100  }
101 };
102 
107 template<unsigned int impl, typename T, typename vector, typename exp,typename NN_type, typename Kernel, typename rtype, bool is_exp=is_expression<T>::value>
109 {
121  inline __host__ __device__ static typename std::remove_reference<rtype>::type apply(const vector & vd, NN_type & cl, const exp & v_exp, const vect_dist_key_dx & key, Kernel & lker)
122  {
123  // accumulator
124  typename std::remove_reference<rtype>::type pse = set_zero<typename std::remove_reference<rtype>::type>::create();
125 
126  // position of particle p
128 
129  // property of the particle x
130  rtype prp_p = v_exp.value(key);
131 
132  // Get the neighborhood of the particle
133  auto NN = cl.template getNNIterator<NO_CHECK>(cl.getCell(p));
134  while(NN.isNext())
135  {
136  auto nnp = NN_index<impl>::get(NN);
137 
138  // Calculate contribution given by the kernel value at position p,
139  // given by the Near particle, exclude itself
140  if (nnp != key.getKey())
141  {
142  vect_dist_key_dx nnp_k;
143  nnp_k.setKey(nnp);
144 
145  // property of the particle x
146  rtype prp_q = v_exp.value(nnp_k);
147 
148  // position of the particle q
150 
151  pse += lker.value(p,q,prp_p,prp_q);
152  }
153 
154  // Next particle
155  ++NN;
156  }
157 
158  return pse;
159  }
160 };
161 
162 
167 template<unsigned int impl, typename vector, typename exp,typename NN_type, typename Kernel, typename rtype>
169 {
180  __device__ __host__ inline static typename std::remove_reference<rtype>::type apply(const vector & vd, NN_type & cl, const vect_dist_key_dx & key, Kernel & lker)
181  {
182  // accumulator
183  typename std::remove_reference<rtype>::type pse = set_zero<typename std::remove_reference<rtype>::type>::create();
184 
185  // position of particle p
187 
188  // Get the neighborhood of the particle
189  auto NN = cl.template getNNIterator<NO_CHECK>(cl.getCell(p));
190  while(NN.isNext())
191  {
192  auto nnp = NN_index<impl>::get(NN);
193 
194  // Calculate contribution given by the kernel value at position p,
195  // given by the Near particle, exclude itself
196  if (nnp != key.getKey())
197  {
198  // position of the particle q
200 
201  pse += lker.value(p,q);
202  }
203 
204  // Next particle
205  ++NN;
206  }
207 
208  return pse;
209  }
210 };
211 
212 
213 
218 template<unsigned int impl, typename T, typename vector, typename exp,typename NN_type, typename Kernel, typename rtype, bool is_exp=is_expression<T>::value>
220 {
232  __device__ __host__ inline static typename std::remove_reference<rtype>::type apply(const vector & vd, NN_type & cl, const exp & v_exp, const vect_dist_key_dx & key, Kernel & lker)
233  {
234  // accumulator
235  typename std::remove_reference<rtype>::type pse = set_zero<typename std::remove_reference<rtype>::type>::create();
236 
237  // property of the particle x
238  rtype prp_p = v_exp.value(key);
239 
240  // position of particle p
242 
243  // Get the neighborhood of the particle
244  auto NN = cl.template getNNIterator<NO_CHECK>(cl.getCell(p));
245  while(NN.isNext())
246  {
247  auto nnp = NN_index<impl>::get(NN);
248 
249  // Calculate contribution given by the kernel value at position p,
250  // given by the Near particle, exclude itself
251  if (nnp != key.getKey())
252  {
253  vect_dist_key_dx nnp_k;
254  nnp_k.setKey(nnp);
255 
256  // property of the particle x
257  rtype prp_q = v_exp.value(nnp_k);
258 
259  pse += lker.value(key.getKey(),nnp,prp_p,prp_q,vd);
260  }
261 
262  // Next particle
263  ++NN;
264  }
265 
266  return pse;
267  }
268 };
269 
270 template<typename T, bool mm>
272 {
273  T obj;
274 
275  mutable_or_not(T & obj)
276  :obj(obj)
277  {}
278 };
279 
280 template<typename T>
281 struct mutable_or_not<T,true>
282 {
283  mutable T obj;
284 
285  mutable_or_not(T & obj)
286  :obj(obj)
287  {}
288 };
289 
290 template<typename T, bool is_reference = std::is_reference<T>::value>
292 {
293  typedef const T type;
294 };
295 
296 template<typename T>
297 struct add_const_reference<T,true>
298 {
299  typedef typename std::remove_reference<T>::type const & type;
300 };
301 
308 template <typename exp1,typename vector_type>
309 class vector_dist_expression_op<exp1,vector_type,VECT_APPLYKER_IN>
310 {
312  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<0>>::type NN;
314  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<1>>::type Kernel;
316  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<2>>::type vector_orig;
317 
319  typedef typename std::remove_reference<NN>::type NN_nr;
321  typedef typename std::remove_reference<Kernel>::type Kernel_nr;
323  typedef typename std::remove_reference<vector_orig>::type vector_orig_nr;
324 
326  const exp1 o1;
327 
330 
333 
336 
338  typedef typename apply_kernel_rtype<decltype(o1.value(vect_dist_key_dx()))>::rtype rtype;
339 
340 public:
341 
344 
347 
349  typedef boost::mpl::bool_<false> is_sort;
350 
352  typedef NN_nr NN_type;
353 
359  inline NN_nr * getNN() const
360  {
361  return &cl.obj;
362  }
363 
369  inline const vtype & getVector() const
370  {
371  return vd;
372  }
373 
379  inline void init() const
380  {
381  o1.init();
382  }
383 
392  vector_dist_expression_op(const exp1 & o1, NN_nr & cl, Kernel & ker, const vector_orig_nr & vd)
393  :o1(o1),cl(cl),ker(ker),vd(vd)
394  {}
395 
403  __device__ __host__ inline typename std::remove_reference<rtype>::type value(const vect_dist_key_dx & key) const
404  {
405  return apply_kernel_is_number_or_expression<NN_index_unsort,
406  decltype(o1.value(key)),
408  exp1,
409  NN_nr,
410  Kernel_nr,
411  rtype>::apply(vd,cl.obj,o1,key,ker.obj);
412  }
413 };
414 
421 template <typename exp1,typename vector_type>
422 class vector_dist_expression_op<exp1,vector_type,VECT_APPLYKER_IN_SORT>
423 {
425  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<0>>::type NN;
427  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<1>>::type Kernel;
429  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<2>>::type vector_orig;
430 
432  typedef typename std::remove_reference<NN>::type NN_nr;
434  typedef typename std::remove_reference<Kernel>::type Kernel_nr;
436  typedef typename std::remove_reference<vector_orig>::type vector_orig_nr;
437 
439  const exp1 o1;
440 
443 
446 
449 
451  typedef typename apply_kernel_rtype<decltype(o1.value(vect_dist_key_dx()))>::rtype rtype;
452 
453 public:
454 
457 
460 
462  typedef boost::mpl::bool_<true> is_sort;
463 
465  typedef NN_nr NN_type;
466 
472  inline NN_nr * getNN() const
473  {
474  return &cl.obj;
475  }
476 
482  inline const vtype & getVector() const
483  {
484  return vd;
485  }
486 
492  inline void init() const
493  {
494  o1.init();
495  }
496 
505  vector_dist_expression_op(const exp1 & o1, NN_nr & cl, Kernel & ker, const vector_orig_nr & vd)
506  :o1(o1),cl(cl),ker(ker),vd(vd)
507  {}
508 
516  __device__ __host__ inline typename std::remove_reference<rtype>::type value(const vect_dist_key_dx & key) const
517  {
518  return apply_kernel_is_number_or_expression<NN_index_sort,
519  decltype(o1.value(key)),
521  exp1,
522  NN_nr,
523  Kernel_nr,
524  rtype>::apply(vd,cl.obj,o1,key,ker.obj);
525  }
526 };
527 
534 template <typename exp1,typename vector_type>
535 class vector_dist_expression_op<exp1,vector_type,VECT_APPLYKER_IN_SIM>
536 {
538  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<0>>::type NN;
540  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<1>>::type Kernel;
542  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<2>>::type vector_orig;
543 
545  typedef typename std::remove_reference<NN>::type NN_nr;
547  typedef typename std::remove_reference<Kernel>::type Kernel_nr;
549  typedef typename std::remove_reference<vector_orig>::type vector_orig_nr;
550 
553 
556 
559 
562 
563 
564 public:
565 
568 
571 
573  typedef boost::mpl::bool_<false> is_sort;
574 
576  typedef NN_nr NN_type;
577 
583  inline NN_nr * getNN() const
584  {
585  return &cl.obj;
586  }
587 
593  inline const vtype & getVector() const
594  {
595  return vd;
596  }
597 
603  inline void init() const
604  {
605  }
606 
615  :cl(cl),ker(ker),vd(vd)
616  {}
617 
625  __device__ __host__ inline typename std::remove_reference<rtype>::type value(const vect_dist_key_dx & key) const
626  {
627  return apply_kernel_is_number_or_expression_sim<NN_index_unsort,
629  exp1,
630  NN_nr,
631  Kernel_nr,
632  rtype>::apply(vd,cl.obj,key,ker.obj);
633  }
634 };
635 
642 template <typename exp1,typename vector_type>
643 class vector_dist_expression_op<exp1,vector_type,VECT_APPLYKER_IN_SIM_SORT>
644 {
646  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<0>>::type NN;
648  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<1>>::type Kernel;
650  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<2>>::type vector_orig;
651 
653  typedef typename std::remove_reference<NN>::type NN_nr;
655  typedef typename std::remove_reference<Kernel>::type Kernel_nr;
657  typedef typename std::remove_reference<vector_orig>::type vector_orig_nr;
658 
661 
664 
667 
670 
671 
672 public:
673 
676 
679 
681  typedef boost::mpl::bool_<true> is_sort;
682 
684  typedef NN_nr NN_type;
685 
691  inline NN_nr * getNN() const
692  {
693  return &cl.obj;
694  }
695 
701  inline const vtype & getVector() const
702  {
703  return vd;
704  }
705 
711  inline void init() const
712  {
713  }
714 
723  :cl(cl),ker(ker),vd(vd)
724  {}
725 
733  __device__ __host__ inline typename std::remove_reference<rtype>::type value(const vect_dist_key_dx & key) const
734  {
735  return apply_kernel_is_number_or_expression_sim<NN_index_sort,
737  exp1,
738  NN_nr,
739  Kernel_nr,
740  rtype>::apply(vd,cl.obj,key,ker.obj);
741  }
742 };
743 
750 template <typename exp1,typename vector_type>
751 class vector_dist_expression_op<exp1,vector_type,VECT_APPLYKER_IN_GEN>
752 {
754  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<0>>::type NN;
756  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<1>>::type Kernel;
757 
759  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<2>>::type vector_orig;
760 
762  typedef typename std::remove_reference<NN>::type NN_nr;
764  typedef typename std::remove_reference<Kernel>::type Kernel_nr;
766  typedef typename std::remove_reference<vector_orig>::type vector_orig_nr;
767 
769  const exp1 o1;
770 
773 
776 
779 
781  typedef typename apply_kernel_rtype<decltype(o1.value(vect_dist_key_dx()))>::rtype rtype;
782 
783 public:
784 
787 
790 
792  typedef boost::mpl::bool_<false> is_sort;
793 
795  typedef NN_nr NN_type;
796 
802  inline NN_nr * getNN() const
803  {
804  return &cl.obj;
805  }
806 
812  inline const vtype & getVector() const
813  {
814  return vd;
815  }
816 
822  inline void init() const
823  {
824  o1.init();
825  }
826 
835  vector_dist_expression_op(const exp1 & o1, NN & cl, Kernel & ker, const vector_orig & vd)
836  :o1(o1),cl(cl),ker(ker),vd(vd)
837  {}
838 
846  __device__ __host__ inline typename std::remove_reference<rtype>::type value(const vect_dist_key_dx & key) const
847  {
848  return apply_kernel_is_number_or_expression_gen<NN_index_unsort,
849  decltype(o1.value(key)),
851  exp1,
852  NN_nr,
853  Kernel_nr,
854  rtype>::apply(vd,cl.obj,o1,key,ker.obj);
855  }
856 };
857 
864 template <typename exp1,typename vector_type>
865 class vector_dist_expression_op<exp1,vector_type,VECT_APPLYKER_IN_GEN_SORT>
866 {
868  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<0>>::type NN;
870  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<1>>::type Kernel;
871 
873  typedef typename boost::mpl::at<vector_type,boost::mpl::int_<2>>::type vector_orig;
874 
876  typedef typename std::remove_reference<NN>::type NN_nr;
878  typedef typename std::remove_reference<Kernel>::type Kernel_nr;
880  typedef typename std::remove_reference<vector_orig>::type vector_orig_nr;
881 
883  const exp1 o1;
884 
887 
890 
893 
895  typedef typename apply_kernel_rtype<decltype(o1.value(vect_dist_key_dx()))>::rtype rtype;
896 
897 public:
898 
901 
904 
906  typedef boost::mpl::bool_<true> is_sort;
907 
909  typedef NN_nr NN_type;
910 
916  inline NN_nr * getNN() const
917  {
918  return &cl.obj;
919  }
920 
926  inline const vtype & getVector() const
927  {
928  return vd;
929  }
930 
936  inline void init() const
937  {
938  o1.init();
939  }
940 
949  vector_dist_expression_op(const exp1 & o1, NN & cl, Kernel & ker, const vector_orig & vd)
950  :o1(o1),cl(cl),ker(ker),vd(vd)
951  {}
952 
960  __device__ __host__ inline typename std::remove_reference<rtype>::type value(const vect_dist_key_dx & key) const
961  {
962  return apply_kernel_is_number_or_expression_gen<NN_index_sort,
963  decltype(o1.value(key)),
965  exp1,
966  NN_nr,
967  Kernel_nr,
968  rtype>::apply(vd,cl.obj,o1,key,ker.obj);
969  }
970 };
971 
972 template<typename cl_type, int impl=2*is_gpu_celllist<cl_type>::type::value + is_gpu_ker_celllist<cl_type>::type::value >
974 {
975  typedef cl_type& ctype;
976 
977  static ctype & get(cl_type & cl)
978  {
979  return cl;
980  }
981 };
982 
983 template<typename cl_type>
984 struct cl_selector_impl<cl_type,2>
985 {
986  typedef decltype(std::declval<cl_type>().toKernel()) ctype;
987 
988  static ctype get(cl_type & cl)
989  {
990  return cl.toKernel();
991  }
992 };
993 
994 template<typename cl_type>
995 struct cl_selector_impl<cl_type,1>
996 {
997  typedef cl_type ctype;
998 
999  static ctype & get(cl_type & cl)
1000  {
1001  return cl;
1002  }
1003 };
1004 
1005 template<typename kl_type, typename cl_type, int impl=2*is_gpu_celllist<cl_type>::type::value + is_gpu_ker_celllist<cl_type>::type::value >
1007 {
1008  typedef kl_type& ktype;
1009 };
1010 
1011 template<typename kl_type, typename cl_type>
1012 struct kl_selector_impl<kl_type,cl_type,2>
1013 {
1014  typedef kl_type ktype;
1015 };
1016 
1017 template<typename kl_type, typename cl_type>
1018 struct kl_selector_impl<kl_type,cl_type,1>
1019 {
1020  typedef kl_type ktype;
1021 };
1022 
1023 template<bool is_sorted, bool uwk, typename T>
1025 {
1026  typedef T type;
1027 
1028  static T & get(T & v)
1029  {
1030  return v;
1031  }
1032 };
1033 
1034 template<typename T>
1035 struct unroll_with_to_kernel<false,true,T>
1036 {
1037  typedef decltype(std::declval<T>().toKernel()) type;
1038 
1039  static type get(T & v)
1040  {
1041  return v.toKernel();
1042  }
1043 };
1044 
1045 template<typename T>
1046 struct unroll_with_to_kernel<true,true,T>
1047 {
1048  typedef decltype(std::declval<T>().toKernel_sorted()) type;
1049 
1050  static type get(T & v)
1051  {
1052  return v.toKernel_sorted();
1053  }
1054 };
1055 
1056 template<bool is_sorted, typename vl_type, typename cl_type, int impl=2*is_gpu_celllist<cl_type>::type::value + is_gpu_ker_celllist<cl_type>::type::value>
1058 {
1059  typedef vl_type& vtype;
1060 
1061  static vtype & get(vl_type & v)
1062  {
1063  return v;
1064  }
1065 };
1066 
1067 template<typename vl_type, typename cl_type>
1068 struct vl_selector_impl<false,vl_type,cl_type,2>
1069 {
1070  typedef decltype(std::declval<vl_type>().toKernel()) vtype;
1071 
1072  static vtype & get(vl_type & v)
1073  {
1074  return v.toKernel();
1075  }
1076 };
1077 
1078 template<typename vl_type, typename cl_type>
1079 struct vl_selector_impl<true,vl_type,cl_type,2>
1080 {
1081  typedef decltype(std::declval<vl_type>().toKernel()) vtype;
1082 
1083  static vtype & get(vl_type & v)
1084  {
1085  return v.toKernel_sorted();
1086  }
1087 };
1088 
1089 template<bool is_sorted, typename vl_type, typename cl_type>
1090 struct vl_selector_impl<is_sorted, vl_type,cl_type,1>
1091 {
1092  typedef typename unroll_with_to_kernel<is_sorted,has_toKernel<vl_type>::type::value,vl_type>::type vtype;
1093 
1094  static vtype get(vl_type & v)
1095  {
1097  }
1098 };
1099 
1100 
1103 
1104 /* \brief Apply kernel expression
1105  *
1106  * \param va vector expression one
1107  * \param vb vector expression two
1108  *
1109  * \return an object that encapsulate the expression
1110  *
1111  */
1112 template<typename exp1, typename exp2, unsigned int op1, typename NN, typename Kernel, typename vector_type>
1114  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1115  typename kl_selector_impl<Kernel,NN>::ktype,
1117  VECT_APPLYKER_IN>
1118 applyKernel_in(const vector_dist_expression_op<exp1,exp2,op1> & va, vector_type & vd, NN & cl, Kernel & ker)
1119 {
1121  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1122  typename kl_selector_impl<Kernel,NN>::ktype,
1124  VECT_APPLYKER_IN> exp_sum(va,
1126  ker,
1128 
1129  return exp_sum;
1130 }
1131 
1132 
1135 
1136 /* \brief Apply kernel expression
1137  *
1138  * \param va vector expression one
1139  * \param vb vector expression two
1140  *
1141  * \return an object that encapsulate the expression
1142  *
1143  */
1144 template<typename exp1, typename exp2, unsigned int op1, typename NN, typename Kernel, typename vector_type>
1146  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1147  typename kl_selector_impl<Kernel,NN>::ktype,
1149  VECT_APPLYKER_IN_SORT>
1150 applyKernel_in_sort(const vector_dist_expression_op<exp1,exp2,op1> & va, vector_type & vd, NN & cl, Kernel & ker)
1151 {
1153  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1154  typename kl_selector_impl<Kernel,NN>::ktype,
1156  VECT_APPLYKER_IN_SORT> exp_sum(va,
1158  ker,
1160 
1161  return exp_sum;
1162 }
1163 
1164 /* \brief Apply kernel expression
1165  *
1166  * \param va vector expression one
1167  * \param vb vector expression two
1168  *
1169  * \return an object that encapsulate the expression
1170  *
1171  */
1172 template<typename exp1, typename exp2, unsigned int op1, typename NN, typename Kernel, typename vector_type>
1174  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1175  typename kl_selector_impl<Kernel,NN>::ktype,
1177  VECT_APPLYKER_IN_GEN>
1178 applyKernel_in_gen(const vector_dist_expression_op<exp1,exp2,op1> & va, vector_type & vd, NN & cl, Kernel & ker)
1179 {
1181  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1182  typename kl_selector_impl<Kernel,NN>::ktype,
1184  VECT_APPLYKER_IN_GEN> exp_sum(va,
1186  ker,
1188 
1189  return exp_sum;
1190 }
1191 
1192 /* \brief Apply kernel expression
1193  *
1194  * \param va vector expression one
1195  * \param vb vector expression two
1196  *
1197  * \return an object that encapsulate the expression
1198  *
1199  */
1200 template<typename exp1, typename exp2, unsigned int op1, typename NN, typename Kernel, typename vector_type>
1202  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1203  typename kl_selector_impl<Kernel,NN>::ktype,
1205  VECT_APPLYKER_IN_GEN_SORT>
1206 applyKernel_in_gen_sort(const vector_dist_expression_op<exp1,exp2,op1> & va, vector_type & vd, NN & cl, Kernel & ker)
1207 {
1209  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1210  typename kl_selector_impl<Kernel,NN>::ktype,
1212  VECT_APPLYKER_IN_GEN_SORT> exp_sum(va,
1214  ker,
1216 
1217  return exp_sum;
1218 }
1219 
1221 
1222 /* \brief Apply kernel expression
1223  *
1224  * \param va vector expression one
1225  * \param vb vector expression two
1226  *
1227  * \return an object that encapsulate the expression
1228  *
1229  */
1230 template<unsigned int prp, typename NN, typename Kernel, typename vector_type, typename vector_type_ker>
1232  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1233  typename kl_selector_impl<Kernel,NN>::ktype,
1235  VECT_APPLYKER_IN>
1236 applyKernel_in(const vector_dist_expression<prp,vector_type_ker> & va, vector_type & vd, NN & cl, Kernel & ker)
1237 {
1239  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1240  typename kl_selector_impl<Kernel,NN>::ktype,
1242  VECT_APPLYKER_IN> exp_sum(va,
1244  ker,
1246 
1247  return exp_sum;
1248 }
1249 
1250 /* \brief Apply kernel expression
1251  *
1252  * \param va vector expression one
1253  * \param vb vector expression two
1254  *
1255  * \return an object that encapsulate the expression
1256  *
1257  */
1258 template<unsigned int prp, typename NN, typename Kernel, typename vector_type, typename vector_type_ker>
1260  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1261  typename kl_selector_impl<Kernel,NN>::ktype,
1263  VECT_APPLYKER_IN_SORT>
1264 applyKernel_in_sort(const vector_dist_expression<prp,vector_type_ker> & va, vector_type & vd, NN & cl, Kernel & ker)
1265 {
1267  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1268  typename kl_selector_impl<Kernel,NN>::ktype,
1270  VECT_APPLYKER_IN_SORT> exp_sum(va,
1272  ker,
1274 
1275  return exp_sum;
1276 }
1277 
1278 /* \brief Apply kernel expression
1279  *
1280  * \param va vector expression one
1281  * \param vb vector expression two
1282  *
1283  * \return an object that encapsulate the expression
1284  *
1285  */
1286 template<unsigned int prp, typename NN, typename Kernel, typename vector_type, typename vector_type_ker>
1288  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1289  typename kl_selector_impl<Kernel,NN>::ktype,
1291  VECT_APPLYKER_IN_GEN>
1292 applyKernel_in_gen(const vector_dist_expression<prp,vector_type_ker> & va, vector_type & vd, NN & cl, Kernel & ker)
1293 {
1295  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1296  typename kl_selector_impl<Kernel,NN>::ktype,
1298  VECT_APPLYKER_IN_GEN> exp_sum(va,
1300  ker,
1302 
1303  return exp_sum;
1304 }
1305 
1306 /* \brief Apply kernel expression
1307  *
1308  * \param va vector expression one
1309  * \param vb vector expression two
1310  *
1311  * \return an object that encapsulate the expression
1312  *
1313  */
1314 template<unsigned int prp, typename NN, typename Kernel, typename vector_type, typename vector_type_ker>
1316  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1317  typename kl_selector_impl<Kernel,NN>::ktype,
1319  VECT_APPLYKER_IN_GEN_SORT>
1320 applyKernel_in_gen_sort(const vector_dist_expression<prp,vector_type_ker> & va, vector_type & vd, NN & cl, Kernel & ker)
1321 {
1323  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1324  typename kl_selector_impl<Kernel,NN>::ktype,
1326  VECT_APPLYKER_IN_GEN_SORT> exp_sum(va,
1328  ker,
1330 
1331  return exp_sum;
1332 }
1333 
1334 /* \brief Apply kernel expression
1335  *
1336  * \param va vector expression one
1337  * \param vb vector expression two
1338  *
1339  * \return an object that encapsulate the expression
1340  *
1341  */
1342 template<typename NN, typename Kernel, typename vector_type>
1343 inline vector_dist_expression_op<void,
1344  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1345  typename kl_selector_impl<Kernel,NN>::ktype,
1347  VECT_APPLYKER_IN_SIM>
1348 applyKernel_in_sim(vector_type & vd, NN & cl, Kernel & ker)
1349 {
1351  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1352  typename kl_selector_impl<Kernel,NN>::ktype,
1354  VECT_APPLYKER_IN_SIM> exp_sum(cl_selector_impl<NN>::get(cl),
1355  ker,
1357 
1358  return exp_sum;
1359 }
1360 
1361 /* \brief Apply kernel expression
1362  *
1363  * \param va vector expression one
1364  * \param vb vector expression two
1365  *
1366  * \return an object that encapsulate the expression
1367  *
1368  */
1369 template<typename NN, typename Kernel, typename vector_type>
1370 inline vector_dist_expression_op<void,
1371  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1372  typename kl_selector_impl<Kernel,NN>::ktype,
1374  VECT_APPLYKER_IN_SIM_SORT>
1375 applyKernel_in_sim_sort(vector_type & vd, NN & cl, Kernel & ker)
1376 {
1378  boost::mpl::vector<typename cl_selector_impl<NN>::ctype,
1379  typename kl_selector_impl<Kernel,NN>::ktype,
1381  VECT_APPLYKER_IN_SIM_SORT> exp_sum(cl_selector_impl<NN>::get(cl),
1382  ker,
1384 
1385  return exp_sum;
1386 }
1387 
1388 #endif /* OPENFPM_NUMERICS_SRC_OPERATORS_VECTOR_VECTOR_DIST_OPERATORS_APPLY_KERNEL_HPP_ */
std::remove_reference< NN >::type NN_nr
Return the type of the Cell-list.
mutable_or_not< NN, is_gpu_celllist< NN >::type::value||is_gpu_ker_celllist< NN >::type::value > cl
Cell-list.
__device__ static __host__ std::remove_reference< rtype >::type apply(const vector &vd, NN_type &cl, const vect_dist_key_dx &key, Kernel &lker)
Apply the kernel expression to a particle.
mutable_or_not< NN, is_gpu_celllist< NN >::type::value||is_gpu_ker_celllist< NN >::type::value > cl
Cell-list.
boost::mpl::at< vector_type, boost::mpl::int_< 2 > >::type vector_orig
Get the type of the vector containing the set of particles.
add_const_reference< vector_orig >::type vd
The vector that contain the particles.
boost::mpl::at< vector_type, boost::mpl::int_< 2 > >::type vector_orig
Return the vector containing the position of the particles.
__device__ __host__ std::remove_reference< rtype >::type value(const vect_dist_key_dx &key) const
Evaluate the expression.
std::remove_reference< vector_orig >::type vector_orig_nr
Return the vector containing the position of the particles.
std::remove_reference< Kernel >::type Kernel_nr
Return the type of the kernel.
boost::mpl::at< vector_type, boost::mpl::int_< 1 > >::type Kernel
Get the type of the kernel.
__device__ static __host__ Point< dim, T > create()
return a point with all the coordinates set to zero
boost::mpl::at< vector_type, boost::mpl::int_< 2 > >::type vector_orig
Return the vector containing the position of the particles.
std::remove_reference< Kernel >::type Kernel_nr
Return the type of the kernel.
std::remove_reference< Kernel >::type Kernel_nr
Return the type of the kernel.
mutable_or_not< NN, is_gpu_celllist< NN >::type::value||is_gpu_ker_celllist< NN >::type::value > cl
Cell-list.
exp rtype
indicate the return type of the expression exp
__device__ __host__ std::remove_reference< rtype >::type value(const vect_dist_key_dx &key) const
Evaluate the expression.
vector_dist_expression_op(const exp1 &o1, NN &cl, Kernel &ker, const vector_orig &vd)
Constructor.
__device__ __host__ std::remove_reference< rtype >::type value(const vect_dist_key_dx &key) const
Evaluate the expression.
apply_kernel_rtype< decltype(o1.value(vect_dist_key_dx()))>::rtype rtype
Get the return type of applying the kernel to a particle.
has_vector_kernel< vector_orig_nr >::type is_ker
indicate if this expression operate on kernel expression
std::remove_reference< vector_orig >::type vector_orig_nr
Return the vector containing the position of the particles.
__device__ __host__ void setKey(size_t key)
set the key
Meta-function to return a compatible zero-element.
apply_kernel_rtype< decltype(o1.value(vect_dist_key_dx()))>::rtype rtype
Return type of the expression.
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:27
Grid key for a distributed grid.
apply_kernel_rtype< decltype(o1.value(vect_dist_key_dx()))>::rtype rtype
Get the return type of applying the kernel to a particle.
boost::mpl::bool_< false > is_sort
indicate that is apply_kernel is not a sorted version
T & value(size_t i)
Return the reference to the value at coordinate i.
Definition: Point.hpp:419
boost::mpl::at< vector_type, boost::mpl::int_< 0 > >::type NN
Get the type of the Cell-list.
std::remove_reference< vector_orig >::type vector_orig_nr
Return the vector containing the position of the particles.
boost::mpl::at< vector_type, boost::mpl::int_< 2 > >::type vector_orig
Get the type of the vector containing the set of particles.
boost::mpl::at< vector_type, boost::mpl::int_< 1 > >::type Kernel
Return the type of the kernel.
vector_dist_expression_op(const exp1 &o1, NN_nr &cl, Kernel &ker, const vector_orig_nr &vd)
Constructor.
mutable_or_not< NN, is_gpu_celllist< NN >::type::value||is_gpu_ker_celllist< NN >::type::value > cl
Cell-list.
__host__ static __device__ std::remove_reference< rtype >::type apply(const vector &vd, NN_type &cl, const exp &v_exp, const vect_dist_key_dx &key, Kernel &lker)
Apply the kernel expression to a particle.
boost::mpl::at< vector_type, boost::mpl::int_< 1 > >::type Kernel
Get the type of the kernel.
std::remove_reference< NN >::type NN_nr
Return the type of the Cell-list.
std::remove_reference< Kernel >::type Kernel_nr
Return the type of the kernel.
vector_dist_expression_op(const exp1 &o1, NN &cl, Kernel &ker, const vector_orig &vd)
Constructor.
boost::mpl::bool_< true > is_sort
indicate that is apply_kernel is not a sorted version
mutable_or_not< Kernel, is_gpu_celllist< NN >::type::value||is_gpu_ker_celllist< NN >::type::value > ker
kernel
mutable_or_not< Kernel, is_gpu_celllist< NN >::type::value||is_gpu_ker_celllist< NN >::type::value > ker
kernel
boost::mpl::bool_< false > is_sort
indicate that is apply_kernel is not a sorted version
boost::mpl::at< vector_type, boost::mpl::int_< 1 > >::type Kernel
Get the type of the kernel.
boost::mpl::at< vector_type, boost::mpl::int_< 2 > >::type vector_orig
Get the type that contain the particle positions.
has_vector_kernel< vector_orig_nr >::type is_ker
indicate if this expression operate on kernel expression
mutable_or_not< Kernel, is_gpu_celllist< NN >::type::value||is_gpu_ker_celllist< NN >::type::value > ker
kernel
std::remove_reference< NN >::type NN_nr
Return the type of the Cell-list.
boost::mpl::bool_< false > is_sort
indicate that is apply_kernel is not a sorted version
has_vector_kernel< vector_orig_nr >::type is_ker
indicate if this expression operate on kernel expression
Unknown operation specialization.
mutable_or_not< Kernel, is_gpu_celllist< NN >::type::value||is_gpu_ker_celllist< NN >::type::value > ker
kernel
has_vector_kernel< vector_orig_nr >::type is_ker
indicate if this expression operate on kernel expression
mutable_or_not< Kernel, is_gpu_celllist< NN >::type::value||is_gpu_ker_celllist< NN >::type::value > ker
kernel
vector_dist_expression_op(NN &cl, Kernel &ker, const vector_orig &vd)
Constructor.
__device__ __host__ std::remove_reference< rtype >::type value(const vect_dist_key_dx &key) const
Evaluate the expression.
boost::mpl::at< vector_type, boost::mpl::int_< 0 > >::type NN
Get the type of the Cell-list.
std::remove_reference< vector_orig >::type vector_orig_nr
Return the vector containing the position of the particles.
Main class that encapsulate a vector properties operand to be used for expressions construction.
std::remove_reference< Kernel >::type Kernel_nr
Return the type of the kernel.
boost::mpl::at< vector_type, boost::mpl::int_< 0 > >::type NN
Return the type of the Cell-list.
boost::mpl::at< vector_type, boost::mpl::int_< 2 > >::type vector_orig
Get the type that contain the particle positions.
__device__ static __host__ rtype create()
return 0
Void structure.
Definition: common.hpp:73
std::remove_reference< NN >::type NN_nr
Return the type of the Cell-list.
Apply the kernel to particle differently that is a number or is an expression.
__device__ __host__ std::remove_reference< rtype >::type value(const vect_dist_key_dx &key) const
Evaluate the expression.
add_const_reference< vector_orig >::type vd
The vector that contain the particles.
boost::mpl::bool_< true > is_sort
indicate that is apply_kernel is not a sorted version
__device__ __host__ void zero()
Set to zero the point coordinate.
Definition: Point.hpp:284
std::remove_reference< vector_orig >::type vector_orig_nr
Return the vector containing the position of the particles.
exp::return_type rtype
indicate the return type of the expression exp
mutable_or_not< NN, is_gpu_celllist< NN >::type::value||is_gpu_ker_celllist< NN >::type::value > cl
Cell-list.
__device__ __host__ std::remove_reference< rtype >::type value(const vect_dist_key_dx &key) const
Evaluate the expression.
std::remove_reference< vector_orig >::type vector_orig_nr
Return the vector containing the position of the particles.
__device__ __host__ size_t getKey() const
Get the key.
apply_kernel_rtype< decltype(o1.value(vect_dist_key_dx()))>::rtype rtype
Return type of the expression.
apply_kernel_rtype< decltype(std::declval< Kernel_nr >).value(Point< vector_orig_nr::dims, typename vector_orig_nr::stype >0.0), Point< vector_orig_nr::dims, typename vector_orig_nr::stype >0.0)))>::rtype rtype
Get the return type of the expression.
Distributed vector.
has_vector_kernel< vector_orig_nr >::type is_ker
indicate if this expression operate on kernel expression
std::remove_reference< NN >::type NN_nr
Return the type of the Cell-list.
has_vector_kernel< vector_orig_nr >::type is_ker
indicate if this expression operate on kernel expression
It give the return type of the expression if applicable.
vector_dist_expression_op(const exp1 &o1, NN_nr &cl, Kernel &ker, const vector_orig_nr &vd)
Constructor.
Apply the kernel to particle differently that is a number or is an expression.
apply_kernel_rtype< decltype(std::declval< Kernel_nr >).value(Point< vector_orig_nr::dims, typename vector_orig_nr::stype >0.0), Point< vector_orig_nr::dims, typename vector_orig_nr::stype >0.0)))>::rtype rtype
Get the return type of the expression.
std::remove_reference< Kernel >::type Kernel_nr
Return the type of the kernel.
boost::mpl::at< vector_type, boost::mpl::int_< 0 > >::type NN
Get the type of the Cell-list.
boost::mpl::at< vector_type, boost::mpl::int_< 1 > >::type Kernel
Return the type of the kernel.
__device__ static __host__ std::remove_reference< rtype >::type apply(const vector &vd, NN_type &cl, const exp &v_exp, const vect_dist_key_dx &key, Kernel &lker)
Apply the kernel expression to a particle.
Check this is a gpu or cpu type cell-list.
Definition: util.hpp:87
boost::mpl::bool_< true > is_sort
indicate that is apply_kernel is not a sorted version
Apply the kernel to particle differently that is a number or is an expression.
mutable_or_not< Kernel, is_gpu_celllist< NN >::type::value||is_gpu_ker_celllist< NN >::type::value > ker
kernel
mutable_or_not< NN, is_gpu_celllist< NN >::type::value||is_gpu_ker_celllist< NN >::type::value > cl
Cell-list.
boost::mpl::at< vector_type, boost::mpl::int_< 1 > >::type Kernel
Get the type of the kernel.
boost::mpl::at< vector_type, boost::mpl::int_< 0 > >::type NN
Get the type of the Cell-list.
boost::mpl::at< vector_type, boost::mpl::int_< 0 > >::type NN
Return the type of the Cell-list.
std::remove_reference< NN >::type NN_nr
Return the type of the Cell-list.
is_expression check if a type is simple a type or is just an encapsulation of an expression