csr_concat.h
Go to the documentation of this file.
#ifndef _RHEOLEF_CSR_CONCAT_H
#define _RHEOLEF_CSR_CONCAT_H
// build csr from initializer list
//
#include "rheolef/csr.h"
#include "rheolef/vec_concat.h" // for constraint_process_rank()
namespace rheolef { namespace details {
// -----------------------------------------------------------------------------
// 1) implementation
// -----------------------------------------------------------------------------
//
// 1rst case : one-line matrix initializer
// A = {a, u}; // matrix & vector
// A = {trans(u), 3.2}; // trans(vector) & scalar
//
// -----------------------------------------------------------------------------
template <class T, class M>
struct vec_trans {
vec<T,M> v;
vec_trans (const vec<T,M>& w) : v(w) {}
};
template <class T, class M>
struct vector_vec_trans {
std::vector<vec<T,M> > v;
vector_vec_trans (const std::vector<vec<T,M> >& w) : v(w) {}
};
template <class T, class M>
class csr_concat_value {
public:
// typedef:
typedef typename csr<T,M>::size_type size_type;
typedef std::pair<size_type,size_type> sizes_type; // [size,dis_size]
typedef std::pair<sizes_type,sizes_type> sizes_pair_type; // [nrow,ncol] = [[nrow,dis_nrow],[ncol,dis_ncol]]
static constexpr size_type undef = std::numeric_limits<size_type>::max();
static constexpr size_type zero = 0;
typedef enum { empty, scalar, vector, vector_transpose, vector_vec, vector_vec_transpose, matrix} variant_type;
// allocators:
csr_concat_value (const sizes_pair_type& x) : e(x), s(), v(), vv(), m(), variant(empty) {}
template <class U,
class Sfinae
= typename std::enable_if<
is_rheolef_arithmetic<U>::value
,void
>::type
>
csr_concat_value (const U& x) : e(), s(x), v(), vv(), m(), variant(scalar) {}
csr_concat_value (const vec<T,M>& x) : e(), s(), v(x), vv(), m(), variant(vector) {}
csr_concat_value (const vec_trans<T,M>& vt) : e(), s(), v(vt.v), vv(), m(), variant(vector_transpose) {}
csr_concat_value (const std::vector<vec<T,M> >& x) : e(), s(), v(), vv(x), m(), variant(vector_vec) {}
csr_concat_value (const vector_vec_trans<T,M>& vt) : e(), s(), v(), vv(vt.v), m(), variant(vector_vec_transpose) {}
csr_concat_value (const csr<T,M>& x) : e(), s(), v(), vv(), m(x), variant(matrix) {}
// data:
public:
sizes_pair_type e;
T s;
vec<T,M> v;
std::vector<vec<T,M> > vv;
csr<T,M> m;
variant_type variant;
};
template <class T, class M>
class csr_concat_line {
public:
// typedef:
typedef typename csr_concat_value<T,M>::size_type size_type;
typedef typename csr_concat_value<T,M>::sizes_type sizes_type; // [size,dis_size]
typedef typename csr_concat_value<T,M>::sizes_pair_type sizes_pair_type; // [nrow,ncol] = [[nrow,dis_nrow],[ncol,dis_ncol]]
static constexpr size_type undef = std::numeric_limits<size_type>::max();
static constexpr size_type zero = 0;
typedef csr_concat_value<T,M> value_type;
// allocators:
csr_concat_line () : _l() {}
csr_concat_line (const std::initializer_list<value_type>& il) : _l() {
typedef typename std::initializer_list<value_type>::const_iterator const_iterator;
for (const_iterator iter = il.begin(); iter != il.end(); ++iter) {
_l.push_back(*iter);
}
}
void push_back (const value_type& x) { _l.push_back (x); }
friend std::ostream& operator<< (std::ostream& o, const csr_concat_line<T,M>& x) {
std::cout << "{";
for(typename std::list<value_type>::const_iterator iter = x._l.begin(); iter != x._l.end(); ++iter) {
std::cout << *iter << " ";
}
return std::cout << "}";
}
// internals:
static void set_sizes (
std::pair<size_type,size_type>& row_sizes,
std::pair<size_type,size_type>& col_sizes,
const std::pair<size_type,size_type>& new_row_sizes,
const std::pair<size_type,size_type>& new_col_sizes);
static void finalize_sizes (
std::pair<size_type,size_type>& sizes,
const communicator& comm);
static void finalize_sizes (
std::vector<std::pair<size_type,size_type> >& sizes,
const communicator& comm);
void build_csr_pass0 (
std::pair<size_type,size_type>& row_sizes,
std::vector<std::pair<size_type,size_type> >& col_sizes,
communicator& comm) const;
void build_csr_pass1 (
const std::pair<size_type,size_type>& row_sizes,
const std::vector<std::pair<size_type,size_type> >& col_sizes,
const communicator& comm,
distributor& row_ownership,
distributor& col_ownership,
std::vector<distributor>& col_start_by_component) const;
void build_csr_pass2 (
asr<T,M>& a,
const std::pair<size_type,size_type>& row_sizes,
const distributor& row_start_by_component,
const std::vector<std::pair<size_type,size_type> >& col_sizes,
const std::vector<distributor>& col_start_by_component) const;
csr<T,M> build_csr () const;
// data:
protected:
std::list<value_type> _l;
};
// -----------------------------------------------------------------------------
//
// 2nd case : multi-line matrix initializer
// A = { {a, u },
// {trans(u), 3.2} };
//
// -----------------------------------------------------------------------------
template <class T, class M>
class csr_concat {
public:
// typedef:
typedef typename csr_concat_value<T,M>::size_type size_type;
typedef typename csr_concat_value<T,M>::sizes_type sizes_type; // [size,dis_size]
typedef typename csr_concat_value<T,M>::sizes_pair_type sizes_pair_type; // [nrow,ncol] = [[nrow,dis_nrow],[ncol,dis_ncol]]
static constexpr size_type undef = std::numeric_limits<size_type>::max();
static constexpr size_type zero = 0;
typedef csr_concat_line<T,M> line_type;
typedef csr_concat_value<T,M> value_type;
// allocators:
csr_concat () : _l() {}
csr_concat (const std::initializer_list<line_type>& il) : _l() {
typedef typename std::initializer_list<line_type>::const_iterator const_iterator;
for(const_iterator iter = il.begin(); iter != il.end(); ++iter) {
_l.push_back(*iter);
}
}
void push_back (const line_type& line) { _l.push_back(line); }
// internals:
csr<T,M> build_csr () const;
// data:
protected:
std::list<line_type> _l;
};
} // namespace details
// -----------------------------------------------------------------------------
// 2) interface with the csr<T,M> class
// -----------------------------------------------------------------------------
template <class T, class M>
inline
details::vec_trans<T,M>
trans (const vec<T,M>& w) {
return details::vec_trans<T,M> (w);
}
template <class T, class M>
inline
details::vector_vec_trans<T,M>
trans (const std::vector<vec<T,M> >& w) {
return details::vector_vec_trans<T,M> (w);
}
// -------------------------------
// csr cstor from std::initializer
// -------------------------------
#define RHEOLEF_csr_cstor(M) \
template <class T> \
inline \
int \
csr<T,M>::constraint_process_rank() const \
{ \
return details::constraint_process_rank (row_ownership().comm()); \
} \
template <class T> \
inline \
csr<T,M>::csr (const std::initializer_list<details::csr_concat_value<T,M> >& init_list) \
{ \
details::csr_concat_line<T,M> cc (init_list); \
csr<T,M>::operator= (cc.build_csr()); \
} \
template <class T> \
inline \
csr<T,M>::csr (const std::initializer_list<details::csr_concat_line<T,M> >& init_list) \
{ \
details::csr_concat<T,M> cc (init_list); \
csr<T,M>::operator= (cc.build_csr()); \
}
RHEOLEF_csr_cstor(sequential)
#ifdef _RHEOLEF_HAVE_MPI
RHEOLEF_csr_cstor(distributed)
#endif // _RHEOLEF_HAVE_MPI
#undef RHEOLEF_csr_cstor
} // namespace rheolef
#endif // _RHEOLEF_CSR_CONCAT_H
rheolef::details::csr_concat_value::variant
variant_type variant
Definition: csr_concat.h:89
rheolef::details::csr_concat_line::build_csr
csr< T, M > build_csr() const
Definition: csr_concat.cc:353
rheolef::details::csr_concat_value::matrix
@ matrix
Definition: csr_concat.h:63
rheolef::details::csr_concat_line::push_back
void push_back(const value_type &x)
Definition: csr_concat.h:117
rheolef::details::csr_concat_value::sizes_type
std::pair< size_type, size_type > sizes_type
Definition: csr_concat.h:57
rheolef::details::csr_concat_line::undef
static constexpr size_type undef
Definition: csr_concat.h:102
rheolef::details::csr_concat_value::size_type
csr< T, M >::size_type size_type
Definition: csr_concat.h:56
rheolef::details::csr_concat_line::build_csr_pass0
void build_csr_pass0(std::pair< size_type, size_type > &row_sizes, std::vector< std::pair< size_type, size_type > > &col_sizes, communicator &comm) const
Definition: csr_concat.cc:91
rheolef::details::csr_concat_line::csr_concat_line
csr_concat_line(const std::initializer_list< value_type > &il)
Definition: csr_concat.h:111
rheolef::details::csr_concat_line::_l
std::list< value_type > _l
Definition: csr_concat.h:165
rheolef::details::csr_concat_line::size_type
csr_concat_value< T, M >::size_type size_type
Definition: csr_concat.h:98
RHEOLEF_csr_cstor
#define RHEOLEF_csr_cstor(M)
Definition: csr_concat.h:231
rheolef::details::csr_concat_value::zero
static constexpr size_type zero
Definition: csr_concat.h:61
rheolef::details::csr_concat_value::m
csr< T, M > m
Definition: csr_concat.h:88
rheolef::details::csr_concat::csr_concat
csr_concat()
Definition: csr_concat.h:192
rheolef::details::vec_trans
Definition: csr_concat.h:40
rheolef::details::vector_vec_trans
Definition: csr_concat.h:45
rheolef::details::csr_concat_value::vv
std::vector< vec< T, M > > vv
Definition: csr_concat.h:87
rheolef::details::csr_concat_line::operator<<
friend std::ostream & operator<<(std::ostream &o, const csr_concat_line< T, M > &x)
Definition: csr_concat.h:119
rheolef::distributor
see the distributor page for the full documentation
Definition: distributor.h:62
rheolef::details::csr_concat::build_csr
csr< T, M > build_csr() const
Definition: csr_concat.cc:378
rheolef::details::csr_concat_value::csr_concat_value
csr_concat_value(const sizes_pair_type &x)
Definition: csr_concat.h:67
rheolef::details::csr_concat_value::v
vec< T, M > v
Definition: csr_concat.h:86
rheolef::details::csr_concat_line::csr_concat_line
csr_concat_line()
Definition: csr_concat.h:109
rheolef::details::csr_concat_line::build_csr_pass2
void build_csr_pass2(asr< T, M > &a, const std::pair< size_type, size_type > &row_sizes, const distributor &row_start_by_component, const std::vector< std::pair< size_type, size_type > > &col_sizes, const std::vector< distributor > &col_start_by_component) const
Definition: csr_concat.cc:236
rheolef::details::csr_concat_value::vector
@ vector
Definition: csr_concat.h:63
rheolef::details::csr_concat_value::csr_concat_value
csr_concat_value(const vec_trans< T, M > &vt)
Definition: csr_concat.h:77
rheolef::details::csr_concat_value::vector_vec
@ vector_vec
Definition: csr_concat.h:63
rheolef::details::csr_concat_value::csr_concat_value
csr_concat_value(const U &x)
Definition: csr_concat.h:75
rheolef::vec
see the vec page for the full documentation
Definition: vec.h:79
rheolef::details::csr_concat::csr_concat
csr_concat(const std::initializer_list< line_type > &il)
Definition: csr_concat.h:194
rheolef::details::csr_concat::undef
static constexpr size_type undef
Definition: csr_concat.h:184
rheolef::details::csr_concat_value
Definition: csr.h:308
rheolef::details::csr_concat_value::csr_concat_value
csr_concat_value(const vec< T, M > &x)
Definition: csr_concat.h:76
rheolef::details::vec_trans::vec_trans
vec_trans(const vec< T, M > &w)
Definition: csr_concat.h:42
rheolef::details::csr_concat::value_type
csr_concat_value< T, M > value_type
Definition: csr_concat.h:188
a
Definition: diffusion_isotropic.h:25
rheolef::details::vector_vec_trans::vector_vec_trans
vector_vec_trans(const std::vector< vec< T, M > > &w)
Definition: csr_concat.h:47
rheolef::type
rheolef::std type
rheolef::details::csr_concat_line::sizes_type
csr_concat_value< T, M >::sizes_type sizes_type
Definition: csr_concat.h:99
rheolef::details::csr_concat
Definition: csr_concat.h:175
rheolef::asr
Definition: asr.h:49
rheolef::csr
see the csr page for the full documentation
Definition: asr.h:31
rheolef::details::csr_concat_value::csr_concat_value
csr_concat_value(const csr< T, M > &x)
Definition: csr_concat.h:80
rheolef::details::csr_concat_value::e
sizes_pair_type e
Definition: csr_concat.h:84
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::details::csr_concat_line::value_type
csr_concat_value< T, M > value_type
Definition: csr_concat.h:105
rheolef::details::vec_trans::v
vec< T, M > v
Definition: csr_concat.h:41
rheolef::details::vector_vec_trans::v
std::vector< vec< T, M > > v
Definition: csr_concat.h:46
rheolef::details::csr_concat_value::scalar
@ scalar
Definition: csr_concat.h:63
rheolef::details::csr_concat_line::set_sizes
static void set_sizes(std::pair< size_type, size_type > &row_sizes, std::pair< size_type, size_type > &col_sizes, const std::pair< size_type, size_type > &new_row_sizes, const std::pair< size_type, size_type > &new_col_sizes)
Definition: csr_concat.cc:37
rheolef::details::csr_concat::sizes_pair_type
csr_concat_value< T, M >::sizes_pair_type sizes_pair_type
Definition: csr_concat.h:182
rheolef::const_iterator
Definition: field_expr_recursive.h:552
rheolef::details::csr_concat_value::variant_type
variant_type
Definition: csr_concat.h:63
rheolef::space_constant::vector
@ vector
Definition: space_constant.h:137
rheolef::details::csr_concat_value::empty
@ empty
Definition: csr_concat.h:63
rheolef::details::csr_concat_value::vector_transpose
@ vector_transpose
Definition: csr_concat.h:63
rheolef::details::is_rheolef_arithmetic
Definition: Float.h:150
rheolef::details::csr_concat_line::zero
static constexpr size_type zero
Definition: csr_concat.h:103
rheolef::details::csr_concat_value::csr_concat_value
csr_concat_value(const vector_vec_trans< T, M > &vt)
Definition: csr_concat.h:79
rheolef::details::csr_concat::line_type
csr_concat_line< T, M > line_type
Definition: csr_concat.h:187
rheolef::details::csr_concat::sizes_type
csr_concat_value< T, M >::sizes_type sizes_type
Definition: csr_concat.h:181
rheolef::details::csr_concat_line
Definition: csr.h:309
rheolef::trans
csr< T, sequential > trans(const csr< T, sequential > &a)
trans(a): see the form page for the full documentation
Definition: csr.h:455
rheolef::distributed
distributed
Definition: asr.cc:228
rheolef::details::csr_concat_value::s
T s
Definition: csr_concat.h:85
rheolef::details::csr_concat_value::sizes_pair_type
std::pair< sizes_type, sizes_type > sizes_pair_type
Definition: csr_concat.h:58
rheolef::details::csr_concat_value::vector_vec_transpose
@ vector_vec_transpose
Definition: csr_concat.h:63
rheolef::details::csr_concat_line::finalize_sizes
static void finalize_sizes(std::pair< size_type, size_type > &sizes, const communicator &comm)
Definition: csr_concat.cc:64
rheolef::details::csr_concat_value::csr_concat_value
csr_concat_value(const std::vector< vec< T, M > > &x)
Definition: csr_concat.h:78
rheolef::details::csr_concat::zero
static constexpr size_type zero
Definition: csr_concat.h:185
rheolef::details::csr_concat_line::build_csr_pass1
void build_csr_pass1(const std::pair< size_type, size_type > &row_sizes, const std::vector< std::pair< size_type, size_type > > &col_sizes, const communicator &comm, distributor &row_ownership, distributor &col_ownership, std::vector< distributor > &col_start_by_component) const
Definition: csr_concat.cc:212
rheolef::details::csr_concat::size_type
csr_concat_value< T, M >::size_type size_type
Definition: csr_concat.h:180
rheolef::details::csr_concat::_l
std::list< line_type > _l
Definition: csr_concat.h:207
T
Expr1::float_type T
Definition: field_expr.h:218
rheolef::details::csr_concat_value::undef
static constexpr size_type undef
Definition: csr_concat.h:60
rheolef::details::csr_concat_line::sizes_pair_type
csr_concat_value< T, M >::sizes_pair_type sizes_pair_type
Definition: csr_concat.h:100
rheolef::details::csr_concat::push_back
void push_back(const line_type &line)
Definition: csr_concat.h:200