3 #ifndef DUNE_FVECTOR_HH
4 #define DUNE_FVECTOR_HH
13 #include <initializer_list>
37 template<
class K,
int SIZE >
class FieldVector;
38 template<
class K,
int SIZE >
44 typedef typename container_type::size_type
size_type;
47 template<
class K,
int SIZE >
62 template<
typename C,
int SIZE>
74 template<
typename T,
int SIZE>
80 template<
typename T,
int SIZE,
int SIZE1>
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=;
214 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
220 result[i] = vector[i] * scalar;
227 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
233 result[i] = scalar * vector[i];
240 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
246 result[i] = vector[i] / scalar;
264 template<
class K,
int SIZE>
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++) {
599 template<
class K,
int SIZE>
602 for(
int i=0; i<SIZE; i++) {
609 template<class K, int SIZE, typename = std::enable_if_t<HasNaN<K>::value>>
612 for(
int i=0; i<SIZE; i++) {
619 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.
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:28
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 ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:257
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 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 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:11
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:610
bool isInf(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Definition: fvector.hh:600
auto isFinite(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Definition: fvector.hh:590
bool isUnordered(const FieldVector< K, 1 > &b, const FieldVector< K, 1 > &c, PriorityTag< 2 >, ADLTag)
Definition: fvector.hh:620
vector space out of a tensor product of fields.
Definition: fvector.hh:95
const K * data() const noexcept
return pointer to underlying array
Definition: fvector.hh:207
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
Base::size_type size_type
Definition: fvector.hh:105
FieldVector(const FieldVector< T, N > &)=delete
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
@ 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
FieldVector(const DenseVector< C > &x, [[maybe_unused]] 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
static constexpr size_type size()
Definition: fvector.hh:189
const K & operator[](size_type i) const
Definition: fvector.hh:195
value_type & reference
The type used for references to the vector entry.
Definition: fvector.hh:109
K * data() noexcept
return pointer to underlying array
Definition: fvector.hh:201
Base::value_type value_type
Definition: fvector.hh:106
K & operator[](size_type i)
Definition: fvector.hh:191
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:43
std::array< K, SIZE > container_type
Definition: fvector.hh:42
container_type::size_type size_type
Definition: fvector.hh:44
FieldVector< K, SIZE > derived_type
Definition: fvector.hh:41
FieldTraits< K >::real_type real_type
Definition: fvector.hh:51
FieldTraits< K >::field_type field_type
Definition: fvector.hh:50
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
Definition: matvectraits.hh:29
Helper class for tagging priorities.
Definition: typeutilities.hh:71