Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
csr_concat.h
Go to the documentation of this file.
1#ifndef _RHEOLEF_CSR_CONCAT_H
2#define _RHEOLEF_CSR_CONCAT_H
23// build csr from initializer list
24//
25#include "rheolef/csr.h"
26#include "rheolef/vec_concat.h" // for constraint_process_rank()
27
28namespace rheolef { namespace details {
29
30// -----------------------------------------------------------------------------
31// 1) implementation
32// -----------------------------------------------------------------------------
33//
34// 1rst case : one-line matrix initializer
35// A = {a, u}; // matrix & vector
36// A = {trans(u), 3.2}; // trans(vector) & scalar
37//
38// -----------------------------------------------------------------------------
39template <class T, class M>
40struct vec_trans {
42 vec_trans (const vec<T,M>& w) : v(w) {}
43};
44template <class T, class M>
46 std::vector<vec<T,M> > v;
47 vector_vec_trans (const std::vector<vec<T,M> >& w) : v(w) {}
48};
49
50template <class T, class M>
52public:
53
54// typedef:
55
57 typedef std::pair<size_type,size_type> sizes_type; // [size,dis_size]
58 typedef std::pair<sizes_type,sizes_type> sizes_pair_type; // [nrow,ncol] = [[nrow,dis_nrow],[ncol,dis_ncol]]
59
60 static constexpr size_type undef = std::numeric_limits<size_type>::max();
61 static constexpr size_type zero = 0;
62
64
65// allocators:
66
67 csr_concat_value (const sizes_pair_type& x) : e(x), s(), v(), vv(), m(), variant(empty) {}
68 template <class U,
69 class Sfinae
70 = typename std::enable_if<
72 ,void
73 >::type
74 >
75 csr_concat_value (const U& x) : e(), s(x), v(), vv(), m(), variant(scalar) {}
76 csr_concat_value (const vec<T,M>& x) : e(), s(), v(x), vv(), m(), variant(vector) {}
77 csr_concat_value (const vec_trans<T,M>& vt) : e(), s(), v(vt.v), vv(), m(), variant(vector_transpose) {}
78 csr_concat_value (const std::vector<vec<T,M> >& x) : e(), s(), v(), vv(x), m(), variant(vector_vec) {}
80 csr_concat_value (const csr<T,M>& x) : e(), s(), v(), vv(), m(x), variant(matrix) {}
81
82// data:
83public:
87 std::vector<vec<T,M> > vv;
90};
91
92template <class T, class M>
94public:
95
96// typedef:
97
99 typedef typename csr_concat_value<T,M>::sizes_type sizes_type; // [size,dis_size]
100 typedef typename csr_concat_value<T,M>::sizes_pair_type sizes_pair_type; // [nrow,ncol] = [[nrow,dis_nrow],[ncol,dis_ncol]]
101
102 static constexpr size_type undef = std::numeric_limits<size_type>::max();
103 static constexpr size_type zero = 0;
104
106
107// allocators:
108
110
111 csr_concat_line (const std::initializer_list<value_type>& il) : _l() {
112 typedef typename std::initializer_list<value_type>::const_iterator const_iterator;
113 for (const_iterator iter = il.begin(); iter != il.end(); ++iter) {
114 _l.push_back(*iter);
115 }
116 }
117 void push_back (const value_type& x) { _l.push_back (x); }
118
119 friend std::ostream& operator<< (std::ostream& o, const csr_concat_line<T,M>& x) {
120 std::cout << "{";
121 for(typename std::list<value_type>::const_iterator iter = x._l.begin(); iter != x._l.end(); ++iter) {
122 std::cout << *iter << " ";
123 }
124 return std::cout << "}";
125 }
126// internals:
127 static void set_sizes (
128 std::pair<size_type,size_type>& row_sizes,
129 std::pair<size_type,size_type>& col_sizes,
130 const std::pair<size_type,size_type>& new_row_sizes,
131 const std::pair<size_type,size_type>& new_col_sizes);
132
133 static void finalize_sizes (
134 std::pair<size_type,size_type>& sizes,
135 const communicator& comm);
136
137 static void finalize_sizes (
138 std::vector<std::pair<size_type,size_type> >& sizes,
139 const communicator& comm);
140
141 void build_csr_pass0 (
142 std::pair<size_type,size_type>& row_sizes,
143 std::vector<std::pair<size_type,size_type> >& col_sizes,
144 communicator& comm) const;
145
146 void build_csr_pass1 (
147 const std::pair<size_type,size_type>& row_sizes,
148 const std::vector<std::pair<size_type,size_type> >& col_sizes,
149 const communicator& comm,
150 distributor& row_ownership,
151 distributor& col_ownership,
152 std::vector<distributor>& col_start_by_component) const;
153
154 void build_csr_pass2 (
155 asr<T,M>& a,
156 const std::pair<size_type,size_type>& row_sizes,
157 const distributor& row_start_by_component,
158 const std::vector<std::pair<size_type,size_type> >& col_sizes,
159 const std::vector<distributor>& col_start_by_component) const;
160
161 csr<T,M> build_csr () const;
162
163// data:
164protected:
165 std::list<value_type> _l;
166};
167// -----------------------------------------------------------------------------
168//
169// 2nd case : multi-line matrix initializer
170// A = { {a, u },
171// {trans(u), 3.2} };
172//
173// -----------------------------------------------------------------------------
174template <class T, class M>
176public:
177
178// typedef:
179
181 typedef typename csr_concat_value<T,M>::sizes_type sizes_type; // [size,dis_size]
182 typedef typename csr_concat_value<T,M>::sizes_pair_type sizes_pair_type; // [nrow,ncol] = [[nrow,dis_nrow],[ncol,dis_ncol]]
183
184 static constexpr size_type undef = std::numeric_limits<size_type>::max();
185 static constexpr size_type zero = 0;
186
189
190// allocators:
191
192 csr_concat () : _l() {}
193
194 csr_concat (const std::initializer_list<line_type>& il) : _l() {
195 typedef typename std::initializer_list<line_type>::const_iterator const_iterator;
196 for(const_iterator iter = il.begin(); iter != il.end(); ++iter) {
197 _l.push_back(*iter);
198 }
199 }
200 void push_back (const line_type& line) { _l.push_back(line); }
201
202// internals:
203 csr<T,M> build_csr () const;
204
205// data:
206protected:
207 std::list<line_type> _l;
208};
209
210} // namespace details
211
212// -----------------------------------------------------------------------------
213// 2) interface with the csr<T,M> class
214// -----------------------------------------------------------------------------
215
216template <class T, class M>
217inline
219trans (const vec<T,M>& w) {
220 return details::vec_trans<T,M> (w);
221}
222template <class T, class M>
223inline
224details::vector_vec_trans<T,M>
225trans (const std::vector<vec<T,M> >& w) {
227}
228// -------------------------------
229// csr cstor from std::initializer
230// -------------------------------
231#define RHEOLEF_csr_cstor(M) \
232template <class T> \
233inline \
234int \
235csr<T,M>::constraint_process_rank() const \
236{ \
237 return details::constraint_process_rank (row_ownership().comm()); \
238} \
239template <class T> \
240inline \
241csr<T,M>::csr (const std::initializer_list<details::csr_concat_value<T,M> >& init_list) \
242{ \
243 details::csr_concat_line<T,M> cc (init_list); \
244 csr<T,M>::operator= (cc.build_csr()); \
245} \
246template <class T> \
247inline \
248csr<T,M>::csr (const std::initializer_list<details::csr_concat_line<T,M> >& init_list) \
249{ \
250 details::csr_concat<T,M> cc (init_list); \
251 csr<T,M>::operator= (cc.build_csr()); \
252}
253
254RHEOLEF_csr_cstor(sequential)
255
256#ifdef _RHEOLEF_HAVE_MPI
257RHEOLEF_csr_cstor(distributed)
258#endif // _RHEOLEF_HAVE_MPI
259
260#undef RHEOLEF_csr_cstor
261
262} // namespace rheolef
263#endif // _RHEOLEF_CSR_CONCAT_H
see the csr page for the full documentation
Definition csr.h:317
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
static constexpr size_type zero
Definition csr_concat.h:103
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
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
std::list< value_type > _l
Definition csr_concat.h:165
csr_concat_value< T, M >::size_type size_type
Definition csr_concat.h:98
csr_concat_value< T, M >::sizes_type sizes_type
Definition csr_concat.h:99
csr_concat_line(const std::initializer_list< value_type > &il)
Definition csr_concat.h:111
void push_back(const value_type &x)
Definition csr_concat.h:117
csr_concat_value< T, M >::sizes_pair_type sizes_pair_type
Definition csr_concat.h:100
friend std::ostream & operator<<(std::ostream &o, const csr_concat_line< T, M > &x)
Definition csr_concat.h:119
csr_concat_value< T, M > value_type
Definition csr_concat.h:105
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
static void finalize_sizes(std::pair< size_type, size_type > &sizes, const communicator &comm)
Definition csr_concat.cc:64
static constexpr size_type undef
Definition csr_concat.h:102
std::pair< sizes_type, sizes_type > sizes_pair_type
Definition csr_concat.h:58
csr_concat_value(const std::vector< vec< T, M > > &x)
Definition csr_concat.h:78
static constexpr size_type zero
Definition csr_concat.h:61
csr_concat_value(const csr< T, M > &x)
Definition csr_concat.h:80
csr_concat_value(const vec_trans< T, M > &vt)
Definition csr_concat.h:77
std::vector< vec< T, M > > vv
Definition csr_concat.h:87
csr_concat_value(const sizes_pair_type &x)
Definition csr_concat.h:67
csr_concat_value(const vec< T, M > &x)
Definition csr_concat.h:76
csr< T, M >::size_type size_type
Definition csr_concat.h:56
csr_concat_value(const vector_vec_trans< T, M > &vt)
Definition csr_concat.h:79
static constexpr size_type undef
Definition csr_concat.h:60
std::pair< size_type, size_type > sizes_type
Definition csr_concat.h:57
csr< T, M > build_csr() const
static constexpr size_type zero
Definition csr_concat.h:185
csr_concat_value< T, M >::size_type size_type
Definition csr_concat.h:180
csr_concat_line< T, M > line_type
Definition csr_concat.h:187
csr_concat_value< T, M >::sizes_type sizes_type
Definition csr_concat.h:181
void push_back(const line_type &line)
Definition csr_concat.h:200
std::list< line_type > _l
Definition csr_concat.h:207
csr_concat_value< T, M >::sizes_pair_type sizes_pair_type
Definition csr_concat.h:182
csr_concat_value< T, M > value_type
Definition csr_concat.h:188
static constexpr size_type undef
Definition csr_concat.h:184
csr_concat(const std::initializer_list< line_type > &il)
Definition csr_concat.h:194
see the distributor page for the full documentation
Definition distributor.h:69
see the vec page for the full documentation
Definition vec.h:79
#define RHEOLEF_csr_cstor(M)
Definition csr_concat.h:231
Expr1::float_type T
Definition field_expr.h:230
This file is part of Rheolef.
csr< T, sequential > trans(const csr< T, sequential > &a)
trans(a): see the form page for the full documentation
Definition csr.h:455
vec_trans(const vec< T, M > &w)
Definition csr_concat.h:42
std::vector< vec< T, M > > v
Definition csr_concat.h:46
vector_vec_trans(const std::vector< vec< T, M > > &w)
Definition csr_concat.h:47