VM2D 1.14
Vortex methods for 2D flows simulation
Loading...
Searching...
No Matches
Gmres2D.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: Gmres2D.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
41#ifndef GMRES2D_H
42#define GMRES2D_H
43
44#include <Point2D.h>
45#include <iostream>
46#include "omp.h"
47
48#ifdef USE_CUDA
49#include <cublas_v2.h>
50#endif
51
52#include <string>
53
54namespace VM2D
55{
69 {
70 std::vector<double> alpha;
71 std::vector<double> beta;
72 std::vector<double> gamma;
73 std::vector<double> delta;
74 std::vector<double> phi;
75 std::vector<double> xi;
76 std::vector<double> psi;
77
78 void resize(size_t n)
79 {
80 alpha.resize(n);
81 beta.resize(n);
82 gamma.resize(n);
83 delta.resize(n);
84 phi.resize(n);
85 xi.resize(n);
86 psi.resize(n);
87 }
88 };
89
91 {
92 int q;
93 };
94
95 class Airfoil;
96 class World2D;
97
101 template<typename T>
102 inline double norm(const std::vector<T>& b)
103 {
104 double norm = 0;
105 #ifndef OLD_OMP
106 #pragma omp simd reduction(+:norm)
107 #endif
108 for (size_t i = 0; i < b.size(); i++)
109 norm += (b[i] * b[i]);
110 return sqrt(norm);
111 }
112
116 template<typename T>
117 inline double norm2(const std::vector<T>& b)
118 {
119 double norm2 = 0;
120 #ifndef OLD_OMP
121 #pragma omp simd reduction(+:norm2)
122 #endif
123 for (size_t i = 0; i < b.size(); i++)
124 norm2 += (b[i] * b[i]);
125 return norm2;
126 }
127
128
130 template<typename T>
131 inline std::vector<T> operator*(const T lambda, const std::vector<T>& x)
132 {
133 std::vector<T> c(x);
134 c.resize(x.size());
135
136 #ifndef OLD_OMP
137 #pragma omp simd
138 #endif
139 for (size_t i = 0; i < x.size(); ++i)
140 c[i] *= lambda;
141 return c;
142 }
143
144
146 {
147 private:
148 const World2D& W;
149#ifdef USE_CUDA
150 cublasHandle_t cublas_handle;
151 double* devViBund;
152 double* devw;
153 //double* mulptr; //если исп.cublas
154#endif
155
156 std::vector<double> w, c, s;
157 std::vector<double> Vflat;
158 std::vector<std::vector<double>> H, diag;
159
160 std::vector<std::vector<Point2D>> prea, prec, prea1, prec1;
161
162 std::vector<sweepVectors> allSW;
163 std::vector<std::vector<double>> allBuf2;
164 std::vector<size_t> np;
165
166 std::vector<double> bufnewSol, bufcurrentSol;
167 std::vector<double> g, Y;
168
170 size_t nTotPan;
171
172 const size_t iterSize = 100;
173
174
175 public:
176 GmresSolver(const World2D& W_);
177 ~GmresSolver();
178
185 bool IterRot(const double nrmRhs, double& gs, int m, bool residualShow);
186
187
188 void PreCalculateCoef(int aflIndex);
189
190 void SolCircleRundirect(const std::vector<double>& A, const std::vector<double>& rhs, size_t startRow, size_t startRowReg, size_t np, std::vector<double>& res);
191
192 void SolMdirect(const std::vector<double>& A, const std::vector<double>& rhs, size_t startRow, size_t startRowReg, size_t np, std::vector<double>& res, bool lin);
193
194 void GMRES_Direct(
195 int nAllVars,
196 int nafl,
197 const std::vector<double>& mtrDir,
198 const std::vector<double>& rhsDir,
199 const std::vector<int>& pos,
200 const std::vector<int>& vsize,
201 std::vector<std::vector<double>>& gam,
202 std::vector<double>& R);
203
204
206
207 void SolM(std::vector<double>& AX, const std::vector<double>& rhs, int p);
208 void SolCircleRun(std::vector<double>& AX, const std::vector<double>& rhs, int p);
209
210#ifdef USE_CUDA
211 void GMRES(
212 std::vector<std::vector<double>>& X,
213 std::vector<double>& R,
214 const std::vector<std::vector<double>>& rhs,
215 const std::vector<double>& rhsReg,
216 int& niter);
217 //bool linScheme);
218#endif
219
220 };//class GmresSolver
221
222
223#endif
224
225}
Заголовочный файл с описанием класса Point2D.
Абстрактный класс, определяющий обтекаемый профиль
Definition Airfoil2D.h:182
std::vector< double > bufcurrentSol
Definition Gmres2D.h:166
std::vector< double > s
Definition Gmres2D.h:156
void SolCircleRun(std::vector< double > &AX, const std::vector< double > &rhs, int p)
Definition Gmres2D.cpp:390
std::vector< std::vector< Point2D > > prec
Definition Gmres2D.h:160
void SolMdirect(const std::vector< double > &A, const std::vector< double > &rhs, size_t startRow, size_t startRowReg, size_t np, std::vector< double > &res, bool lin)
Definition Gmres2D.cpp:128
const World2D & W
Definition Gmres2D.h:148
std::vector< std::vector< double > > allBuf2
Definition Gmres2D.h:163
std::vector< std::vector< Point2D > > prea1
Definition Gmres2D.h:160
std::vector< std::vector< Point2D > > prea
Definition Gmres2D.h:160
std::vector< double > c
Definition Gmres2D.h:156
size_t totalVsize
Definition Gmres2D.h:169
std::vector< double > bufnewSol
Definition Gmres2D.h:166
std::vector< std::vector< double > > H
Definition Gmres2D.h:158
void PreCalculateCoef(int aflIndex)
Definition Gmres2D.cpp:532
std::vector< size_t > np
Definition Gmres2D.h:164
void SolCircleRundirect(const std::vector< double > &A, const std::vector< double > &rhs, size_t startRow, size_t startRowReg, size_t np, std::vector< double > &res)
Definition Gmres2D.cpp:91
std::vector< double > Vflat
Definition Gmres2D.h:157
const size_t iterSize
Definition Gmres2D.h:172
std::vector< sweepVectors > allSW
Definition Gmres2D.h:162
bool IterRot(const double nrmRhs, double &gs, int m, bool residualShow)
Контроль невязки после выполнения очередной итерации GMRES.
Definition Gmres2D.cpp:59
void GMRES_Direct(int nAllVars, int nafl, const std::vector< double > &mtrDir, const std::vector< double > &rhsDir, const std::vector< int > &pos, const std::vector< int > &vsize, std::vector< std::vector< double > > &gam, std::vector< double > &R)
Definition Gmres2D.cpp:204
std::vector< std::vector< double > > diag
Definition Gmres2D.h:158
std::vector< std::vector< Point2D > > prec1
Definition Gmres2D.h:160
void SolM(std::vector< double > &AX, const std::vector< double > &rhs, int p)
Definition Gmres2D.cpp:445
std::vector< double > Y
Definition Gmres2D.h:167
std::vector< double > g
Definition Gmres2D.h:167
std::vector< double > w
Definition Gmres2D.h:156
Класс, опеделяющий текущую решаемую задачу
Definition World2D.h:77
double norm(const std::vector< T > &b)
Шаблонная функция вычисления евклидовой нормы вектора или списка
Definition Gmres2D.h:102
std::vector< T > operator*(const T lambda, const std::vector< T > &x)
Шаблонная функция умножения числа на вектор
Definition Gmres2D.h:131
double norm2(const std::vector< T > &b)
Шаблонная функция вычисления евклидовой нормы вектора или списка
Definition Gmres2D.h:117
Структура, определяющий необходимые массивы для рализации метода прогонки
Definition Gmres2D.h:69
std::vector< double > phi
Definition Gmres2D.h:74
std::vector< double > beta
Definition Gmres2D.h:71
void resize(size_t n)
Definition Gmres2D.h:78
std::vector< double > psi
Definition Gmres2D.h:76
std::vector< double > delta
Definition Gmres2D.h:73
std::vector< double > alpha
Definition Gmres2D.h:70
std::vector< double > gamma
Definition Gmres2D.h:72
std::vector< double > xi
Definition Gmres2D.h:75