OpenLB 1.7
Loading...
Searching...
No Matches
genericVector.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2020 Adrian Kummerlaender
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24
25#ifndef GENERIC_VECTOR_H
26#define GENERIC_VECTOR_H
27
28#include <type_traits>
29
30#include "meta.h"
31
32namespace olb {
33
34
36template<typename T, unsigned D, typename IMPL>
38 constexpr GenericVector() = default;
39 GenericVector(const GenericVector&) = delete;
41
43
44 using value_type = T;
45 static constexpr unsigned d = D;
46 static constexpr unsigned size() { return D; }
47
48 constexpr const T& operator [] (unsigned iDim) const any_platform
49 {
50 return *static_cast<const IMPL*>(this)->getComponentPointer(iDim);
51 }
52
53 constexpr T& operator [] (unsigned iDim) any_platform
54 {
55 return *static_cast<IMPL*>(this)->getComponentPointer(iDim);
56 }
57
58 template<typename IMPL_>
60 {
61 for (unsigned iDim=0; iDim < D; ++iDim) {
62 operator[](iDim) = rhs[iDim];
63 }
64 return *static_cast<IMPL*>(this);
65 }
66
67 template<typename U, typename IMPL_>
69 {
70 for (unsigned iDim=0; iDim < D; ++iDim) {
71 operator[](iDim) += rhs[iDim];
72 }
73 return *static_cast<IMPL*>(this);
74 }
75
76 template<typename IMPL_>
78 {
79 for (unsigned iDim=0; iDim < D; ++iDim) {
80 operator[](iDim) -= rhs[iDim];
81 }
82 return *static_cast<IMPL*>(this);
83 }
84
85 template<typename U, typename IMPL_>
87 {
88 for (unsigned iDim=0; iDim < D; ++iDim) {
89 operator[](iDim) *= rhs[iDim];
90 }
91 return *static_cast<IMPL*>(this);
92 }
93
94 template<typename U>
96 {
97 for (unsigned iDim=0; iDim < D; ++iDim) {
98 operator[](iDim) += rhs;
99 }
100 return *static_cast<IMPL*>(this);
101 }
102
103 template<typename U>
105 {
106 for (unsigned iDim=0; iDim < D; ++iDim) {
107 operator[](iDim) -= rhs;
108 }
109 return *static_cast<IMPL*>(this);
110 }
111
112 template<typename U>
114 {
115 for (unsigned iDim=0; iDim < D; ++iDim) {
116 operator[](iDim) *= rhs;
117 }
118 return *static_cast<IMPL*>(this);
119 }
120
121 template<typename U>
123 {
124 for (unsigned iDim=0; iDim < D; ++iDim) {
125 operator[](iDim) /= rhs;
126 }
127 return *static_cast<IMPL*>(this);
128 }
129
130
131 template<typename IMPL_>
132 constexpr bool operator == (const GenericVector<T,D,IMPL_>& rhs) const any_platform
133 {
134 bool isEqual = true;
135 for (unsigned iDim=0; iDim < D; ++iDim) {
136 isEqual &= operator[](iDim) == rhs[iDim];
137 }
138 return isEqual;
139 }
140
141 template<typename IMPL_>
142 constexpr bool operator != (const GenericVector<T,D,IMPL_>& rhs) const any_platform
143 {
144 for (unsigned iDim=0; iDim < D; ++iDim) {
145 if (operator[](iDim) != rhs[iDim]) {
146 return true;
147 }
148 }
149 return false;
150 }
151
152};
153
154
155}
156
157#endif
std::enable_if_t< is_arithmetic< T >::type::value, U > enable_if_arithmetic_t
Definition meta.h:121
Top level namespace for all of OpenLB.
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:78
Generic vector of values supporting basic arithmetic.
GenericVector(GenericVector &&)=delete
GenericVector(const GenericVector &)=delete
constexpr const T & operator[](unsigned iDim) const any_platform
constexpr GenericVector()=default
constexpr IMPL & operator*=(const GenericVector< U, D, IMPL_ > &rhs) any_platform
static constexpr unsigned size()
constexpr bool operator!=(const GenericVector< T, D, IMPL_ > &rhs) const any_platform
constexpr IMPL & operator-=(const GenericVector< T, D, IMPL_ > &rhs) any_platform
constexpr bool operator==(const GenericVector< T, D, IMPL_ > &rhs) const any_platform
constexpr IMPL & operator+=(const GenericVector< U, D, IMPL_ > &rhs) any_platform
constexpr meta::enable_if_arithmetic_t< U, IMPL & > operator/=(const U &rhs) any_platform
GenericVector & operator=(GenericVector &&rhs)=delete
static constexpr unsigned d