Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
tensor3.cc
Go to the documentation of this file.
1
21
22#include "rheolef/tensor3.h"
23namespace rheolef {
24using namespace std;
25
26template<class T>
27tensor3_basic<T>&
29{
30 for (size_type i = 0; i < 3; i++)
31 for (size_type j = 0; j < 3; j++)
32 for (size_type k = 0; k < 3; k++)
33 _x[i][j][k] = val;
34 return *this;
35}
36template<class T>
39{
40 for (size_type i = 0; i < 3; i++)
41 for (size_type j = 0; j < 3; j++)
42 for (size_type k = 0; k < 3; k++)
43 _x[i][j][k] = a._x[i][j][k];
44 return *this;
45}
46// algebra
47template <class T>
50{
52 for (size_type i = 0; i < 3; i++)
53 for (size_type j = 0; j < 3; j++)
54 for (size_type z = 0; z < 3; z++)
55 b(i,j) += _x[i][j][z]*v[z];
56 return b;
57}
58template <class T>
61{
63 for (size_type i = 0; i < 3; i++)
64 for (size_type j = 0; j < 3; j++)
65 for (size_type k = 0; k < 3; k++)
66 for (size_type z = 0; z < 3; z++)
67 b(i,j,k) += _x[i][j][z]*t(z,k);
68 return b;
69}
70template <class T>
73{
75 for (size_type i = 0; i < 3; i++)
76 for (size_type j = 0; j < 3; j++)
77 for (size_type k = 0; k < 3; k++)
78 c(i,j,k) = _x[i][j][k] + b(i,j,k);
79 return c;
80}
81template <class T>
84{
86 for (size_type i = 0; i < 3; i++)
87 for (size_type j = 0; j < 3; j++)
88 for (size_type k = 0; k < 3; k++)
89 c(i,j,k) = _x[i][j][k] - b(i,j,k);
90 return c;
91}
92template<class T>
93T
95{
96 T r = 0;
98 for (size_type i = 0; i < 3; i++)
99 for (size_type j = 0; j < 3; j++)
100 for (size_type k = 0; k < 3; k++)
101 r += a(i,j,k) * b(i,j,k);
102 return r;
103}
104template<class T>
105tensor3_basic<T>&
107{
108 for (size_type i = 0; i < 3; i++)
109 for (size_type j = 0; j < 3; j++)
110 for (size_type k = 0; k < 3; k++)
111 _x[i][j][k] += b._x[i][j][k];
112 return *this;
113}
114template<class T>
117{
118 for (size_type i = 0; i < 3; i++)
119 for (size_type j = 0; j < 3; j++)
120 for (size_type k = 0; k < 3; k++)
121 _x[i][j][k] -= b._x[i][j][k];
122 return *this;
123}
124template <class T>
127{
128 for (size_type i = 0; i < 3; i++)
129 for (size_type j = 0; j < 3; j++)
130 for (size_type k = 0; k < 3; k++)
131 _x[i][j][k] *= fact;
132 return *this;
133}
134// ----------------------------------------------------------------------------
135// io
136// ----------------------------------------------------------------------------
137// output
138template<class T>
139ostream&
140tensor3_basic<T>::put (ostream& out, size_type d) const
141{
142 switch (d) {
143 case 0 : return out;
144 case 1 : return out << _x[0][0];
145 case 2 : return out << "[[" << _x[0][0][0] << ", " << _x[0][0][1] << ";" << endl
146 << " " << _x[0][1][0] << ", " << _x[0][1][1] << "]," << endl
147 << " [" << _x[1][0][0] << ", " << _x[1][0][1] << ";" << endl
148 << " " << _x[1][1][0] << ", " << _x[1][1][1] << "]]";
149
150 default: return out << "[[" << _x[0][0][0] << ", " << _x[0][0][1] << ", " << _x[0][0][2] << ";" << endl
151 << " " << _x[0][1][0] << ", " << _x[0][1][1] << ", " << _x[0][1][2] << ";" << endl
152 << " " << _x[0][2][0] << ", " << _x[0][2][1] << ", " << _x[0][2][2] << "]," << endl
153 << " [" << _x[1][0][0] << ", " << _x[1][0][1] << ", " << _x[1][0][2] << ";" << endl
154 << " " << _x[1][1][0] << ", " << _x[1][1][1] << ", " << _x[1][1][2] << ";" << endl
155 << " " << _x[1][2][0] << ", " << _x[1][2][1] << ", " << _x[1][2][2] << "]," << endl
156 << " [" << _x[2][0][0] << ", " << _x[2][0][1] << ", " << _x[2][0][2] << ";" << endl
157 << " " << _x[2][1][0] << ", " << _x[2][1][1] << ", " << _x[2][1][2] << ";" << endl
158 << " " << _x[2][2][0] << ", " << _x[2][2][1] << ", " << _x[2][2][2] << "]]";
159 }
160}
161template<class T>
162istream&
164{
165 // TODO: as output, aka octave-like
166 fatal_macro ("tensor3::get: not yet");
167 return in;
168}
169// ----------------------------------------------------------------------------
170// instanciation in library
171// ----------------------------------------------------------------------------
172#define _RHEOLEF_instanciation(T) \
173template class tensor3_basic<T>; \
174template T dddot (const tensor3_basic<T>&, const tensor3_basic<T>&); \
175
177
178}// namespace rheolef
#define _RHEOLEF_instanciation(T, M, A)
Definition asr.cc:223
field::size_type size_type
Definition branch.cc:430
see the Float page for the full documentation
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 tensor3_basic< T > &)
Definition tensor3.cc:106
tensor3_basic< T > operator+(const tensor3_basic< T > &b) const
Definition tensor3.cc:72
#define fatal_macro(message)
Definition dis_macros.h:33
Expr1::float_type T
Definition field_expr.h:230
This file is part of Rheolef.
T dddot(const tensor3_basic< T > &a, const tensor3_basic< T > &b)
Definition tensor3.cc:94
STL namespace.