Loading...
Searching...
No Matches
scalarmatrixview.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_COMMON_SCALARMATRIXVIEW_HH
#define DUNE_COMMON_SCALARMATRIXVIEW_HH
#include <cstddef>
#include <type_traits>
#include <ostream>
#include <dune/common/boundschecking.hh>
#include <dune/common/typetraits.hh>
#include <dune/common/matvectraits.hh>
#include <dune/common/densematrix.hh>
#include <dune/common/fmatrix.hh>
#include <dune/common/scalarvectorview.hh>
namespace Dune {
namespace Impl {
template<class K>
class ScalarMatrixView :
public DenseMatrix<ScalarMatrixView<K>>
{
ScalarVectorView<K> data_;
using Base = DenseMatrix<ScalarMatrixView<K>>;
template <class>
friend class ScalarMatrixView;
public:
//===== type definitions and constants
constexpr static int blocklevel = 1;
using size_type = typename Base::size_type;
using row_type = typename Base::row_type;
using row_reference = typename Base::row_reference;
using const_row_reference = typename Base::const_row_reference;
constexpr static int rows = 1;
constexpr static int cols = 1;
//===== constructors
constexpr ScalarMatrixView ()
: data_()
{}
ScalarMatrixView (K* p) :
data_(p)
{}
ScalarMatrixView (const ScalarMatrixView &other) :
Base(),
data_(other.data_)
{}
ScalarMatrixView (ScalarMatrixView &&other) :
Base(),
data_( other.data_ )
{}
ScalarMatrixView& operator= (const ScalarMatrixView& other)
{
data_ = other.data_;
return *this;
}
template<class KK>
ScalarMatrixView& operator= (const ScalarMatrixView<KK>& other)
{
data_ = other.data_;
return *this;
}
template<typename T,
std::enable_if_t<std::is_convertible<T, K>::value, int> = 0>
inline ScalarMatrixView& operator= (const T& k)
{
data_ = k;
return *this;
}
// make this thing a matrix
static constexpr size_type mat_rows() { return 1; }
static constexpr size_type mat_cols() { return 1; }
row_reference mat_access ([[maybe_unused]] size_type i)
{
DUNE_ASSERT_BOUNDS(i == 0);
return data_;
}
const_row_reference mat_access ([[maybe_unused]] size_type i) const
{
DUNE_ASSERT_BOUNDS(i == 0);
return data_;
}
}; // class ScalarMatrixView
template<typename K>
std::ostream& operator<< (std::ostream& s, const ScalarMatrixView<K>& a)
{
s << a[0][0];
return s;
}
template<class T,
std::enable_if_t<IsNumber<T>::value, int> = 0>
auto asMatrix(T& t)
{
return ScalarMatrixView<T>{&t};
}
template<class T,
std::enable_if_t<IsNumber<T>::value, int> = 0>
auto asMatrix(const T& t)
{
return ScalarMatrixView<const T>{&t};
}
template<class T,
std::enable_if_t<not IsNumber<T>::value, int> = 0>
T& asMatrix(T& t)
{
return t;
}
template<class T,
std::enable_if_t<not IsNumber<T>::value, int> = 0>
const T& asMatrix(const T& t)
{
return t;
}
} // end namespace Impl
template<class K>
struct FieldTraits<Impl::ScalarMatrixView<K>> : public FieldTraits<std::remove_const_t<K>> {};
template<class K>
struct DenseMatVecTraits<Impl::ScalarMatrixView<K>>
{
using derived_type = Impl::ScalarMatrixView<K>;
using row_type = Impl::ScalarVectorView<K>;
using row_reference = row_type&;
using const_row_reference = const row_type&;
using value_type = std::remove_const_t<K>;
using size_type = std::size_t;
};
template<class K>
struct AutonomousValueType<Impl::ScalarMatrixView<K>>
{
using type = FieldMatrix<std::remove_const_t<K>,1,1>;
};
} // end namespace Dune
#endif // DUNE_COMMON_SCALARMATRIXVIEW_HH
typetraits.hh
Traits for type conversions and type information.
matvectraits.hh
Documentation of the traits classes you need to write for each implementation of DenseVector or Dense...
densematrix.hh
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
scalarvectorview.hh
Implements a scalar vector view wrapper around an existing scalar.
boundschecking.hh
Macro for wrapping boundary checks.
fmatrix.hh
Implements a matrix constructed from a given type representing a field and compile-time given number ...
DUNE_ASSERT_BOUNDS
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition boundschecking.hh:30
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::DenseMatrix< ScalarMatrixView< K > >::row_type
Traits::row_type row_type
Definition densematrix.hh:174
Dune::DenseMatrix< ScalarMatrixView< K > >::size_type
Traits::size_type size_type
Definition densematrix.hh:171
Dune::DenseMatrix< ScalarMatrixView< K > >::const_row_reference
Traits::const_row_reference const_row_reference
Definition densematrix.hh:180
Dune::DenseMatrix< ScalarMatrixView< K > >::row_reference
Traits::row_reference row_reference
Definition densematrix.hh:177
Dune::DenseMatrix< ScalarMatrixView< K > >::DenseMatrix
friend class DenseMatrix
Definition densematrix.hh:153
Dune::FieldTraits
Definition ftraits.hh:26
Dune::DenseMatVecTraits
Definition matvectraits.hh:31
Dune::AutonomousValueType
Type free of internal references that T can be converted to.
Definition typetraits.hh:509
Dune::AutonomousValueType::type
T type
Definition typetraits.hh:509