15#include <initializer_list>
19#include "exceptions.hh"
39 template<
class K,
int SIZE >
class FieldVector;
40 template<
class K,
int SIZE >
41 struct DenseMatVecTraits< FieldVector<K,SIZE> >
43 typedef FieldVector<K,SIZE> derived_type;
44 typedef std::array<K,SIZE> container_type;
46 typedef typename container_type::size_type size_type;
49 template<
class K,
int SIZE >
50 struct FieldTraits< FieldVector<K,SIZE> >
52 typedef typename FieldTraits<K>::field_type field_type;
53 typedef typename FieldTraits<K>::real_type real_type;
64 template<
typename C,
int SIZE>
71 constexpr static bool value =
true;
74 template<
typename T,
int SIZE>
77 constexpr static bool value =
true;
80 template<
typename T,
int SIZE,
int SIZE1>
81 struct IsFieldVectorSizeCorrect<FieldVector<T,SIZE1>,SIZE>
83 constexpr static bool value =
false;
92 template<
class K,
int SIZE >
96 std::array<K,SIZE> _data;
119 std::fill(_data.begin(),_data.end(),t);
122#if __GNUC__ == 5 && !defined(__clang__)
134 assert(l.size() == dimension);
135 std::copy_n(l.begin(),
std::min(
static_cast<std::size_t
>(dimension),
143 template <
typename T>
146 std::copy_n(x.
begin(), SIZE, _data.begin());
150 template<
typename T,
int N>
169 assert(x.
size() == SIZE);
170 std::copy_n(x.
begin(),
std::min(
static_cast<std::size_t
>(SIZE),x.
size()), _data.begin());
177 std::copy_n(x.
begin(), SIZE, _data.begin());
180 template<
typename T,
int N>
183 using Base::operator=;
186 static constexpr size_type size () {
return SIZE; }
188 K & operator[](size_type i) {
192 const K & operator[](size_type i)
const {
211 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
216 for (size_type i = 0; i < vector.size(); ++i)
217 result[i] = vector[i] * scalar;
224 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
229 for (size_type i = 0; i < vector.size(); ++i)
230 result[i] = scalar * vector[i];
237 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
242 for (size_type i = 0; i < vector.size(); ++i)
243 result[i] = vector[i] / scalar;
261 template<
class K,
int SIZE>
266 for(
typename FieldVector<K, SIZE>::size_type i = 0; i < SIZE; ++i )
278 typedef K container_type;
279 typedef K value_type;
280 typedef size_t size_type;
286 class FieldVector<K, 1> :
287 public DenseVector< FieldVector<K,1> >
290 typedef DenseVector< FieldVector<K,1> > Base;
293 constexpr static int dimension = 1;
295 typedef typename Base::size_type size_type;
298 typedef K& reference;
301 typedef const K& const_reference;
306 constexpr FieldVector ()
312 typename EnableIf =
typename std::enable_if<
313 std::is_convertible<T, K>::value &&
314 ! std::is_base_of<DenseVector<typename FieldTraits<T>::field_type>, K
318 FieldVector (
const T& k) : _data(k) {}
323 std::is_assignable<K&, typename DenseVector<C>::value_type>::value,
int> = 0>
324 FieldVector (
const DenseVector<C> & x)
326 static_assert(((bool)IsFieldVectorSizeCorrect<C,1>::value),
"FieldVectors do not match in dimension!");
327 assert(x.size() == 1);
332 FieldVector(
const FieldVector&) =
default;
335 FieldVector& operator=(
const FieldVector&) =
default;
337 template <
typename T>
338 FieldVector& operator= (
const FieldVector<T, 1>& other)
344 template<
typename T,
int N>
345 FieldVector& operator=(
const FieldVector<T, N>&) =
delete;
348 FieldVector (std::initializer_list<K>
const &l)
350 assert(l.size() == 1);
356 typename EnableIf =
typename std::enable_if<
357 std::is_assignable<K&, T>::value &&
358 ! std::is_base_of<DenseVector<typename FieldTraits<T>::field_type>, K
362 inline FieldVector& operator= (
const T& k)
369 static constexpr size_type size () {
return 1; }
371 K & operator[]([[maybe_unused]] size_type i)
376 const K & operator[]([[maybe_unused]] size_type i)
const
389 const K* data() const noexcept
397 operator K& () {
return _data; }
400 operator const K& ()
const {
return _data; }
408 inline bool operator> (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
415 inline bool operator>= (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
422 inline bool operator< (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
429 inline bool operator<= (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
438 inline FieldVector<K,1> operator+ (
const FieldVector<K,1>& a,
const K b)
445 inline FieldVector<K,1> operator- (
const FieldVector<K,1>& a,
const K b)
452 inline FieldVector<K,1> operator* (
const FieldVector<K,1>& a,
const K b)
459 inline FieldVector<K,1> operator/ (
const FieldVector<K,1>& a,
const K b)
466 inline bool operator> (
const FieldVector<K,1>& a,
const K b)
473 inline bool operator>= (
const FieldVector<K,1>& a,
const K b)
480 inline bool operator< (
const FieldVector<K,1>& a,
const K b)
487 inline bool operator<= (
const FieldVector<K,1>& a,
const K b)
494 inline bool operator== (
const FieldVector<K,1>& a,
const K b)
501 inline bool operator!= (
const FieldVector<K,1>& a,
const K b)
510 inline FieldVector<K,1> operator+ (
const K a,
const FieldVector<K,1>& b)
517 inline FieldVector<K,1> operator- (
const K a,
const FieldVector<K,1>& b)
524 inline FieldVector<K,1> operator* (
const K a,
const FieldVector<K,1>& b)
531 inline FieldVector<K,1> operator/ (
const K a,
const FieldVector<K,1>& b)
538 inline bool operator> (
const K a,
const FieldVector<K,1>& b)
545 inline bool operator>= (
const K a,
const FieldVector<K,1>& b)
552 inline bool operator< (
const K a,
const FieldVector<K,1>& b)
559 inline bool operator<= (
const K a,
const FieldVector<K,1>& b)
566 inline bool operator== (
const K a,
const FieldVector<K,1>& b)
573 inline bool operator!= (
const K a,
const FieldVector<K,1>& b)
580 namespace MathOverloads {
583 template<
class K,
int SIZE>
586 for(
int i=0; i<SIZE; i++) {
587 out &= Dune::isFinite(b[i]);
593 template<
class K,
int SIZE>
596 for(
int i=0; i<SIZE; i++) {
597 out |= Dune::isInf(b[i]);
603 template<class K, int SIZE, typename = std::enable_if_t<HasNaN<K>::value>>
606 for(
int i=0; i<SIZE; i++) {
607 out |= Dune::isNaN(b[i]);
613 template<class K, typename = std::enable_if_t<HasNaN<K>::value>>
616 return Dune::isUnordered(b[0],c[0]);
Macro for wrapping boundary checks.
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
Iterator begin()
begin iterator
Definition: densevector.hh:347
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
vector space out of a tensor product of fields.
Definition: fvector.hh:95
K * data() noexcept
return pointer to underlying array
Definition: fvector.hh:198
constexpr FieldVector()
Constructor making default-initialized vector.
Definition: fvector.hh:112
const value_type & const_reference
The type used for const references to the vector entry.
Definition: fvector.hh:109
FieldVector(const DenseVector< C > &x, typename std::enable_if< IsFieldVectorSizeCorrect< C, SIZE >::value >::type *dummy=0)
Copy constructor from a second vector of possibly different type.
Definition: fvector.hh:165
FieldVector(const K &t)
Constructor making vector with identical coordinates.
Definition: fvector.hh:117
FieldVector(std::initializer_list< K > const &l)
Construct from a std::initializer_list.
Definition: fvector.hh:132
const K * data() const noexcept
return pointer to underlying array
Definition: fvector.hh:204
static constexpr int dimension
The size of this vector.
Definition: fvector.hh:100
FieldVector(const FieldVector< K1, SIZE > &x)
Constructor making vector with identical coordinates.
Definition: fvector.hh:175
value_type & reference
The type used for references to the vector entry.
Definition: fvector.hh:106
FieldVector(const FieldVector &)=default
Copy constructor.
Implements the dense vector interface, with an exchangeable storage class.
Type traits to determine the type of reals (when working with complex numbers)
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:30
std::istream & operator>>(std::istream &in, DynamicVector< K, Allocator > &v)
Read a DynamicVector from an input stream.
Definition: dynvector.hh:189
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:637
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:683
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:660
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:237
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:705
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:259
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition: defaults.hh:89
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
Element type of some SIMD type.
Definition: interface.hh:235
Some useful basic math stuff.
Dune namespace.
Definition: alignedallocator.hh:13
TMP to check the size of a DenseVectors statically, if possible.
Definition: fvector.hh:66
static constexpr bool value
True if C is not of type FieldVector or its dimension is not equal SIZE.
Definition: fvector.hh:71
Tag to make sure the functions in this namespace can be found by ADL.
Definition: math.hh:230
Helper class for tagging priorities.
Definition: typeutilities.hh:73
Traits for type conversions and type information.