46template <
typename T,
unsigned D>
49 std::array<T,D> _data;
78 template <
typename W,
typename IMPL>
81 for (
unsigned iDim=0; iDim < D; ++iDim) {
82 _data[iDim] = rhs[iDim];
86 template <
typename... I,
87 typename std::enable_if_t< (
sizeof...(I) > 1
89 &&
sizeof...(I) == D),
int> = 0>
98 for (
unsigned iDim=0; iDim < D; ++iDim) {
99 _data[iDim] =
static_cast<T
>(v[iDim]);
104 constexpr Vector(
const std::vector<T>& v)
107 for (
unsigned iDim=0; iDim < D; ++iDim) {
108 _data[iDim] = v[iDim];
112 #ifndef __CUDA_ARCH__
113 constexpr Vector(std::initializer_list<T> v)
116 std::copy(v.begin(), v.end(), _data.begin());
122 for (
unsigned iDim=0; iDim < D; ++iDim) {
123 _data[iDim] = scalar;
128 template <typename F, typename = decltype(std::declval<F&>()(std::size_t{0}))>
131 for (
unsigned iDim=0; iDim < D; ++iDim) {
132 _data[iDim] = f(iDim);
136 template <
typename U,
typename IMPL_>
139 for (
unsigned iDim=0; iDim < D; ++iDim) {
147 for (
unsigned iDim=0; iDim < D; ++iDim) {
148 _data[iDim] = rhs[iDim];
155 for (
unsigned iDim=0; iDim < D; ++iDim) {
156 _data[iDim] = rhs[iDim];
173 return _data.begin();
190 for (
unsigned iDim=0; iDim < D; ++iDim) {
191 tmp[iDim+1] = _data[iDim];
199 return D *
sizeof(T);
201 bool*
getBlock(std::size_t iBlock, std::size_t& sizeBlock,
bool loadingMode)
203 std::size_t currentBlock = 0;
204 bool* dataPtr =
nullptr;
206 if (iBlock == currentBlock) {
207 sizeBlock =
sizeof(T) * D;
208 dataPtr = (
bool*) _data.data();
216template <
typename T,
typename IMPL,
typename IMPL_>
220 return (a[0]*b[1] - a[1]*b[0]);
223template <
typename T,
typename IMPL,
typename IMPL_>
228 a[1]*b[2] - a[2]*b[1],
229 a[2]*b[0] - a[0]*b[2],
230 a[0]*b[1] - a[1]*b[0]
234template <
typename T,
unsigned D,
typename IMPL,
typename IMPL_>
236 static_assert((D==2 || D==3),
"ERROR: Unknown dimension!");
244template <
typename T,
unsigned D,
typename IMPL>
247 T invScale (scale /
norm(a));
248 return Vector<T,D>([invScale,&a](
unsigned iDim) -> T {
249 return a[iDim] * invScale;
253template <
typename T,
unsigned D,
typename IMPL>
256 using namespace util;
263template <
typename T,
unsigned D,
typename U,
typename IMPL>
264constexpr meta::enable_if_arithmetic_t<U, Vector<T,D>>
270template <
typename T,
unsigned D,
typename U,
typename IMPL>
271constexpr meta::enable_if_arithmetic_t<U, Vector<T,D>>
277template <
typename T,
unsigned D,
typename IMPL,
typename IMPL_>
284template <
typename T,
typename W,
unsigned D,
typename IMPL,
typename IMPL_>
285constexpr Vector<
decltype(T{}+W{}),D>
operator+ (
286 const ScalarVector<T,D,IMPL>& a,
const ScalarVector<W,D,IMPL_>& b)
any_platform
288 Vector<
decltype(T{}+W{}),D> result;
289 for (
unsigned iDim=0; iDim < D; ++iDim) {
290 result[iDim] = a[iDim] + b[iDim];
295template <
typename T,
unsigned D,
typename U,
typename IMPL>
296constexpr meta::enable_if_arithmetic_t<U, Vector<T,D>>
302template <
typename T,
unsigned D,
typename U,
typename IMPL>
303constexpr meta::enable_if_arithmetic_t<U, Vector<T,D>>
309template <
typename T,
unsigned D,
typename IMPL,
typename IMPL_>
316template <
typename T,
typename W,
unsigned D,
typename IMPL,
typename IMPL_>
317constexpr Vector<
decltype(T{}-W{}),D>
operator- (
318 const ScalarVector<T,D,IMPL>& a,
const ScalarVector<W,D,IMPL_>& b)
any_platform
320 Vector<
decltype(T{}-W{}),D> result;
321 for (
unsigned iDim=0; iDim < D; ++iDim) {
322 result[iDim] = a[iDim] - b[iDim];
327template <
typename T,
unsigned D,
typename U,
typename IMPL>
331 Vector<
decltype(T{}*U{}),D> result(b);
335template <
typename T,
unsigned D,
typename U,
typename IMPL>
339 Vector<
decltype(T{}*U{}),D> result(a);
344template <
typename T,
typename U,
unsigned D,
typename IMPL,
typename IMPL_>
348 decltype(T{}*U{}) scalarProduct{};
349 for (
unsigned iDim=0; iDim < D; ++iDim) {
350 scalarProduct += a[iDim] * b[iDim];
352 return scalarProduct;
355template <
typename T,
unsigned D,
typename U,
typename IMPL>
356constexpr meta::enable_if_arithmetic_t<U, Vector<T,D>>
362template<
typename T,
unsigned D,
typename U,
typename IMPL>
369template<
typename T,
unsigned D,
typename U,
typename IMPL>
370constexpr meta::enable_if_arithmetic_t<U, bool>
376template<
typename T,
unsigned D,
typename U,
typename IMPL>
383template<
typename T,
unsigned D,
typename U,
typename IMPL>
384constexpr meta::enable_if_arithmetic_t<U, bool>
390template <
typename T,
unsigned D,
typename IMPL,
typename IMPL_>
399template <
typename T,
unsigned D,
typename IMPL,
typename IMPL_>
constexpr Vector< T, D+1 > withPrefix(T prefix) const any_platform
constexpr Vector() any_platform
constexpr Vector(F &&f) any_platform
Construct with entries given by a lambda expression.
constexpr const T * data() const any_platform
constexpr std::size_t getNblock() const
constexpr Vector(const std::vector< T > &v)
bool * getBlock(std::size_t iBlock, std::size_t &sizeBlock, bool loadingMode)
constexpr Vector(I... indexes) any_platform
constexpr Vector & operator=(const GenericVector< U, D, IMPL_ > &rhs) any_platform
constexpr T * data() any_platform
constexpr int getDim() const any_platform
constexpr Vector(std::initializer_list< T > v)
constexpr const T * getComponentPointer(unsigned iDim) const any_platform
constexpr Vector(const Vector &rhs) any_platform
constexpr std::size_t getSerializableSize() const
constexpr Vector(const U *v) any_platform
constexpr Vector(T scalar) any_platform
constexpr Vector(Vector &&rhs) any_platform
constexpr Vector(const ScalarVector< W, D, IMPL > &rhs) any_platform
constexpr T * getComponentPointer(unsigned iDim) any_platform
cpu::simd::Pack< T > min(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
cpu::simd::Pack< T > max(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
Top level namespace for all of OpenLB.
constexpr Vector< T, D > minv(const ScalarVector< T, D, IMPL > &v, const ScalarVector< T, D, IMPL_ > &w)
constexpr meta::enable_if_arithmetic_t< U, Vector< T, D > > operator-(U a, const ScalarVector< T, D, IMPL > &b) any_platform
constexpr bool operator<(const ScalarVector< T, D, IMPL > &lhs, const ScalarVector< U, D, IMPL_ > &rhs)
Returns true if all lhs components are smaller than rhs.
std::enable_if_t< std::is_arithmetic< T >::type::value, T > abs(T x)
constexpr bool operator>=(const ScalarVector< T, D, IMPL > &lhs, const ScalarVector< U, D, IMPL_ > &rhs)
Returns true if all lhs components are smaller or equal than rhs.
constexpr Vector< T, D > maxv(const ScalarVector< T, D, IMPL > &v, const ScalarVector< T, D, IMPL_ > &w)
constexpr T norm(const ScalarVector< T, D, IMPL > &a)
Euclidean vector norm.
auto crossProduct(const ScalarVector< T, D, IMPL > &a, const ScalarVector< T, D, IMPL_ > &b)
constexpr T crossProduct2D(const ScalarVector< T, 2, IMPL > &a, const ScalarVector< T, 2, IMPL_ > &b)
constexpr meta::enable_if_arithmetic_t< U, Vector< T, D > > operator+(U a, const ScalarVector< T, D, IMPL > &b) any_platform
constexpr meta::enable_if_arithmetic_t< U, Vector< decltype(T{} *U{}), D > > operator*(U a, const ScalarVector< T, D, IMPL > &b) any_platform
constexpr meta::enable_if_arithmetic_t< U, Vector< T, D > > operator/(const ScalarVector< T, D, IMPL > &a, U b) any_platform
constexpr Vector< T, 3 > crossProduct3D(const ScalarVector< T, 3, IMPL > &a, const ScalarVector< T, 3, IMPL_ > &b) any_platform
constexpr bool operator>(const ScalarVector< T, D, IMPL > &lhs, const ScalarVector< U, D, IMPL_ > &rhs)
Returns true if all lhs components are greater than rhs.
constexpr Vector< T, D > normalize(const ScalarVector< T, D, IMPL > &a, T scale=T{1})
constexpr bool operator<=(const ScalarVector< T, D, IMPL > &lhs, const ScalarVector< U, D, IMPL_ > &rhs)
Returns true if all lhs components are smaller or equal than rhs.
#define OLB_PRECONDITION(COND)
Generic vector of values supporting basic arithmetic.
constexpr const T & operator[](unsigned iDim) const any_platform
GenericVector< T, D, Vector< T, D > > type