Loading...
Searching...
No Matches
disarray_seq.icc
Go to the documentation of this file.
# include "rheolef/disarray.h"
# include "rheolef/load_chunk.h"
namespace rheolef {
// ----------------------------------------------------------------------------
// class member functions
// ----------------------------------------------------------------------------
template <class T, class A>
disarray_rep<T,sequential,A>::disarray_rep (const A& alloc)
: base(alloc),
_ownership ()
{
}
template <class T, class A>
disarray_rep<T,sequential,A>::disarray_rep (size_type loc_size1, const T& init_val, const A& alloc)
: base(loc_size1, init_val, alloc),
_ownership (distributor (distributor::decide, communicator(), loc_size1))
{
}
template <class T, class A>
disarray_rep<T,sequential,A>::disarray_rep (const distributor& ownership, const T& init_val, const A& alloc)
: base(ownership.size(),init_val), // TODO: add alloc extra-arg for heap_allocator
_ownership(ownership)
{
}
template <class T, class A>
disarray_rep<T,sequential,A>::disarray_rep (const disarray_rep<T,sequential,A>& x)
: base(x.size()),
_ownership(x._ownership)
{
std::copy (x.begin(), x.end(), begin());
}
template <class T, class A>
void
disarray_rep<T,sequential,A>::resize (const distributor& ownership, const T& init_val)
{
// note: also called by disarray_rep<T,distributed,A>, so should works in distributed mode
_ownership = ownership;
base::resize (_ownership.size(), init_val);
std::fill (begin(), end(), init_val);
}
template <class T, class A>
void
disarray_rep<T,sequential,A>::resize (size_type loc_size1, const T& init_val)
{
// note: also called by disarray_rep<T,distributed,A>, so should works in distributed mode
_ownership.resize (distributor::decide, _ownership.comm(), loc_size1);
base::resize (_ownership.size(), init_val);
std::fill (begin(), end(), init_val);
}
template <class T, class A>
template <class GetFunction>
idiststream&
disarray_rep<T,sequential,A>::get_values (idiststream& ips, GetFunction get_element) {
std::istream& is = ips.is();
if (!load_chunk (is, begin(), end(), get_element))
error_macro("read failed on input stream.");
return ips;
}
template <class T, class A>
idiststream&
disarray_rep<T,sequential,A>::get_values (idiststream& ips)
{
return get_values (ips, _disarray_get_element_type<T>());
}
template <class T, class A>
template <class PutFunction>
odiststream&
disarray_rep<T,sequential,A>::put_values (odiststream& ops, PutFunction put_element) const
{
std::ostream& os = ops.os();
for (size_type i = 0; i < size(); i++) {
put_element (os, operator[](i));
os << std::endl;
}
return ops;
}
template <class T, class A>
odiststream&
disarray_rep<T,sequential,A>::put_values (odiststream& ops) const
{
return put_values (ops, _disarray_put_element_type<T>());
}
template <class T, class A>
odiststream&
disarray_rep<T,sequential,A>::put_matlab (odiststream& ops) const
{
ops << "[";
put_values (ops, _disarray_put_matlab_type<T>());
return ops << "];";
}
template <class T, class A>
void
disarray_rep<T,sequential,A>::dump (std::string name) const {
std::ofstream os (name.c_str());
std::cerr << "! file \"" << name << "\" created." << std::endl;
odiststream ops(os);
put_values(ops);
}
template <class T, class A>
template<class A2>
void
disarray_rep<T,sequential,A>::reverse_permutation ( // old_ownership for *this=iold2inew
disarray_rep<size_type,sequential,A2>& inew2iold) const // new_ownership
{
check_macro (inew2iold.size() == size(), "reverse permutation[0:"<<inew2iold.size()
<<"[ has incompatible dis_range with oriinal permutation[0:"<<size()<<"[");
for (size_type iold = 0, nold = size(); iold < nold; iold++) {
size_type inew = operator[] (iold);
inew2iold [inew] = iold;
}
}
template <class T, class A>
void
disarray_rep<T,sequential,A>::get_dis_indexes (std::set<size_type>& ext_idx_set) const
{
ext_idx_set.clear();
}
//=======================================
} // namespace rheolef
rheolef::disarray_rep< T, sequential, A >::size_type
base::size_type size_type
Definition disarray.h:223
rheolef::disarray_rep< T, sequential, A >::base
std::vector< T > base
Definition disarray.h:222
rheolef::disarray_rep
Definition disarray.h:214
rheolef::distributor
see the distributor page for the full documentation
Definition distributor.h:69
rheolef::distributor::decide
static const size_type decide
Definition distributor.h:83
rheolef::idiststream
idiststream: see the diststream page for the full documentation
Definition diststream.h:336
rheolef::idiststream::is
std::istream & is()
Definition diststream.h:400
rheolef::odiststream
odiststream: see the diststream page for the full documentation
Definition diststream.h:137
rheolef::odiststream::os
std::ostream & os()
Definition diststream.h:247
error_macro
#define error_macro(message)
Definition dis_macros.h:49
T
Expr1::float_type T
Definition field_expr.h:230
check_macro
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
rheolef
This file is part of Rheolef.
Definition compiler_eigen.h:39
rheolef::load_chunk
bool load_chunk(std::istream &s, RandomIterator iter, RandomIterator last)
Definition load_chunk.h:27
A
Definition diffusion_isotropic.h:25
rheolef::_disarray_get_element_type
disarray element input helper
Definition disarray.h:205
rheolef::_disarray_put_element_type
disarray element output helper
Definition disarray.h:196
rheolef::_disarray_put_matlab_type
Definition disarray.h:200