5 #ifndef DUNE_COMMON_FVECTOR_HH 6 #define DUNE_COMMON_FVECTOR_HH 14 #include <type_traits> 16 #include <initializer_list> 41 template<
class K,
int SIZE >
class FieldVector;
42 template<
class K,
int SIZE >
48 typedef typename container_type::size_type
size_type;
51 template<
class K,
int SIZE >
66 template<
typename C,
int SIZE>
73 constexpr
static bool value =
true;
76 template<
typename T,
int SIZE>
79 constexpr
static bool value =
true;
82 template<
typename T,
int SIZE,
int SIZE1>
85 constexpr
static bool value =
false;
94 template<
class K,
int SIZE >
101 std::array<K,SIZE> _data;
124 noexcept(
std::is_nothrow_default_constructible_v<K>)
131 : _data{filledArray<SIZE>(value)}
135 template<Concept::Number S>
136 requires (std::constructible_from<K,S>)
139 noexcept(std::is_nothrow_constructible_v<K,S>)
140 : _data{filledArray<SIZE,K>(K(scalar))}
144 constexpr
FieldVector (
const std::initializer_list<K>& l)
147 assert(l.size() ==
size());
149 _data[
i] = std::data(l)[
i];
155 std::is_assignable_v<K&, decltype(std::declval<const V&>()[0])>)
158 assert(x.size() ==
size());
164 template<
class OtherK>
165 requires (std::is_assignable_v<K&, const OtherK&>)
166 explicit constexpr
FieldVector (
const FieldVector<OtherK, SIZE>& x)
167 noexcept(std::is_nothrow_assignable_v<K&, const OtherK&>)
180 std::is_assignable_v<K&, decltype(std::declval<const V&>()[0])>)
183 assert(x.size() ==
size());
190 template<Concept::Number S>
191 requires std::constructible_from<K,S>
193 noexcept(std::is_nothrow_constructible_v<K,S>)
195 _data.fill(K(scalar));
200 template<
class OtherK>
201 requires (std::is_assignable_v<K&, const OtherK&>)
203 noexcept(std::is_nothrow_assignable_v<K&, const OtherK&>)
253 constexpr
const K*
data () const noexcept
279 template<Concept::Number S>
283 return a._data[0] == b;
287 template<Concept::Number S>
291 return a == b._data[0];
296 requires (Std::three_way_comparable_with<K,T>)
297 friend constexpr
auto operator<=> (
const FieldVector& a,
const FieldVector<T,SIZE>& b) noexcept
299 #if __cpp_lib_three_way_comparison 300 return a._data <=> b._data;
307 template<Concept::Number S>
308 friend constexpr
auto operator<=> (
const FieldVector& a,
const S& b) noexcept
311 return a._data[0] <=> b;
315 template<Concept::Number S>
316 friend constexpr
auto operator<=> (
const S& a,
const FieldVector& b) noexcept
319 return a <=> b._data[0];
329 template<Concept::Number S>
333 FieldVector<ResultValueType,dimension> result;
335 result[
i] = a[
i] * b;
340 template<Concept::Number S>
344 FieldVector<ResultValueType,dimension> result;
346 result[
i] = a * b[
i];
351 template<Concept::Number S>
355 FieldVector<ResultValueType,dimension> result;
357 result[
i] = a[
i] / b;
362 template<Concept::Number S>
370 template<Concept::Number S>
375 return FieldVector<ResultValueType,dimension>{a[0] + b};
379 template<Concept::Number S>
384 return FieldVector<ResultValueType,dimension>{a + b[0]};
388 template<Concept::Number S>
393 return FieldVector<ResultValueType,dimension>{a[0] - b};
397 template<Concept::Number S>
402 return FieldVector<ResultValueType,dimension>{a - b[0]};
419 template<
class K,
int SIZE>
423 for (
int i = 0;
i < SIZE; ++
i)
431 namespace MathOverloads {
434 template<
class K,
int SIZE>
438 for (
int i = 0;
i < SIZE; ++
i) {
445 template<
class K,
int SIZE>
449 for (
int i = 0;
i < SIZE; ++
i) {
456 template<
class K,
int SIZE,
457 std::enable_if_t<HasNaN<K>::value,
int> = 0>
461 for (
int i = 0;
i < SIZE; ++
i) {
469 std::enable_if_t<HasNaN<K>::value,
int> = 0>
482 #endif // DUNE_COMMON_FVECTOR_HH constexpr bool operator==(const DenseVector< Other > &x) const
Binary vector comparison.
Definition: densevector.hh:570
Type traits to determine the type of reals (when working with complex numbers)
Implements the dense vector interface, with an exchangeable storage class.
auto isFinite(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Returns whether all entries are finite.
Definition: fvector.hh:435
decltype(std::declval< T1 >()+std::declval< T2 >()) typedef PromotedType
Definition: promotiontraits.hh:28
bool isNaN(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Returns whether any entry is NaN.
Definition: fvector.hh:458
Utility to generate an array with a certain value.
bool isUnordered(const FieldVector< K, 1 > &b, const FieldVector< K, 1 > &c, PriorityTag< 2 >, ADLTag)
Returns true if either b or c is NaN.
Definition: fvector.hh:470
This file provides some concepts introduced in the C++20 standard library <compare> and <concepts> no...
Some useful basic math stuff.
std::istream & operator>>(std::istream &stream, std::tuple< Ts... > &t)
Read a std::tuple.
Definition: streamoperators.hh:43
constexpr auto lexicographical_compare_three_way(I1 f1, I1 l1, I2 f2, I2 l2, Cmp comp={}) -> decltype(comp(*f1, *f2))
Lexicographically compares two ranges [first1, last1) and [first2, last2) using three-way comparison ...
Definition: algorithm.hh:37
constexpr DenseVector()=default
constexpr derived_type operator+(const DenseVector< Other > &b) const
Binary vector addition.
Definition: densevector.hh:454
constexpr FieldVector() noexcept(std::is_nothrow_default_constructible_v< K >)
Default constructor, making value-initialized vector with all components set to zero.
Definition: fvector.hh:123
value_type & reference
The type used for references to the vector entries.
Definition: fvector.hh:115
container_type::size_type size_type
Definition: fvector.hh:48
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:30
Definition: matvectraits.hh:31
static constexpr int dimension
The size of this vector.
Definition: fvector.hh:106
constexpr PromotionTraits< field_type, typename DenseVector< Other >::field_type >::PromotedType operator*(const DenseVector< Other > &x) const
indefinite vector dot product which corresponds to Petsc's VecTDot
Definition: densevector.hh:606
I i
Definition: hybridmultiindex.hh:328
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:30
typename Base::value_type value_type
The type of the elements stored in the vector.
Definition: fvector.hh:112
static constexpr bool value
True if C is not of type FieldVector or its dimension is not equal SIZE.
Definition: fvector.hh:73
Macro for wrapping boundary checks.
FieldTraits< K >::real_type real_type
Definition: fvector.hh:55
std::array< K, SIZE > container_type
Definition: fvector.hh:46
FieldVector< K, SIZE > derived_type
Definition: fvector.hh:45
Tag to make sure the functions in this namespace can be found by ADL.
Definition: math.hh:212
Dune namespace
Definition: alignedallocator.hh:12
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densevector.hh:274
Utilities for type computations, constraining overloads, ...
Interface for a class of dense vectors over a given field.
Definition: densevector.hh:23
const value_type & const_reference
The type used for const references to the vector entries.
Definition: fvector.hh:118
vector space out of a tensor product of fields.
Definition: densematrix.hh:40
bigunsignedint< k > operator/(const bigunsignedint< k > &x, std::uintmax_t y)
Definition: bigunsignedint.hh:579
Compute type of the result of an arithmetic operation involving two different number types...
Definition: ftraits.hh:25
constexpr derived_type & operator=(const value_type &k)
Assignment operator for scalar.
Definition: densevector.hh:281
bool isInf(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Returns whether any entry is infinite.
Definition: fvector.hh:446
Helper class for tagging priorities.
Definition: typeutilities.hh:72
T field_type
export the type representing the field
Definition: ftraits.hh:28
constexpr K * data() noexcept
Return pointer to underlying array.
Definition: fvector.hh:247
constexpr derived_type operator-() const
Vector negation.
Definition: densevector.hh:469
TMP to check the size of a DenseVectors statically, if possible.
Definition: fvector.hh:67
Traits for type conversions and type information.
K value_type
Definition: fvector.hh:47
Traits::value_type value_type
export the type representing the field
Definition: densevector.hh:265
typename Base::size_type size_type
The type used for the index access and size operation.
Definition: fvector.hh:109
constexpr const K * data() const noexcept
Return pointer to underlying array.
Definition: fvector.hh:253
requires(std::constructible_from< K, S >) explicit(SIZE !
Constructor with a given scalar initializing all entries to this value.
FieldTraits< K >::field_type field_type
Definition: fvector.hh:54
static constexpr size_type size() noexcept
Obtain the number of elements stored in the vector.
Definition: fvector.hh:218
constexpr reference operator[](size_type i)
Return a reference to the ith element.
Definition: fvector.hh:230