13#include <initializer_list>
16#include "typetraits.hh"
37 template<
class K,
int SIZE >
class FieldVector;
38 template<
class K,
int SIZE >
39 struct DenseMatVecTraits< FieldVector<K,SIZE> >
41 typedef FieldVector<K,SIZE> derived_type;
42 typedef std::array<K,SIZE> container_type;
44 typedef typename container_type::size_type size_type;
47 template<
class K,
int SIZE >
48 struct FieldTraits< FieldVector<K,SIZE> >
50 typedef typename FieldTraits<K>::field_type field_type;
51 typedef typename FieldTraits<K>::real_type real_type;
62 template<
typename C,
int SIZE>
74 template<
typename T,
int SIZE>
75 struct IsFieldVectorSizeCorrect<FieldVector<T,SIZE>,SIZE>
80 template<
typename T,
int SIZE,
int SIZE1>
81 struct IsFieldVectorSizeCorrect<FieldVector<T,SIZE1>,SIZE>
92 template<
class K,
int SIZE >
96 std::array<K,SIZE> _data;
122 std::fill(_data.begin(),_data.end(),t);
125#if __GNUC__ == 5 && !defined(__clang__)
137 assert(l.size() == dimension);
138 std::copy_n(l.begin(),
std::min(
static_cast<std::size_t
>(dimension),
146 template <
typename T>
149 std::copy_n(x.
begin(), SIZE, _data.begin());
153 template<
typename T,
int N>
172 assert(x.
size() == SIZE);
173 std::copy_n(x.
begin(),
std::min(
static_cast<std::size_t
>(SIZE),x.
size()), _data.begin());
180 std::copy_n(x.
begin(), SIZE, _data.begin());
183 template<
typename T,
int N>
186 using Base::operator=;
189 static constexpr size_type size () {
return SIZE; }
191 K & operator[](size_type i) {
195 const K & operator[](size_type i)
const {
214 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
219 for (size_type i = 0; i < vector.size(); ++i)
220 result[i] = vector[i] * scalar;
227 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
232 for (size_type i = 0; i < vector.size(); ++i)
233 result[i] = scalar * vector[i];
240 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
245 for (size_type i = 0; i < vector.size(); ++i)
246 result[i] = vector[i] / scalar;
264 template<
class K,
int SIZE>
269 for(
typename FieldVector<K, SIZE>::size_type i = 0; i < SIZE; ++i )
281 typedef K container_type;
282 typedef K value_type;
283 typedef size_t size_type;
289 class FieldVector<K, 1> :
290 public DenseVector< FieldVector<K,1> >
293 typedef DenseVector< FieldVector<K,1> > Base;
301 typedef typename Base::size_type size_type;
304 typedef K& reference;
307 typedef const K& const_reference;
312 constexpr FieldVector ()
318 typename EnableIf =
typename std::enable_if<
319 std::is_convertible<T, K>::value &&
320 ! std::is_base_of<DenseVector<typename FieldTraits<T>::field_type>, K
324 FieldVector (
const T& k) : _data(k) {}
329 std::is_assignable<K&, typename DenseVector<C>::value_type>::value,
int> = 0>
330 FieldVector (
const DenseVector<C> & x)
332 static_assert(((bool)IsFieldVectorSizeCorrect<C,1>::value),
"FieldVectors do not match in dimension!");
333 assert(x.size() == 1);
338 FieldVector(
const FieldVector&) =
default;
341 FieldVector& operator=(
const FieldVector&) =
default;
343 template <
typename T>
344 FieldVector& operator= (
const FieldVector<T, 1>& other)
350 template<
typename T,
int N>
351 FieldVector& operator=(
const FieldVector<T, N>&) =
delete;
354 FieldVector (std::initializer_list<K>
const &l)
356 assert(l.size() == 1);
362 typename EnableIf =
typename std::enable_if<
363 std::is_assignable<K&, T>::value &&
364 ! std::is_base_of<DenseVector<typename FieldTraits<T>::field_type>, K
368 inline FieldVector& operator= (
const T& k)
375 static constexpr size_type size () {
return 1; }
377 K & operator[]([[maybe_unused]] size_type i)
382 const K & operator[]([[maybe_unused]] size_type i)
const
395 const K* data() const noexcept
403 operator K& () {
return _data; }
406 operator const K& ()
const {
return _data; }
414 inline bool operator> (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
421 inline bool operator>= (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
428 inline bool operator< (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
435 inline bool operator<= (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
444 inline FieldVector<K,1> operator+ (
const FieldVector<K,1>& a,
const K b)
451 inline FieldVector<K,1> operator- (
const FieldVector<K,1>& a,
const K b)
458 inline FieldVector<K,1> operator* (
const FieldVector<K,1>& a,
const K b)
465 inline FieldVector<K,1> operator/ (
const FieldVector<K,1>& a,
const K b)
472 inline bool operator> (
const FieldVector<K,1>& a,
const K b)
479 inline bool operator>= (
const FieldVector<K,1>& a,
const K b)
486 inline bool operator< (
const FieldVector<K,1>& a,
const K b)
493 inline bool operator<= (
const FieldVector<K,1>& a,
const K b)
500 inline bool operator== (
const FieldVector<K,1>& a,
const K b)
507 inline bool operator!= (
const FieldVector<K,1>& a,
const K b)
516 inline FieldVector<K,1> operator+ (
const K a,
const FieldVector<K,1>& b)
523 inline FieldVector<K,1> operator- (
const K a,
const FieldVector<K,1>& b)
530 inline FieldVector<K,1> operator* (
const K a,
const FieldVector<K,1>& b)
537 inline FieldVector<K,1> operator/ (
const K a,
const FieldVector<K,1>& b)
544 inline bool operator> (
const K a,
const FieldVector<K,1>& b)
551 inline bool operator>= (
const K a,
const FieldVector<K,1>& b)
558 inline bool operator< (
const K a,
const FieldVector<K,1>& b)
565 inline bool operator<= (
const K a,
const FieldVector<K,1>& b)
572 inline bool operator== (
const K a,
const FieldVector<K,1>& b)
579 inline bool operator!= (
const K a,
const FieldVector<K,1>& b)
586 namespace MathOverloads {
589 template<
class K,
int SIZE>
592 for(
int i=0; i<SIZE; i++) {
593 out &= Dune::isFinite(b[i]);
599 template<
class K,
int SIZE>
602 for(
int i=0; i<SIZE; i++) {
603 out |= Dune::isInf(b[i]);
609 template<class K, int SIZE, typename = std::enable_if_t<HasNaN<K>::value>>
612 for(
int i=0; i<SIZE; i++) {
613 out |= Dune::isNaN(b[i]);
619 template<class K, typename = std::enable_if_t<HasNaN<K>::value>>
622 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:227
Traits::value_type value_type
export the type representing the field
Definition: densevector.hh:248
Iterator begin()
begin iterator
Definition: densevector.hh:348
size_type size() const
size method
Definition: densevector.hh:337
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densevector.hh:257
vector space out of a tensor product of fields.
Definition: fvector.hh:95
K * data() noexcept
return pointer to underlying array
Definition: fvector.hh:201
constexpr FieldVector()
Constructor making default-initialized vector.
Definition: fvector.hh:115
const value_type & const_reference
The type used for const references to the vector entry.
Definition: fvector.hh:112
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:168
FieldVector(const K &t)
Constructor making vector with identical coordinates.
Definition: fvector.hh:120
FieldVector(std::initializer_list< K > const &l)
Construct from a std::initializer_list.
Definition: fvector.hh:135
const K * data() const noexcept
return pointer to underlying array
Definition: fvector.hh:207
@ dimension
The size of this vector.
Definition: fvector.hh:102
FieldVector(const FieldVector< K1, SIZE > &x)
Constructor making vector with identical coordinates.
Definition: fvector.hh:178
value_type & reference
The type used for references to the vector entry.
Definition: fvector.hh:109
FieldVector(const FieldVector &)=default
Copy constructor.
Implements the dense vector interface, with an exchangeable storage class.
TypeTree-specific exceptions.
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:28
std::istream & operator>>(std::istream &in, DynamicVector< K, Allocator > &v)
Read a DynamicVector from an input stream.
Definition: dynvector.hh:187
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:635
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:681
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:658
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:235
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:703
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:257
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition: defaults.hh:87
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
Element type of some SIMD type.
Definition: interface.hh:233
Some useful basic math stuff.
Dune namespace.
Definition: alignedallocator.hh:11
TMP to check the size of a DenseVectors statically, if possible.
Definition: fvector.hh:64
@ value
Definition: fvector.hh:70
Tag to make sure the functions in this namespace can be found by ADL.
Definition: math.hh:227
Helper class for tagging priorities.
Definition: typeutilities.hh:71