Rheolef  7.1
an efficient C++ finite element environment
form_concat.h
Go to the documentation of this file.
1 #ifndef _RHEOLEF_FORM_CONCAT_H
2 #define _RHEOLEF_FORM_CONCAT_H
23 // build form from initializer list (c++ 2011)
24 //
25 #include "rheolef/form.h"
26 #include "rheolef/csr_concat.h"
27 #include "rheolef/field_expr_recursive.h"
28 
29 namespace rheolef { namespace details {
30 
31 // =========================================================================
32 // 1rst case : one-line matrix initializer
33 // A = {a, b}; // matrix & vector
34 // =========================================================================
35 
36 template <class T, class M>
39  std::vector<field_basic<T,M> > vv;
40 };
41 
42 } // namespace details
43 
44 template <class T, class M>
45 inline
48 {
50 }
51 
52 namespace details {
53 
54 template <class T, class M>
56 public:
57 
58 // typedef:
59 
61  typedef typename csr_concat_value<T,M>::sizes_type sizes_type; // [size,dis_size]
62  typedef typename csr_concat_value<T,M>::sizes_pair_type sizes_pair_type; // [nrow,ncol] = [[nrow,dis_nrow],[ncol,dis_ncol]]
63 
64  static constexpr size_type undef = std::numeric_limits<size_type>::max();
65  static constexpr size_type zero = 0;
66 
67  typedef enum {
73  form
75 
77  trans_
79  >
81 
82 // allocators:
83 
84  template <class U,
85  class Sfinae
86  = typename std::enable_if<
88  ,void
89  >::type
90  >
91  form_concat_value (const U& x) : s(x), v(), vv(), m(), variant(scalar) {}
92  form_concat_value (const field_basic<T,M>& x) : s(), v(x), vv(), m(), variant(field) {}
93  form_concat_value (const trans_field_type& x) : s(), v(x.expr().expr()), vv(), m(), variant(field_transpose) {}
96  form_concat_value (const form_basic<T,M>& x) : s(), v(), vv(), m(x), variant(form) {}
97 
98 // io/debug:
99  friend std::ostream& operator<< (std::ostream& o, const form_concat_value<T,M>& x) {
100  if (x.variant == scalar) return o << "s";
101  else if (x.variant == field) return o << "f";
102  else if (x.variant == field_transpose) return o << "ft";
103  else if (x.variant == vector_field) return o << "vf";
104  else if (x.variant == vector_field_transpose) return o << "vft";
105  else return o << "m";
106  }
107 // data:
108 public:
109  T s;
111  std::vector<field_basic<T,M>> vv;
114 };
115 template <class T, class M>
117 public:
118 
119 // typedef:
120 
122  typedef typename csr_concat_value<T,M>::sizes_type sizes_type; // [size,dis_size]
123  typedef typename csr_concat_value<T,M>::sizes_pair_type sizes_pair_type; // [nrow,ncol] = [[nrow,dis_nrow],[ncol,dis_ncol]]
124 
125  static constexpr size_type undef = std::numeric_limits<size_type>::max();
126  static constexpr size_type zero = 0;
127 
129  typedef typename std::list<value_type>::const_iterator const_iterator;
130 
131 // allocators:
132 
134 
135  form_concat_line (const std::initializer_list<value_type>& il) : _l() {
136  typedef typename std::initializer_list<value_type>::const_iterator const_iterator;
137  for(const_iterator iter = il.begin(); iter != il.end(); ++iter) {
138  _l.push_back(*iter);
139  }
140  }
141 
142 // accessors:
143 
144  const_iterator begin() const { return _l.begin(); }
145  const_iterator end() const { return _l.end(); }
146 
147  friend std::ostream& operator<< (std::ostream& o, const form_concat_line<T,M>& x) {
148  std::cout << "{";
149  for(typename std::list<value_type>::const_iterator iter = x._l.begin(); iter != x._l.end(); ++iter) {
150  std::cout << *iter << " ";
151  }
152  return std::cout << "}";
153  }
154 // internals:
155 
156  void build_form_pass0 (std::vector<std::pair<bool,space_basic<T,M> > >& l_Xh, space_basic<T,M>& Yh, size_t i_comp = 0) const;
157  static void build_first_space (const std::vector<std::pair<bool,space_basic<T,M> > >& l_Xh, space_basic<T,M>& Xh);
158  void build_form_pass1 (space_basic<T,M>& Xh, space_basic<T,M>& Yh) const;
160  form_basic<T,M> build_form () const;
161 
162 // data:
163 protected:
164  std::list<value_type> _l;
165 };
166 
167 } // namespace details
168 
169 // -------------------------------
170 // form cstor from std::initializer
171 // -------------------------------
172 template <class T, class M>
173 inline
174 form_basic<T,M>::form_basic (const std::initializer_list<details::form_concat_value<T,M> >& init_list)
175  : _X(), _Y(), _uu(), _ub(), _bu(), _bb()
176 {
177  details::form_concat_line<T,M> cc (init_list);
179 }
180 
181 namespace details {
182 // =========================================================================
183 // 2nd case : multi-line form initializer
184 // A = { {a, b },
185 // {c, d} };
186 // =========================================================================
187 template <class T, class M>
188 class form_concat {
189 public:
190 
191 // typedef:
192 
194  typedef typename csr_concat_value<T,M>::sizes_type sizes_type; // [size,dis_size]
195  typedef typename csr_concat_value<T,M>::sizes_pair_type sizes_pair_type; // [nrow,ncol] = [[nrow,dis_nrow],[ncol,dis_ncol]]
196 
197  static constexpr size_type undef = std::numeric_limits<size_type>::max();
198  static constexpr size_type zero = 0;
199 
202 
203 // allocators:
204 
205  form_concat () : _l() {}
206 
207  form_concat (const std::initializer_list<line_type>& il) : _l() {
208  typedef typename std::initializer_list<line_type>::const_iterator const_iterator;
209  for(const_iterator iter = il.begin(); iter != il.end(); ++iter) {
210  _l.push_back(*iter);
211  }
212  }
213  friend std::ostream& operator<< (std::ostream& o, const form_concat<T,M>& x) {
214  std::cout << "{";
215  for(typename std::list<line_type>::const_iterator iter = x._l.begin(); iter != x._l.end(); ++iter) {
216  std::cout << *iter << " ";
217  }
218  return std::cout << "}";
219  }
220 // internals:
221  form_basic<T,M> build_form () const;
222 
223 // data:
224 protected:
225  std::list<line_type> _l;
226 };
227 
228 } // namespace details
229 
230 template <class T, class M>
231 inline
232 form_basic<T,M>::form_basic (const std::initializer_list<details::form_concat_line<T,M> >& init_list)
233  : _X(), _Y(), _uu(), _ub(), _bu(), _bb()
234 {
235  details::form_concat<T,M> cc (init_list);
237 }
238 
239 } // namespace rheolef
240 #endif // _RHEOLEF_FORM_CONCAT_H
see the field page for the full documentation
see the form page for the full documentation
std::pair< sizes_type, sizes_type > sizes_pair_type
Definition: csr_concat.h:58
csr< T, M >::size_type size_type
Definition: csr_concat.h:56
std::pair< size_type, size_type > sizes_type
Definition: csr_concat.h:57
void build_form_pass0(std::vector< std::pair< bool, space_basic< T, M > > > &l_Xh, space_basic< T, M > &Yh, size_t i_comp=0) const
Definition: form_concat.cc:36
static constexpr size_type zero
Definition: form_concat.h:126
const_iterator begin() const
Definition: form_concat.h:144
friend std::ostream & operator<<(std::ostream &o, const form_concat_line< T, M > &x)
Definition: form_concat.h:147
std::list< value_type > _l
Definition: form_concat.h:164
csr_concat_value< T, M >::size_type size_type
Definition: form_concat.h:121
csr_concat_value< T, M >::sizes_type sizes_type
Definition: form_concat.h:122
form_basic< T, M > build_form_pass2(const space_basic< T, M > &Xh, const space_basic< T, M > &Yh) const
Definition: form_concat.cc:200
form_basic< T, M > build_form() const
Definition: form_concat.cc:228
csr_concat_value< T, M >::sizes_pair_type sizes_pair_type
Definition: form_concat.h:123
void build_form_pass1(space_basic< T, M > &Xh, space_basic< T, M > &Yh) const
Definition: form_concat.cc:189
form_concat_line(const std::initializer_list< value_type > &il)
Definition: form_concat.h:135
const_iterator end() const
Definition: form_concat.h:145
form_concat_value< T, M > value_type
Definition: form_concat.h:128
std::list< value_type >::const_iterator const_iterator
Definition: form_concat.h:129
static constexpr size_type undef
Definition: form_concat.h:125
static void build_first_space(const std::vector< std::pair< bool, space_basic< T, M > > > &l_Xh, space_basic< T, M > &Xh)
Definition: form_concat.cc:172
field_expr_v2_nonlinear_node_unary< trans_,field_expr_v2_nonlinear_terminal_field< T, M, differentiate_option::none > > trans_field_type
Definition: form_concat.h:80
static constexpr size_type zero
Definition: form_concat.h:65
form_concat_value(const trans_field_type &x)
Definition: form_concat.h:93
std::vector< field_basic< T, M > > vv
Definition: form_concat.h:111
form_concat_value(const std::vector< field_basic< T, M >> &x)
Definition: form_concat.h:94
csr_concat_value< T, M >::size_type size_type
Definition: form_concat.h:60
csr_concat_value< T, M >::sizes_type sizes_type
Definition: form_concat.h:61
form_concat_value(const vector_field_trans< T, M > &x)
Definition: form_concat.h:95
form_concat_value(const field_basic< T, M > &x)
Definition: form_concat.h:92
csr_concat_value< T, M >::sizes_pair_type sizes_pair_type
Definition: form_concat.h:62
form_concat_value(const form_basic< T, M > &x)
Definition: form_concat.h:96
friend std::ostream & operator<<(std::ostream &o, const form_concat_value< T, M > &x)
Definition: form_concat.h:99
static constexpr size_type undef
Definition: form_concat.h:64
static constexpr size_type zero
Definition: form_concat.h:198
form_concat_line< T, M > line_type
Definition: form_concat.h:200
csr_concat_value< T, M >::size_type size_type
Definition: form_concat.h:193
csr_concat_value< T, M >::sizes_type sizes_type
Definition: form_concat.h:194
form_basic< T, M > build_form() const
Definition: form_concat.cc:242
std::list< line_type > _l
Definition: form_concat.h:225
csr_concat_value< T, M >::sizes_pair_type sizes_pair_type
Definition: form_concat.h:195
form_concat(const std::initializer_list< line_type > &il)
Definition: form_concat.h:207
form_concat_value< T, M > value_type
Definition: form_concat.h:201
static constexpr size_type undef
Definition: form_concat.h:197
friend std::ostream & operator<<(std::ostream &o, const form_concat< T, M > &x)
Definition: form_concat.h:213
form_basic< T, M > & operator=(const form_basic< T, M > &)
Definition: form.h:313
rheolef::std type
Expr1::float_type T
Definition: field_expr.h:261
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
std::vector< field_basic< T, M > > vv
Definition: form_concat.h:39
vector_field_trans(const std::vector< field_basic< T, M > > &vv1)
Definition: form_concat.h:38