Loading...
Searching...
No Matches
tensor3.cc
Go to the documentation of this file.
#include "rheolef/tensor3.h"
namespace rheolef {
using namespace std;
template<class T>
tensor3_basic<T>&
tensor3_basic<T>::operator= (const T& val)
{
for (size_type i = 0; i < 3; i++)
for (size_type j = 0; j < 3; j++)
for (size_type k = 0; k < 3; k++)
_x[i][j][k] = val;
return *this;
}
template<class T>
tensor3_basic<T>&
tensor3_basic<T>::operator= (const tensor3_basic<T>& a)
{
for (size_type i = 0; i < 3; i++)
for (size_type j = 0; j < 3; j++)
for (size_type k = 0; k < 3; k++)
_x[i][j][k] = a._x[i][j][k];
return *this;
}
// algebra
template <class T>
tensor_basic<T>
tensor3_basic<T>::operator* (const point_basic<T>& v) const
{
tensor_basic<T> b;
for (size_type i = 0; i < 3; i++)
for (size_type j = 0; j < 3; j++)
for (size_type z = 0; z < 3; z++)
b(i,j) += _x[i][j][z]*v[z];
return b;
}
template <class T>
tensor3_basic<T>
tensor3_basic<T>::operator* (const tensor_basic<T>& t) const
{
tensor3_basic<T> b;
for (size_type i = 0; i < 3; i++)
for (size_type j = 0; j < 3; j++)
for (size_type k = 0; k < 3; k++)
for (size_type z = 0; z < 3; z++)
b(i,j,k) += _x[i][j][z]*t(z,k);
return b;
}
template <class T>
tensor3_basic<T>
tensor3_basic<T>::operator+ (const tensor3_basic<T>& b) const
{
tensor3_basic<T> c;
for (size_type i = 0; i < 3; i++)
for (size_type j = 0; j < 3; j++)
for (size_type k = 0; k < 3; k++)
c(i,j,k) = _x[i][j][k] + b(i,j,k);
return c;
}
template <class T>
tensor3_basic<T>
tensor3_basic<T>::operator- (const tensor3_basic<T>& b) const
{
tensor3_basic<T> c;
for (size_type i = 0; i < 3; i++)
for (size_type j = 0; j < 3; j++)
for (size_type k = 0; k < 3; k++)
c(i,j,k) = _x[i][j][k] - b(i,j,k);
return c;
}
template<class T>
T
dddot (const tensor3_basic<T>& a, const tensor3_basic<T> & b)
{
T r = 0;
typedef typename tensor_basic<T>::size_type size_type;
for (size_type i = 0; i < 3; i++)
for (size_type j = 0; j < 3; j++)
for (size_type k = 0; k < 3; k++)
r += a(i,j,k) * b(i,j,k);
return r;
}
template<class T>
tensor3_basic<T>&
tensor3_basic<T>::operator+= (const tensor3_basic<T>& b)
{
for (size_type i = 0; i < 3; i++)
for (size_type j = 0; j < 3; j++)
for (size_type k = 0; k < 3; k++)
_x[i][j][k] += b._x[i][j][k];
return *this;
}
template<class T>
tensor3_basic<T>&
tensor3_basic<T>::operator-= (const tensor3_basic<T>& b)
{
for (size_type i = 0; i < 3; i++)
for (size_type j = 0; j < 3; j++)
for (size_type k = 0; k < 3; k++)
_x[i][j][k] -= b._x[i][j][k];
return *this;
}
template <class T>
tensor3_basic<T>&
tensor3_basic<T>::operator*= (const T& fact)
{
for (size_type i = 0; i < 3; i++)
for (size_type j = 0; j < 3; j++)
for (size_type k = 0; k < 3; k++)
_x[i][j][k] *= fact;
return *this;
}
// ----------------------------------------------------------------------------
// io
// ----------------------------------------------------------------------------
// output
template<class T>
ostream&
tensor3_basic<T>::put (ostream& out, size_type d) const
{
switch (d) {
case 0 : return out;
case 1 : return out << _x[0][0];
case 2 : return out << "[[" << _x[0][0][0] << ", " << _x[0][0][1] << ";" << endl
<< " " << _x[0][1][0] << ", " << _x[0][1][1] << "]," << endl
<< " [" << _x[1][0][0] << ", " << _x[1][0][1] << ";" << endl
<< " " << _x[1][1][0] << ", " << _x[1][1][1] << "]]";
default: return out << "[[" << _x[0][0][0] << ", " << _x[0][0][1] << ", " << _x[0][0][2] << ";" << endl
<< " " << _x[0][1][0] << ", " << _x[0][1][1] << ", " << _x[0][1][2] << ";" << endl
<< " " << _x[0][2][0] << ", " << _x[0][2][1] << ", " << _x[0][2][2] << "]," << endl
<< " [" << _x[1][0][0] << ", " << _x[1][0][1] << ", " << _x[1][0][2] << ";" << endl
<< " " << _x[1][1][0] << ", " << _x[1][1][1] << ", " << _x[1][1][2] << ";" << endl
<< " " << _x[1][2][0] << ", " << _x[1][2][1] << ", " << _x[1][2][2] << "]," << endl
<< " [" << _x[2][0][0] << ", " << _x[2][0][1] << ", " << _x[2][0][2] << ";" << endl
<< " " << _x[2][1][0] << ", " << _x[2][1][1] << ", " << _x[2][1][2] << ";" << endl
<< " " << _x[2][2][0] << ", " << _x[2][2][1] << ", " << _x[2][2][2] << "]]";
}
}
template<class T>
istream&
tensor3_basic<T>::get (istream& in)
{
// TODO: as output, aka octave-like
fatal_macro ("tensor3::get: not yet");
return in;
}
// ----------------------------------------------------------------------------
// instanciation in library
// ----------------------------------------------------------------------------
#define _RHEOLEF_instanciation(T) \
template class tensor3_basic<T>; \
template T dddot (const tensor3_basic<T>&, const tensor3_basic<T>&); \
_RHEOLEF_instanciation(Float)
}// namespace rheolef
_RHEOLEF_instanciation
#define _RHEOLEF_instanciation(T, M, A)
Definition asr.cc:223
size_type
field::size_type size_type
Definition branch.cc:430
Float
see the Float page for the full documentation
rheolef::point_basic
Definition point.h:86
rheolef::tensor3_basic
Definition tensor3.h:73
rheolef::tensor3_basic::operator-
tensor3_basic< T > operator-(const tensor3_basic< T > &b) const
Definition tensor3.cc:83
rheolef::tensor3_basic::put
std::ostream & put(std::ostream &s, size_type d=3) const
Definition tensor3.cc:140
rheolef::tensor3_basic::operator-=
tensor3_basic< T > & operator-=(const tensor3_basic< T > &)
Definition tensor3.cc:116
rheolef::tensor3_basic::get
std::istream & get(std::istream &)
Definition tensor3.cc:163
rheolef::tensor3_basic::operator*=
tensor3_basic< T > & operator*=(const T &k)
Definition tensor3.cc:126
rheolef::tensor3_basic::operator=
tensor3_basic< T > & operator=(const tensor3_basic< T > &a)
Definition tensor3.cc:38
rheolef::tensor3_basic::size_type
size_t size_type
Definition tensor3.h:76
rheolef::tensor3_basic::operator*
tensor3_basic< T > operator*(const T &k) const
Definition tensor3.h:159
rheolef::tensor3_basic::operator+=
tensor3_basic< T > & operator+=(const tensor3_basic< T > &)
Definition tensor3.cc:106
rheolef::tensor3_basic::operator+
tensor3_basic< T > operator+(const tensor3_basic< T > &b) const
Definition tensor3.cc:72
rheolef::tensor_basic
Definition tensor.h:90
rheolef::tensor_basic::size_type
size_t size_type
Definition tensor.h:93
fatal_macro
#define fatal_macro(message)
Definition dis_macros.h:33
T
Expr1::float_type T
Definition field_expr.h:230
rheolef
This file is part of Rheolef.
Definition compiler_eigen.h:39
rheolef::dddot
T dddot(const tensor3_basic< T > &a, const tensor3_basic< T > &b)
Definition tensor3.cc:94
std
STL namespace.
d
size_t d
Definition neumann-laplace-lambda.cc:28