VM2D 1.14
Vortex methods for 2D flows simulation
Loading...
Searching...
No Matches
Point2D.h
Go to the documentation of this file.
1/*--------------------------------*- VM2D -*-----------------*---------------*\
2| ## ## ## ## #### ##### | | Version 1.14 |
3| ## ## ### ### ## ## ## ## | VM2D: Vortex Method | 2026/03/06 |
4| ## ## ## # ## ## ## ## | for 2D Flow Simulation *----------------*
5| #### ## ## ## ## ## | Open Source Code |
6| ## ## ## ###### ##### | https://www.github.com/vortexmethods/VM2D |
7| |
8| Copyright (C) 2017-2026 I. Marchevsky, K. Sokol, E. Ryatina, A. Kolganova |
9*-----------------------------------------------------------------------------*
10| File name: Point2D.h |
11| Info: Source code of VM2D |
12| |
13| This file is part of VM2D. |
14| VM2D is free software: you can redistribute it and/or modify it |
15| under the terms of the GNU General Public License as published by |
16| the Free Software Foundation, either version 3 of the License, or |
17| (at your option) any later version. |
18| |
19| VM2D is distributed in the hope that it will be useful, but WITHOUT |
20| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
21| FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
22| for more details. |
23| |
24| You should have received a copy of the GNU General Public License |
25| along with VM2D. If not, see <http://www.gnu.org/licenses/>. |
26\*---------------------------------------------------------------------------*/
27
28
40#ifndef POINT2D_H_
41#define POINT2D_H_
42
43#include "numvector.h"
44
45#if defined(__CUDACC__)
46#define HD __host__ __device__
47#else
48#define HD
49#endif
50
51
52namespace VMlib
53{
55 {
57 unsigned int key;
58
61 };
62
63
76 : public numvector<float, 2>
77 {
78 public:
79 HD Point2Df() { };
80
85 data[0] = _r[0];
86 data[1] = _r[1];
87 };
88
92 HD Point2Df(const Point2Df& _r) {
93 data[0] = _r[0];
94 data[1] = _r[1];
95 }
96
97#if !defined(__CUDACC__)
102 Point2Df(const std::initializer_list<float>& z);
103#endif
104
107
112 HD Point2Df rotated(const float angle = 1.5707963267948966192313216916398f) const {
113 Point2Df res;
114 float cosa = cosf(angle);
115 float sina = sinf(angle);
116
117 res[0] = data[0] * cosa - data[1] * sina;
118 res[1] = data[0] * sina + data[1] * cosa;
119 return res;
120 }
121 };
122
123
125 : public numvector<double, 4>
126 {
127 public:
128#if !defined(__CUDACC__)
133 Point4D(const std::initializer_list<double>& z);
134 Point4D() = default;
135#endif
136 };
137
139 : public numvector<double, 2>
140 {
141 public:
143 HD Point2D() { };
144
149 data[0] = _r[0];
150 data[1] = _r[1];
151 };
152
156 HD Point2D(const Point2D& _r) {
157 data[0] = _r[0];
158 data[1] = _r[1];
159 }
160
161#if !defined(__CUDACC__)
166 Point2D(const std::initializer_list<double>& z);
167#endif
168
171
176 HD Point2D rotated(const double angle = 1.5707963267948966) const {
177 Point2D res;
178 double cosa = cos(angle);
179 double sina = sin(angle);
180
181 res[0] = data[0] * cosa - data[1] * sina;
182 res[1] = data[0] * sina + data[1] * cosa;
183 return res;
184 }
185
186 template <char letter>
187 HD static bool cmp(const Point2D& ptA, const Point2D& ptB)
188 {
189 switch (letter)
190 {
191 case 0:
192 case 'x':
193 return (ptA[0] < ptB[0]);
194 case 1:
195 case 'y':
196 return (ptA[1] < ptB[1]);
197 case 'r':
198 return ((ptA[0] * ptA[0] + ptA[1] * ptA[1]) < (ptB[0] * ptB[0] + ptB[1] * ptB[1]));
199 default:
200 throw(-1);
201 return true;
202 }
203 }
204 };
205
206
208 HD inline Point2D multz(const Point2D& a, const Point2D& b)
209 {
210 Point2D result;
211 result[0] = a[0] * b[0] - a[1] * b[1];
212 result[1] = a[1] * b[0] + a[0] * b[1];
213 return result;
214 }
215
217 HD inline Point2D multzA(const Point2D& a, const Point2D& b)
218 {
219 Point2D result;
220 result[0] = a[0] * b[0] + a[1] * b[1];
221 result[1] = a[1] * b[0] - a[0] * b[1];
222 return result;
223 }
224
225
240 struct GeomPoint : public Point2D
241 {
242 //private:
243 std::string type;
244 //public:
245
247
248 GeomPoint(const Point2D& _r, const std::string& _type)
249 : Point2D(_r), type(_type) {
250 }
251
253 };
254
255}//namespace VMlib
256
257using VMlib::Point2D;
258using VMlib::Point4D;
259using VMlib::Point2Df;
261using VMlib::GeomPoint;
262
263
264#endif
265
Point2D(const Point2D &_r)
Конструктор копирования
Definition Point2D.h:156
Point2D()
Пустой конструктор
Definition Point2D.h:143
static bool cmp(const Point2D &ptA, const Point2D &ptB)
Definition Point2D.h:187
~Point2D()
Деструктор
Definition Point2D.h:170
Point2D(const numvector< double, 2 > &_r)
Конструктор и приведение типа из numvector<double, 2>
Definition Point2D.h:148
Point2D rotated(const double angle=1.5707963267948966) const
Поворот вектора на произвольный угол против часовой стрелки (по умолчанию 90 градусов)
Definition Point2D.h:176
Класс, опеделяющий двумерный вектор
Definition Point2D.h:77
Point2Df rotated(const float angle=1.5707963267948966192313216916398f) const
Поворот вектора на произвольный угол против часовой стрелки (по умолчанию 90 градусов)
Definition Point2D.h:112
~Point2Df()
Деструктор
Definition Point2D.h:106
Point2Df(const numvector< float, 2 > &_r)
Конструктор и приведение типа из numvector<double, 2>
Definition Point2D.h:84
Point2Df(const Point2Df &_r)
Конструктор копирования
Definition Point2D.h:92
Point4D()=default
Шаблонный класс, определяющий вектор фиксированной длины Фактически представляет собой массив,...
Definition numvector.h:99
Point2D multz(const Point2D &a, const Point2D &b)
Умножение комплексных чисел
Definition Point2D.h:208
Point2D multzA(const Point2D &a, const Point2D &b)
Умножение a на комплексно сопряженноe к b.
Definition Point2D.h:217
Описание класса numvector.
#define HD
Definition numvector.h:63
Класс, опеделяющий двумерный вектор
Definition Point2D.h:241
std::string type
Definition Point2D.h:243
GeomPoint(const Point2D &_r, const std::string &_type)
Definition Point2D.h:248
int originNumber
Индекс частицы в глобальном массиве частиц
Definition Point2D.h:60
unsigned int key
Мортоновский код частицы
Definition Point2D.h:57