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