diff options
author | Adrian Kummerlaender | 2018-03-31 18:09:09 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2018-03-31 18:09:09 +0200 |
commit | 1a30c8427f7711064462ee436de614f90dbad002 (patch) | |
tree | c5819a35c53af3f84d0f3c1eff3ce43b532e2bea /src | |
parent | c753dbb064a90d140a5a4ec2b970c9a1d4af91be (diff) | |
download | boltzbub-1a30c8427f7711064462ee436de614f90dbad002.tar boltzbub-1a30c8427f7711064462ee436de614f90dbad002.tar.gz boltzbub-1a30c8427f7711064462ee436de614f90dbad002.tar.bz2 boltzbub-1a30c8427f7711064462ee436de614f90dbad002.tar.lz boltzbub-1a30c8427f7711064462ee436de614f90dbad002.tar.xz boltzbub-1a30c8427f7711064462ee436de614f90dbad002.tar.zst boltzbub-1a30c8427f7711064462ee436de614f90dbad002.zip |
Fix and improve wall handling
Use three neighbor cells for bounceback instead of three directions of a single cell.
Generalize neighbor cell determination using normal vector of wall.
Diffstat (limited to 'src')
-rw-r--r-- | src/vector.h | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/vector.h b/src/vector.h index 55c7663..e0dc239 100644 --- a/src/vector.h +++ b/src/vector.h @@ -4,41 +4,43 @@ inline double sq(double x) noexcept { return x * x; } +template <typename T> struct Vector { - double data[2]; + T data[2]; - double comp(int x, int y) const { + T comp(int x, int y) const { return x*data[0] + y*data[1]; } - double norm() const { + T norm() const { return std::sqrt(sq(data[0]) + sq(data[1])); } - double& operator[](std::size_t i) { + T& operator[](std::size_t i) { return data[i]; } - double operator[](std::size_t i) const { + T operator[](std::size_t i) const { return data[i]; } - Vector operator*(double scalar) const { - return Vector{ + Vector<T> operator*(T scalar) const { + return Vector<T>{ data[0] * scalar, data[1] * scalar }; } - Vector& operator+=(const Vector& rhs) { + Vector<T>& operator+=(const Vector<T>& rhs) { data[0] += rhs[0]; data[1] += rhs[1]; return *this; } }; -Vector operator*(double scalar, const Vector& vec) { - return Vector{ +template <typename T> +Vector<T> operator*(T scalar, const Vector<T>& vec) { + return Vector<T>{ vec[0] * scalar, vec[1] * scalar }; |