5 #ifndef DUNE_FVECTOR_HH
6 #define DUNE_FVECTOR_HH
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);
129 assert(l.size() == dimension);
130 for(std::size_t i=0; i<std::min(static_cast<std::size_t>(dimension), l.size()); ++i)
131 _data[i] = std::data(l)[i];
137 template <
typename T>
140 std::copy_n(x.
begin(), SIZE, _data.begin());
144 template<
typename T,
int N>
163 assert(x.
size() == SIZE);
164 std::copy_n(x.
begin(),
std::min(
static_cast<std::size_t
>(SIZE),x.
size()), _data.begin());
171 std::copy_n(x.
begin(), SIZE, _data.begin());
174 template<
typename T,
int N>
177 using Base::operator=;
180 static constexpr size_type size () {
return SIZE; }
182 K & operator[](size_type i) {
186 const K & operator[](size_type i)
const {
205 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
210 for (size_type i = 0; i < vector.size(); ++i)
211 result[i] = vector[i] * scalar;
218 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
223 for (size_type i = 0; i < vector.size(); ++i)
224 result[i] = scalar * vector[i];
231 std::enable_if_t<IsNumber<Scalar>::value,
int> = 0>
236 for (size_type i = 0; i < vector.size(); ++i)
237 result[i] = vector[i] / scalar;
255 template<
class K,
int SIZE>
260 for(
typename FieldVector<K, SIZE>::size_type i = 0; i < SIZE; ++i )
272 typedef K container_type;
273 typedef K value_type;
274 typedef size_t size_type;
280 class FieldVector<K, 1> :
281 public DenseVector< FieldVector<K,1> >
284 typedef DenseVector< FieldVector<K,1> > Base;
287 constexpr
static int dimension = 1;
289 typedef typename Base::size_type size_type;
292 typedef K& reference;
295 typedef const K& const_reference;
300 constexpr FieldVector ()
306 typename EnableIf =
typename std::enable_if<
307 std::is_convertible<T, K>::value &&
308 ! std::is_base_of<DenseVector<typename FieldTraits<T>::field_type>, K
312 FieldVector (
const T& k) : _data(k) {}
317 std::is_assignable<K&, typename DenseVector<C>::value_type>::value,
int> = 0>
318 FieldVector (
const DenseVector<C> & x)
320 static_assert(((
bool)IsFieldVectorSizeCorrect<C,1>::value),
"FieldVectors do not match in dimension!");
321 assert(x.size() == 1);
326 FieldVector(
const FieldVector&) =
default;
329 FieldVector& operator=(
const FieldVector&) =
default;
331 template <
typename T>
332 FieldVector& operator= (
const FieldVector<T, 1>& other)
338 template<
typename T,
int N>
339 FieldVector& operator=(
const FieldVector<T, N>&) =
delete;
342 FieldVector (std::initializer_list<K>
const &l)
344 assert(l.size() == 1);
350 typename EnableIf =
typename std::enable_if<
351 std::is_assignable<K&, T>::value &&
352 ! std::is_base_of<DenseVector<typename FieldTraits<T>::field_type>, K
356 inline FieldVector& operator= (
const T& k)
363 static constexpr size_type size () {
return 1; }
365 K & operator[]([[maybe_unused]] size_type i)
370 const K & operator[]([[maybe_unused]] size_type i)
const
383 const K* data() const noexcept
391 operator K& () {
return _data; }
394 operator const K& ()
const {
return _data; }
402 inline bool operator> (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
409 inline bool operator>= (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
416 inline bool operator< (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
423 inline bool operator<= (
const FieldVector<K,1>& a,
const FieldVector<K,1>& b)
432 inline FieldVector<K,1> operator+ (
const FieldVector<K,1>& a,
const K b)
439 inline FieldVector<K,1> operator- (
const FieldVector<K,1>& a,
const K b)
446 inline FieldVector<K,1> operator* (
const FieldVector<K,1>& a,
const K b)
453 inline FieldVector<K,1> operator/ (
const FieldVector<K,1>& a,
const K b)
460 inline bool operator> (
const FieldVector<K,1>& a,
const K b)
467 inline bool operator>= (
const FieldVector<K,1>& a,
const K b)
474 inline bool operator< (
const FieldVector<K,1>& a,
const K b)
481 inline bool operator<= (
const FieldVector<K,1>& a,
const K b)
488 inline bool operator== (
const FieldVector<K,1>& a,
const K b)
495 inline bool operator!= (
const FieldVector<K,1>& a,
const K b)
504 inline FieldVector<K,1> operator+ (
const K a,
const FieldVector<K,1>& b)
511 inline FieldVector<K,1> operator- (
const K a,
const FieldVector<K,1>& b)
518 inline FieldVector<K,1> operator* (
const K a,
const FieldVector<K,1>& b)
525 inline FieldVector<K,1> operator/ (
const K a,
const FieldVector<K,1>& b)
532 inline bool operator> (
const K a,
const FieldVector<K,1>& b)
539 inline bool operator>= (
const K a,
const FieldVector<K,1>& b)
546 inline bool operator< (
const K a,
const FieldVector<K,1>& b)
553 inline bool operator<= (
const K a,
const FieldVector<K,1>& b)
560 inline bool operator== (
const K a,
const FieldVector<K,1>& b)
567 inline bool operator!= (
const K a,
const FieldVector<K,1>& b)
574 namespace MathOverloads {
577 template<
class K,
int SIZE>
580 for(
int i=0; i<SIZE; i++) {
581 out &= Dune::isFinite(b[i]);
587 template<
class K,
int SIZE>
590 for(
int i=0; i<SIZE; i++) {
591 out |= Dune::isInf(b[i]);
597 template<class K, int SIZE, typename = std::enable_if_t<HasNaN<K>::value>>
600 for(
int i=0; i<SIZE; i++) {
601 out |= Dune::isNaN(b[i]);
607 template<class K, typename = std::enable_if_t<HasNaN<K>::value>>
610 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
const K * data() const 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
constexpr static int dimension
The size of this vector.
Definition: fvector.hh:100
FieldVector(const K &t)
Constructor making vector with identical coordinates.
Definition: fvector.hh:117
FieldVector(const FieldVector< K1, SIZE > &x)
Constructor making vector with identical coordinates.
Definition: fvector.hh:169
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:159
value_type & reference
The type used for references to the vector entry.
Definition: fvector.hh:106
K * data() noexcept
return pointer to underlying array
Definition: fvector.hh:192
constexpr FieldVector(std::initializer_list< K > const &l)
Construct from a std::initializer_list.
Definition: fvector.hh:126
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
constexpr auto min
Function object that returns the smaller of the given values.
Definition: hybridutilities.hh:506
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
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:637
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 RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:660
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
constexpr static 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.