3 #ifndef DUNE_FVECTOR_HH
4 #define DUNE_FVECTOR_HH
13 #include <initializer_list>
38 template<
class K,
int SIZE >
class FieldVector;
39 template<
class K,
int SIZE >
45 typedef typename container_type::size_type
size_type;
48 template<
class K,
int SIZE >
63 template<
typename C,
int SIZE>
75 template<
typename T,
int SIZE>
81 template<
typename T,
int SIZE,
int SIZE1>
93 template<
class K,
int SIZE >
97 std::array<K,SIZE> _data;
123 std::fill(_data.begin(),_data.end(),t);
126 #if __GNUC__ == 5 && !defined(__clang__)
138 assert(l.size() == dimension);
139 std::copy_n(l.begin(),
std::min(
static_cast<std::size_t
>(dimension),
147 template <
typename T>
150 std::copy_n(x.
begin(), SIZE, _data.begin());
154 template<
typename T,
int N>
173 assert(x.
size() == SIZE);
174 std::copy_n(x.
begin(),
std::min(
static_cast<std::size_t
>(SIZE),x.
size()), _data.begin());
181 std::copy_n(x.
begin(), SIZE, _data.begin());
184 template<
typename T,
int N>
187 using Base::operator=;
215 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
221 result[i] = vector[i] * scalar;
228 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
234 result[i] = scalar * vector[i];
241 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
247 result[i] = vector[i] / scalar;
265 template<
class K,
int SIZE>
282 typedef K container_type;
283 typedef K value_type;
284 typedef size_t size_type;
290 class FieldVector<K, 1> :
291 public DenseVector< FieldVector<K,1> >
294 typedef DenseVector< FieldVector<K,1> > Base;
302 typedef typename Base::size_type size_type;
305 typedef K& reference;
308 typedef const K& const_reference;
313 constexpr FieldVector ()
319 typename EnableIf =
typename std::enable_if<
320 std::is_convertible<T, K>::value &&
321 ! std::is_base_of<DenseVector<typename FieldTraits<T>::field_type>, K
325 FieldVector (
const T& k) : _data(k) {}
330 std::is_assignable<K&, typename DenseVector<C>::value_type>::value,
int> = 0>
331 FieldVector (
const DenseVector<C> & x)
333 static_assert(((
bool)IsFieldVectorSizeCorrect<C,1>::value),
"FieldVectors do not match in dimension!");
334 assert(x.size() == 1);
339 FieldVector(
const FieldVector&) =
default;
342 FieldVector& operator=(
const FieldVector&) =
default;
344 template <
typename T>
345 FieldVector& operator= (
const FieldVector<T, 1>& other)
351 template<
typename T,
int N>
352 FieldVector& operator=(
const FieldVector<T, N>&) =
delete;
355 FieldVector (std::initializer_list<K>
const &l)
357 assert(l.size() == 1);
363 typename EnableIf =
typename std::enable_if<
364 std::is_assignable<K&, T>::value &&
365 ! std::is_base_of<DenseVector<typename FieldTraits<T>::field_type>, K
369 inline FieldVector& operator= (
const T& k)
376 static constexpr size_type size () {
return 1; }
378 K & operator[](size_type i)
384 const K & operator[](size_type i)
const
398 const K* data() const noexcept
406 operator K& () {
return _data; }
409 operator const K& ()
const {
return _data; }
417 inline bool operator> (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
424 inline bool operator>= (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
431 inline bool operator< (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
438 inline bool operator<= (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
447 inline FieldVector<K,1>
operator+ (
const FieldVector<K,1>& a,
const K b)
454 inline FieldVector<K,1>
operator- (
const FieldVector<K,1>& a,
const K b)
461 inline FieldVector<K,1>
operator* (
const FieldVector<K,1>& a,
const K b)
468 inline FieldVector<K,1>
operator/ (
const FieldVector<K,1>& a,
const K b)
475 inline bool operator> (
const FieldVector<K,1>& a,
const K b)
482 inline bool operator>= (
const FieldVector<K,1>& a,
const K b)
489 inline bool operator< (
const FieldVector<K,1>& a,
const K b)
496 inline bool operator<= (
const FieldVector<K,1>& a,
const K b)
503 inline bool operator== (
const FieldVector<K,1>& a,
const K b)
510 inline bool operator!= (
const FieldVector<K,1>& a,
const K b)
519 inline FieldVector<K,1>
operator+ (
const K a,
const FieldVector<K,1>& b)
526 inline FieldVector<K,1>
operator- (
const K a,
const FieldVector<K,1>& b)
533 inline FieldVector<K,1>
operator* (
const K a,
const FieldVector<K,1>& b)
540 inline FieldVector<K,1>
operator/ (
const K a,
const FieldVector<K,1>& b)
547 inline bool operator> (
const K a,
const FieldVector<K,1>& b)
554 inline bool operator>= (
const K a,
const FieldVector<K,1>& b)
561 inline bool operator< (
const K a,
const FieldVector<K,1>& b)
568 inline bool operator<= (
const K a,
const FieldVector<K,1>& b)
575 inline bool operator== (
const K a,
const FieldVector<K,1>& b)
582 inline bool operator!= (
const K a,
const FieldVector<K,1>& b)
589 namespace MathOverloads {
592 template<
class K,
int SIZE>
595 for(
int i=0; i<SIZE; i++) {
602 template<
class K,
int SIZE>
605 for(
int i=0; i<SIZE; i++) {
612 template<class K, int SIZE, typename = std::enable_if_t<HasNaN<K>::value>>
615 for(
int i=0; i<SIZE; i++) {
622 template<class K, typename = std::enable_if_t<HasNaN<K>::value>>
Macro for wrapping boundary checks.
Implements the dense vector interface, with an exchangeable storage class.
A few common exception classes.
Type traits to determine the type of reals (when working with complex numbers)
Some useful basic math stuff.
Compute type of the result of an arithmetic operation involving two different number types.
Traits for type conversions and type information.
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:28
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:25
bigunsignedint< k > operator+(const bigunsignedint< k > &x, std::uintmax_t y)
Definition: bigunsignedint.hh:530
bigunsignedint< k > operator*(const bigunsignedint< k > &x, std::uintmax_t y)
Definition: bigunsignedint.hh:544
bigunsignedint< k > operator-(const bigunsignedint< k > &x, std::uintmax_t y)
Definition: bigunsignedint.hh:537
bigunsignedint< k > operator/(const bigunsignedint< k > &x, std::uintmax_t y)
Definition: bigunsignedint.hh:551
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: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: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:703
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
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
Element type of some SIMD type.
Definition: simd/interface.hh:233
Dune namespace.
Definition: alignedallocator.hh:14
constexpr bool operator!=(const DebugAllocator< T > &, const DebugAllocator< T > &)
check whether allocators are not equivalent
Definition: debugallocator.hh:318
constexpr bool operator==(const DebugAllocator< T > &, const DebugAllocator< T > &)
check whether allocators are equivalent
Definition: debugallocator.hh:310
auto min(const AlignedNumber< T, align > &a, const AlignedNumber< T, align > &b)
Definition: debugalign.hh:434
bool isNaN(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Definition: fvector.hh:613
bool isInf(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Definition: fvector.hh:603
auto isFinite(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Definition: fvector.hh:593
bool isUnordered(const FieldVector< K, 1 > &b, const FieldVector< K, 1 > &c, PriorityTag< 2 >, ADLTag)
Definition: fvector.hh:623
vector space out of a tensor product of fields.
Definition: fvector.hh:96
const K * data() const noexcept
return pointer to underlying array
Definition: fvector.hh:208
constexpr FieldVector()
Constructor making default-initialized vector.
Definition: fvector.hh:116
const value_type & const_reference
The type used for const references to the vector entry.
Definition: fvector.hh:113
Base::size_type size_type
Definition: fvector.hh:106
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:169
FieldVector(const FieldVector< T, N > &)=delete
FieldVector(const K &t)
Constructor making vector with identical coordinates.
Definition: fvector.hh:121
FieldVector(std::initializer_list< K > const &l)
Construct from a std::initializer_list.
Definition: fvector.hh:136
@ dimension
The size of this vector.
Definition: fvector.hh:103
FieldVector(const FieldVector< K1, SIZE > &x)
Constructor making vector with identical coordinates.
Definition: fvector.hh:179
static constexpr size_type size()
Definition: fvector.hh:190
const K & operator[](size_type i) const
Definition: fvector.hh:196
value_type & reference
The type used for references to the vector entry.
Definition: fvector.hh:110
K * data() noexcept
return pointer to underlying array
Definition: fvector.hh:202
Base::value_type value_type
Definition: fvector.hh:107
K & operator[](size_type i)
Definition: fvector.hh:192
FieldVector(const FieldVector &)=default
Copy constructor.
FieldVector & operator=(const FieldVector< T, N > &)=delete
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
Definition: ftraits.hh:24
T field_type
export the type representing the field
Definition: ftraits.hh:26
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:28
K value_type
Definition: fvector.hh:44
std::array< K, SIZE > container_type
Definition: fvector.hh:43
container_type::size_type size_type
Definition: fvector.hh:45
FieldVector< K, SIZE > derived_type
Definition: fvector.hh:42
FieldTraits< K >::real_type real_type
Definition: fvector.hh:52
FieldTraits< K >::field_type field_type
Definition: fvector.hh:51
TMP to check the size of a DenseVectors statically, if possible.
Definition: fvector.hh:65
@ value
Definition: fvector.hh:71
Tag to make sure the functions in this namespace can be found by ADL.
Definition: math.hh:227
Definition: matvectraits.hh:29
Helper class for tagging priorities.
Definition: typeutilities.hh:71