Loading...
Searching...
No Matches
geo_element_indirect.h
Go to the documentation of this file.
#ifndef _RHEOLEF_GEO_ELEMENT_INDIRECT_H
#define _RHEOLEF_GEO_ELEMENT_INDIRECT_H
#include "rheolef/compiler_mpi.h"
namespace rheolef {
// =====================================================================
// geo_element_indirect = index + orient + face shift
// =====================================================================
// TODO: compact the sign bit and size_t in a long int
class geo_element_indirect {
public:
// typedefs:
typedef size_t size_type;
typedef short int orientation_type; // for sign (+1,-1)
typedef short int shift_type; // for face [0:4[ shift
// allocators:
geo_element_indirect ()
: _all(std::numeric_limits<size_type>::max()) {}
geo_element_indirect (orientation_type orient, size_type ige, size_type shift = 0)
: _all(std::numeric_limits<size_type>::max())
{ set (orient, ige, shift); }
// accessors:
size_type index() const { return _all & index_mask; }
orientation_type orientation() const { return (_all & orient_mask) ? -1 : 1; }
shift_type shift() const { return (_all & shift_mask) >> shift_position; }
// modifiers:
void set_orientation (orientation_type orient) {
_all = (_all & (~orient_mask));
if (orient < 0) _all = _all | orient_mask;
}
void set_shift (size_type shift) {
_all = (_all & (~shift_mask));
_all = _all | (shift_mask & (shift << shift_position));
}
void set_index (size_type ige) {
_all = (_all & (~index_mask));
_all = _all | (index_mask & ige);
}
void set (orientation_type orient, size_type ige, size_type shift = 0) {
set_orientation (orient);
set_index (ige);
set_shift (shift);
}
// i/o:
void dump(std::ostream& out = std::clog) const {
for (int i = 8*sizeof(size_type) - 1; i >= 0; i--) {
size_type bit = (_all & (size_type(1) << i)) >> i;
out << bit;
if (i % 8 == 0 && i != 0) out << " ";
}
}
template<class Archive>
void serialize (Archive& ar, const unsigned int version) { ar & _all; }
protected:
// implementation:
// left bit(0) = first left bit: orientation
static const size_type orient_position = 8*sizeof(size_type)-1;
static const size_type orient_mask = (size_type(1) << orient_position);
// left bits(1:3) = face shift (for 3d faces)
static const size_type shift_position = 8*sizeof(size_type)-4;
static const size_type shift_mask = (size_type(1) << shift_position) |
(size_type(1) << (shift_position+1)) |
(size_type(1) << (shift_position+2));
// others right bits = index of the subgeo (face or edge)
static const size_type index_mask = ~(orient_mask | shift_mask);
// data:
size_type _all;
};
// i/o:
std::istream& operator>> (std::istream& is, geo_element_indirect& x);
std::ostream& operator<< (std::ostream& os, const geo_element_indirect& x);
} // namespace rheolef
#ifdef _RHEOLEF_HAVE_MPI
#include "rheolef/compiler.h"
// =====================================================================
// Some serializable types, have a fixed amount of data stored at fixed field positions.
// When this is the case, boost::mpi can optimize their serialization and transmission to avoid extraneous
// copy operations.
// To enable this optimization, we specialize the type trait is_mpi_datatype, e.g.:
namespace boost {
namespace mpi {
template <> struct is_mpi_datatype<rheolef::geo_element_indirect> : mpl::true_ { };
} // namespace mpi
} // namespace boost
#endif // _RHEOLEF_HAVE_MPI
#endif // _RHEOLEF_GEO_ELEMENT_INDIRECT_H
rheolef::geo_element_indirect
Definition geo_element_indirect.h:32
rheolef::geo_element_indirect::dump
void dump(std::ostream &out=std::clog) const
Definition geo_element_indirect.h:77
rheolef::geo_element_indirect::_all
size_type _all
Definition geo_element_indirect.h:107
rheolef::geo_element_indirect::shift
shift_type shift() const
Definition geo_element_indirect.h:53
rheolef::geo_element_indirect::orient_position
static const size_type orient_position
Definition geo_element_indirect.h:92
rheolef::geo_element_indirect::shift_type
short int shift_type
Definition geo_element_indirect.h:39
rheolef::geo_element_indirect::shift_position
static const size_type shift_position
Definition geo_element_indirect.h:96
rheolef::geo_element_indirect::size_type
size_t size_type
Definition geo_element_indirect.h:37
rheolef::geo_element_indirect::set_shift
void set_shift(size_type shift)
Definition geo_element_indirect.h:61
rheolef::geo_element_indirect::serialize
void serialize(Archive &ar, const unsigned int version)
Definition geo_element_indirect.h:85
rheolef::geo_element_indirect::shift_mask
static const size_type shift_mask
Definition geo_element_indirect.h:97
rheolef::geo_element_indirect::geo_element_indirect
geo_element_indirect()
Definition geo_element_indirect.h:43
rheolef::geo_element_indirect::set_orientation
void set_orientation(orientation_type orient)
Definition geo_element_indirect.h:57
rheolef::geo_element_indirect::set_index
void set_index(size_type ige)
Definition geo_element_indirect.h:65
rheolef::geo_element_indirect::orient_mask
static const size_type orient_mask
Definition geo_element_indirect.h:93
rheolef::geo_element_indirect::orientation
orientation_type orientation() const
Definition geo_element_indirect.h:52
rheolef::geo_element_indirect::orientation_type
short int orientation_type
Definition geo_element_indirect.h:38
rheolef::geo_element_indirect::geo_element_indirect
geo_element_indirect(orientation_type orient, size_type ige, size_type shift=0)
Definition geo_element_indirect.h:45
rheolef::geo_element_indirect::set
void set(orientation_type orient, size_type ige, size_type shift=0)
Definition geo_element_indirect.h:69
rheolef::geo_element_indirect::index
size_type index() const
Definition geo_element_indirect.h:51
rheolef::geo_element_indirect::index_mask
static const size_type index_mask
Definition geo_element_indirect.h:103
boost
Definition mpi_pair_datatype.h:51
rheolef
This file is part of Rheolef.
Definition compiler_eigen.h:39
rheolef::operator<<
std::ostream & operator<<(std::ostream &os, const catchmark &m)
Definition catchmark.h:99
rheolef::operator>>
std::istream & operator>>(std::istream &is, const catchmark &m)
Definition catchmark.h:88
std
STL namespace.