Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
point_util.h
Go to the documentation of this file.
1#ifndef _RHEOLEF_POINT_UTIL_H
2#define _RHEOLEF_POINT_UTIL_H
23// 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// -----------------------------------------------------------
36namespace rheolef {
37
38template <class T>
39struct 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.:
55namespace 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
64namespace rheolef {
65
66template <class T>
67struct 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// -----------------------------------------------------------
82namespace rheolef {
83
84template <class T>
85struct 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.:
101namespace 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
110namespace rheolef {
111
112template <class T>
113struct pt2_minimum : public std::binary_function<pt2_t<T>, pt2_t<T>, pt2_t<T> > {
115 pt2_t<T> operator() (const pt2_t<T>& a, const pt2_t<T>& b) {
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
This file is part of Rheolef.
id_pt_t< T > operator()(const id_pt_t< T > &a, const id_pt_t< T > &b)
Definition point_util.h:69
void serialize(Archive &ar, const unsigned int version)
Definition point_util.h:44
std::pair< size_t, point_basic< T > > base
Definition point_util.h:40
id_pt_t(size_t dis_i, const point_basic< T > &x)
Definition point_util.h:42
pt2_t< T > operator()(const pt2_t< T > &a, const pt2_t< T > &b)
Definition point_util.h:115
pt2_t(const point_basic< T > &x, const point_basic< T > &y)
Definition point_util.h:88
void serialize(Archive &ar, const unsigned int version)
Definition point_util.h:90
std::pair< point_basic< T >, point_basic< T > > base
Definition point_util.h:86