From 7a8d5ca4329ee2dac77ea4216fcf16f558ecb48f Mon Sep 17 00:00:00 2001 From: Oliver Sander <sander@igpm.rwth-aachen.de> Date: Tue, 31 Aug 2010 16:22:21 +0000 Subject: [PATCH] add various vector-space operations [[Imported from SVN: r6299]] --- dune/gfe/tensor3.hh | 75 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/dune/gfe/tensor3.hh b/dune/gfe/tensor3.hh index 4845b6be..28598fc8 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 -- GitLab