rheolef  6.3
point_util.h
Go to the documentation of this file.
1 #ifndef _RHEOLEF_POINT_UTIL_H
2 #define _RHEOLEF_POINT_UTIL_H
3 // mpi::all_reduce (omega.comm(), array[dis_i,x], mpi::minimum<pair<size_t,point> >());
4 // where mpi::minimum<pair<size_t,point> >(a,b) takes min of idx and point coords
5 
6 #include "rheolef/distributor.h"
7 #include "rheolef/point.h"
8 
9 namespace rheolef {
10 
11 template <class T>
12 struct id_pt_t : std::pair<size_t,point_basic<T> > {
13  typedef std::pair<size_t,point_basic<T> > base;
14  id_pt_t () : base() {}
15  id_pt_t (size_t dis_i, const point_basic<T>& x) : base(dis_i,x) {}
16  template<class Archive>
17  void serialize (Archive& ar, const unsigned int version) {
18  ar & base::first;
19  ar & base::second;
20  }
21 };
22 } // namespace rheolef
23 
24 #ifdef _RHEOLEF_HAVE_MPI
25 namespace boost {
26  namespace mpi {
27  // TODO: when id_pt_t<T> is not a simple type, such as T=doubledouble or T=gmp, etc
28  template <>
29  struct is_mpi_datatype<rheolef::id_pt_t<double> > : mpl::true_ { };
30  } // namespace mpi
31 } // namespace boost
32 #endif // _RHEOLEF_HAVE_MPI
33 
34 namespace rheolef {
35 
36 template <class T>
37 struct id_pt_minimum : public std::binary_function<id_pt_t<T>, id_pt_t<T>, id_pt_t<T> > {
40  size_t id = std::min(a.first, b.first);
41  point_basic<T> pt (std::min(a.second[0],b.second[0]),
42  std::min(a.second[1],b.second[1]),
43  std::min(a.second[2],b.second[2]));
44  return id_pt_t<T>(id,pt);
45  }
46 };
47 
48 } // namespace rheolef
49 namespace rheolef {
50 
51 template <class T>
52 struct pt2_t : std::pair<point_basic<T>,point_basic<T> > {
53  typedef std::pair<point_basic<T>,point_basic<T> > base;
54  pt2_t () : base() {}
55  pt2_t (const point_basic<T>& x, const point_basic<T>& y) : base(x,y) {}
56  template<class Archive>
57  void serialize (Archive& ar, const unsigned int version) {
58  ar & base::first;
59  ar & base::second;
60  }
61 };
62 } // namespace rheolef
63 
64 #ifdef _RHEOLEF_HAVE_MPI
65 namespace boost {
66  namespace mpi {
67  // TODO: when pt2_t<T> is not a simple type, such as T=doubledouble or T=gmp, etc
68  template <>
69  struct is_mpi_datatype<rheolef::pt2_t<double> > : mpl::true_ { };
70  } // namespace mpi
71 } // namespace boost
72 #endif // _RHEOLEF_HAVE_MPI
73 
74 namespace rheolef {
75 
76 template <class T>
77 struct pt2_minimum : public std::binary_function<pt2_t<T>, pt2_t<T>, pt2_t<T> > {
79  pt2_t<T> operator() (const pt2_t<T>& a, const pt2_t<T>& b) {
80  point_basic<T> pt1 (std::min(a.first [0],b.first [0]),
81  std::min(a.first [1],b.first [1]),
82  std::min(a.first [2],b.first [2]));
83  point_basic<T> pt2 (std::min(a.second[0],b.second[0]),
84  std::min(a.second[1],b.second[1]),
85  std::min(a.second[2],b.second[2]));
86  return pt2_t<T>(pt1,pt2);
87  }
88 };
89 
90 } // namespace rheolef
91 
92 
93 #endif // _RHEOLEF_POINT_UTIL_H
94