Rheolef  7.1
an efficient C++ finite element environment
tensor3.cc
Go to the documentation of this file.
1 
22 #include "rheolef/tensor3.h"
23 namespace rheolef {
24 using namespace std;
25 
26 template<class 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 }
36 template<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
47 template <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 }
58 template <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 }
70 template <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 }
81 template <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 }
92 template<class T>
93 T
95 {
96  T r = 0;
97  typedef typename tensor_basic<T>::size_type size_type;
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 }
104 template<class 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 }
114 template<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 }
124 template <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
138 template<class T>
139 ostream&
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 }
161 template<class T>
162 istream&
163 tensor3_basic<T>::get (istream& in)
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) \
173 template class tensor3_basic<T>; \
174 template T dddot (const tensor3_basic<T>&, const tensor3_basic<T>&); \
175 
177 
178 }// namespace rheolef
field::size_type size_type
Definition: branch.cc:425
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
tensor3_basic< T > & operator*=(const T &k)
Definition: tensor3.cc:126
tensor3_basic< T > & operator=(const tensor3_basic< T > &a)
Definition: tensor3.cc:38
std::istream & get(std::istream &)
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
tensor_basic< T > tensor3_basic< T >
Definition: piola_fem.h:137
size_t size_type
Definition: basis_get.cc:76
Expr1::float_type T
Definition: field_expr.h:261
This file is part of Rheolef.
T dddot(const tensor3_basic< T > &a, const tensor3_basic< T > &b)
Definition: tensor3.cc:94
_RHEOLEF_instanciation(Float) _RHEOLEF_instanciation_evaluate(Float