DUNE-FEM (unstable)

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// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_COMMON_SCALARMATRIXVIEW_HH
6#define DUNE_COMMON_SCALARMATRIXVIEW_HH
7
8#include <cstddef>
9#include <type_traits>
10#include <ostream>
11
18
19
20namespace Dune {
21
22namespace Impl {
23
39 template<class K>
40 class ScalarMatrixView :
41 public DenseMatrix<ScalarMatrixView<K>>
42 {
43 ScalarVectorView<K> data_;
44 using Base = DenseMatrix<ScalarMatrixView<K>>;
45
46 template <class>
47 friend class ScalarMatrixView;
48 public:
49
50 //===== type definitions and constants
51
54 constexpr static int blocklevel = 1;
55
56 using size_type = typename Base::size_type;
57 using row_type = typename Base::row_type;
58 using row_reference = typename Base::row_reference;
60
63 constexpr static int rows = 1;
66 constexpr static int cols = 1;
67
68 //===== constructors
71 constexpr ScalarMatrixView ()
72 : data_()
73 {}
74
76 ScalarMatrixView (K* p) :
77 data_(p)
78 {}
79
81 ScalarMatrixView (const ScalarMatrixView &other) :
82 Base(),
83 data_(other.data_)
84 {}
85
87 ScalarMatrixView (ScalarMatrixView &&other) :
88 Base(),
89 data_( other.data_ )
90 {}
91
93 ScalarMatrixView& operator= (const ScalarMatrixView& other)
94 {
95 data_ = other.data_;
96 return *this;
97 }
98
99 template<class KK>
100 ScalarMatrixView& operator= (const ScalarMatrixView<KK>& other)
101 {
102 data_ = other.data_;
103 return *this;
104 }
105
107 template<typename T,
108 std::enable_if_t<std::is_convertible<T, K>::value, int> = 0>
109 inline ScalarMatrixView& operator= (const T& k)
110 {
111 data_ = k;
112 return *this;
113 }
114
115 // make this thing a matrix
116 static constexpr size_type mat_rows() { return 1; }
117 static constexpr size_type mat_cols() { return 1; }
118
119 row_reference mat_access ([[maybe_unused]] size_type i)
120 {
121 DUNE_ASSERT_BOUNDS(i == 0);
122 return data_;
123 }
124
125 const_row_reference mat_access ([[maybe_unused]] size_type i) const
126 {
127 DUNE_ASSERT_BOUNDS(i == 0);
128 return data_;
129 }
130 }; // class ScalarMatrixView
131
133 template<typename K>
134 std::ostream& operator<< (std::ostream& s, const ScalarMatrixView<K>& a)
135 {
136 s << a[0][0];
137 return s;
138 }
139
141 template<class T,
142 std::enable_if_t<IsNumber<T>::value, int> = 0>
143 auto asMatrix(T& t)
144 {
145 return ScalarMatrixView<T>{&t};
146 }
147
149 template<class T,
150 std::enable_if_t<IsNumber<T>::value, int> = 0>
151 auto asMatrix(const T& t)
152 {
153 return ScalarMatrixView<const T>{&t};
154 }
155
157 template<class T,
158 std::enable_if_t<not IsNumber<T>::value, int> = 0>
159 T& asMatrix(T& t)
160 {
161 return t;
162 }
163
165 template<class T,
166 std::enable_if_t<not IsNumber<T>::value, int> = 0>
167 const T& asMatrix(const T& t)
168 {
169 return t;
170 }
171
174} // end namespace Impl
175
176 template<class K>
177 struct FieldTraits<Impl::ScalarMatrixView<K>> : public FieldTraits<std::remove_const_t<K>> {};
178
179 template<class K>
180 struct DenseMatVecTraits<Impl::ScalarMatrixView<K>>
181 {
182 using derived_type = Impl::ScalarMatrixView<K>;
183 using row_type = Impl::ScalarVectorView<K>;
184 using row_reference = row_type&;
185 using const_row_reference = const row_type&;
186 using value_type = std::remove_const_t<K>;
187 using size_type = std::size_t;
188 };
189
190
191 template<class K>
192 struct AutonomousValueType<Impl::ScalarMatrixView<K>>
193 {
194 using type = FieldMatrix<std::remove_const_t<K>,1,1>;
195 };
196
197
198} // end namespace Dune
199
200#endif // DUNE_COMMON_SCALARMATRIXVIEW_HH
Macro for wrapping boundary checks.
constexpr size_type cols() const
number of columns
Definition: densematrix.hh:715
constexpr size_type rows() const
number of rows
Definition: densematrix.hh:709
static constexpr int blocklevel
The number of block levels we contain. This is the leaf, that is, 1.
Definition: densematrix.hh:178
Traits::row_type row_type
The type used to represent a row (must fulfill the Dune::DenseVector interface)
Definition: densematrix.hh:169
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densematrix.hh:166
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:175
Traits::row_reference row_reference
The type used to represent a reference to a row (usually row_type &)
Definition: densematrix.hh:172
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:30
Documentation of the traits classes you need to write for each implementation of DenseVector or Dense...
Dune namespace.
Definition: alignedallocator.hh:13
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)