47template <
typename T,
unsigned D>
48class Vector :
public ScalarVector<T,D,Vector<T,D>> {
50 std::array<T,D> _data;
71 template <
typename W,
typename IMPL>
74 for (
unsigned iDim=0; iDim < D; ++iDim) {
75 _data[iDim] = rhs[iDim];
79 template <
typename... I,
80 typename std::enable_if_t< (
sizeof...(I) > 1
82 &&
sizeof...(I) == D),
int> = 0>
91 for (
unsigned iDim=0; iDim < D; ++iDim) {
92 _data[iDim] =
static_cast<T
>(v[iDim]);
99 for (
unsigned iDim=0; iDim < D; ++iDim) {
100 _data[iDim] = ref[iDim][idx];
105 constexpr Vector(
const std::vector<T>& v)
108 for (
unsigned iDim=0; iDim < D; ++iDim) {
109 _data[iDim] = v[iDim];
113 #ifndef __CUDA_ARCH__
114 constexpr Vector(std::initializer_list<T> v)
117 std::copy(v.begin(), v.end(), _data.begin());
123 for (
unsigned iDim=0; iDim < D; ++iDim) {
124 _data[iDim] = scalar;
129 template <typename F, typename = decltype(std::declval<F&>()(std::size_t{0}))>
132 for (
unsigned iDim=0; iDim < D; ++iDim) {
133 _data[iDim] = f(iDim);
147 template <
typename U,
typename IMPL_>
150 for (
unsigned iDim=0; iDim < D; ++iDim) {
158 for (
unsigned iDim=0; iDim < D; ++iDim) {
159 _data[iDim] = rhs[iDim];
166 for (
unsigned iDim=0; iDim < D; ++iDim) {
167 _data[iDim] = rhs[iDim];
184 return _data.begin();
202 for (
unsigned iDim=0; iDim < D; ++iDim) {
203 tmp[iDim+1] = _data[iDim];
212 for (
unsigned iDim=1; iDim < D; ++iDim) {
213 tmp[iDim-1] = _data[iDim];
219 template <
unsigned E>
223 for (
unsigned iDim=0; iDim < D; ++iDim) {
224 tmp[iDim] = _data[iDim];
226 for (
unsigned iDim=0; iDim < E; ++iDim) {
227 tmp[iDim+D] = rhs[iDim];
235 return D *
sizeof(T);
237 bool*
getBlock(std::size_t iBlock, std::size_t& sizeBlock,
bool loadingMode)
239 std::size_t currentBlock = 0;
240 bool* dataPtr =
nullptr;
242 if (iBlock == currentBlock) {
243 sizeBlock =
sizeof(T) * D;
244 dataPtr = (
bool*) _data.data();
252template <
typename T,
typename... Ts>
255template <
typename T,
typename IMPL,
typename IMPL_>
259 return (a[0]*b[1] - a[1]*b[0]);
262template <
typename T,
typename IMPL,
typename IMPL_>
267 a[1]*b[2] - a[2]*b[1],
268 a[2]*b[0] - a[0]*b[2],
269 a[0]*b[1] - a[1]*b[0]
273template <
typename T,
unsigned D,
typename IMPL,
typename IMPL_>
275 static_assert((D==2 || D==3),
"ERROR: Unknown dimension!");
283template <
typename T,
unsigned D,
typename IMPL>
286 T invScale (scale /
norm(a));
287 return Vector<T,D>([invScale,&a](
unsigned iDim) -> T {
288 return a[iDim] * invScale;
292template <
typename T,
unsigned D,
typename IMPL>
295 using namespace util;
301template <
typename T,
unsigned D,
typename IMPL>
309template <
typename T,
unsigned D,
typename U,
typename IMPL>
316template <
typename T,
unsigned D,
typename U,
typename IMPL>
323template <
typename T,
unsigned D,
typename IMPL,
typename IMPL_>
330template <
typename T,
typename W,
unsigned D,
typename IMPL,
typename IMPL_>
331constexpr Vector<
decltype(T{}+W{}),D>
operator+ (
332 const ScalarVector<T,D,IMPL>& a,
const ScalarVector<W,D,IMPL_>& b)
any_platform
334 Vector<
decltype(T{}+W{}),D> result;
335 for (
unsigned iDim=0; iDim < D; ++iDim) {
336 result[iDim] = a[iDim] + b[iDim];
341template <
typename T,
unsigned D,
typename U,
typename IMPL>
348template <
typename T,
unsigned D,
typename U,
typename IMPL>
355template <
typename T,
unsigned D,
typename IMPL,
typename IMPL_>
362template <
typename T,
typename W,
unsigned D,
typename IMPL,
typename IMPL_>
363constexpr Vector<
decltype(T{}-W{}),D>
operator- (
364 const ScalarVector<T,D,IMPL>& a,
const ScalarVector<W,D,IMPL_>& b)
any_platform
366 Vector<
decltype(T{}-W{}),D> result;
367 for (
unsigned iDim=0; iDim < D; ++iDim) {
368 result[iDim] = a[iDim] - b[iDim];
373template <
typename T,
unsigned D,
typename U,
typename IMPL>
377 Vector<
decltype(T{}*U{}),D> result(b);
381template <
typename T,
unsigned D,
typename U,
typename IMPL>
385 Vector<
decltype(T{}*U{}),D> result(a);
390template <
typename T,
typename U,
unsigned D,
typename IMPL,
typename IMPL_>
394 decltype(T{}*U{}) scalarProduct{};
395 for (
unsigned iDim=0; iDim < D; ++iDim) {
396 scalarProduct += a[iDim] * b[iDim];
398 return scalarProduct;
401template <
typename T,
unsigned D,
typename U,
typename IMPL>
408template <
typename T,
unsigned D,
typename U,
typename IMPL>
413 for (
unsigned iDim=0; iDim < D; ++iDim) {
414 r[iDim] = a[iDim] % b;
419template<
typename T,
unsigned D,
typename U,
typename IMPL>
426template<
typename T,
unsigned D,
typename U,
typename IMPL>
433template<
typename T,
unsigned D,
typename U,
typename IMPL>
440template<
typename T,
unsigned D,
typename U,
typename IMPL>
447template <
typename T,
unsigned D,
typename IMPL,
typename IMPL_>
456template <
typename T,
unsigned D,
typename IMPL,
typename IMPL_>
465template <
typename T,
unsigned D,
typename IMPL>
469 for (
unsigned iD=1; iD < D; ++iD) {
479template<
typename T,
typename DESCRIPTOR,
typename FIELD>
481 typename FIELD::template value_type<T>,
482 DESCRIPTOR::template size<FIELD>()
constexpr int getDim() const any_platform
constexpr Vector(const std::vector< T > &v)
constexpr Vector & operator=(const GenericVector< U, D, IMPL_ > &rhs) any_platform
constexpr Vector(const ScalarVector< W, D, IMPL > &rhs) any_platform
constexpr const T * data() const any_platform
constexpr Vector(const Vector< T *, D > &ref, std::size_t idx) any_platform
Construct from Structure-of-Arrays addresses given by ref and index idx.
constexpr const T * getComponentPointer(unsigned iDim) const any_platform
constexpr std::size_t getSerializableSize() const
constexpr Vector(F &&f) any_platform
Construct with entries given by a lambda expression.
constexpr Vector(Vector &&rhs) any_platform
constexpr std::size_t getNblock() const
constexpr Vector(I... indexes) any_platform
constexpr Vector() any_platform
bool * getBlock(std::size_t iBlock, std::size_t &sizeBlock, bool loadingMode)
constexpr Vector(std::initializer_list< T > v)
constexpr Vector< T, D+E > append(const Vector< T, E > &rhs) const any_platform
Return new (this..., rhs...) vector.
constexpr Vector(const Vector &rhs) any_platform
constexpr Vector(T scalar) any_platform
constexpr Vector(const U *v) any_platform
Construct from Array-of-Structures element at v.
constexpr Vector< T, D+1 > withPrefix(T prefix) const any_platform
Return new (prefix,this...) vector.
constexpr T * data() any_platform
constexpr T * getComponentPointer(unsigned iDim) any_platform
constexpr Vector< T, D-1 > withoutPrefix() const any_platform
Return vector without first element.
ADf< T, DIM > round(const ADf< T, DIM > &a)
Top level namespace for all of OpenLB.
constexpr Vector< T, D > minv(const ScalarVector< T, D, IMPL > &v, const ScalarVector< T, D, IMPL_ > &w)
bool operator>=(const Expr &rhs, const Expr &lhs)
Expr operator/(Expr lhs, Expr rhs)
bool operator>(const Expr &rhs, const Expr &lhs)
bool operator<=(const Expr &rhs, const Expr &lhs)
Vector(T &&t, Ts &&... ts) -> Vector< std::remove_cvref_t< T >, 1+sizeof...(Ts)>
constexpr T max(const ScalarVector< T, D, IMPL > &v)
Expr operator*(Expr lhs, Expr rhs)
Expr operator%(Expr lhs, int rhs)
constexpr Vector< T, D > maxv(const ScalarVector< T, D, IMPL > &v, const ScalarVector< T, D, IMPL_ > &w)
Expr operator+(Expr lhs, Expr rhs)
constexpr T crossProduct2D(const ScalarVector< T, 2, IMPL > &a, const ScalarVector< T, 2, IMPL_ > &b)
constexpr Vector< T, D > round(const ScalarVector< T, D, IMPL > &a) any_platform
std::enable_if_t< std::is_arithmetic< T >::type::value, T > abs(T x) any_platform
Expr operator-(Expr lhs, Expr rhs)
auto crossProduct(const ScalarVector< T, D, IMPL > &a, const ScalarVector< T, D, IMPL_ > &b) any_platform
constexpr T norm(const ScalarVector< T, D, IMPL > &a) any_platform
Euclidean vector norm.
bool operator<(const Expr &rhs, const Expr &lhs)
constexpr Vector< T, 3 > crossProduct3D(const ScalarVector< T, 3, IMPL > &a, const ScalarVector< T, 3, IMPL_ > &b) any_platform
constexpr Vector< T, D > normalize(const ScalarVector< T, D, IMPL > &a, T scale=T{1})
#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
constexpr ScalarVector()=default