Dune Core Modules (2.7.1)

scalarmatrixview.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_COMMON_SCALARMATRIXVIEW_HH
4#define DUNE_COMMON_SCALARMATRIXVIEW_HH
5
6#include <cstddef>
7#include <type_traits>
8#include <ostream>
9
16
17
18namespace Dune {
19
20namespace Impl {
21
37 template<class K>
38 class ScalarMatrixView :
39 public DenseMatrix<ScalarMatrixView<K>>
40 {
41 ScalarVectorView<K> data_;
42 using Base = DenseMatrix<ScalarMatrixView<K>>;
43
44 template <class>
45 friend class ScalarMatrixView;
46 public:
47
48 //===== type definitions and constants
49
51 enum {
54 blocklevel = 1
55 };
56
57 using size_type = typename Base::size_type;
58 using row_type = typename Base::row_type;
59 using row_reference = typename Base::row_reference;
61
63 enum {
66 rows = 1,
69 cols = 1
70 };
71
72 //===== constructors
75 constexpr ScalarMatrixView ()
76 : data_()
77 {}
78
80 ScalarMatrixView (K* p) :
81 data_(p)
82 {}
83
85 ScalarMatrixView (const ScalarMatrixView &other) :
86 Base(),
87 data_(other.data_)
88 {}
89
91 ScalarMatrixView (ScalarMatrixView &&other) :
92 Base(),
93 data_( other.data_ )
94 {}
95
97 ScalarMatrixView& operator= (const ScalarMatrixView& other)
98 {
99 data_ = other.data_;
100 return *this;
101 }
102
103 template<class KK>
104 ScalarMatrixView& operator= (const ScalarMatrixView<KK>& other)
105 {
106 data_ = other.data_;
107 return *this;
108 }
109
111 template<typename T,
112 std::enable_if_t<std::is_convertible<T, K>::value, int> = 0>
113 inline ScalarMatrixView& operator= (const T& k)
114 {
115 data_ = k;
116 return *this;
117 }
118
119 // make this thing a matrix
120 static constexpr size_type mat_rows() { return 1; }
121 static constexpr size_type mat_cols() { return 1; }
122
123 row_reference mat_access ( size_type i )
124 {
126 DUNE_ASSERT_BOUNDS(i == 0);
127 return data_;
128 }
129
130 const_row_reference mat_access ( size_type i ) const
131 {
133 DUNE_ASSERT_BOUNDS(i == 0);
134 return data_;
135 }
136 }; // class ScalarMatrixView
137
139 template<typename K>
140 std::ostream& operator<< (std::ostream& s, const ScalarMatrixView<K>& a)
141 {
142 s << a[0][0];
143 return s;
144 }
145
147 template<class T,
148 std::enable_if_t<IsNumber<T>::value, int> = 0>
149 auto asMatrix(T& t)
150 {
151 return ScalarMatrixView<T>{&t};
152 }
153
155 template<class T,
156 std::enable_if_t<IsNumber<T>::value, int> = 0>
157 auto asMatrix(const T& t)
158 {
159 return ScalarMatrixView<const T>{&t};
160 }
161
163 template<class T,
164 std::enable_if_t<not IsNumber<T>::value, int> = 0>
165 T& asMatrix(T& t)
166 {
167 return t;
168 }
169
171 template<class T,
172 std::enable_if_t<not IsNumber<T>::value, int> = 0>
173 const T& asMatrix(const T& t)
174 {
175 return t;
176 }
177
180} // end namespace Impl
181
182 template<class K>
183 struct FieldTraits<Impl::ScalarMatrixView<K>> : public FieldTraits<std::remove_const_t<K>> {};
184
185 template<class K>
186 struct DenseMatVecTraits<Impl::ScalarMatrixView<K>>
187 {
188 using derived_type = Impl::ScalarMatrixView<K>;
189 using row_type = Impl::ScalarVectorView<K>;
190 using row_reference = row_type&;
191 using const_row_reference = const row_type&;
192 using value_type = std::remove_const_t<K>;
193 using size_type = std::size_t;
194 };
195
196
197 template<class K>
198 struct AutonomousValueType<Impl::ScalarMatrixView<K>>
199 {
200 using type = FieldMatrix<std::remove_const_t<K>,1,1>;
201 };
202
203
204} // end namespace Dune
205
206#endif // DUNE_COMMON_SCALARMATRIXVIEW_HH
Macro for wrapping boundary checks.
size_type cols() const
number of columns
Definition: densematrix.hh:742
size_type rows() const
number of rows
Definition: densematrix.hh:736
@ blocklevel
The number of block levels we contain. This is 1.
Definition: densematrix.hh:204
Traits::row_type row_type
The type used to represent a row (must fulfill the Dune::DenseVector interface)
Definition: densematrix.hh:193
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densematrix.hh:190
Traits::const_row_reference const_row_reference
The type used to represent a reference to a constant row (usually const row_type &)
Definition: densematrix.hh:199
Traits::row_reference row_reference
The type used to represent a reference to a row (usually row_type &)
Definition: densematrix.hh:196
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
Implements a matrix constructed from a given type representing a field and compile-time given number ...
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:28
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:25
Documentation of the traits classes you need to write for each implementation of DenseVector or Dense...
Dune namespace.
Definition: alignedallocator.hh:14
Implements a scalar vector view wrapper around an existing scalar.
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)