From: wolf Date: Fri, 6 Nov 1998 19:05:02 +0000 (+0000) Subject: Further work on the tensor classes. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f7b3c03d7e6935068ff1e8b072ba089ead680ba;p=dealii-svn.git Further work on the tensor classes. git-svn-id: https://svn.dealii.org/trunk@651 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/point.h b/deal.II/base/include/base/point.h index a546fe6ca0..c8b1a3e2e1 100644 --- a/deal.II/base/include/base/point.h +++ b/deal.II/base/include/base/point.h @@ -43,6 +43,13 @@ class Point : public Tensor<1,dim> { * to zero. */ explicit Point (); + + /** + * Convert a tensor to a point. Since no + * additional data is inside a point, + * this is ok. + */ + Point (const Tensor<1,dim> &); /** * Constructor for one dimensional points. This @@ -103,6 +110,11 @@ class Point : public Tensor<1,dim> { */ Point operator * (const double) const; + /** + * Returns the scalar product of two vectors. + */ + double operator * (const Point &) const; + /** * Divide by a factor. If possible, use * #operator /=# instead since this does not @@ -110,32 +122,6 @@ class Point : public Tensor<1,dim> { */ Point operator / (const double) const; - /** - * Add another vector, i.e. move this point by - * the given offset. - */ - Point & operator += (const Point &); - /** - * Subtract another vector. - */ - Point & operator -= (const Point &); - - /** - * Scale the vector by #factor#, i.e. multiply - * all coordinates by #factor#. - */ - Point & operator *= (const double &factor); - - /** - * Scale the vector by #1/factor#. - */ - Point & operator /= (const double &factor); - - /** - * Returns the scalar product of two vectors. - */ - double operator * (const Point &) const; - /** * Returns the scalar product of this point * vector with itself, i.e. the square, or @@ -174,6 +160,12 @@ Point::Point () : Tensor<1,dim>() {}; +template +inline +Point::Point (const Tensor<1,dim> &t) : + Tensor<1,dim>(t) {}; + + template <> inline @@ -246,71 +238,29 @@ Point Point::operator * (const double factor) const { template inline -Point operator * (const double factor, const Point &p) { - return p*factor; -}; - - - -template -inline -Point Point::operator / (const double factor) const { - return (Point(*this) /= factor); -}; - - - -template -inline -Point & Point::operator += (const Point &p) { - for (unsigned int i=0; i -inline -Point & Point::operator -= (const Point &p) { - for (unsigned int i=0; i -inline -Point & Point::operator *= (const double &s) { - for (unsigned int i=0; i::operator * (const Point &p) const { + // simply pass down + return Tensor<1,dim>::operator * (p); }; template inline -Point & Point::operator /= (const double &s) { - for (unsigned int i=0; i operator * (const double factor, const Point &p) { + return p*factor; }; template inline -double Point::operator * (const Point &p) const { - double q=0; - for (unsigned int i=0; i Point::operator / (const double factor) const { + return (Point(*this) /= factor); }; - + template inline double Point::square () const { diff --git a/deal.II/base/include/base/tensor.h b/deal.II/base/include/base/tensor.h index 47951acbb3..de90959cdf 100644 --- a/deal.II/base/include/base/tensor.h +++ b/deal.II/base/include/base/tensor.h @@ -66,15 +66,37 @@ class Tensor { Tensor & operator = (const Tensor &); /** - * Test for equality of two points. + * Test for equality of two tensors. */ bool operator == (const Tensor &) const; /** - * Test for inequality of two points. + * Test for inequality of two tensors. */ bool operator != (const Tensor &) const; + /** + * Add another vector, i.e. move this tensor by + * the given offset. + */ + Tensor & operator += (const Tensor &); + + /** + * Subtract another vector. + */ + Tensor & operator -= (const Tensor &); + + /** + * Scale the vector by #factor#, i.e. multiply + * all coordinates by #factor#. + */ + Tensor & operator *= (const double &factor); + + /** + * Scale the vector by #1/factor#. + */ + Tensor & operator /= (const double &factor); + /** * Reset all values to zero. */ @@ -126,7 +148,7 @@ template inline Tensor & Tensor::operator = (const Tensor &t) { for (unsigned int i=0; i inline bool Tensor::operator == (const Tensor &p) const { for (unsigned int i=0; i::operator != (const Tensor &p) const { +template +inline +Tensor & Tensor::operator += (const Tensor &p) { + for (unsigned int i=0; i +inline +Tensor & Tensor::operator -= (const Tensor &p) { + for (unsigned int i=0; i +inline +Tensor & Tensor::operator *= (const double &s) { + for (unsigned int i=0; i +inline +Tensor & Tensor::operator /= (const double &s) { + for (unsigned int i=0; i inline void Tensor::clear () { @@ -165,6 +227,29 @@ void Tensor::clear () { +/* Exception class. This is certainly not the best possible place for its + declaration, but at present, local classes to any of Tensor<> can't + be properly accessed (haven't investigated why). If anyone has a better + idea, realize it! +*/ +DeclException1 (ExcInvalidTensorIndex, + int, + << "Invalid tensor index " << arg1); + + + +template +inline +void contract (Tensor<1,dim> &dest, + const Tensor<2,dim> &src1, + const Tensor<1,dim> &src2) { + dest.clear (); + for (unsigned int i=0; i inline @@ -180,6 +265,100 @@ void contract (Tensor<2,dim> &dest, +template +inline +void contract (Tensor<2,dim> &dest, + const Tensor<2,dim> &src1, const unsigned int index1, + const Tensor<2,dim> &src2, const unsigned int index2) { + dest.clear (); + + switch (index1) + { + case 1: + switch (index2) + { + case 1: + for (unsigned int i=0; i +inline +void contract (Tensor<2,dim> &dest, + const Tensor<3,dim> &src1, const unsigned int index1, + const Tensor<1,dim> &src2) { + dest.clear (); + + switch (index1) + { + case 1: + for (unsigned int i=0; i inline void contract (Tensor<3,dim> &dest, @@ -224,7 +403,14 @@ void contract (Tensor<4,dim> &dest, dest[i][j][k][l] += src1[i][j][m] * src2[m][k][l]; }; - + + +inline +double determinant (const Tensor<2,2> &t) { + return ((t[0][0] * t[1][1]) - + (t[1][0] * t[0][1])); +}; + diff --git a/deal.II/base/include/base/tensor_base.h b/deal.II/base/include/base/tensor_base.h index 2c775d119d..077c722c53 100644 --- a/deal.II/base/include/base/tensor_base.h +++ b/deal.II/base/include/base/tensor_base.h @@ -102,6 +102,32 @@ class Tensor<1,dim> { */ bool operator != (const Tensor<1,dim> &) const; + /** + * Add another vector, i.e. move this point by + * the given offset. + */ + Tensor<1,dim> & operator += (const Tensor<1,dim> &); + /** + * Subtract another vector. + */ + Tensor<1,dim> & operator -= (const Tensor<1,dim> &); + + /** + * Scale the vector by #factor#, i.e. multiply + * all coordinates by #factor#. + */ + Tensor<1,dim> & operator *= (const double &factor); + + /** + * Scale the vector by #1/factor#. + */ + Tensor<1,dim> & operator /= (const double &factor); + + /** + * Returns the scalar product of two vectors. + */ + double operator * (const Tensor<1,dim> &) const; + /** * Reset all values to zero. */ @@ -208,6 +234,57 @@ bool Tensor<1,dim>::operator != (const Tensor<1,dim> &p) const { +template +inline +Tensor<1,dim> & Tensor<1,dim>::operator += (const Tensor<1,dim> &p) { + for (unsigned int i=0; i +inline +Tensor<1,dim> & Tensor<1,dim>::operator -= (const Tensor<1,dim> &p) { + for (unsigned int i=0; i +inline +Tensor<1,dim> & Tensor<1,dim>::operator *= (const double &s) { + for (unsigned int i=0; i +inline +Tensor<1,dim> & Tensor<1,dim>::operator /= (const double &s) { + for (unsigned int i=0; i +inline +double Tensor<1,dim>::operator * (const Tensor<1,dim> &p) const { + double q=0; + for (unsigned int i=0; i inline void Tensor<1,dim>::clear () { diff --git a/deal.II/base/source/log.cc b/deal.II/base/source/log.cc index 6707f31f2b..520acdd938 100644 --- a/deal.II/base/source/log.cc +++ b/deal.II/base/source/log.cc @@ -3,9 +3,12 @@ #include #include + + LogStream deallog; + LogStream::LogStream() : std(&cerr), file(0), was_endl(true), std_depth(10000), file_depth(10000)