rheolef  7.0
tensor3.h
Go to the documentation of this file.
1 # ifndef _RHEOLEF_TENSOR3_H
2 # define _RHEOLEF_TENSOR3_H
3 
14 #include "rheolef/point.h"
15 #include "rheolef/tensor.h"
16 namespace rheolef {
17 
18 template<class T>
20 public:
21 
22  typedef size_t size_type;
23  typedef T element_type;
24  typedef T float_type;
25 
26 
27  tensor3_basic (const T& init_val = 0);
29 
30 
32  tensor3_basic<T>& operator= (const T& val);
33 
34 
35  T& operator()(size_type i, size_type j, size_type k);
36  const T& operator()(size_type i, size_type j, size_type k) const;
37 
38  tensor3_basic<T>& operator*= (const T& k);
39  tensor3_basic<T>& operator/= (const T& k) { return operator*= (1./k); }
40  tensor3_basic<T> operator* (const T& k) const;
41  tensor3_basic<T> operator/ (const T& k) const;
46 
47 // inputs/outputs:
48 
49  std::ostream& put (std::ostream& s, size_type d = 3) const;
50  std::istream& get (std::istream&);
51 
52 protected:
53  T _x [3][3][3];
54 };
56 
57 @endcode
58 template<class T> struct float_traits<tensor3_basic<T> > { typedef typename float_traits<T>::type type; };
59 template<class T> struct scalar_traits<tensor3_basic<T> > { typedef T type; };
60 
61 template<class T>
62 inline
64 {
65  operator= (init_val);
66 }
67 template<class T>
68 inline
70 {
71  operator= (a);
72 }
73 template<class T>
74 inline
75 T&
77 {
78  return _x[i%3][j%3][k%3];
79 }
80 template<class T>
81 inline
82 const T&
84 {
85  return _x[i%3][j%3][k%3];
86 }
87 template <class T>
88 inline
91 {
92  tensor3_basic<T> b = *this;
93  b *= k;
94  return b;
95 }
96 template <class T, class U>
97 inline
98 typename
99 std::enable_if<
102 >::type
103 operator* (const U& k, const tensor3_basic<T>& a)
104 {
105  return a*k;
106 }
107 template <class T>
108 inline
111 {
112  return operator* (1./k);
113 }
114 template <class U>
115 U dddot (const tensor3_basic<U>&, const tensor3_basic<U>&);
116 
117 template <class T>
118 inline
119 T
121 {
122  return dddot(a,a);
123 }
124 template <class T>
125 inline
126 T
128 {
129  return norm2(a-b);
130 }
131 template <class U>
132 inline
133 U
135 {
136  return sqrt(norm2(a));
137 }
138 template <class U>
139 inline
140 U
142 {
143  return norm(a-b);
144 }
145 
146 // inputs/outputs:
147 template<class T>
148 inline
149 std::istream& operator>> (std::istream& in, tensor3_basic<T>& a)
150 {
151  return a.get (in);
152 }
153 template<class T>
154 inline
155 std::ostream& operator<< (std::ostream& out, const tensor3_basic<T>& a)
156 {
157  return a.put (out);
158 }
159 
160 }// namespace rheolef
161 # endif /* _RHEOLEF_TENSOR3_H */
tensor3_basic< T > & operator/=(const T &k)
Definition: tensor3.h:39
tensor3_basic< Float > tensor3
Definition: tensor3.h:55
tensor3_basic< T > operator/(const T &k) const
Definition: tensor3.h:110
tensor3_basic< T > operator*(const T &k) const
Definition: tensor3.h:90
T dist2(const point_basic< T > &x, const point_basic< T > &y)
Definition: point.h:165
T dddot(const tensor3_basic< T > &a, const tensor3_basic< T > &b)
Definition: tensor3.cc:83
point - vertex of a mesh
Definition: point.h:22
tensor3_basic< T > & operator*=(const T &k)
Definition: tensor3.cc:28
T & operator()(size_type i, size_type j, size_type k)
Definition: tensor3.h:76
irheostream, orheostream - large data streams
Definition: compiler.h:7
T norm2(const vec< T, M > &x)
Definition: vec.h:334
T norm(const vec< T, M > &x)
Definition: vec.h:341
tensor3_basic< T > operator+(const tensor3_basic< T > &b) const
Definition: tensor3.cc:61
tensor3_basic< T > operator-(const tensor3_basic< T > &b) const
Definition: tensor3.cc:72
size_t d
std::istream & get(std::istream &)
Definition: tensor3.cc:118
helper for point_basic<T> & tensor_basic<T>: get basic T type
Definition: point.h:234
std::istream & operator>>(std::istream &is, const catchmark &m)
Definition: catchmark.h:48
rheolef::std type
tensor3_basic< T > & operator=(const tensor3_basic< T > &a)
Definition: tensor3.cc:18
std::ostream & put(std::ostream &s, size_type d=3) const
Definition: tensor3.cc:95
tensor3_basic(const T &init_val=0)
Definition: tensor3.h:63
T dist(const point_basic< T > &x, const point_basic< T > &y)
Definition: point.h:171