From a2b25fb03cdb1843e1cf08ac3c6a07eb95b9c268 Mon Sep 17 00:00:00 2001 From: wolf Date: Thu, 5 Nov 1998 18:33:37 +0000 Subject: [PATCH] Import initial tensor files. Not yet workable. git-svn-id: https://svn.dealii.org/trunk@635 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/tensor.h | 178 ++++++++++++++++++++++++ deal.II/base/include/base/tensor_base.h | 160 +++++++++++++++++++++ 2 files changed, 338 insertions(+) create mode 100644 deal.II/base/include/base/tensor.h create mode 100644 deal.II/base/include/base/tensor_base.h diff --git a/deal.II/base/include/base/tensor.h b/deal.II/base/include/base/tensor.h new file mode 100644 index 0000000000..df5882797c --- /dev/null +++ b/deal.II/base/include/base/tensor.h @@ -0,0 +1,178 @@ +/*---------------------------- tensor.h ---------------------------*/ +/* $Id$ */ +#ifndef __tensor_H +#define __tensor_H +/*---------------------------- tensor.h ---------------------------*/ + + +#include + + + +template +class Tensor { + public: + /** + * Provide a way to get the dimension of + * an object without explicit knowledge + * of it's data type. Implementation is + * this way instead of providing a function + * #dimension()# because now it is possible + * to get the dimension at compile time + * without the expansion and preevaluation + * of an inlined function; the compiler may + * therefore produce more efficient code + * and you may use this value to declare + * other data types. + */ + static const unsigned int dimension = dim; + + /** + * Publish the rank of this tensor to + * the outside world. + */ + static const unsigned int rank = rank_; + + /** + * Read-Write access operator. + */ + Tensor &operator [] (const unsigned int i); + + /** + * Read-only access operator. + */ + const Tensor &operator [] (const unsigned int i) const; + + /** + * Reset all values to zero. + */ + void clear (); + + + /** + * Exception + */ + DeclException1 (ExcInvalidIndex, + int, + << "Invalid index " << arg1); + private: + /** + * Array of tensors holding the + * subelements. + */ + Tensor subtensor[dim]; +}; + + + + + +/*--------------------------- Inline functions -----------------------------*/ + +template +inline +Tensor & +Tensor::operator[] (const unsigned int i) { + Assert (i +inline +const Tensor & +Tensor::operator[] (const unsigned int i) const { + Assert (i +inline +void Tensor::clear () { + for (unsigned int i=0; i +inline +void contract (Tensor<2,dim> &dest, + const Tensor<2,dim> &src1, + const Tensor<2,dim> &src2) { + dest.clear (); + for (unsigned int i=0; i +inline +void contract (Tensor<3,dim> &dest, + const Tensor<3,dim> &src1, + const Tensor<2,dim> &src2) { + dest.clear (); + for (unsigned int i=0; i +inline +void contract (Tensor<3,dim> &dest, + const Tensor<2,dim> &src1, + const Tensor<3,dim> &src2) { + dest.clear (); + for (unsigned int i=0; i +inline +void contract (Tensor<4,dim> &dest, + const Tensor<3,dim> &src1, + const Tensor<3,dim> &src2) { + dest.clear (); + for (unsigned int i=0; i +// from Tensor<1,dim>. However, the point class will not need all the +// tensor stuff, so we don't want the whole tensor package to be included +// everytime we use a point. + +#include + + + + +// general template; specialized for rank==1; the general template is in +// tensor.h +template class Tensor; + + + +template +class Tensor<1,dim> { + public: + /** + * Provide a way to get the dimension of + * an object without explicit knowledge + * of it's data type. Implementation is + * this way instead of providing a function + * #dimension()# because now it is possible + * to get the dimension at compile time + * without the expansion and preevaluation + * of an inlined function; the compiler may + * therefore produce more efficient code + * and you may use this value to declare + * other data types. + */ + static const unsigned int dimension = dim; + + /** + * Publish the rank of this tensor to + * the outside world. + */ + static const unsigned int rank = 1; + + /** + * Constructor. Initialize all entries + * to zero. + */ + explicit Tensor (); + + /** + * Copy constructor. + */ + Tensor (const Tensor<1,dim> &); + + /** + * Read access to the #index#th coordinate. + * + * Note that the derived #Point# class also + * provides access through the #()# + * operator for backcompatibility. + */ + double operator [] (const unsigned int index) const; + + /** + * Read and write access to the #index#th + * coordinate. + * + * Note that the derived #Point# class also + * provides access through the #()# + * operator for backcompatibility. + */ + double & operator [] (const unsigned int index); + + /** + * Reset all values to zero. + */ + void clear (); + + /** + * Exception + */ + DeclException1 (ExcDimTooSmall, + int, + << "Given dimensions must be >= 1, but was " << arg1); + + /** + * Exception + */ + DeclException1 (ExcInvalidIndex, + int, + << "Invalid index " << arg1); + protected: + /** + * Stores the values in a simple array. + */ + double values[dim]; +}; + + + + +/*------------------------------- Inline functions: Tensor ---------------------------*/ + + +template +inline +Tensor<1,dim>::Tensor () { + Assert (dim>0, ExcDimTooSmall(dim)); + + for (unsigned int i=0; i +inline +Tensor<1,dim>::Tensor (const Tensor<1,dim> &p) { + for (unsigned int i=0; i +inline +double Tensor<1,dim>::operator [] (const unsigned int index) const { + Assert (index +inline +double & Tensor<1,dim>::operator [] (const unsigned int index) { + Assert (index +inline +void Tensor<1,dim>::clear () { + for (unsigned int i=0; i