Rheolef  7.1
an efficient C++ finite element environment
hack_array_seq.icc
Go to the documentation of this file.
1 # include "rheolef/hack_array.h"
22 namespace rheolef {
23 
24 // ===============================================================
25 // allocators
26 // ===============================================================
27 template<class T, class A>
29  : base (alloc),
30  _ownership (),
31  _parameter (),
32  _value_size (),
33  _data_size ()
34 {
35 }
36 template<class T, class A>
37 hack_array_seq_rep<T,A>::hack_array_seq_rep (const distributor& ownership, const parameter_type& param, const A& alloc)
38  : base (alloc),
39  _ownership (ownership),
40  _parameter (param),
41  _value_size (T::_size_of (_parameter)),
42  _data_size (T::_data_size(_parameter))
43 {
45 }
46 template<class T, class A>
48  : base (alloc),
49  _ownership (distributor::decide, communicator(), n),
50  _parameter (param),
51  _value_size (T::_size_of (_parameter)),
52  _data_size (T::_data_size(_parameter))
53 {
55 }
56 template<class T, class A>
57 void
59 {
60  _ownership = ownership;
61  _parameter = param;
62  _value_size = T::_size_of (_parameter);
63  _data_size = T::_data_size(_parameter);
64  _init (_ownership, _parameter);
65 }
66 template<class T, class A>
67 void
69 {
70  _ownership = distributor (distributor::decide, communicator(), n);
71  _parameter = param;
72  _value_size = T::_size_of (_parameter);
73  _data_size = T::_data_size(_parameter);
74  _init (_ownership, _parameter);
75 }
76 template<class T, class A>
77 void
79 {
80  base::_ownership = distributor (ownership.dis_size()*_value_size, ownership.comm(), ownership.size()*_value_size),
81  base::resize (base::_ownership, std::numeric_limits<raw_type>::max());
82  size_type *p = base::begin().operator->();
83  for (size_type i = 0, n = ownership.size(); i < n; i++) {
84  new (p) T;
85  T* q = (T*)p;
86  q -> _set_parameter(param);
87  p += _value_size;
88  }
89 }
90 // ===============================================================
91 // put & get
92 // ===============================================================
93 template <class T, class A>
94 template <class PutFunction>
96 hack_array_seq_rep<T,A>::put_values (odiststream& ops, PutFunction put_element) const
97 {
98  std::ostream& os = ops.os();
99  for (size_type i = 0; i < size(); i++) {
100  put_element (os, operator[](i));
101  os << std::endl;
102  }
103  return ops;
104 }
105 template <class T, class A>
108 {
109  return put_values (ops, _disarray_put_element_type<generic_value_type>());
110 }
111 template <class T, class A>
112 template <class GetFunction>
113 idiststream&
114 hack_array_seq_rep<T,A>::get_values (idiststream& ips, GetFunction get_element) {
115  check_macro (load_chunk (ips.is(), begin(), end(), get_element), "read failed on input stream.");
116  return ips;
117 }
118 template <class T, class A>
119 idiststream&
121 {
122  return get_values (ips, _disarray_get_element_type<generic_value_type>());
123 }
124 
125 } // namespace rheolef
see the distributor page for the full documentation
Definition: distributor.h:62
size_type dis_size() const
global and local sizes
Definition: distributor.h:207
size_type size(size_type iproc) const
Definition: distributor.h:163
static const size_type decide
Definition: distributor.h:76
const communicator_type & comm() const
Definition: distributor.h:145
odiststream & put_values(odiststream &ops) const
hack_array_seq_rep(const A &alloc=A())
base::size_type size_type
Definition: hack_array.h:91
parameter_type _parameter
Definition: hack_array.h:148
void resize(const distributor &ownership, const parameter_type &param)
T::parameter_type parameter_type
Definition: hack_array.h:89
void _init(const distributor &ownership, const parameter_type &param)
idiststream & get_values(idiststream &ips)
odiststream: see the diststream page for the full documentation
Definition: diststream.h:126
std::ostream & os()
Definition: diststream.h:236
Expr1::float_type T
Definition: field_expr.h:261
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
This file is part of Rheolef.
bool load_chunk(std::istream &s, RandomIterator iter, RandomIterator last)
Definition: load_chunk.h:27
Definition: sphere.icc:25
disarray element input helper
Definition: disarray.h:206
disarray element output helper
Definition: disarray.h:197