MathTL
|
00001 // -*- c++ -*- 00002 00003 // +--------------------------------------------------------------------+ 00004 // | This file is part of MathTL - the Mathematical Template Library | 00005 // | | 00006 // | Copyright (c) 2002-2009 | 00007 // | Thorsten Raasch, Manuel Werner | 00008 // +--------------------------------------------------------------------+ 00009 00010 #ifndef _MATHTL_TENSOR_H 00011 #define _MATHTL_TENSOR_H 00012 00013 #include <iostream> 00014 #include "algebra/tensor_base.h" 00015 00016 namespace MathTL 00017 { 00018 template <unsigned int RANK, unsigned int DIM, class VALUE> class Tensor; 00019 template <unsigned int DIM, class VALUE> class Tensor<1, DIM, VALUE>; 00020 00027 template <unsigned int RANK, unsigned int DIM, class VALUE = double> 00028 class Tensor 00029 { 00030 public: 00035 typedef Tensor<RANK-1, DIM, VALUE> value_type; 00036 00040 typedef size_t size_type; 00041 00045 static const unsigned int dimension = DIM; 00046 00050 static const unsigned int rank = RANK; 00051 00055 Tensor(); 00056 00061 void clear(); 00062 00066 const Tensor<RANK-1, DIM, VALUE>& operator [] (const size_type i) const; 00067 00071 Tensor<RANK-1, DIM, VALUE>& operator [] (const size_type i); 00072 00076 Tensor<RANK, DIM, VALUE>& operator = (const Tensor<RANK, DIM, VALUE>&); 00077 00081 bool operator == (const Tensor<RANK, DIM, VALUE>&) const; 00082 00086 bool operator != (const Tensor<RANK, DIM, VALUE>&) const; 00087 00091 Tensor<RANK, DIM, VALUE>& operator += (const Tensor<RANK, DIM, VALUE>&); 00092 00096 void add(const VALUE s, const Tensor<RANK, DIM, VALUE>& T); 00097 00101 Tensor<RANK, DIM, VALUE>& operator -= (const Tensor<RANK, DIM, VALUE>&); 00102 00106 Tensor<RANK, DIM, VALUE>& operator *= (const VALUE s); 00107 00111 Tensor<RANK, DIM, VALUE>& operator /= (const VALUE s); 00112 00116 Tensor<RANK, DIM, VALUE> operator + (const Tensor<RANK, DIM, VALUE>&) const; 00117 00121 Tensor<RANK, DIM, VALUE> operator - (const Tensor<RANK, DIM, VALUE>&) const; 00122 00126 Tensor<RANK, DIM, VALUE> operator - () const; 00127 00131 static const size_type memory_consumption(); 00132 00133 protected: 00134 // internally, we store a tensor of rank r just as a d-dimensional array 00135 // of tensors of lower rank 00136 Tensor<RANK-1, DIM, VALUE> subtensor[DIM]; 00137 }; 00138 00139 // 00140 // 00141 // external functionality for general tensors 00142 00148 template <unsigned int RANK, unsigned int DIM, class VALUE> 00149 std::ostream& operator << (std::ostream& os, 00150 const Tensor<RANK, DIM, VALUE>& T); 00151 00155 template <unsigned int RANK, class VALUE> 00156 std::ostream& operator << (std::ostream& os, 00157 const Tensor<RANK, 1, VALUE>& T); 00158 } 00159 00160 // include implementation of inline functions 00161 #include <algebra/tensor.cpp> 00162 00163 #endif