OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
vector_dist_operators_unit_tests.hpp
1 /*
2  * vector_dist_operators_unit_tests.hpp
3  *
4  * Created on: Jun 11, 2016
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_NUMERICS_SRC_OPERATORS_VECTOR_VECTOR_DIST_OPERATORS_UNIT_TESTS_HPP_
9 #define OPENFPM_NUMERICS_SRC_OPERATORS_VECTOR_VECTOR_DIST_OPERATORS_UNIT_TESTS_HPP_
10 
11 #include "Operators/Vector/vector_dist_operators.hpp"
12 
13 constexpr int A = 0;
14 constexpr int B = 1;
15 constexpr int C = 2;
16 
17 constexpr int VA = 3;
18 constexpr int VB = 4;
19 constexpr int VC = 5;
20 
21 constexpr int TA = 6;
22 
24 
25 template <unsigned int prp, typename vector> bool check_values(vector & v,float a)
26 {
27  bool ret = true;
28  auto it = v.getDomainIterator();
29 
30  while (it.isNext())
31  {
32  ret &= v.template getProp<prp>(it.get()) == a;
33 
34  ++it;
35  }
36 
37  BOOST_REQUIRE_EQUAL(ret,true);
38 
39  return ret;
40 }
41 
42 template <typename vector> bool check_values_complex_expr(vector & vd)
43 {
44  bool ret = true;
45  auto it = vd.getDomainIterator();
46 
47  while (it.isNext())
48  {
49  auto key = it.get();
50 
51  float base1 = vd.template getProp<B>(key) + 2.0 + vd.template getProp<B>(key) - 2.0*vd.template getProp<C>(key) / 5.0;
52  float base2 = vd.template getProp<A>(key);
53 
54  ret &= base1 == base2;
55 
56  ++it;
57  }
58 
59  BOOST_REQUIRE_EQUAL(ret,true);
60 
61  return ret;
62 }
63 
64 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_pos_sum(vector & vd, const rtype & p)
65 {
66  bool ret = true;
67  auto it = vd.getDomainIterator();
68 
69  while (it.isNext())
70  {
71  auto key = it.get();
72 
74 
75  rtype base1 = rtype(xp) + p;
76  rtype base2 = vd.template getProp<A>(key);
77 
78  ret &= base1 == base2;
79 
80  ++it;
81  }
82 
83  BOOST_REQUIRE_EQUAL(ret,true);
84 
85  return ret;
86 }
87 
88 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_pos_sub(vector & vd, const rtype & p)
89 {
90  bool ret = true;
91  auto it = vd.getDomainIterator();
92 
93  while (it.isNext())
94  {
95  auto key = it.get();
96 
98 
99  rtype base1 = rtype(xp) - p;
100  rtype base2 = vd.template getProp<A>(key);
101 
102  ret &= base1 == base2;
103 
104  ++it;
105  }
106 
107  BOOST_REQUIRE_EQUAL(ret,true);
108 
109  return ret;
110 }
111 
112 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_pos_sub_minus(vector & vd, const rtype & p)
113 {
114  bool ret = true;
115  auto it = vd.getDomainIterator();
116 
117  while (it.isNext())
118  {
119  auto key = it.get();
120 
122 
123  rtype base1 = -(rtype(xp) - p);
124  rtype base2 = vd.template getProp<A>(key);
125 
126  ret &= base1 == base2;
127 
128  ++it;
129  }
130 
131  BOOST_REQUIRE_EQUAL(ret,true);
132 
133  return ret;
134 }
135 
136 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_point_sub(vector & vd, const rtype & p)
137 {
138  bool ret = true;
139  auto it = vd.getDomainIterator();
140 
141  while (it.isNext())
142  {
143  auto key = it.get();
144 
145  rtype base1 = -vd.template getProp<B>(key);
146  rtype base2 = vd.template getProp<A>(key);
147 
148  ret &= base1 == base2;
149 
150  ++it;
151  }
152 
153  BOOST_REQUIRE_EQUAL(ret,true);
154 
155  return ret;
156 }
157 
158 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sum(vector & vd, double d)
159 {
160  bool ret = true;
161  auto it = vd.getDomainIterator();
162 
163  while (it.isNext())
164  {
165  auto key = it.get();
166 
167  rtype base1 = vd.template getProp<B>(key) + d;
168  rtype base2 = vd.template getProp<A>(key);
169 
170  ret &= base1 == base2;
171 
172  ++it;
173  }
174 
175  BOOST_REQUIRE_EQUAL(ret,true);
176 
177  return ret;
178 }
179 
180 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sum(vector & vd1, vector & vd2)
181 {
182  bool ret = true;
183  auto it = vd1.getDomainIterator();
184 
185  while (it.isNext())
186  {
187  auto key = it.get();
188 
189  rtype base1 = vd1.template getProp<B>(key) + vd2.template getProp<C>(key);
190  rtype base2 = vd1.template getProp<A>(key);
191 
192  ret &= base1 == base2;
193 
194  ++it;
195  }
196 
197  BOOST_REQUIRE_EQUAL(ret,true);
198 
199  return ret;
200 }
201 
202 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sum_3(vector & vd1)
203 {
204  bool ret = true;
205  auto it = vd1.getDomainIterator();
206 
207  while (it.isNext())
208  {
209  auto key = it.get();
210 
211  rtype base1 = vd1.template getProp<B>(key) + vd1.template getProp<C>(key) + vd1.template getProp<B>(key);
212  rtype base2 = vd1.template getProp<A>(key);
213 
214  ret &= base1 == base2;
215 
216  ++it;
217  }
218 
219  BOOST_REQUIRE_EQUAL(ret,true);
220 
221  return ret;
222 }
223 
224 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sum_4(vector & vd1)
225 {
226  bool ret = true;
227  auto it = vd1.getDomainIterator();
228 
229  while (it.isNext())
230  {
231  auto key = it.get();
232 
233  rtype base1 = (vd1.template getProp<B>(key) + vd1.template getProp<C>(key)) + (vd1.template getProp<B>(key) + vd1.template getProp<C>(key));
234  rtype base2 = vd1.template getProp<A>(key);
235 
236 
237  ret &= base1 == base2;
238 
239  ++it;
240  }
241 
242  BOOST_REQUIRE_EQUAL(ret,true);
243 
244  return ret;
245 }
246 
247 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sub(vector & vd, double d)
248 {
249  bool ret = true;
250  auto it = vd.getDomainIterator();
251 
252  while (it.isNext())
253  {
254  auto key = it.get();
255 
256  rtype base1 = vd.template getProp<B>(key) - d;
257  rtype base2 = vd.template getProp<A>(key);
258 
259  ret &= base1 == base2;
260 
261  ++it;
262  }
263 
264  BOOST_REQUIRE_EQUAL(ret,true);
265 
266  return ret;
267 }
268 
269 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sub(double d, vector & vd)
270 {
271  bool ret = true;
272  auto it = vd.getDomainIterator();
273 
274  while (it.isNext())
275  {
276  auto key = it.get();
277 
278  rtype base1 = d - vd.template getProp<B>(key);
279  rtype base2 = vd.template getProp<A>(key);
280 
281  ret &= base1 == base2;
282 
283  ++it;
284  }
285 
286  BOOST_REQUIRE_EQUAL(ret,true);
287 
288  return ret;
289 }
290 
291 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sub(vector & vd1, vector & vd2)
292 {
293  bool ret = true;
294  auto it = vd1.getDomainIterator();
295 
296  while (it.isNext())
297  {
298  auto key = it.get();
299 
300  rtype base1 = vd1.template getProp<C>(key) - vd2.template getProp<B>(key);
301  rtype base2 = vd1.template getProp<A>(key);
302 
303  ret &= base1 == base2;
304 
305  ++it;
306  }
307 
308  BOOST_REQUIRE_EQUAL(ret,true);
309 
310  return ret;
311 }
312 
313 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sub_31(vector & vd1)
314 {
315  bool ret = true;
316  auto it = vd1.getDomainIterator();
317 
318  while (it.isNext())
319  {
320  auto key = it.get();
321 
322  rtype base1 = vd1.template getProp<B>(key) - (vd1.template getProp<C>(key) + vd1.template getProp<B>(key));
323  rtype base2 = vd1.template getProp<A>(key);
324 
325  ret &= base1 == base2;
326 
327  ++it;
328  }
329 
330  BOOST_REQUIRE_EQUAL(ret,true);
331 
332  return ret;
333 }
334 
335 
336 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sub_32(vector & vd1)
337 {
338  bool ret = true;
339  auto it = vd1.getDomainIterator();
340 
341  while (it.isNext())
342  {
343  auto key = it.get();
344 
345  rtype base1 = (vd1.template getProp<C>(key) + vd1.template getProp<B>(key)) - vd1.template getProp<B>(key);
346  rtype base2 = vd1.template getProp<A>(key);
347 
348  ret &= base1 == base2;
349 
350  ++it;
351  }
352 
353  BOOST_REQUIRE_EQUAL(ret,true);
354 
355  return ret;
356 }
357 
358 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sub_4(vector & vd1)
359 {
360  bool ret = true;
361  auto it = vd1.getDomainIterator();
362 
363  while (it.isNext())
364  {
365  auto key = it.get();
366 
367  rtype base1 = (vd1.template getProp<C>(key) + vd1.template getProp<B>(key)) - (vd1.template getProp<C>(key) + vd1.template getProp<B>(key));
368  rtype base2 = vd1.template getProp<A>(key);
369 
370  ret &= base1 == base2;
371 
372  ++it;
373  }
374 
375  BOOST_REQUIRE_EQUAL(ret,true);
376 
377  return ret;
378 }
379 
380 
381 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_mul(vector & vd, double d)
382 {
383  bool ret = true;
384  auto it = vd.getDomainIterator();
385 
386  while (it.isNext())
387  {
388  auto key = it.get();
389 
390  rtype base1 = vd.template getProp<B>(key) * d;
391  rtype base2 = vd.template getProp<A>(key);
392 
393  ret &= base1 == base2;
394 
395  ++it;
396  }
397 
398  BOOST_REQUIRE_EQUAL(ret,true);
399 
400  return ret;
401 }
402 
403 
404 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_mul(vector & vd1, vector & vd2)
405 {
406  bool ret = true;
407  auto it = vd1.getDomainIterator();
408 
409  while (it.isNext())
410  {
411  auto key = it.get();
412 
413  rtype base1 = vd1.template getProp<C>(key) * vd2.template getProp<B>(key);
414  rtype base2 = vd1.template getProp<A>(key);
415 
416  ret &= base1 == base2;
417 
418  ++it;
419  }
420 
421  BOOST_REQUIRE_EQUAL(ret,true);
422 
423  return ret;
424 }
425 
426 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_mul_3(vector & vd1)
427 {
428  bool ret = true;
429  auto it = vd1.getDomainIterator();
430 
431  while (it.isNext())
432  {
433  auto key = it.get();
434 
435  rtype base1 = vd1.template getProp<B>(key) * (vd1.template getProp<B>(key) + vd1.template getProp<C>(key));
436  rtype base2 = vd1.template getProp<A>(key);
437 
438  ret &= base1 == base2;
439 
440  ++it;
441  }
442 
443  BOOST_REQUIRE_EQUAL(ret,true);
444 
445  return ret;
446 }
447 
448 
449 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_mul_4(vector & vd1)
450 {
451  bool ret = true;
452  auto it = vd1.getDomainIterator();
453 
454  while (it.isNext())
455  {
456  auto key = it.get();
457 
458  rtype base1 = (vd1.template getProp<B>(key) + vd1.template getProp<C>(key)) * (vd1.template getProp<B>(key) + vd1.template getProp<C>(key));
459  rtype base2 = vd1.template getProp<A>(key);
460 
461  ret &= base1 == base2;
462 
463  ++it;
464  }
465 
466  BOOST_REQUIRE_EQUAL(ret,true);
467 
468  return ret;
469 }
470 
471 
472 
473 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_div(vector & vd, double d)
474 {
475  bool ret = true;
476  auto it = vd.getDomainIterator();
477 
478  while (it.isNext())
479  {
480  auto key = it.get();
481 
482  rtype base1 = vd.template getProp<B>(key) / d;
483  rtype base2 = vd.template getProp<A>(key);
484 
485  ret &= base1 == base2;
486 
487  ++it;
488  }
489 
490  BOOST_REQUIRE_EQUAL(ret,true);
491 
492  return ret;
493 }
494 
495 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_div(double d, vector & vd)
496 {
497  bool ret = true;
498  auto it = vd.getDomainIterator();
499 
500  while (it.isNext())
501  {
502  auto key = it.get();
503 
504  rtype base1 = d / vd.template getProp<B>(key);
505  rtype base2 = vd.template getProp<A>(key);
506 
507  ret &= base1 == base2;
508 
509  ++it;
510  }
511 
512  BOOST_REQUIRE_EQUAL(ret,true);
513 
514  return ret;
515 }
516 
517 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_div(vector & vd1, vector & vd2)
518 {
519  bool ret = true;
520  auto it = vd1.getDomainIterator();
521 
522  while (it.isNext())
523  {
524  auto key = it.get();
525 
526  rtype base1 = vd1.template getProp<C>(key) / vd2.template getProp<B>(key);
527  rtype base2 = vd1.template getProp<A>(key);
528 
529  ret &= base1 == base2;
530 
531  ++it;
532  }
533 
534  BOOST_REQUIRE_EQUAL(ret,true);
535 
536  return ret;
537 }
538 
539 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_div_31(vector & vd1)
540 {
541  bool ret = true;
542  auto it = vd1.getDomainIterator();
543 
544  while (it.isNext())
545  {
546  auto key = it.get();
547 
548  rtype base1 = vd1.template getProp<B>(key) / (vd1.template getProp<B>(key) + vd1.template getProp<C>(key));
549  rtype base2 = vd1.template getProp<A>(key);
550 
551  ret &= base1 == base2;
552 
553  ++it;
554  }
555 
556  BOOST_REQUIRE_EQUAL(ret,true);
557 
558  return ret;
559 }
560 
561 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_div_32(vector & vd1)
562 {
563  bool ret = true;
564  auto it = vd1.getDomainIterator();
565 
566  while (it.isNext())
567  {
568  auto key = it.get();
569 
570  rtype base1 = (vd1.template getProp<C>(key) + vd1.template getProp<B>(key)) / vd1.template getProp<B>(key);
571  rtype base2 = vd1.template getProp<A>(key);
572 
573  ret &= base1 == base2;
574 
575  ++it;
576  }
577 
578  BOOST_REQUIRE_EQUAL(ret,true);
579 
580  return ret;
581 }
582 
583 
584 template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_div_4(vector & vd1)
585 {
586  bool ret = true;
587  auto it = vd1.getDomainIterator();
588 
589  while (it.isNext())
590  {
591  auto key = it.get();
592 
593  rtype base1 = (vd1.template getProp<B>(key) + vd1.template getProp<C>(key)) / (vd1.template getProp<B>(key) + vd1.template getProp<C>(key));
594  rtype base2 = vd1.template getProp<A>(key);
595 
596  ret &= base1 == base2;
597 
598  ++it;
599  }
600 
601  BOOST_REQUIRE_EQUAL(ret,true);
602 
603  return ret;
604 }
605 
606 template <typename vector> bool check_values_scal_norm_dist(vector & vd)
607 {
608  bool ret = true;
609  auto it = vd.getDomainIterator();
610 
611  while (it.isNext())
612  {
613  auto key = it.get();
614 
615  float base1 = vd.template getProp<VB>(key) * vd.template getProp<VC>(key) + norm(vd.template getProp<VC>(key) + vd.template getProp<VB>(key)) + distance(vd.template getProp<VC>(key),vd.template getProp<VB>(key));
616  float base2 = vd.template getProp<A>(key);
617 
618  ret &= base1 == base2;
619 
620  ++it;
621  }
622 
623  BOOST_REQUIRE_EQUAL(ret,true);
624 
625  return ret;
626 }
627 
628 template <typename vector> void fill_values(vector & v)
629 {
630  auto it = v.getDomainIterator();
631 
632  while (it.isNext())
633  {
634  auto p = it.get();
635 
636  v.getPos(p)[0] = (float)rand() / RAND_MAX;
637  v.getPos(p)[1] = (float)rand() / RAND_MAX;
638  v.getPos(p)[2] = (float)rand() / RAND_MAX;
639 
640  v.template getProp<A>(p) = fabs(sin(p.getKey()+1.0));
641  v.template getProp<B>(p) = fabs(sin(2.0*p.getKey()+3.0));
642  v.template getProp<C>(p) = fabs(sin(3.0*p.getKey()+18.0));
643 
644  for (size_t k = 0 ; k < 3 ; k++)
645  {
646  v.template getProp<VA>(p)[k] = fabs(sin(p.getKey()+1.0+k));
647  v.template getProp<VB>(p)[k] = fabs(sin(2.0*p.getKey()+1.0+3.0));
648  v.template getProp<VC>(p)[k] = fabs(sin(3.0*p.getKey()+1.0+k));
649  }
650 
651  ++it;
652  }
653 }
654 
655 
657 
660 {
662  float var;
663 
666  :var(var)
667  {}
668 
679  inline float value(const Point<3,float> & p, const Point<3,float> & q,float pA,float pB)
680  {
681  float dist = norm(p-q);
682 
683  return (pA + pB) * exp(dist * dist / var);
684  }
685 
696  inline Point<3,float> value(const Point<3,float> & p, const Point<3,float> & q,const Point<3,float> & pA, const Point<3,float> & pB)
697  {
698  float dist = norm(p-q);
699 
700  return (pA + pB) * exp(dist * dist / var);
701  }
702 
714  inline float value(size_t p, size_t q, float pA, float pB, const vector_type & vd1)
715  {
716  Point<3,float> pp = vd1.getPos(p);
717  Point<3,float> pq = vd1.getPos(q);
718 
719  float dist = norm(pp-pq);
720 
721  return (pA + pB) * exp(dist * dist / var);
722  }
723 
735  inline Point<3,float> value(size_t p, size_t q, const Point<3,float> & pA, const Point<3,float> & pB , const vector_type & vd1)
736  {
737  Point<3,float> pp = vd1.getPos(p);
738  Point<3,float> pq = vd1.getPos(q);
739 
740  float dist = norm(pp-pq);
741 
742  return (pA + pB) * exp(dist * dist / var);
743  }
744 
753  inline Point<2,float> value(const Point<3,float> & p, const Point<3,float> & q)
754  {
755  float dist = norm(p-q);
756 
757  return exp(dist * dist / var);
758  }
759 };
760 
762 
763 BOOST_AUTO_TEST_SUITE( vector_dist_operators_test )
764 
765 
766 BOOST_AUTO_TEST_CASE( vector_dist_operators_test )
767 {
768  if (create_vcluster().getProcessingUnits() > 3)
769  return;
770 
771  Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
772 
773  // Boundary conditions
774  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
775 
776  // ghost
777  Ghost<3,float> ghost(0.05);
778 
779  // vector type
780  typedef vector_dist<3,float,aggregate<float,float,float,VectorS<3,float>,VectorS<3,float>,VectorS<3,float>>> vtype;
781 
782  vector_dist<3,float,aggregate<float,float,float,VectorS<3,float>,VectorS<3,float>,VectorS<3,float>>> vd(100,box,bc,ghost);
783 
784  auto vA = getV<A>(vd);
785  auto vB = getV<B>(vd);
786  auto vC = getV<C>(vd);
787 
788  auto vVA = getV<VA>(vd);
789  auto vVB = getV<VB>(vd);
790  auto vVC = getV<VC>(vd);
791 
792  auto vPOS = getV<PROP_POS>(vd);
793 
794  vA = 1.0;
795  vB = 2.0f;
796  vC = 3.0;
797 
798  check_values<A>(vd,1.0);
799  check_values<B>(vd,2.0);
800  check_values<C>(vd,3.0);
801 
802  vA = vB;
803  check_values<A>(vd,2.0);
804 
805  fill_values(vd);
806 
807  vA = vB + 2.0 + vB - 2.0*vC / 5.0;
808  check_values_complex_expr(vd);
809 
810  // Various combination of 2 operator
811 
812  vA = vB + 2.0;
813  check_values_sum<float,vtype,A,B,C>(vd,2.0);
814  vA = 2.0 + vB;
815  check_values_sum<float,vtype,A,B,C>(vd,2.0);
816  vA = vC + vB;
817  check_values_sum<float,vtype,A,B,C>(vd,vd);
818 
819  vA = vB - 2.0;
820  check_values_sub<float,vtype,A,B,C>(vd,2.0);
821  vA = 2.0 - vB;
822  check_values_sub<float,vtype,A,B,C>(2.0,vd);
823  vA = vC - vB;
824  check_values_sub<float,vtype,A,B,C>(vd,vd);
825 
826  vA = vB * 2.0;
827  check_values_mul<float,vtype,A,B,C>(vd,2.0);
828  vA = 2.0 * vB;
829  check_values_mul<float,vtype,A,B,C>(vd,2.0);
830  vA = vC * vB;
831  check_values_mul<float,vtype,A,B,C>(vd,vd);
832 
833  vA = vB / 2.0;
834  check_values_div<float,vtype,A,B,C>(vd,2.0);
835  vA = 2.0 / vB;
836  check_values_div<float,vtype,A,B,C>(2.0,vd);
837  vA = vC / vB;
838  check_values_div<float,vtype,A,B,C>(vd,vd);
839 
840  // Variuos combination 3 operator
841 
842  vA = vB + (vC + vB);
843  check_values_sum_3<float,vtype,A,B,C>(vd);
844  vA = (vC + vB) + vB;
845  check_values_sum_3<float,vtype,A,B,C>(vd);
846  vA = (vC + vB) + (vC + vB);
847  check_values_sum_4<float,vtype,A,B,C>(vd);
848 
849  vA = vB - (vC + vB);
850  check_values_sub_31<float,vtype,A,B,C>(vd);
851  vA = (vC + vB) - vB;
852  check_values_sub_32<float,vtype,A,B,C>(vd);
853  vA = (vC + vB) - (vC + vB);
854  check_values_sub_4<float,vtype,A,B,C>(vd);
855 
856  vA = vB * (vC + vB);
857  check_values_mul_3<float,vtype,A,B,C>(vd);
858  vA = (vC + vB) * vB;
859  check_values_mul_3<float,vtype,A,B,C>(vd);
860  vA = (vC + vB) * (vC + vB);
861  check_values_mul_4<float,vtype,A,B,C>(vd);
862 
863  vA = vB / (vC + vB);
864  check_values_div_31<float,vtype,A,B,C>(vd);
865  vA = (vC + vB) / vB;
866  check_values_div_32<float,vtype,A,B,C>(vd);
867  vA = (vC + vB) / (vC + vB);
868  check_values_div_4<float,vtype,A,B,C>(vd);
869 
870  // We try with vectors
871 
872  // Various combination of 2 operator
873 
874  vVA = vVB + 2.0;
875  check_values_sum<VectorS<3,float>,vtype,VA,VB,VC>(vd,2.0f);
876  vVA = 2.0 + vVB;
877  check_values_sum<VectorS<3,float>,vtype,VA,VB,VC>(vd,2.0f);
878  vVA = vVC + vVB;
879  check_values_sum<VectorS<3,float>,vtype,VA,VB,VC>(vd,vd);
880 
881  vVA = vVB - 2.0;
882  check_values_sub<VectorS<3,float>,vtype,VA,VB,VC>(vd,2.0f);
883  vVA = 2.0 - vVB;
884  check_values_sub<VectorS<3,float>,vtype,VA,VB,VC>(2.0f,vd);
885  vVA = vVC - vVB;
886  check_values_sub<VectorS<3,float>,vtype,VA,VB,VC>(vd,vd);
887 
888  vVA = vVB * 2.0;
889  check_values_mul<VectorS<3,float>,vtype,VA,VB,VC>(vd,2.0f);
890  vVA = 2.0 * vVB;
891  check_values_mul<VectorS<3,float>,vtype,VA,VB,VC>(vd,2.0f);
892  vVA = vVC * vVB;
893  check_values_mul<VectorS<3,float>,vtype,VA,VB,VC>(vd,vd);
894 
895  vVA = vVB / 2.0;
896  check_values_div<VectorS<3,float>,vtype,VA,VB,VC>(vd,2.0f);
897  vVA = 2.0 / vVB;
898  check_values_div<VectorS<3,float>,vtype,VA,VB,VC>(2.0f,vd);
899  vVA = vVC / vVB;
900  check_values_div<VectorS<3,float>,vtype,VA,VB,VC>(vd,vd);
901 
902  // Variuos combination 3 operator
903 
904  vVA = vVB + (vVC + vVB);
905  check_values_sum_3<VectorS<3,float>,vtype,VA,VB,VC>(vd);
906  vVA = (vVC + vVB) + vVB;
907  check_values_sum_3<VectorS<3,float>,vtype,VA,VB,VC>(vd);
908  vVA = (vVC + vVB) + (vVC + vVB);
909  check_values_sum_4<VectorS<3,float>,vtype,VA,VB,VC>(vd);
910 
911  vVA = vVB - (vVC + vVB);
912  check_values_sub_31<VectorS<3,float>,vtype,VA,VB,VC>(vd);
913  vVA = (vVC + vVB) - vVB;
914  check_values_sub_32<VectorS<3,float>,vtype,VA,VB,VC>(vd);
915  vVA = (vVC + vVB) - (vVC + vVB);
916  check_values_sub_4<VectorS<3,float>,vtype,VA,VB,VC>(vd);
917 
918  vVA = vVB * (vVC + vVB);
919  check_values_mul_3<VectorS<3,float>,vtype,VA,VB,VC>(vd);
920  vVA = (vVC + vVB) * vVB;
921  check_values_mul_3<VectorS<3,float>,vtype,VA,VB,VC>(vd);
922  vVA = (vVC + vVB) * (vVC + vVB);
923  check_values_mul_4<VectorS<3,float>,vtype,VA,VB,VC>(vd);
924  vA = vVB * (vVC + vVB);
925  check_values_mul_3<float,vtype,A,VB,VC>(vd);
926  vA = (vVC + vVB) * vVB;
927  check_values_mul_3<float,vtype,A,VB,VC>(vd);
928  vA = (vVC + vVB) * (vVC + vVB);
929  check_values_mul_4<float,vtype,A,VB,VC>(vd);
930 
931  vVA = vVB / (vVC + vVB);
932  check_values_div_31<VectorS<3,float>,vtype,VA,VB,VC>(vd);
933  vVA = (vVC + vVB) / vVB;
934  check_values_div_32<VectorS<3,float>,vtype,VA,VB,VC>(vd);
935  vVA = (vVC + vVB) / (vVC + vVB);
936  check_values_div_4<VectorS<3,float>,vtype,VA,VB,VC>(vd);
937 
938  // normalization function
939 
940  vA = vVB * vVC + norm(vVC + vVB) + openfpm::distance(vVC,vVB);
941  check_values_scal_norm_dist(vd);
942 
943  Point<3,float> p0({2.0,2.0,2.0});
944  auto p0_e = getVExpr(p0);
945 
946  vVA = vPOS + p0_e;
947  check_values_pos_sum<VectorS<3,float>,vtype,VA,VB,VC>(vd,p0);
948 
949  vVA = vPOS - p0_e;
950  check_values_pos_sub<Point<3,float>,vtype,VA,VB,VC>(vd,p0);
951 
952  vVA = -(vPOS - p0_e);
953  check_values_pos_sub_minus<Point<3,float>,vtype,VA,VB,VC>(vd,p0);
954 
955  vVA = -vVB;
956  check_values_point_sub<Point<3,float>,vtype,VA,VB,VC>(vd,p0);
957 
958  // Just check it compile testing it will test the same code
959  // as the previuous one
960  vVC = exp(vVB);
961  vA = norm(vPOS);
962  vVA = vPOS + 2.0;
963  vVA = 2.0 + vPOS;
964  vVA = vPOS + vPOS;
965  vVA = vPOS - 2.0f;
966  vVA = 2.0 - vPOS;
967  vVA = vPOS - vPOS;
968 
969  vVA = vPOS * 2.0;
970  vVA = 2.0 * vPOS;
971  vVA = vPOS * vPOS;
972 
973  vVA = vPOS / 2.0f;
974  vVA = 2.0f / vPOS;
975  vVA = vPOS / vPOS;
976 
977  // Variuos combination 3 operator
978 
979  vVA = vPOS + (vPOS + vPOS);
980  vVA = (vPOS + vPOS) + vPOS;
981  vVA = (vPOS + vPOS) + (vPOS + vPOS);
982 
983  vVA = vPOS - (vPOS + vPOS);
984  vVA = (vPOS + vPOS) - vPOS;
985  vVA = (vVC + vPOS) - (vPOS + vPOS);
986 
987  vVA = vPOS * (vPOS + vPOS);
988  vVA = (vPOS + vPOS) * vPOS;
989  vVA = (vPOS + vPOS) * (vPOS + vPOS);
990  vA = vPOS * (vPOS + vPOS);
991  vA = (vPOS + vPOS) * vPOS;
992  vA = (vPOS + vPOS) * (vPOS + vPOS);
993 
994  vVA = vPOS / (vPOS + vPOS);
995  vVA = (vPOS + vPOS) / vPOS;
996  vVA = (vPOS + vPOS) / (vPOS + vPOS);
997 }
998 
999 #include "vector_dist_operators_apply_kernel_unit_tests.hpp"
1000 
1002 {
1003  auto it = v1.getDomainIterator();
1004 
1005  while (it.isNext())
1006  {
1007  auto p = it.get();
1008 
1009  v1.template getProp<0>(p) = -1.0;
1010  v1.template getProp<1>(p) = -1.0;
1011  v1.template getProp<2>(p) = -1.0;
1012  v1.template getProp<3>(p) = -1.0;
1013  v1.template getProp<4>(p) = -1.0;
1014  v1.template getProp<5>(p) = -1.0;
1015  v1.template getProp<6>(p) = -1.0;
1016  v1.template getProp<7>(p) = -1.0;
1017 
1018  ++it;
1019  }
1020 }
1021 
1022 template<unsigned int i> void loop_check(vector_dist<3,float,aggregate<float,float,float,float,float,float,float,float>> & v1, float check)
1023 {
1024  auto it = v1.getDomainIterator();
1025  bool ret = true;
1026 
1027  while (it.isNext())
1028  {
1029  auto p = it.get();
1030 
1031  ret &= v1.template getProp<i>(p) == check;
1032 
1033  ++it;
1034  }
1035 
1036  BOOST_REQUIRE_EQUAL(ret,true);
1037 }
1038 
1040 {
1041  float check = -1.0;
1042 
1043  if (0 < i) check = 0.0;
1044  else check = -1.0;
1045  loop_check<0>(v1,check);
1046 
1047  if (1 < i) check = 1.0;
1048  else check = -1.0;
1049  loop_check<1>(v1,check);
1050 
1051  if (2 < i) check = 2.0;
1052  else check = -1.0;
1053  loop_check<2>(v1,check);
1054 
1055  if (3 < i) check = 3.0;
1056  else check = -1.0;
1057  loop_check<3>(v1,check);
1058 
1059  if (4 < i) check = 4.0;
1060  else check = -1.0;
1061  loop_check<4>(v1,check);
1062 
1063  if (5 < i) check = 5.0;
1064  else check = -1.0;
1065  loop_check<5>(v1,check);
1066 
1067  if (6 < i) check = 6.0;
1068  else check = -1.0;
1069  loop_check<6>(v1,check);
1070 
1071  if (7 < i) check = 7.0;
1072  else check = -1.0;
1073  loop_check<7>(v1,check);
1074 }
1075 
1076 BOOST_AUTO_TEST_CASE( vector_dist_operators_assign_test )
1077 {
1078  if (create_vcluster().getProcessingUnits() > 3)
1079  return;
1080 
1081  Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
1082 
1083  // Boundary conditions
1084  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
1085 
1086  // ghost
1087  Ghost<3,float> ghost(0.05);
1088 
1090 
1091  auto v1 = getV<0>(vd);
1092  auto v2 = getV<1>(vd);
1093  auto v3 = getV<2>(vd);
1094  auto v4 = getV<3>(vd);
1095  auto v5 = getV<4>(vd);
1096  auto v6 = getV<5>(vd);
1097  auto v7 = getV<6>(vd);
1098  auto v8 = getV<7>(vd);
1099 
1100  reset(vd);
1101 
1102  assign(v1,0.0,
1103  v2,1.0);
1104 
1105  check(vd,2);
1106 
1107  reset(vd);
1108 
1109  assign(v1,0.0,
1110  v2,1.0,
1111  v3,2.0);
1112 
1113  check(vd,3);
1114 
1115  reset(vd);
1116 
1117  assign(v1,0.0,
1118  v2,1.0,
1119  v3,2.0,
1120  v4,3.0);
1121 
1122  check(vd,4);
1123 
1124  reset(vd);
1125 
1126  assign(v1,0.0,
1127  v2,1.0,
1128  v3,2.0,
1129  v4,3.0,
1130  v5,4.0);
1131 
1132  check(vd,5);
1133 
1134  reset(vd);
1135 
1136  assign(v1,0.0,
1137  v2,1.0,
1138  v3,2.0,
1139  v4,3.0,
1140  v5,4.0,
1141  v6,5.0);
1142 
1143  check(vd,6);
1144 
1145  reset(vd);
1146 
1147  assign(v1,0.0,
1148  v2,1.0,
1149  v3,2.0,
1150  v4,3.0,
1151  v5,4.0,
1152  v6,5.0,
1153  v7,6.0);
1154 
1155  check(vd,7);
1156 
1157  reset(vd);
1158 
1159  assign(v1,0.0,
1160  v2,1.0,
1161  v3,2.0,
1162  v4,3.0,
1163  v5,4.0,
1164  v6,5.0,
1165  v7,6.0,
1166  v8,7.0);
1167 
1168  check(vd,8);
1169 }
1170 
1171 BOOST_AUTO_TEST_SUITE_END()
1172 
1173 
1174 #endif /* OPENFPM_NUMERICS_SRC_OPERATORS_VECTOR_VECTOR_DIST_OPERATORS_UNIT_TESTS_HPP_ */
Point< 3, float > value(const Point< 3, float > &p, const Point< 3, float > &q, const Point< 3, float > &pA, const Point< 3, float > &pB)
Result of the exponential kernel.
auto getPos(vect_dist_key_dx vec_key) -> decltype(v_pos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:22
Definition: Ghost.hpp:39
float value(size_t p, size_t q, float pA, float pB, const vector_type &vd1)
Result of the exponential kernel.
Point< 3, float > value(size_t p, size_t q, const Point< 3, float > &pA, const Point< 3, float > &pB, const vector_type &vd1)
Result of the exponential kernel.
exp_kernel(float var)
Exponential kernel giving variance.
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:201
float value(const Point< 3, float > &p, const Point< 3, float > &q, float pA, float pB)
Result of the exponential kernel.
Point< 2, float > value(const Point< 3, float > &p, const Point< 3, float > &q)
Result of the exponential kernel.
float var
variance of the exponential kernel
Distributed vector.
auto distance(T exp1, P exp2) -> decltype(norm(exp1-exp2))
General distance formula.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Definition: aggregate.hpp:81