dune-common 3.0-git
dynmatrix.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_DYNMATRIX_HH
4#define DUNE_DYNMATRIX_HH
5
6#include <cmath>
7#include <cstddef>
8#include <iostream>
9#include <initializer_list>
10
15
16namespace Dune
17{
18
28 template< class K > class DynamicMatrix;
29
30 template< class K >
32 {
34
36
39
40 typedef std::vector<K> container_type;
41 typedef K value_type;
42 typedef typename container_type::size_type size_type;
43 };
44
45 template< class K >
51
56 template<class K>
57 class DynamicMatrix : public DenseMatrix< DynamicMatrix<K> >
58 {
59 std::vector< DynamicVector<K> > _data;
61 public:
62 typedef typename Base::size_type size_type;
63 typedef typename Base::value_type value_type;
64 typedef typename Base::row_type row_type;
65
66 //===== constructors
69
72 _data(r, row_type(c, v) )
73 {}
74
77 DynamicMatrix (std::initializer_list<DynamicVector<K>> const &ll)
78 : _data(ll)
79 {}
80
81
82 //==== resize related methods
97 {
98 _data.resize(0);
99 _data.resize(r, row_type(c, v) );
100 }
101
102 //===== assignment
103 using Base::operator=;
104
105 // make this thing a matrix
106 size_type mat_rows() const { return _data.size(); }
108 assert(this->rows());
109 return _data.front().size();
110 }
112 DUNE_ASSERT_BOUNDS(i < _data.size());
113 return _data[i];
114 }
115 const row_type & mat_access(size_type i) const {
116 DUNE_ASSERT_BOUNDS(i < _data.size());
117 return _data[i];
118 }
119 };
120
123} // end namespace
124
125#endif
#define DUNE_ASSERT_BOUNDS(cond)
Definition boundschecking.hh:20
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
A few common exception classes.
This file implements a dense vector with a dynamic size.
Dune namespace.
Definition alignment.hh:11
A dense n x m matrix.
Definition densematrix.hh:135
Traits::value_type value_type
export the type representing the field
Definition densematrix.hh:149
size_type rows() const
number of rows
Definition densematrix.hh:664
Traits::row_type row_type
The type used to represent a row (must fulfill the Dune::DenseVector interface)
Definition densematrix.hh:161
Traits::size_type size_type
The type used for the index access and size operation.
Definition densematrix.hh:158
Construct a matrix with a dynamic size.
Definition dynmatrix.hh:58
size_type mat_cols() const
Definition dynmatrix.hh:107
DynamicMatrix(std::initializer_list< DynamicVector< K > > const &ll)
Constructor initializing the matrix from a list of vector.
Definition dynmatrix.hh:77
Base::row_type row_type
Definition dynmatrix.hh:64
Base::value_type value_type
Definition dynmatrix.hh:63
row_type & mat_access(size_type i)
Definition dynmatrix.hh:111
Base::size_type size_type
Definition dynmatrix.hh:62
size_type mat_rows() const
Definition dynmatrix.hh:106
const row_type & mat_access(size_type i) const
Definition dynmatrix.hh:115
void resize(size_type r, size_type c, value_type v=value_type())
resize matrix to r × c
Definition dynmatrix.hh:96
DynamicMatrix()
Default constructor.
Definition dynmatrix.hh:68
DynamicMatrix(size_type r, size_type c, value_type v=value_type())
Constructor initializing the whole matrix with a scalar.
Definition dynmatrix.hh:71
container_type::size_type size_type
Definition dynmatrix.hh:42
DynamicVector< K > row_type
Definition dynmatrix.hh:35
row_type & row_reference
Definition dynmatrix.hh:37
K value_type
Definition dynmatrix.hh:41
DynamicMatrix< K > derived_type
Definition dynmatrix.hh:33
const row_type & const_row_reference
Definition dynmatrix.hh:38
std::vector< K > container_type
Definition dynmatrix.hh:40
FieldTraits< K >::real_type real_type
Definition dynmatrix.hh:49
FieldTraits< K >::field_type field_type
Definition dynmatrix.hh:48
Construct a vector with a dynamic size.
Definition dynvector.hh:57
Definition ftraits.hh:24
T field_type
export the type representing the field
Definition ftraits.hh:26
T real_type
export the type representing the real type of the field
Definition ftraits.hh:28
Definition matvectraits.hh:29