VM2D 1.14
Vortex methods for 2D flows simulation
Loading...
Searching...
No Matches
defsBH.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: defsBH.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
39#pragma once
40
41#include <iostream>
42#include "PointsCopyBH.h"
43
44#include "Gpudefs.h"
45
46#ifdef calcOp
47 #define ADDOP(n) BH::op += ((int)n)
48#else
49 #define ADDOP(n)
50#endif
51
52namespace BH
53{
54 extern long long op;
55
56 //Мировые константы
57 static const double PI = 3.1415926535897932384626;
58 static const double DPI = 2.0 * 3.1415926535897932384626;
59 static const double IPI = 1.0 / PI;
60 static const double IDPI = 0.5 / PI;
61
62
64 static const int twoPowCodeLengthVar = (1 << codeLength);
65
66
68 inline void SizeCheck(std::vector<Point2D>& i00)
69 {
70 if (i00.capacity() == i00.size())
71 i00.reserve(i00.size() * 2);
72 }
73
74
76 //inline Point2D multz(const Point2D& a, const Point2D& b)
77 //{
78 // ADDOP(4);
79 // return Point2D({ a[0] * b[0] - a[1] * b[1], a[1] * b[0] + a[0] * b[1] });
80 //}
81
83 inline Point2D powz(const Point2D& z, double n)
84 {
85 double phi, R;
86 ADDOP(10);
87 phi = n * atan2(z[1], z[0]);
88 R = pow(z.length2(), 0.5*n);
89 return Point2D({ R * cos(phi), R * sin(phi) });
90 }
91
93 //inline Point2D multzA(const Point2D& a, const Point2D& b)
94 //{
95 // ADDOP(4);
96 // return Point2D({ a[0] * b[0] + a[1] * b[1], a[1] * b[0] - a[0] * b[1] });
97 //}
98
100 template <typename T>
101 inline T sqr(T x)
102 {
103 ADDOP(1);
104 return x * x;
105 }
106
110 template <typename T>
111 inline int sign(T val)
112 {
113 return (T(0) < val) - (val < T(0));
114 }
115
116
117 //Округление "в потолок" результата деления x на y
118 //(годится для любых натуральных, но работает довольно медленно, здесь не нужна)
119 //unsigned int ceil(unsigned int x, unsigned int y)
120 //{
121 // return x / y + (x % y != 0);
122 //}
123
128 inline int ceilpow2(unsigned int x, unsigned int p)
129 {
130 return (x >> p) + !!(x & ((1 << p) - 1));
131 }
132
134 inline int ceilhalf(unsigned int x)
135 {
136 return (x >> 1) + (x & 1);
137 }
138
142 template<typename T>
143 inline double norm(const T& b)
144 {
145 double norm = 0;
146#ifndef OLD_OMP
147#pragma omp simd reduction(+:norm)
148#endif
149 for (size_t i = 0; i < b.size(); i++)
150 norm += (b[i] * b[i]);
151 ADDOP(2*b.size() + 1);
152 return sqrt(norm);
153 }
154
156 template<typename T>
157 inline std::vector<T> operator+(const std::vector<T>& x, const std::vector<T>& y)
158 {
159 std::vector<T> c(x);
160#ifndef OLD_OMP
161#pragma omp simd
162#endif
163 for (size_t i = 0; i < x.size(); ++i)
164 c[i] += y[i];
165 return c;
166 }
167
168
170 template<typename T>
171 inline std::vector<T>& operator+=(std::vector<T>& x, const std::vector<T>& y)
172 {
173#ifndef OLD_OMP
174#pragma omp simd
175#endif
176 for (size_t i = 0; i < x.size(); ++i)
177 x[i] += y[i];
178 return x;
179 }
180
182 template<typename T>
183 inline std::vector<T> operator-(const std::vector<T>& x, const std::vector<T>& y)
184 {
185 std::vector<T> c(x);
186#ifndef OLD_OMP
187#pragma omp simd
188#endif
189 for (size_t i = 0; i < x.size(); ++i)
190 c[i] -= y[i];
191 return c;
192 }
193
195 template<typename T>
196 inline std::vector<T>& operator-=(std::vector<T>& x, const std::vector<T>& y)
197 {
198#ifndef OLD_OMP
199#pragma omp simd
200#endif
201 for (size_t i = 0; i < x.size(); ++i)
202 x[i] -= y[i];
203 return x;
204 }
205
207 template<typename T>
208 inline std::vector<T> operator*(const T lambda, const std::vector<T>& x)
209 {
210 std::vector<T> c(x);
211 c.resize(x.size());
212
213#ifndef OLD_OMP
214#pragma omp simd
215#endif
216 for (size_t i = 0; i < x.size(); ++i)
217 c[i] *= lambda;
218 ADDOP(x.size());
219 return c;
220 }
221
222
224 template<typename T>
225 inline T operator&(const std::vector<T>& x, const std::vector<T>& y)
226 {
227 T c = 0;
228#ifndef OLD_OMP
229#pragma omp simd reduction(+:c)
230#endif
231 for (size_t i = 0; i < x.size(); ++i)
232 c += x[i] * y[i];
233 ADDOP(x.size());
234 return c;
235 }
236
237}//namespace BH
Описание констант и параметров для взаимодействия с графическим ускорителем
#define codeLength
Definition Gpudefs.h:97
Заголовок класса-обертки для точек и панелей для метода Барнса - Хата для CPU.
auto length2() const -> typename std::remove_const< typename std::remove_reference< decltype(this->data[0])>::type >::type
Вычисление квадрата нормы (длины) вектора
Definition numvector.h:389
#define ADDOP(n)
Definition defsBH.h:49
std::vector< T > operator+(const std::vector< T > &x, const std::vector< T > &y)
Шаблонная функция сложения двух векторов
Definition defsBH.h:157
Point2D powz(const Point2D &z, double n)
Умножение комплексных чисел
Definition defsBH.h:83
int ceilhalf(unsigned int x)
Округление "в потолок" результата деления пополам, эквивалент ceil(x / 2)
Definition defsBH.h:134
T operator&(const std::vector< T > &x, const std::vector< T > &y)
Шаблонная функция вычисления скалярного произведения двух векторов
Definition defsBH.h:225
static const double DPI
Definition defsBH.h:58
static const int twoPowCodeLengthVar
2 в степени длины мортоновского кода (на каждую координату)
Definition defsBH.h:64
std::vector< T > & operator+=(std::vector< T > &x, const std::vector< T > &y)
Шаблонная функция прибавления к одному вектору другого
Definition defsBH.h:171
static const double PI
Definition defsBH.h:57
static const double IDPI
Definition defsBH.h:60
double norm(const T &b)
Шаблонная функция вычисления евклидовой нормы вектора или списка
Definition defsBH.h:143
int ceilpow2(unsigned int x, unsigned int p)
Округление "в потолок" результата деления на степень двойки, эквивалент ceil(x / (2^p))
Definition defsBH.h:128
T sqr(T x)
Умножение a на комплексно сопряженноe к b.
Definition defsBH.h:101
std::vector< T > operator*(const T lambda, const std::vector< T > &x)
Шаблонная функция умножения числа на вектор
Definition defsBH.h:208
int sign(T val)
Шаблонная функция знака числа Написана оптимизированная версия, которая работает самым быстрым возмож...
Definition defsBH.h:111
static const double IPI
Definition defsBH.h:59
std::vector< T > & operator-=(std::vector< T > &x, const std::vector< T > &y)
Шаблонная функция вычитания из одного вектора другого
Definition defsBH.h:196
std::vector< T > operator-(const std::vector< T > &x, const std::vector< T > &y)
Шаблонная функция вычитания векторов
Definition defsBH.h:183
void SizeCheck(std::vector< Point2D > &i00)
Вспомогательная функция корректировки capacity вектора (при необходимости - удваивает)
Definition defsBH.h:68
long long op
Глобальная переменная - счетчик количества операций
Definition TreeBH.cpp:46