Rheolef  7.1
an efficient C++ finite element environment
point_util.h
Go to the documentation of this file.
1 #ifndef _RHEOLEF_POINT_UTIL_H
2 #define _RHEOLEF_POINT_UTIL_H
3 // utility: handle for pair(size_t,point)
24 //
25 // formaly, we want to do in distributed ernvironment:
26 // mpi::all_reduce (omega.comm(), disarray[dis_i,x], mpi::minimum<pair<size_t,point> >());
27 // where mpi::minimum<pair<size_t,point> >(a,b) takes min of idx and point coords
28 //
29 
30 #include "rheolef/distributor.h"
31 #include "rheolef/point.h"
32 
33 // -----------------------------------------------------------
34 // pair(size_t,point)
35 // -----------------------------------------------------------
36 namespace rheolef {
37 
38 template <class T>
39 struct id_pt_t : std::pair<size_t,point_basic<T> > {
40  typedef std::pair<size_t,point_basic<T> > base;
41  id_pt_t () : base() {}
42  id_pt_t (size_t dis_i, const point_basic<T>& x) : base(dis_i,x) {}
43  template<class Archive>
44  void serialize (Archive& ar, const unsigned int version) {
45  ar & base::first;
46  ar & base::second;
47  }
48 };
49 } // namespace rheolef
50 
51 #ifdef _RHEOLEF_HAVE_MPI
52 // Some serializable types have a fixed amount of data stored at fixed field positions.
53 // When this is the case, boost::mpi can optimize their serialization and transmission to avoid extraneous copy operations.
54 // To enable this optimization, we specialize the type trait is_mpi_datatype, e.g.:
55 namespace boost {
56  namespace mpi {
57  // TODO: when id_pt_t<T> is not a simple type, such as T=bigfloat or T=gmp, etc
58  template <>
59  struct is_mpi_datatype<rheolef::id_pt_t<double> > : mpl::true_ { };
60  } // namespace mpi
61 } // namespace boost
62 #endif // _RHEOLEF_HAVE_MPI
63 
64 namespace rheolef {
65 
66 template <class T>
67 struct id_pt_minimum : public std::binary_function<id_pt_t<T>, id_pt_t<T>, id_pt_t<T> > {
70  size_t id = std::min(a.first, b.first);
71  point_basic<T> pt (std::min(a.second[0],b.second[0]),
72  std::min(a.second[1],b.second[1]),
73  std::min(a.second[2],b.second[2]));
74  return id_pt_t<T>(id,pt);
75  }
76 };
77 
78 } // namespace rheolef
79 // -----------------------------------------------------------
80 // pair(point,point)
81 // -----------------------------------------------------------
82 namespace rheolef {
83 
84 template <class T>
85 struct pt2_t : std::pair<point_basic<T>,point_basic<T> > {
86  typedef std::pair<point_basic<T>,point_basic<T> > base;
87  pt2_t () : base() {}
88  pt2_t (const point_basic<T>& x, const point_basic<T>& y) : base(x,y) {}
89  template<class Archive>
90  void serialize (Archive& ar, const unsigned int version) {
91  ar & base::first;
92  ar & base::second;
93  }
94 };
95 } // namespace rheolef
96 
97 #ifdef _RHEOLEF_HAVE_MPI
98 // Some serializable types have a fixed amount of data stored at fixed field positions.
99 // When this is the case, boost::mpi can optimize their serialization and transmission to avoid extraneous copy operations.
100 // To enable this optimization, we specialize the type trait is_mpi_datatype, e.g.:
101 namespace boost {
102  namespace mpi {
103  // TODO: when pt2_t<T> is not a simple type, such as T=bigfloat or T=gmp, etc
104  template <>
105  struct is_mpi_datatype<rheolef::pt2_t<double> > : mpl::true_ { };
106  } // namespace mpi
107 } // namespace boost
108 #endif // _RHEOLEF_HAVE_MPI
109 
110 namespace rheolef {
111 
112 template <class T>
113 struct pt2_minimum : public std::binary_function<pt2_t<T>, pt2_t<T>, pt2_t<T> > {
116  point_basic<T> pt1 (std::min(a.first [0],b.first [0]),
117  std::min(a.first [1],b.first [1]),
118  std::min(a.first [2],b.first [2]));
119  point_basic<T> pt2 (std::min(a.second[0],b.second[0]),
120  std::min(a.second[1],b.second[1]),
121  std::min(a.second[2],b.second[2]));
122  return pt2_t<T>(pt1,pt2);
123  }
124 };
125 
126 } // namespace rheolef
127 
128 
129 #endif // _RHEOLEF_POINT_UTIL_H
rheolef::pt2_minimum::pt2_minimum
pt2_minimum()
Definition: point_util.h:114
rheolef::point_basic
Definition: point.h:87
rheolef::id_pt_t
Definition: point_util.h:39
rheolef::pt2_t
Definition: point_util.h:85
rheolef::id_pt_minimum::id_pt_minimum
id_pt_minimum()
Definition: point_util.h:68
rheolef::pt2_t::base
std::pair< point_basic< T >, point_basic< T > > base
Definition: point_util.h:86
boost
Definition: mpi_pair_datatype.h:46
rheolef-config.version
version
Definition: rheolef-config.in:126
rheolef::id_pt_t::id_pt_t
id_pt_t()
Definition: point_util.h:41
rheolef::id_pt_minimum
Definition: point_util.h:67
boost::mpi
Definition: mpi_pair_datatype.h:47
a
Definition: diffusion_isotropic.h:25
rheolef::id_pt_t::base
std::pair< size_t, point_basic< T > > base
Definition: point_util.h:40
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::pt2_minimum::operator()
pt2_t< T > operator()(const pt2_t< T > &a, const pt2_t< T > &b)
Definition: point_util.h:115
mkgeo_ball.b
b
Definition: mkgeo_ball.sh:152
rheolef::pt2_minimum
Definition: point_util.h:113
rheolef::pt2_t::pt2_t
pt2_t()
Definition: point_util.h:87
rheolef::pt2_t::pt2_t
pt2_t(const point_basic< T > &x, const point_basic< T > &y)
Definition: point_util.h:88
rheolef::id_pt_t::id_pt_t
id_pt_t(size_t dis_i, const point_basic< T > &x)
Definition: point_util.h:42
rheolef::id_pt_minimum::operator()
id_pt_t< T > operator()(const id_pt_t< T > &a, const id_pt_t< T > &b)
Definition: point_util.h:69
rheolef::pt2_t::serialize
void serialize(Archive &ar, const unsigned int version)
Definition: point_util.h:90
rheolef::id_pt_t::serialize
void serialize(Archive &ar, const unsigned int version)
Definition: point_util.h:44