Rheolef  7.1
an efficient C++ finite element environment
tensor4.h
Go to the documentation of this file.
1 # ifndef _RHEOLEF_TENSOR4_H
2 # define _RHEOLEF_TENSOR4_H
3 //
4 // This file is part of Rheolef.
5 //
6 // Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
7 //
8 // Rheolef is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // Rheolef is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with Rheolef; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 //
22 // =========================================================================
23 
24 namespace rheolef {
72 } // namespace rheolef
73 
74 #include "rheolef/point.h"
75 #include "rheolef/tensor.h"
76 namespace rheolef {
77 
78 // [verbatim_tensor4_basic]
79 template<class T>
81 public:
82 
83  typedef size_t size_type;
84  typedef T element_type;
85  typedef T float_type;
86 
87 // allocators:
88 
89  tensor4_basic ();
90  explicit tensor4_basic (const T& init_val);
92  static tensor4_basic<T> eye (size_type d = 3);
93 
94  tensor4_basic (const std::initializer_list<std::initializer_list<
95  std::initializer_list<std::initializer_list<T> > > >& il);
96 
97 // affectation:
98 
100  tensor4_basic<T>& operator= (const T& val);
101 
102 // accessors:
103 
105  const T& operator()(size_type i, size_type j, size_type k, size_type l) const;
106 
108  const tensor_basic<T>& operator()(size_type i, size_type j) const;
109 
110 // algebra:
111 
112  tensor4_basic<T> operator* (const T& k) const;
113  tensor4_basic<T> operator/ (const T& k) const;
118  tensor4_basic<T>& operator*= (const T& k);
119  tensor4_basic<T>& operator/= (const T& k) { return operator*= (1./k); }
120 
121 // io:
122  std::ostream& put (std::ostream& out, size_type d=3) const;
123 // [verbatim_tensor4_basic]
124 
125 // data:
126 protected:
128 // [verbatim_tensor4_basic_cont]
129 };
130 // [verbatim_tensor4_basic_cont]
131 
132 // [verbatim_tensor4]
134 // [verbatim_tensor4]
135 
136 // [verbatim_tensor4_basic_cont2]
137 template <class T>
138 T norm (const tensor4_basic<T>& a) { return sqrt(norm2(a)); }
139 
140 template <class T>
141 T norm2 (const tensor4_basic<T>&);
142 
143 template <class T>
144 tensor_basic<T> ddot (const tensor4_basic<T>&, const tensor_basic<T>&);
145 
146 template <class T>
147 tensor_basic<T> ddot (const tensor_basic<T>&, const tensor4_basic<T>&);
148 
149 template <class T>
150 tensor4_basic<T> dexp (const tensor_basic<T>& a, size_t d = 3);
151 // [verbatim_tensor4_basic_cont2]
152 // -----------------------------------------------------------------------
153 // inlined
154 // -----------------------------------------------------------------------
155 template<class T> struct float_traits<tensor4_basic<T> > { typedef typename float_traits<T>::type type; };
156 template<class T> struct scalar_traits<tensor4_basic<T> > { typedef T type; };
157 
158 template<class T>
159 inline
161  : _x (tensor_basic<T>(T()))
162 {
163 }
164 template<class T>
165 inline
167  : _x (tensor_basic<T>(init_val))
168 {
169 }
170 template<class T>
171 inline
173  : _x (tensor_basic<T>(T()))
174 {
175  operator= (a);
176 }
177 template<class T>
178 inline
181 {
182  return _x(i,j);
183 }
184 template<class T>
185 inline
186 const tensor_basic<T>&
188 {
189  return _x(i,j);
190 }
191 template<class T>
192 inline
193 T&
195 {
196  return _x(i,j)(k,l);
197 }
198 template<class T>
199 inline
200 const T&
202 {
203  return _x(i,j)(k,l);
204 }
205 template <class T>
206 inline
209 {
210  tensor4_basic<T> b = *this;
211  b *= k;
212  return b;
213 }
214 template <class T, class U>
215 inline
216 typename
217 std::enable_if<
218  details::is_rheolef_arithmetic<U>::value
220 >::type
221 operator* (const U& k, const tensor4_basic<T>& a)
222 {
223  return a*k;
224 }
225 template <class T>
226 inline
227 tensor4_basic<T>
229 {
230  return operator* (1./k);
231 }
232 // inputs/outputs:
233 #ifdef TODO
234 template<class T>
235 inline
236 std::istream& operator>> (std::istream& in, tensor4_basic<T>& a)
237 {
238  return a.get (in);
239 }
240 #endif // TODO
241 template<class T>
242 inline
243 std::ostream& operator<< (std::ostream& out, const tensor4_basic<T>& a)
244 {
245  return a.put (out);
246 }
247 
248 }// namespace rheolef
249 # endif /* _RHEOLEF_TENSOR4_H */
field::size_type size_type
Definition: branch.cc:425
std::ostream & put(std::ostream &out, size_type d=3) const
Definition: tensor4.cc:198
tensor4_basic< T > operator+(const tensor4_basic< T > &b) const
Definition: tensor4.cc:125
tensor4_basic< T > operator-(const tensor4_basic< T > &b) const
Definition: tensor4.cc:138
tensor4_basic< T > & operator/=(const T &k)
Definition: tensor4.h:119
tensor_basic< tensor_basic< T > > _x
Definition: tensor4.h:127
tensor4_basic< T > & operator-=(const tensor4_basic< T > &)
Definition: tensor4.cc:162
tensor4_basic< T > & operator+=(const tensor4_basic< T > &)
Definition: tensor4.cc:151
tensor4_basic< T > operator*(const T &k) const
Definition: tensor4.h:208
tensor4_basic< T > & operator*=(const T &k)
Definition: tensor4.cc:173
tensor4_basic< T > & operator=(const tensor4_basic< T > &a)
Definition: tensor4.cc:114
static tensor4_basic< T > eye(size_type d=3)
Definition: tensor4.cc:29
tensor4_basic< T > operator/(const T &k) const
Definition: tensor4.h:228
T & operator()(size_type i, size_type j, size_type k, size_type l)
Definition: tensor4.h:194
rheolef::std type
tensor4_basic< Float > tensor4
Definition: tensor4.h:133
Expr1::float_type T
Definition: field_expr.h:261
This file is part of Rheolef.
std::istream & operator>>(std::istream &is, const catchmark &m)
Definition: catchmark.h:88
tensor4_basic< T > dexp(const tensor_basic< T > &chi, size_t dim)
Definition: tensor4-dexp.cc:37
T norm(const vec< T, M > &x)
norm(x): see the expression page for the full documentation
Definition: vec.h:387
csr< T, sequential > operator*(const T &lambda, const csr< T, sequential > &a)
Definition: csr.h:437
T norm2(const vec< T, M > &x)
norm2(x): see the expression page for the full documentation
Definition: vec.h:379
T ddot(const tensor_basic< T > &a, const tensor_basic< T > &b)
ddot(x,y): see the expression page for the full documentation
Definition: tensor.cc:278
std::ostream & operator<<(std::ostream &os, const catchmark &m)
Definition: catchmark.h:99
helper for std::complex<T>: get basic T type
Definition: Float.h:93
helper for point_basic<T> & tensor_basic<T>: get basic T type
Definition: point.h:324