diff --git a/dune/gfe/tensor3.hh b/dune/gfe/tensor3.hh index 4845b6bec7180be13bbb5a5d3848c231122f54a6..28598fc8c9040d7ed1696e574379dfe34d25f4ea 100644 --- a/dune/gfe/tensor3.hh +++ b/dune/gfe/tensor3.hh @@ -9,9 +9,82 @@ template <class T, int N1, int N2, int N3> class Tensor3 : public Dune::array<Dune::FieldMatrix<T,N2,N3>,N1> { + public: - + + static Tensor3<T,N1,N2,N3> product(const Dune::FieldVector<T,N1>& a, const Dune::FieldVector<T,N2>& b, const Dune::FieldVector<T,N3>& c) + { + Tensor3<T,N1,N2,N3> result; + + for (int i=0; i<N1; i++) + for (int j=0; j<N2; j++) + for (int k=0; k<N3; k++) + result[i][j][k] = a[i]*b[j]*c[k]; + + return result; + } + + static Tensor3<T,N1,N2,N3> product(const Dune::FieldMatrix<T,N1,N2>& ab, const Dune::FieldVector<T,N3>& c) + { + Tensor3<T,N1,N2,N3> result; + + for (int i=0; i<N1; i++) + for (int j=0; j<N2; j++) + for (int k=0; k<N3; k++) + result[i][j][k] = ab[i][j]*c[k]; + + return result; + } + + static Tensor3<T,N1,N2,N3> product(const Dune::FieldVector<T,N3>& a, const Dune::FieldMatrix<T,N1,N2>& bc) + { + Tensor3<T,N1,N2,N3> result; + + for (int i=0; i<N1; i++) + for (int j=0; j<N2; j++) + for (int k=0; k<N3; k++) + result[i][j][k] = a[i]*bc[j][k]; + + return result; + } + friend Tensor3<T,N1,N2,N3> operator+(const Tensor3<T,N1,N2,N3>& a, const Tensor3<T,N1,N2,N3>& b) + { + Tensor3<T,N1,N2,N3> result; + + for (int i=0; i<N1; i++) + for (int j=0; j<N2; j++) + for (int k=0; k<N3; k++) + result[i][j][k] = a[i][j][k] + b[i][j][k]; + + return result; + } + + friend Tensor3<T,N1,N2,N3> operator-(const Tensor3<T,N1,N2,N3>& a, const Tensor3<T,N1,N2,N3>& b) + { + Tensor3<T,N1,N2,N3> result; + + for (int i=0; i<N1; i++) + for (int j=0; j<N2; j++) + for (int k=0; k<N3; k++) + result[i][j][k] = a[i][j][k] - b[i][j][k]; + + return result; + } + + friend Tensor3<T,N1,N2,N3> operator*(const T& scalar, const Tensor3<T,N1,N2,N3>& tensor) + { + Tensor3<T,N1,N2,N3> result; + + for (int i=0; i<N1; i++) + for (int j=0; j<N2; j++) + for (int k=0; k<N3; k++) + result[i][j][k] = scalar * tensor[i][j][k]; + + return result; + + } + }; #endif \ No newline at end of file