Dune Core Modules (2.4.2)

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
13
14namespace Dune
15{
16
26 template< class K > class DynamicMatrix;
27
28 template< class K >
29 struct DenseMatVecTraits< DynamicMatrix<K> >
30 {
31 typedef DynamicMatrix<K> derived_type;
32
33 typedef DynamicVector<K> row_type;
34
35 typedef row_type &row_reference;
36 typedef const row_type &const_row_reference;
37
38 typedef std::vector<K> container_type;
39 typedef K value_type;
40 typedef typename container_type::size_type size_type;
41 };
42
43 template< class K >
44 struct FieldTraits< DynamicMatrix<K> >
45 {
46 typedef typename FieldTraits<K>::field_type field_type;
47 typedef typename FieldTraits<K>::real_type real_type;
48 };
49
54 template<class K>
55 class DynamicMatrix : public DenseMatrix< DynamicMatrix<K> >
56 {
57 std::vector< DynamicVector<K> > _data;
59 public:
60 typedef typename Base::size_type size_type;
61 typedef typename Base::value_type value_type;
62 typedef typename Base::row_type row_type;
63
64 //===== constructors
67
69 DynamicMatrix (size_type r, size_type c, value_type v = value_type() ) :
70 _data(r, row_type(c, v) )
71 {}
72
73 //==== resize related methods
74 void resize (size_type r, size_type c, value_type v = value_type() )
75 {
76 _data.resize(0);
77 _data.resize(r, row_type(c, v) );
78 }
79
80 //===== assignment
81 using Base::operator=;
82
83 // make this thing a matrix
84 size_type mat_rows() const { return _data.size(); }
85 size_type mat_cols() const {
86 assert(this->rows());
87 return _data.front().size();
88 }
89 row_type & mat_access(size_type i) { return _data[i]; }
90 const row_type & mat_access(size_type i) const { return _data[i]; }
91 };
92
95} // end namespace
96
97#endif
A dense n x m matrix.
Definition: densematrix.hh:185
Traits::value_type value_type
export the type representing the field
Definition: densematrix.hh:199
size_type rows() const
number of rows
Definition: densematrix.hh:695
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densematrix.hh:208
Construct a matrix with a dynamic size.
Definition: dynmatrix.hh:56
DynamicMatrix()
Default constructor.
Definition: dynmatrix.hh:66
DynamicMatrix(size_type r, size_type c, value_type v=value_type())
Constructor initializing the whole matrix with a scalar.
Definition: dynmatrix.hh:69
Construct a vector with a dynamic size.
Definition: dynvector.hh:55
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:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)