dune-common
2.2.0
|
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 00036 typedef DynamicVector<K> row_type; 00037 00038 typedef row_type &row_reference; 00039 typedef const row_type &const_row_reference; 00040 00041 typedef std::vector<K> container_type; 00042 typedef K value_type; 00043 typedef typename container_type::size_type size_type; 00044 }; 00045 00046 template< class K > 00047 struct FieldTraits< DynamicMatrix<K> > 00048 { 00049 typedef typename FieldTraits<K>::field_type field_type; 00050 typedef typename FieldTraits<K>::real_type real_type; 00051 }; 00052 00057 template<class K> 00058 class DynamicMatrix : public DenseMatrix< DynamicMatrix<K> > 00059 { 00060 std::vector< DynamicVector<K> > _data; 00061 typedef DenseMatrix< DynamicMatrix<K> > Base; 00062 public: 00063 typedef typename Base::size_type size_type; 00064 typedef typename Base::value_type value_type; 00065 typedef typename Base::row_type row_type; 00066 00067 //===== constructors 00069 DynamicMatrix () {} 00070 00072 DynamicMatrix (size_type r, size_type c, value_type v = value_type() ) : 00073 _data(r, row_type(c, v) ) 00074 {} 00075 00076 //==== resize related methods 00077 void resize (size_type r, size_type c, value_type v = value_type() ) 00078 { 00079 _data.resize(0); 00080 _data.resize(r, row_type(c, v) ); 00081 } 00082 00083 //===== assignment 00084 using Base::operator=; 00085 00086 // make this thing a matrix 00087 size_type mat_rows() const { return _data.size(); } 00088 size_type mat_cols() const { 00089 assert(this->rows()); 00090 return _data.front().size(); 00091 } 00092 row_type & mat_access(size_type i) { return _data[i]; } 00093 const row_type & mat_access(size_type i) const { return _data[i]; } 00094 }; 00095 00098 } // end namespace 00099 00100 #endif