- Home
- About DUNE
- Download
- Documentation
- Community
- Development
00001 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 00002 // vi: set et ts=8 sw=2 sts=2: 00003 // $Id: fmatrix.hh 6181 2010-10-13 18:53:40Z christi $ 00004 #ifndef DUNE_DYNMATRIX_HH 00005 #define DUNE_DYNMATRIX_HH 00006 00007 #include <cmath> 00008 #include <cstddef> 00009 #include <iostream> 00010 00011 #include <dune/common/misc.hh> 00012 #include <dune/common/exceptions.hh> 00013 #include <dune/common/dynvector.hh> 00014 #include <dune/common/densematrix.hh> 00015 #include <dune/common/static_assert.hh> 00016 00017 namespace Dune 00018 { 00019 00029 template< class K > class DynamicMatrix; 00030 00031 template< class K > 00032 struct DenseMatVecTraits< DynamicMatrix<K> > 00033 { 00034 typedef DynamicMatrix<K> derived_type; 00035 typedef DynamicVector<K> row_type; 00036 typedef std::vector<K> container_type; 00037 typedef K value_type; 00038 typedef typename container_type::size_type size_type; 00039 }; 00040 00041 template< class K > 00042 struct FieldTraits< DynamicMatrix<K> > 00043 { 00044 typedef typename FieldTraits<K>::field_type field_type; 00045 typedef typename FieldTraits<K>::real_type real_type; 00046 }; 00047 00052 template<class K> 00053 class DynamicMatrix : public DenseMatrix< DynamicMatrix<K> > 00054 { 00055 std::vector< DynamicVector<K> > _data; 00056 typedef DenseMatrix< DynamicMatrix<K> > Base; 00057 public: 00058 typedef typename Base::size_type size_type; 00059 typedef typename Base::value_type value_type; 00060 typedef typename Base::row_type row_type; 00061 00062 //===== constructors 00064 DynamicMatrix () {} 00065 00067 DynamicMatrix (size_type r, size_type c, value_type v = value_type() ) : 00068 _data(r, row_type(c, v) ) 00069 {} 00070 00071 //==== resize related methods 00072 void resize (size_type r, size_type c, value_type v = value_type() ) 00073 { 00074 _data.resize(0); 00075 _data.resize(r, row_type(c, v) ); 00076 } 00077 00078 //===== assignment 00079 using Base::operator=; 00080 00081 // make this thing a matrix 00082 size_type mat_rows() const { return _data.size(); } 00083 size_type mat_cols() const { 00084 assert(this->rows()); 00085 return _data.front().size(); 00086 } 00087 row_type & mat_access(size_type i) { return _data[i]; } 00088 const row_type & mat_access(size_type i) const { return _data[i]; } 00089 }; 00090 00093 } // end namespace 00094 00095 #endif
Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].