Rheolef  7.1
an efficient C++ finite element environment
tiny_matvec.h
Go to the documentation of this file.
1 # ifndef _RHEO_TINY_MATVEC_H
2 # define _RHEO_TINY_MATVEC_H
3 //
24 // very small matrix - vector
25 //
26 // authors: Pierre.Saramito@imag.fr
27 //
28 // date: 7 july 1997
29 //
30 #include "rheolef/compiler.h"
31 
32 namespace rheolef {
33 // take a 2^n since a(i,j) -> table (tiny_size_max*j + i)
34 // and tiny_size_max*j == j << log2(tiny_size_max*j) is fast
35 
36 const unsigned int tiny_size_max = 32;
37 
38 template <class T>
39 class tiny_vector {
40 public:
42 
43  tiny_vector (size_type n = 0);
44  tiny_vector (size_type n, const T& value);
45  size_type size() const { return size_; }
46  void resize(size_type n);
47  const T& operator() (size_type i) const { return t_[i+i0_]; }
48  const T& operator[] (size_type i) const { return t_[i+i0_]; }
49  T& operator() (size_type i) { return t_[i+i0_]; }
50  T& operator[] (size_type i) { return t_[i+i0_]; }
51  void set_origin(size_type i) { i0_ = i; }
52  size_type get_origin() const { return i0_; }
53  void fill(const T& val) {
54  for (size_type i = i0_; i < i0_ + size_; i++) t_ [i] = val; }
55  void reset() { fill(T()); }
56 protected:
60 };
61 template <class T>
62 class tiny_matrix {
63 public:
65  tiny_matrix (size_type nr = 0, size_type nc = 0);
66  size_type nrow() const { return nrow_; }
67  size_type ncol() const { return ncol_; }
68  T& operator() (size_type i, size_type j) { return t_[i+i0_][j+j0_]; }
69  const T& operator() (size_type i, size_type j) const { return t_[i+i0_][j+j0_]; }
70  T& operator() (size_type i) { return t_[i+i0_][i+j0_]; }
71  const T& operator() (size_type i) const { return t_[i+i0_][i+j0_]; }
72  void set_origin(size_type i, size_type j) { i0_ = i; j0_ = j; }
73  void resize(size_type nr, size_type nc);
74  size_type get_row_origin() const { return i0_; }
75  size_type get_col_origin() const { return j0_; }
76  void fill(const T& val);
77  void reset() { fill(T()); }
78 private:
80  size_type nrow_;
81  size_type ncol_;
82  size_type i0_;
83  size_type j0_;
84 };
85 // =====================================================================
86 // inlined
87 // =====================================================================
88 
89 template <class T>
90 inline
92  : size_(n), i0_(0)
93 {
94  check_macro (n <= tiny_size_max, "invalid size");
95 #ifdef _RHEOLEF_PARANO
96  std::fill (t_, t_+tiny_size_max, std::numeric_limits<T>::max());
97 #endif // _RHEOLEF_PARANO
98 }
99 template <class T>
100 inline
102  : size_(n), i0_(0)
103 {
104  check_macro (n <= tiny_size_max, "invalid size");
106 }
107 template <class T>
108 inline
109 void
111 {
112  size_ = n;
113  check_macro (n <= tiny_size_max, "invalid size");
114 #ifdef _RHEOLEF_PARANO
115  std::fill (t_, t_+tiny_size_max, std::numeric_limits<T>::max());
116 #endif // _RHEOLEF_PARANO
117 }
118 template <class T>
119 inline
121  : nrow_(nr), ncol_(nc), i0_(0), j0_(0)
122 {
123  check_macro (nr <= tiny_size_max && nc <= tiny_size_max, "invalid sizes");
124 #ifdef _RHEOLEF_PARANO
125  for (size_type i = 0; i < tiny_size_max; i++)
126  for (size_type j = 0; j < tiny_size_max; j++)
127  t_[i][j] = std::numeric_limits<T>::max();
128 #endif // _RHEOLEF_PARANO
129 
130 }
131 template <class T>
132 inline
133 void
135 {
136  nrow_ = nr;
137  ncol_ = nc;
138  check_macro (nr <= tiny_size_max && nc <= tiny_size_max, "invalid sizes");
139 #ifdef _RHEOLEF_PARANO
140  for (size_type i = 0; i < tiny_size_max; i++)
141  for (size_type j = 0; j < tiny_size_max; j++)
142  t_[i][j] = std::numeric_limits<T>::max();
143 #endif // _RHEOLEF_PARANO
144 }
145 template <class T>
146 inline
147 void
149 {
150  for (size_type i = i0_; i < i0_ + nrow_; i++)
151  for (size_type j = j0_; j < j0_ + ncol_; j++)
152  t_ [i][j] = val;
153 }
154 template <class T>
155 void
157 {
158  typedef typename tiny_matrix<T>::size_type size_type;
159  b.resize (a.ncol(), a.nrow());
160  for (size_type i = 0; i < a.nrow(); i++)
161  for (size_type j = 0; j < a.ncol(); j++)
162  b(j,i) = a(i,j);
163 }
164 template<class T>
165 tiny_matrix<T>
167  {
168  check_macro(a.ncol()==b.nrow(),"Error in matrices sizes for multiplication, "
169  << a.nrow()<<"x"<<a.ncol() <<" and "<< b.nrow()<<"x"<<b.ncol());
170  typedef typename tiny_matrix<T>::size_type size_type;
171  tiny_matrix<T> c(a.nrow(),b.ncol());
172  c.fill(0);
173  for (size_type i=0; i<a.nrow(); i++)
174  for (size_type j=0; j<b.ncol(); j++)
175  for (size_type k=0; k<b.nrow(); k++)
176  c(i,j)+=a(i,k)*b(k,j);
177  return c;
178  }
179 template<class T>
180 tiny_vector<T>
182  {
183  check_macro(a.ncol()==u.size(),"Error in matrice-vector sizes for multiplication, "
184  << a.nrow()<<"x"<<a.ncol() <<" and "<< u.size());
185  typedef typename tiny_matrix<T>::size_type size_type;
186  tiny_vector<T> v(a.nrow());
187  v.fill(0);
188  for (size_type i=0; i<a.nrow(); i++)
189  for (size_type j=0; j<u.size(); j++)
190  v(i)+=a(i,j)*u(j);
191  return v;
192  }
193 }// namespace rheolef
194 # endif /* _RHEO_TINY_MATVEC_H */
rheolef::tiny_vector::set_origin
void set_origin(size_type i)
Definition: tiny_matvec.h:51
rheolef::tiny_vector::size_
size_type size_
Definition: tiny_matvec.h:58
rheolef::tiny_matrix::get_col_origin
size_type get_col_origin() const
Definition: tiny_matvec.h:75
check_macro
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
rheolef::tiny_vector::size_type
std::vector< int >::size_type size_type
Definition: tiny_matvec.h:41
rheolef::operator*
csr< T, sequential > operator*(const T &lambda, const csr< T, sequential > &a)
Definition: csr.h:437
rheolef::value
rheolef::std value
rheolef::tiny_vector
Definition: tiny_matvec.h:39
rheolef::tiny_vector::operator[]
const T & operator[](size_type i) const
Definition: tiny_matvec.h:48
mkgeo_ball.c
c
Definition: mkgeo_ball.sh:153
rheolef::tiny_matrix::ncol
size_type ncol() const
Definition: tiny_matvec.h:67
rheolef::size_type
size_t size_type
Definition: basis_get.cc:76
rheolef::tiny_matrix::get_row_origin
size_type get_row_origin() const
Definition: tiny_matvec.h:74
rheolef::tiny_vector::size
size_type size() const
Definition: tiny_matvec.h:45
rheolef::tiny_vector::get_origin
size_type get_origin() const
Definition: tiny_matvec.h:52
rheolef::tiny_vector::operator()
const T & operator()(size_type i) const
Definition: tiny_matvec.h:47
rheolef::tiny_matrix
Definition: tiny_matvec.h:62
rheolef::tiny_matrix::operator()
T & operator()(size_type i, size_type j)
Definition: tiny_matvec.h:68
rheolef::tiny_matrix::reset
void reset()
Definition: tiny_matvec.h:77
a
Definition: diffusion_isotropic.h:25
rheolef::tiny_matrix::size_type
tiny_vector< T >::size_type size_type
Definition: tiny_matvec.h:64
rheolef::tiny_matrix::fill
void fill(const T &val)
Definition: tiny_matvec.h:148
rheolef::tiny_vector::t_
T t_[tiny_size_max]
Definition: tiny_matvec.h:57
rheolef::tiny_vector::i0_
size_type i0_
Definition: tiny_matvec.h:59
rheolef::tiny_vector::reset
void reset()
Definition: tiny_matvec.h:55
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
u
Definition: leveque.h:25
rheolef::tiny_vector::resize
void resize(size_type n)
Definition: tiny_matvec.h:110
u
Float u(const point &x)
Definition: transmission_error.cc:26
mkgeo_ball.b
b
Definition: mkgeo_ball.sh:152
rheolef::tiny_vector::tiny_vector
tiny_vector(size_type n=0)
Definition: tiny_matvec.h:91
mkgeo_ball.a
a
Definition: mkgeo_ball.sh:151
rheolef::tiny_vector::fill
void fill(const T &val)
Definition: tiny_matvec.h:53
mkgeo_ball.n
n
Definition: mkgeo_ball.sh:150
rheolef::tiny_size_max
const unsigned int tiny_size_max
Definition: tiny_matvec.h:36
size_type
field::size_type size_type
Definition: branch.cc:425
rheolef::tiny_matrix::resize
void resize(size_type nr, size_type nc)
Definition: tiny_matvec.h:134
rheolef::tiny_matrix::nrow
size_type nrow() const
Definition: tiny_matvec.h:66
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::tiny_matrix::set_origin
void set_origin(size_type i, size_type j)
Definition: tiny_matvec.h:72
rheolef::tiny_matrix::tiny_matrix
tiny_matrix(size_type nr=0, size_type nc=0)
Definition: tiny_matvec.h:120
T
Expr1::float_type T
Definition: field_expr.h:218