Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
tensor3.h
Go to the documentation of this file.
1# ifndef _RHEOLEF_TENSOR3_H
2# define _RHEOLEF_TENSOR3_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
24namespace rheolef {
65} // namespace rheolef
66
67#include "rheolef/point.h"
68#include "rheolef/tensor.h"
69namespace rheolef {
70
71// [verbatim_tensor3_basic]
72template<class T>
74public:
75
76 typedef size_t size_type;
77 typedef T element_type;
78 typedef T float_type;
79
80// allocators:
81
82 tensor3_basic (const T& init_val = 0);
84
85// affectation:
86
88 tensor3_basic<T>& operator= (const T& val);
89
90// accessors:
91
93 const T& operator()(size_type i, size_type j, size_type k) const;
94
95// algebra
96 tensor3_basic<T> operator* (const T& k) const;
97 tensor3_basic<T> operator/ (const T& k) const;
104 tensor3_basic<T>& operator*= (const T& k);
105 tensor3_basic<T>& operator/= (const T& k) { return operator*= (1./k); }
106
107// inputs/outputs:
108
109 std::ostream& put (std::ostream& s, size_type d = 3) const;
110 std::istream& get (std::istream&);
111// [verbatim_tensor3_basic]
112
113// data:
114protected:
115 T _x [3][3][3];
116// [verbatim_tensor3_basic_cont]
117};
118// [verbatim_tensor3_basic_cont]
119
120// [verbatim_tensor3]
122// [verbatim_tensor3]
123
124// -----------------------------------------------------------------------
125// inlined
126// -----------------------------------------------------------------------
127template<class T> struct float_traits<tensor3_basic<T> > { typedef typename float_traits<T>::type type; };
128template<class T> struct scalar_traits<tensor3_basic<T> > { typedef T type; };
129
130template<class T>
131inline
133{
134 operator= (init_val);
135}
136template<class T>
137inline
139{
140 operator= (a);
141}
142template<class T>
143inline
144T&
146{
147 return _x[i%3][j%3][k%3];
148}
149template<class T>
150inline
151const T&
153{
154 return _x[i%3][j%3][k%3];
155}
156template <class T>
157inline
160{
161 tensor3_basic<T> b = *this;
162 b *= k;
163 return b;
164}
165template <class T, class U>
166inline
167typename
168std::enable_if<
169 details::is_rheolef_arithmetic<U>::value
171>::type
172operator* (const U& k, const tensor3_basic<T>& a)
173{
174 return a*k;
175}
176template <class T>
177inline
178tensor3_basic<T>
180{
181 return operator* (1./k);
182}
183template <class U>
185
186template <class T>
187inline
188T
190{
191 return dddot(a,a);
192}
193template <class T>
194inline
195T
197{
198 return norm2(a-b);
199}
200template <class U>
201inline
202U
204{
205 return sqrt(norm2(a));
206}
207template <class U>
208inline
209U
211{
212 return norm(a-b);
213}
214
215// inputs/outputs:
216template<class T>
217inline
218std::istream& operator>> (std::istream& in, tensor3_basic<T>& a)
219{
220 return a.get (in);
221}
222template<class T>
223inline
224std::ostream& operator<< (std::ostream& out, const tensor3_basic<T>& a)
225{
226 return a.put (out);
227}
228
229}// namespace rheolef
230# endif /* _RHEOLEF_TENSOR3_H */
field::size_type size_type
Definition branch.cc:430
tensor3_basic< T > operator-(const tensor3_basic< T > &b) const
Definition tensor3.cc:83
std::ostream & put(std::ostream &s, size_type d=3) const
Definition tensor3.cc:140
tensor3_basic< T > & operator-=(const tensor3_basic< T > &)
Definition tensor3.cc:116
std::istream & get(std::istream &)
Definition tensor3.cc:163
tensor3_basic< T > & operator*=(const T &k)
Definition tensor3.cc:126
tensor3_basic< T > & operator=(const tensor3_basic< T > &a)
Definition tensor3.cc:38
tensor3_basic< T > operator*(const T &k) const
Definition tensor3.h:159
tensor3_basic< T > & operator/=(const T &k)
Definition tensor3.h:105
T & operator()(size_type i, size_type j, size_type k)
Definition tensor3.h:145
tensor3_basic< T > & operator+=(const tensor3_basic< T > &)
Definition tensor3.cc:106
tensor3_basic< T > operator+(const tensor3_basic< T > &b) const
Definition tensor3.cc:72
tensor3_basic(const T &init_val=0)
Definition tensor3.h:132
tensor3_basic< T > operator/(const T &k) const
Definition tensor3.h:179
tensor3_basic< Float > tensor3
Definition tensor3.h:121
Expr1::float_type T
Definition field_expr.h:230
This file is part of Rheolef.
std::ostream & operator<<(std::ostream &os, const catchmark &m)
Definition catchmark.h:99
T norm2(const vec< T, M > &x)
norm2(x): see the expression page for the full documentation
Definition vec.h:379
T dddot(const tensor3_basic< T > &a, const tensor3_basic< T > &b)
Definition tensor3.cc:94
T dist2(const point_basic< T > &x, const point_basic< T > &y)
Definition point.h:292
std::istream & operator>>(std::istream &is, const catchmark &m)
Definition catchmark.h:88
T dist(const point_basic< T > &x, const point_basic< T > &y)
Definition point.h:298
csr< T, sequential > operator*(const T &lambda, const csr< T, sequential > &a)
Definition csr.h:437
T norm(const vec< T, M > &x)
norm(x): see the expression page for the full documentation
Definition vec.h:387
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:323