Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
disarray_seq.icc
Go to the documentation of this file.
1
21# include "rheolef/disarray.h"
22# include "rheolef/load_chunk.h"
23namespace rheolef {
24// ----------------------------------------------------------------------------
25// class member functions
26// ----------------------------------------------------------------------------
27template <class T, class A>
29 : base(alloc),
30 _ownership ()
31{
32}
33template <class T, class A>
34disarray_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}
39template <class T, class A>
40disarray_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}
45template <class T, class A>
47 : base(x.size()),
48 _ownership(x._ownership)
49{
50 std::copy (x.begin(), x.end(), begin());
51}
52template <class T, class A>
53void
54disarray_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}
61template <class T, class A>
62void
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}
70template <class T, class A>
71template <class GetFunction>
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}
79template <class T, class A>
85template <class T, class A>
86template <class PutFunction>
88disarray_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}
97template <class T, class A>
100{
101 return put_values (ops, _disarray_put_element_type<T>());
102}
103template <class T, class A>
106{
107 ops << "[";
108 put_values (ops, _disarray_put_matlab_type<T>());
109 return ops << "];";
110}
111template <class T, class A>
112void
113disarray_rep<T,sequential,A>::dump (std::string name) const {
114 std::ofstream os (name.c_str());
115 std::cerr << "! file \"" << name << "\" created." << std::endl;
116 odiststream ops(os);
117 put_values(ops);
118}
119template <class T, class A>
120template<class A2>
121void
122disarray_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}
132template <class T, class A>
133void
134disarray_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)")
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