5#ifndef DUNE_COMMON_FVECTOR_HH
6#define DUNE_COMMON_FVECTOR_HH
14#include <initializer_list>
35 template<
class K,
int SIZE >
class FieldVector;
36 template<
class K,
int SIZE >
42 typedef typename container_type::size_type
size_type;
45 template<
class K,
int SIZE >
60 template<
typename C,
int SIZE>
67 constexpr static bool value =
true;
70 template<
typename T,
int SIZE>
73 constexpr static bool value =
true;
76 template<
typename T,
int SIZE,
int SIZE1>
79 constexpr static bool value =
false;
88 template<
class K,
int SIZE >
92 std::array<K,SIZE> _data;
114 noexcept(std::is_nothrow_copy_assignable_v<K>)
116 for (
auto& d : _data)
126 _data[i] = std::data(l)[i];
131 std::enable_if_t<IsFieldVectorSizeCorrect<T,dimension>::value,
int> = 0,
132 decltype(std::declval<K&>() = std::declval<const T&>()[0],
bool{}) =
true>
142 std::enable_if_t<std::is_assignable_v<K&, const T&>,
int> = 0>
144 noexcept(std::is_nothrow_assignable_v<K&, const T&>)
151 template<
class K1,
int SIZE1,
152 std::enable_if_t<(SIZE1 != SIZE),
int> = 0>
161 std::enable_if_t<IsFieldVectorSizeCorrect<T,dimension>::value,
int> = 0,
162 decltype(std::declval<K&>() = std::declval<const T&>()[0],
bool{}) =
true>
173 std::enable_if_t<std::is_assignable_v<K&, const T&>,
int> = 0>
175 noexcept(std::is_nothrow_assignable_v<K&, const T&>)
183 template<
class K1,
int SIZE1,
184 std::enable_if_t<(SIZE1 != SIZE),
int> = 0>
190 using Base::operator=;
216 constexpr const K*
data () const noexcept
222 template<
class Scalar,
223 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
230 result[i] = vector[i] * scalar;
235 template<
class Scalar,
236 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
243 result[i] = scalar * vector[i];
248 template<
class Scalar,
249 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
256 result[i] = vector[i] / scalar;
274 template<
class K,
int SIZE>
278 for (
int i = 0; i < SIZE; ++i)
290 typedef K container_type;
291 typedef K value_type;
292 typedef size_t size_type;
298 class FieldVector<K, 1> :
299 public DenseVector< FieldVector<K,1> >
302 typedef DenseVector< FieldVector<K,1> > Base;
324 std::enable_if_t<std::is_constructible_v<K,T>,
int> = 0>
330 constexpr FieldVector (
const std::initializer_list<K>& l)
332 assert(l.size() == 1);
338 std::enable_if_t<std::is_constructible_v<K,T>,
int> = 0>
339 constexpr FieldVector (
const FieldVector<T,1>& x) noexcept
345 std::enable_if_t<IsFieldVectorSizeCorrect<T,1>::value,
int> = 0,
346 decltype(std::declval<K&>() = std::declval<const T&>()[0],
bool{}) =
true>
349 assert(x.size() == 1);
361 decltype(std::declval<K&>() = std::declval<const T&>(),
bool{}) =
true>
362 constexpr FieldVector&
operator= (
const FieldVector<T,1>& other)
noexcept
370 std::enable_if_t<IsFieldVectorSizeCorrect<T,1>::value,
int> = 0,
371 decltype(std::declval<K&>() = std::declval<const T&>()[0],
bool{}) =
true>
372 FieldVector&
operator= (
const DenseVector<T>& other)
374 assert(other.size() == 1);
381 decltype(std::declval<K&>() = std::declval<const T&>(),
bool{}) =
true>
382 constexpr FieldVector&
operator= (
const T& k)
noexcept
403 constexpr K*
data () noexcept
409 constexpr const K*
data () const noexcept
417 constexpr operator reference () noexcept {
return _data; }
428 constexpr bool operator> (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
noexcept
435 constexpr bool operator>= (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
noexcept
442 constexpr bool operator< (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
noexcept
449 constexpr bool operator<= (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
noexcept
458 constexpr FieldVector<K,1>
operator+ (
const FieldVector<K,1>& a,
const K b)
noexcept
465 constexpr FieldVector<K,1>
operator- (
const FieldVector<K,1>& a,
const K b)
noexcept
472 constexpr FieldVector<K,1>
operator* (
const FieldVector<K,1>& a,
const K b)
noexcept
479 constexpr FieldVector<K,1>
operator/ (
const FieldVector<K,1>& a,
const K b)
noexcept
486 constexpr bool operator> (
const FieldVector<K,1>& a,
const K b)
noexcept
493 constexpr bool operator>= (
const FieldVector<K,1>& a,
const K b)
noexcept
500 constexpr bool operator< (
const FieldVector<K,1>& a,
const K b)
noexcept
507 constexpr bool operator<= (
const FieldVector<K,1>& a,
const K b)
noexcept
514 constexpr bool operator== (
const FieldVector<K,1>& a,
const K b)
noexcept
521 constexpr bool operator!= (
const FieldVector<K,1>& a,
const K b)
noexcept
530 constexpr FieldVector<K,1>
operator+ (
const K a,
const FieldVector<K,1>& b)
noexcept
537 constexpr FieldVector<K,1>
operator- (
const K a,
const FieldVector<K,1>& b)
noexcept
544 constexpr FieldVector<K,1>
operator* (
const K a,
const FieldVector<K,1>& b)
noexcept
551 constexpr FieldVector<K,1>
operator/ (
const K a,
const FieldVector<K,1>& b)
noexcept
558 constexpr bool operator> (
const K a,
const FieldVector<K,1>& b)
noexcept
565 constexpr bool operator>= (
const K a,
const FieldVector<K,1>& b)
noexcept
572 constexpr bool operator< (
const K a,
const FieldVector<K,1>& b)
noexcept
579 constexpr bool operator<= (
const K a,
const FieldVector<K,1>& b)
noexcept
586 constexpr bool operator== (
const K a,
const FieldVector<K,1>& b)
noexcept
593 constexpr bool operator!= (
const K a,
const FieldVector<K,1>& b)
noexcept
600 namespace MathOverloads {
603 template<
class K,
int SIZE>
607 for (
int i = 0; i < SIZE; ++i) {
608 out &= Dune::isFinite(b[i]);
614 template<
class K,
int SIZE>
618 for (
int i = 0; i < SIZE; ++i) {
619 out |= Dune::isInf(b[i]);
625 template<
class K,
int SIZE,
626 std::enable_if_t<HasNaN<K>::value,
int> = 0>
630 for (
int i = 0; i < SIZE; ++i) {
631 out |= Dune::isNaN(b[i]);
638 std::enable_if_t<HasNaN<K>::value,
int> = 0>
642 return Dune::isUnordered(b[0],c[0]);
Macro for wrapping boundary checks.
Utilities for type computations, constraining overloads, ...
Implements the dense vector interface, with an exchangeable storage class.
Traits for type conversions and type information.
Compute type of the result of an arithmetic operation involving two different number types.
Some useful basic math stuff.
Type traits to determine the type of reals (when working with complex numbers)
Stream & operator>>(Stream &stream, std::tuple< Ts... > &t)
Read a std::tuple.
Definition streamoperators.hh:43
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition boundschecking.hh:30
bigunsignedint< k > operator*(const bigunsignedint< k > &x, std::uintmax_t y)
Definition bigunsignedint.hh:549
bigunsignedint< k > operator/(const bigunsignedint< k > &x, std::uintmax_t y)
Definition bigunsignedint.hh:556
bigunsignedint< k > operator-(const bigunsignedint< k > &x, std::uintmax_t y)
Definition bigunsignedint.hh:542
bigunsignedint< k > operator+(const bigunsignedint< k > &x, std::uintmax_t y)
Definition bigunsignedint.hh:535
EnableIfInterOperable< T1, T2, bool >::type operator<(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition iteratorfacades.hh:638
EnableIfInterOperable< T1, T2, bool >::type operator>(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition iteratorfacades.hh:684
EnableIfInterOperable< T1, T2, bool >::type operator<=(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition iteratorfacades.hh:661
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition iteratorfacades.hh:238
EnableIfInterOperable< T1, T2, bool >::type operator>=(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition iteratorfacades.hh:706
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition iteratorfacades.hh:260
Dune namespace.
Definition alignedallocator.hh:13
bool isNaN(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Returns whether any entry is NaN.
Definition fvector.hh:627
bool isInf(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Returns whether any entry is infinite.
Definition fvector.hh:615
auto isFinite(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Returns whether all entries are finite.
Definition fvector.hh:604
bool isUnordered(const FieldVector< K, 1 > &b, const FieldVector< K, 1 > &c, PriorityTag< 2 >, ADLTag)
Returns true if either b or c is NaN.
Definition fvector.hh:639
vector space out of a tensor product of fields.
Definition fvector.hh:91
constexpr FieldVector(const K &k) noexcept(std::is_nothrow_copy_assignable_v< K >)
Constructor making vector with identical coordinates.
Definition fvector.hh:113
const value_type & const_reference
The type used for const references to the vector entry.
Definition fvector.hh:105
constexpr FieldVector(const std::initializer_list< K > &l)
Construct from a std::initializer_list.
Definition fvector.hh:121
static constexpr size_type size() noexcept
Obtain the number of elements stored in the vector.
Definition fvector.hh:193
Base::size_type size_type
Definition fvector.hh:98
FieldVector & operator=(const DenseVector< T > &x)
Assignment from another dense vector.
Definition fvector.hh:163
static constexpr int dimension
The size of this vector.
Definition fvector.hh:96
constexpr FieldVector() noexcept
Default constructor, making value-initialized vector with all components set to zero.
Definition fvector.hh:108
friend constexpr auto operator/(const FieldVector &vector, Scalar scalar)
Vector space division by scalar.
Definition fvector.hh:250
friend constexpr auto operator*(const FieldVector &vector, Scalar scalar)
Vector space multiplication with scalar.
Definition fvector.hh:224
value_type & reference
The type used for references to the vector entry.
Definition fvector.hh:102
Base::value_type value_type
Definition fvector.hh:99
constexpr FieldVector(const FieldVector< T, SIZE > &x) noexcept(std::is_nothrow_assignable_v< K &, const T & >)
Converting constructor from FieldVector with different element type.
Definition fvector.hh:143
constexpr const K * data() const noexcept
Return pointer to underlying array.
Definition fvector.hh:216
FieldVector(const FieldVector &)=default
Copy constructor with default behavior.
reference operator[](size_type i)
Return a reference to the ith element.
Definition fvector.hh:196
constexpr K * data() noexcept
Return pointer to underlying array.
Definition fvector.hh:210
Interface for a class of dense vectors over a given field.
Definition densevector.hh:229
Traits::value_type value_type
export the type representing the field
Definition densevector.hh:250
size_type size() const
size method
Definition densevector.hh:336
Traits::size_type size_type
The type used for the index access and size operation.
Definition densevector.hh:259
T field_type
export the type representing the field
Definition ftraits.hh:28
T real_type
export the type representing the real type of the field
Definition ftraits.hh:30
K value_type
Definition fvector.hh:41
std::array< K, SIZE > container_type
Definition fvector.hh:40
container_type::size_type size_type
Definition fvector.hh:42
FieldVector< K, SIZE > derived_type
Definition fvector.hh:39
FieldTraits< K >::real_type real_type
Definition fvector.hh:49
FieldTraits< K >::field_type field_type
Definition fvector.hh:48
TMP to check the size of a DenseVectors statically, if possible.
Definition fvector.hh:62
static constexpr bool value
True if C is not of type FieldVector or its dimension is not equal SIZE.
Definition fvector.hh:67
Tag to make sure the functions in this namespace can be found by ADL.
Definition math.hh:230
Definition matvectraits.hh:31
decltype(std::declval< T1 >()+std::declval< T2 >()) PromotedType
Definition promotiontraits.hh:28
Helper class for tagging priorities.
Definition typeutilities.hh:73