form_concat.h
Go to the documentation of this file.
#ifndef _RHEOLEF_FORM_CONCAT_H
#define _RHEOLEF_FORM_CONCAT_H
// build form from initializer list (c++ 2011)
//
#include "rheolef/form.h"
#include "rheolef/csr_concat.h"
#include "rheolef/field_expr_recursive.h"
namespace rheolef { namespace details {
// =========================================================================
// 1rst case : one-line matrix initializer
// A = {a, b}; // matrix & vector
// =========================================================================
template <class T, class M>
struct vector_field_trans {
vector_field_trans (const std::vector<field_basic<T,M> >& vv1) : vv(vv1) {}
std::vector<field_basic<T,M> > vv;
};
} // namespace details
template <class T, class M>
inline
details::vector_field_trans<T,M>
trans (const std::vector<field_basic<T,M> >& vv)
{
return details::vector_field_trans<T,M> (vv);
}
namespace details {
template <class T, class M>
class form_concat_value {
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 enum {
scalar,
field,
field_transpose,
vector_field,
vector_field_transpose,
form
} variant_type;
typedef field_expr_v2_nonlinear_node_unary<
trans_
,field_expr_v2_nonlinear_terminal_field<T, M, differentiate_option::none>
>
trans_field_type;
// allocators:
template <class U,
class Sfinae
= typename std::enable_if<
is_rheolef_arithmetic<U>::value
,void
>::type
>
form_concat_value (const U& x) : s(x), v(), vv(), m(), variant(scalar) {}
form_concat_value (const field_basic<T,M>& x) : s(), v(x), vv(), m(), variant(field) {}
form_concat_value (const trans_field_type& x) : s(), v(x.expr().expr()), vv(), m(), variant(field_transpose) {}
form_concat_value (const std::vector<field_basic<T,M>>& x) : s(), v(), vv(x), m(), variant(vector_field) {}
form_concat_value (const vector_field_trans<T,M>& x) : s(), v(), vv(x.vv), m(), variant(vector_field_transpose) {}
form_concat_value (const form_basic<T,M>& x) : s(), v(), vv(), m(x), variant(form) {}
// io/debug:
friend std::ostream& operator<< (std::ostream& o, const form_concat_value<T,M>& x) {
if (x.variant == scalar) return o << "s";
else if (x.variant == field) return o << "f";
else if (x.variant == field_transpose) return o << "ft";
else if (x.variant == vector_field) return o << "vf";
else if (x.variant == vector_field_transpose) return o << "vft";
else return o << "m";
}
// data:
public:
T s;
field_basic<T,M> v;
std::vector<field_basic<T,M>> vv;
form_basic<T,M> m;
variant_type variant;
};
template <class T, class M>
class form_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 form_concat_value<T,M> value_type;
typedef typename std::list<value_type>::const_iterator const_iterator;
// allocators:
form_concat_line () : _l() {}
form_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);
}
}
// accessors:
const_iterator begin() const { return _l.begin(); }
const_iterator end() const { return _l.end(); }
friend std::ostream& operator<< (std::ostream& o, const form_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:
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;
static void build_first_space (const std::vector<std::pair<bool,space_basic<T,M> > >& l_Xh, space_basic<T,M>& Xh);
void build_form_pass1 (space_basic<T,M>& Xh, space_basic<T,M>& Yh) const;
form_basic<T,M> build_form_pass2 (const space_basic<T,M>& Xh, const space_basic<T,M>& Yh) const;
form_basic<T,M> build_form () const;
// data:
protected:
std::list<value_type> _l;
};
} // namespace details
// -------------------------------
// form cstor from std::initializer
// -------------------------------
template <class T, class M>
inline
form_basic<T,M>::form_basic (const std::initializer_list<details::form_concat_value<T,M> >& init_list)
: _X(), _Y(), _uu(), _ub(), _bu(), _bb()
{
details::form_concat_line<T,M> cc (init_list);
form_basic<T,M>::operator= (cc.build_form());
}
namespace details {
// =========================================================================
// 2nd case : multi-line form initializer
// A = { {a, b },
// {c, d} };
// =========================================================================
template <class T, class M>
class form_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 form_concat_line<T,M> line_type;
typedef form_concat_value<T,M> value_type;
// allocators:
form_concat () : _l() {}
form_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);
}
}
friend std::ostream& operator<< (std::ostream& o, const form_concat<T,M>& x) {
std::cout << "{";
for(typename std::list<line_type>::const_iterator iter = x._l.begin(); iter != x._l.end(); ++iter) {
std::cout << *iter << " ";
}
return std::cout << "}";
}
// internals:
form_basic<T,M> build_form () const;
// data:
protected:
std::list<line_type> _l;
};
} // namespace details
template <class T, class M>
inline
form_basic<T,M>::form_basic (const std::initializer_list<details::form_concat_line<T,M> >& init_list)
: _X(), _Y(), _uu(), _ub(), _bu(), _bb()
{
details::form_concat<T,M> cc (init_list);
form_basic<T,M>::operator= (cc.build_form());
}
} // namespace rheolef
#endif // _RHEOLEF_FORM_CONCAT_H
field
see the field page for the full documentation
form
see the form page for the full documentation
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::size_type
csr< T, M >::size_type size_type
Definition: csr_concat.h:56
rheolef::details::csr_concat_value::sizes_type
std::pair< size_type, size_type > sizes_type
Definition: csr_concat.h:57
rheolef::details::field_expr_v2_nonlinear_node_unary
Definition: field_expr_recursive.h:59
rheolef::details::field_expr_v2_nonlinear_terminal_field
Definition: field_expr_terminal.h:802
rheolef::details::form_concat_line
Definition: form_concat.h:116
rheolef::details::form_concat_line::build_form_pass0
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
rheolef::details::form_concat_line::zero
static constexpr size_type zero
Definition: form_concat.h:126
rheolef::details::form_concat_line::begin
const_iterator begin() const
Definition: form_concat.h:144
rheolef::details::form_concat_line::form_concat_line
form_concat_line()
Definition: form_concat.h:133
rheolef::details::form_concat_line::operator<<
friend std::ostream & operator<<(std::ostream &o, const form_concat_line< T, M > &x)
Definition: form_concat.h:147
rheolef::details::form_concat_line::_l
std::list< value_type > _l
Definition: form_concat.h:164
rheolef::details::form_concat_line::size_type
csr_concat_value< T, M >::size_type size_type
Definition: form_concat.h:121
rheolef::details::form_concat_line::sizes_type
csr_concat_value< T, M >::sizes_type sizes_type
Definition: form_concat.h:122
rheolef::details::form_concat_line::build_form_pass2
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
rheolef::details::form_concat_line::build_form
form_basic< T, M > build_form() const
Definition: form_concat.cc:228
rheolef::details::form_concat_line::sizes_pair_type
csr_concat_value< T, M >::sizes_pair_type sizes_pair_type
Definition: form_concat.h:123
rheolef::details::form_concat_line::build_form_pass1
void build_form_pass1(space_basic< T, M > &Xh, space_basic< T, M > &Yh) const
Definition: form_concat.cc:189
rheolef::details::form_concat_line::form_concat_line
form_concat_line(const std::initializer_list< value_type > &il)
Definition: form_concat.h:135
rheolef::details::form_concat_line::end
const_iterator end() const
Definition: form_concat.h:145
rheolef::details::form_concat_line::value_type
form_concat_value< T, M > value_type
Definition: form_concat.h:128
rheolef::details::form_concat_line::const_iterator
std::list< value_type >::const_iterator const_iterator
Definition: form_concat.h:129
rheolef::details::form_concat_line::undef
static constexpr size_type undef
Definition: form_concat.h:125
rheolef::details::form_concat_line::build_first_space
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
rheolef::details::form_concat_value
Definition: form_concat.h:55
rheolef::details::form_concat_value::trans_field_type
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
rheolef::details::form_concat_value::zero
static constexpr size_type zero
Definition: form_concat.h:65
rheolef::details::form_concat_value::form_concat_value
form_concat_value(const trans_field_type &x)
Definition: form_concat.h:93
rheolef::details::form_concat_value::v
field_basic< T, M > v
Definition: form_concat.h:110
rheolef::details::form_concat_value::form_concat_value
form_concat_value(const U &x)
Definition: form_concat.h:91
rheolef::details::form_concat_value::vv
std::vector< field_basic< T, M > > vv
Definition: form_concat.h:111
rheolef::details::form_concat_value::form_concat_value
form_concat_value(const std::vector< field_basic< T, M >> &x)
Definition: form_concat.h:94
rheolef::details::form_concat_value::size_type
csr_concat_value< T, M >::size_type size_type
Definition: form_concat.h:60
rheolef::details::form_concat_value::sizes_type
csr_concat_value< T, M >::sizes_type sizes_type
Definition: form_concat.h:61
rheolef::details::form_concat_value::m
form_basic< T, M > m
Definition: form_concat.h:112
rheolef::details::form_concat_value::variant_type
variant_type
Definition: form_concat.h:67
rheolef::details::form_concat_value::field_transpose
@ field_transpose
Definition: form_concat.h:70
rheolef::details::form_concat_value::field
@ field
Definition: form_concat.h:69
rheolef::details::form_concat_value::vector_field_transpose
@ vector_field_transpose
Definition: form_concat.h:72
rheolef::details::form_concat_value::scalar
@ scalar
Definition: form_concat.h:68
rheolef::details::form_concat_value::vector_field
@ vector_field
Definition: form_concat.h:71
rheolef::details::form_concat_value::form_concat_value
form_concat_value(const vector_field_trans< T, M > &x)
Definition: form_concat.h:95
rheolef::details::form_concat_value::form_concat_value
form_concat_value(const field_basic< T, M > &x)
Definition: form_concat.h:92
rheolef::details::form_concat_value::sizes_pair_type
csr_concat_value< T, M >::sizes_pair_type sizes_pair_type
Definition: form_concat.h:62
rheolef::details::form_concat_value::form_concat_value
form_concat_value(const form_basic< T, M > &x)
Definition: form_concat.h:96
rheolef::details::form_concat_value::operator<<
friend std::ostream & operator<<(std::ostream &o, const form_concat_value< T, M > &x)
Definition: form_concat.h:99
rheolef::details::form_concat_value::s
T s
Definition: form_concat.h:109
rheolef::details::form_concat_value::variant
variant_type variant
Definition: form_concat.h:113
rheolef::details::form_concat_value::undef
static constexpr size_type undef
Definition: form_concat.h:64
rheolef::details::form_concat
Definition: form_concat.h:188
rheolef::details::form_concat::zero
static constexpr size_type zero
Definition: form_concat.h:198
rheolef::details::form_concat::line_type
form_concat_line< T, M > line_type
Definition: form_concat.h:200
rheolef::details::form_concat::size_type
csr_concat_value< T, M >::size_type size_type
Definition: form_concat.h:193
rheolef::details::form_concat::sizes_type
csr_concat_value< T, M >::sizes_type sizes_type
Definition: form_concat.h:194
rheolef::details::form_concat::build_form
form_basic< T, M > build_form() const
Definition: form_concat.cc:242
rheolef::details::form_concat::_l
std::list< line_type > _l
Definition: form_concat.h:225
rheolef::details::form_concat::sizes_pair_type
csr_concat_value< T, M >::sizes_pair_type sizes_pair_type
Definition: form_concat.h:195
rheolef::details::form_concat::form_concat
form_concat(const std::initializer_list< line_type > &il)
Definition: form_concat.h:207
rheolef::details::form_concat::value_type
form_concat_value< T, M > value_type
Definition: form_concat.h:201
rheolef::details::form_concat::undef
static constexpr size_type undef
Definition: form_concat.h:197
rheolef::details::form_concat::form_concat
form_concat()
Definition: form_concat.h:205
rheolef::details::form_concat::operator<<
friend std::ostream & operator<<(std::ostream &o, const form_concat< T, M > &x)
Definition: form_concat.h:213
rheolef::field_basic< T, M >
rheolef::form_basic
Definition: form.h:144
rheolef::form_basic::form_basic
form_basic()
Definition: form.h:300
rheolef::form_basic::operator=
form_basic< T, M > & operator=(const form_basic< T, M > &)
Definition: form.h:313
rheolef::space_basic< T, M >
rheolef::type
rheolef::std type
T
Expr1::float_type T
Definition: field_expr.h:261
rheolef::space_constant::vector
@ vector
Definition: space_constant.h:137
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
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::const_iterator
Definition: field_expr_recursive.h:552
rheolef::details::is_rheolef_arithmetic
Definition: Float.h:150
rheolef::details::trans_
Definition: expression.h:325
rheolef::details::vector_field_trans
Definition: form_concat.h:37
rheolef::details::vector_field_trans::vv
std::vector< field_basic< T, M > > vv
Definition: form_concat.h:39
rheolef::details::vector_field_trans::vector_field_trans
vector_field_trans(const std::vector< field_basic< T, M > > &vv1)
Definition: form_concat.h:38