Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
geo_element_indirect.h
Go to the documentation of this file.
1#ifndef _RHEOLEF_GEO_ELEMENT_INDIRECT_H
2#define _RHEOLEF_GEO_ELEMENT_INDIRECT_H
23
24#include "rheolef/compiler_mpi.h"
25
26namespace rheolef {
27
28// =====================================================================
29// geo_element_indirect = index + orient + face shift
30// =====================================================================
31// TODO: compact the sign bit and size_t in a long int
33public:
34
35// typedefs:
36
37 typedef size_t size_type;
38 typedef short int orientation_type; // for sign (+1,-1)
39 typedef short int shift_type; // for face [0:4[ shift
40
41// allocators:
42
44 : _all(std::numeric_limits<size_type>::max()) {}
46 : _all(std::numeric_limits<size_type>::max())
47 { set (orient, ige, shift); }
48
49// accessors:
50
51 size_type index() const { return _all & index_mask; }
52 orientation_type orientation() const { return (_all & orient_mask) ? -1 : 1; }
53 shift_type shift() const { return (_all & shift_mask) >> shift_position; }
54
55// modifiers:
56
58 _all = (_all & (~orient_mask));
59 if (orient < 0) _all = _all | orient_mask;
60 }
62 _all = (_all & (~shift_mask));
64 }
65 void set_index (size_type ige) {
66 _all = (_all & (~index_mask));
67 _all = _all | (index_mask & ige);
68 }
69 void set (orientation_type orient, size_type ige, size_type shift = 0) {
70 set_orientation (orient);
71 set_index (ige);
73 }
74
75// i/o:
76
77 void dump(std::ostream& out = std::clog) const {
78 for (int i = 8*sizeof(size_type) - 1; i >= 0; i--) {
79 size_type bit = (_all & (size_type(1) << i)) >> i;
80 out << bit;
81 if (i % 8 == 0 && i != 0) out << " ";
82 }
83 }
84 template<class Archive>
85 void serialize (Archive& ar, const unsigned int version) { ar & _all; }
86
87protected:
88
89// implementation:
90
91 // left bit(0) = first left bit: orientation
92 static const size_type orient_position = 8*sizeof(size_type)-1;
94
95 // left bits(1:3) = face shift (for 3d faces)
96 static const size_type shift_position = 8*sizeof(size_type)-4;
98 (size_type(1) << (shift_position+1)) |
99 (size_type(1) << (shift_position+2));
100
101
102 // others right bits = index of the subgeo (face or edge)
104
105// data:
106
108};
109// i/o:
110std::istream& operator>> (std::istream& is, geo_element_indirect& x);
111std::ostream& operator<< (std::ostream& os, const geo_element_indirect& x);
112
113} // namespace rheolef
114
115#ifdef _RHEOLEF_HAVE_MPI
116#include "rheolef/compiler.h"
117// =====================================================================
118// Some serializable types, have a fixed amount of data stored at fixed field positions.
119// When this is the case, boost::mpi can optimize their serialization and transmission to avoid extraneous
120// copy operations.
121// To enable this optimization, we specialize the type trait is_mpi_datatype, e.g.:
122namespace boost {
123 namespace mpi {
124 template <> struct is_mpi_datatype<rheolef::geo_element_indirect> : mpl::true_ { };
125 } // namespace mpi
126} // namespace boost
127#endif // _RHEOLEF_HAVE_MPI
128
129#endif // _RHEOLEF_GEO_ELEMENT_INDIRECT_H
void dump(std::ostream &out=std::clog) const
static const size_type orient_position
static const size_type shift_position
void serialize(Archive &ar, const unsigned int version)
static const size_type shift_mask
void set_orientation(orientation_type orient)
static const size_type orient_mask
orientation_type orientation() const
geo_element_indirect(orientation_type orient, size_type ige, size_type shift=0)
void set(orientation_type orient, size_type ige, size_type shift=0)
This file is part of Rheolef.
std::ostream & operator<<(std::ostream &os, const catchmark &m)
Definition catchmark.h:99
std::istream & operator>>(std::istream &is, const catchmark &m)
Definition catchmark.h:88
STL namespace.