Rheolef  7.2
an efficient C++ finite element environment
disarray_seq.icc
Go to the documentation of this file.
1 # include "rheolef/disarray.h"
22 # include "rheolef/load_chunk.h"
23 namespace rheolef {
24 // ----------------------------------------------------------------------------
25 // class member functions
26 // ----------------------------------------------------------------------------
27 template <class T, class A>
29  : base(alloc),
30  _ownership ()
31 {
32 }
33 template <class T, class A>
34 disarray_rep<T,sequential,A>::disarray_rep (size_type loc_size1, const T& init_val, const A& alloc)
35  : base(loc_size1, init_val, alloc),
36  _ownership (distributor (distributor::decide, communicator(), loc_size1))
37 {
38 }
39 template <class T, class A>
40 disarray_rep<T,sequential,A>::disarray_rep (const distributor& ownership, const T& init_val, const A& alloc)
41  : base(ownership.size(),init_val), // TODO: add alloc extra-arg for heap_allocator
42  _ownership(ownership)
43 {
44 }
45 template <class T, class A>
47  : base(x.size()),
48  _ownership(x._ownership)
49 {
50  std::copy (x.begin(), x.end(), begin());
51 }
52 template <class T, class A>
53 void
54 disarray_rep<T,sequential,A>::resize (const distributor& ownership, const T& init_val)
55 {
56  // note: also called by disarray_rep<T,distributed,A>, so should works in distributed mode
57  _ownership = ownership;
58  base::resize (_ownership.size(), init_val);
59  std::fill (begin(), end(), init_val);
60 }
61 template <class T, class A>
62 void
63 disarray_rep<T,sequential,A>::resize (size_type loc_size1, const T& init_val)
64 {
65  // note: also called by disarray_rep<T,distributed,A>, so should works in distributed mode
66  _ownership.resize (distributor::decide, _ownership.comm(), loc_size1);
67  base::resize (_ownership.size(), init_val);
68  std::fill (begin(), end(), init_val);
69 }
70 template <class T, class A>
71 template <class GetFunction>
73 disarray_rep<T,sequential,A>::get_values (idiststream& ips, GetFunction get_element) {
74  std::istream& is = ips.is();
75  if (!load_chunk (is, begin(), end(), get_element))
76  error_macro("read failed on input stream.");
77  return ips;
78 }
79 template <class T, class A>
82 {
83  return get_values (ips, _disarray_get_element_type<T>());
84 }
85 template <class T, class A>
86 template <class PutFunction>
88 disarray_rep<T,sequential,A>::put_values (odiststream& ops, PutFunction put_element) const
89 {
90  std::ostream& os = ops.os();
91  for (size_type i = 0; i < size(); i++) {
92  put_element (os, operator[](i));
93  os << std::endl;
94  }
95  return ops;
96 }
97 template <class T, class A>
100 {
101  return put_values (ops, _disarray_put_element_type<T>());
102 }
103 template <class T, class A>
106 {
107  ops << "[";
108  put_values (ops, _disarray_put_matlab_type<T>());
109  return ops << "];";
110 }
111 template <class T, class A>
112 void
114  std::ofstream os (name.c_str());
115  std::cerr << "! file \"" << name << "\" created." << std::endl;
116  odiststream ops(os);
117  put_values(ops);
118 }
119 template <class T, class A>
120 template<class A2>
121 void
122 disarray_rep<T,sequential,A>::reverse_permutation ( // old_ownership for *this=iold2inew
123  disarray_rep<size_type,sequential,A2>& inew2iold) const // new_ownership
124 {
125  check_macro (inew2iold.size() == size(), "reverse permutation[0:"<<inew2iold.size()
126  <<"[ has incompatible dis_range with oriinal permutation[0:"<<size()<<"[");
127  for (size_type iold = 0, nold = size(); iold < nold; iold++) {
128  size_type inew = operator[] (iold);
129  inew2iold [inew] = iold;
130  }
131 }
132 template <class T, class A>
133 void
134 disarray_rep<T,sequential,A>::get_dis_indexes (std::set<size_type>& ext_idx_set) const
135 {
136  ext_idx_set.clear();
137 }
138 //=======================================
139 } // namespace rheolef
see the distributor page for the full documentation
Definition: distributor.h:69
static const size_type decide
Definition: distributor.h:83
idiststream: see the diststream page for the full documentation
Definition: diststream.h:336
std::istream & is()
Definition: diststream.h:400
odiststream: see the diststream page for the full documentation
Definition: diststream.h:137
std::ostream & os()
Definition: diststream.h:247
#define error_macro(message)
Definition: dis_macros.h:49
Expr1::float_type T
Definition: field_expr.h:230
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
verbose clean transpose logscale grid shrink ball stereo iso volume skipvtk deformation fastfieldload lattice reader_on_stdin color format format format format format format format format format format format format format format format format format format dump
This file is part of Rheolef.
bool load_chunk(std::istream &s, RandomIterator iter, RandomIterator last)
Definition: load_chunk.h:27
disarray element input helper
Definition: disarray.h:205
disarray element output helper
Definition: disarray.h:196