MathTL
algebra/tensor_base.h
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_BASE_H
00011 #define _MATHTL_TENSOR_BASE_H
00012 
00013 #include <iostream>
00014 #include "algebra/tensor.h"
00015 #include "utils/fixed_array1d.h"
00016 
00017 namespace MathTL
00018 {
00019   // general template declaration, see tensor.h
00020   template <unsigned int RANK, unsigned int DIM, class VALUE> class Tensor;
00021   template <unsigned int DIM, class VALUE> class Tensor<1, DIM, VALUE>;
00022 
00027   template <unsigned int DIM, class VALUE>
00028   class Tensor<1, DIM, VALUE>
00029   {
00030   public:
00034     typedef VALUE value_type;
00035 
00039     typedef size_t size_type;
00040 
00044     static const unsigned int dimension = DIM;
00045 
00049     static const unsigned int rank = 1;
00050 
00056     explicit Tensor(const bool initialize = true);
00057 
00062     void clear();
00063 
00067     const size_type size() const;
00068     
00072     const VALUE operator [] (const size_type i) const;
00073 
00077     VALUE& operator [] (const size_type i);
00078 
00082     bool operator == (const Tensor<1, DIM, VALUE>&) const;
00083 
00087     bool operator != (const Tensor<1, DIM, VALUE>&) const;
00088 
00092     Tensor<1, DIM, VALUE>& operator += (const Tensor<1, DIM, VALUE>&);
00093 
00097     void add(const VALUE s, const Tensor<1, DIM, VALUE>& T);
00098 
00102     Tensor<1, DIM, VALUE>& operator -= (const Tensor<1, DIM, VALUE>&);
00103 
00107     Tensor<1, DIM, VALUE>& operator *= (const VALUE s);
00108 
00112     Tensor<1, DIM, VALUE>& operator /= (const VALUE s);
00113 
00117     Tensor<1, DIM, VALUE> operator + (const Tensor<1, DIM, VALUE>&) const;
00118 
00122     Tensor<1, DIM, VALUE> operator - (const Tensor<1, DIM, VALUE>&) const;
00123 
00127     Tensor<1, DIM, VALUE> operator - () const;
00128     
00132     VALUE operator * (const Tensor<1, DIM, VALUE>&) const;
00133 
00137     static const size_type memory_consumption();
00138     
00139   protected:
00143     FixedArray1D<VALUE,DIM> values;
00144   };
00145 
00149   template <unsigned int DIM, class VALUE>
00150     std::ostream& operator << (std::ostream& os,
00151                                const Tensor<1, DIM, VALUE>& T);
00152 
00156   template <class VALUE>
00157   std::ostream& operator << (std::ostream& os,
00158                              const Tensor<1, 1, VALUE>& T);
00159 }
00160 
00161 #include <algebra/tensor_base.cpp>
00162 
00163 #endif
 All Classes Functions Variables Typedefs Enumerations