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#include <string>
49
50namespace VM2D
51{
65 {
66 std::vector<double> alpha;
67 std::vector<double> beta;
68 std::vector<double> gamma;
69 std::vector<double> delta;
70 std::vector<double> phi;
71 std::vector<double> xi;
72 std::vector<double> psi;
73
74 void resize(size_t n)
75 {
76 alpha.resize(n);
77 beta.resize(n);
78 gamma.resize(n);
79 delta.resize(n);
80 phi.resize(n);
81 xi.resize(n);
82 psi.resize(n);
83 }
84 };
85
86 class Airfoil;
87 class World2D;
88
92 template<typename T>
93 inline double norm(const std::vector<T>& b)
94 {
95 double norm = 0;
96 #ifndef OLD_OMP
97 #pragma omp simd reduction(+:norm)
98 #endif
99 for (size_t i = 0; i < b.size(); i++)
100 norm += (b[i] * b[i]);
101 return sqrt(norm);
102 }
103
107 template<typename T>
108 inline double norm2(const std::vector<T>& b)
109 {
110 double norm2 = 0;
111 //#ifndef OLD_OMP
112 //#pragma omp simd reduction(+:norm)
113 //#endif
114 for (size_t i = 0; i < b.size(); i++)
115 norm2 += (b[i] * b[i]);
116 return norm2;
117 }
118
119
121 template<typename T>
122 inline std::vector<T> operator*(const T lambda, const std::vector<T>& x)
123 {
124 std::vector<T> c(x);
125 c.resize(x.size());
126
127 //#ifndef OLD_OMP
128 //#pragma omp simd
129 //#endif
130 for (size_t i = 0; i < x.size(); ++i)
131 c[i] *= lambda;
132 return c;
133 }
134
135
142 bool IterRot(std::vector<std::vector<double>>& H, const double nrmRhs, double& gs, std::vector<double>& c, std::vector<double>& s, int m, int n, double epsGMRES, int iter, bool residualShow);
143
144 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);
145
146 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);
147
148 void GMRES_Direct(
149 const World2D& W,
150 int nAllVars,
151 int nafl,
152 const std::vector<double>& mtrDir,
153 const std::vector<double>& rhsDir,
154 const std::vector<int>& pos,
155 const std::vector<int>& vsize,
156 std::vector<std::vector<double>>& gam,
157 std::vector<double>& R);
158
159
161
162 void SolCircleRun(std::vector<double>& AX, const std::vector<double>& rhs, const Airfoil& afl, const std::vector<std::vector<Point2D>>& prea1, const std::vector<std::vector<Point2D>>& prec1, int p, int n, sweepVectors& sw);
163
164 void SolM(std::vector<double>& AX, const std::vector<double>& rhs, const Airfoil& afl,
165 const std::vector<std::vector<Point2D>>& prea, const std::vector<std::vector<Point2D>>& prec, int p, int n, bool linScheme, sweepVectors& sw);
166
167#ifdef USE_CUDA
168 void GMRES(const World2D& W,
169 std::vector<std::vector<double>>& X,
170 std::vector<double>& R,
171 const std::vector<std::vector<double>>& rhs,
172 const std::vector<double> rhsReg,
173 int& niter,
174 bool linScheme);
175#endif
176
177
178#endif
179
180}
Заголовочный файл с описанием класса Point2D.
void GMRES_Direct(const World2D &W, 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:206
double norm(const std::vector< T > &b)
Шаблонная функция вычисления евклидовой нормы вектора или списка
Definition Gmres2D.h:93
void SolCircleRun(std::vector< double > &AX, const std::vector< double > &rhs, const Airfoil &afl, const std::vector< std::vector< Point2D > > &prea1, const std::vector< std::vector< Point2D > > &prec1, int p, int n, sweepVectors &sw)
Definition Gmres2D.cpp:393
bool IterRot(std::vector< std::vector< double > > &H, const double nrmRhs, double &gs, std::vector< double > &c, std::vector< double > &s, int m, int n, double epsGMRES, int iter, bool residualShow)
Контроль невязки после выполнения очередной итерации GMRES.
Definition Gmres2D.cpp:59
std::vector< T > operator*(const T lambda, const std::vector< T > &x)
Шаблонная функция умножения числа на вектор
Definition Gmres2D.h:122
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:130
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:93
void SolM(std::vector< double > &AX, const std::vector< double > &rhs, const Airfoil &afl, const std::vector< std::vector< Point2D > > &prea, const std::vector< std::vector< Point2D > > &prec, int p, int n, bool linScheme, sweepVectors &sw)
Definition Gmres2D.cpp:444
double norm2(const std::vector< T > &b)
Шаблонная функция вычисления евклидовой нормы вектора или списка
Definition Gmres2D.h:108
Структура, определяющий необходимые массивы для рализации метода прогонки
Definition Gmres2D.h:65
std::vector< double > phi
Definition Gmres2D.h:70
std::vector< double > beta
Definition Gmres2D.h:67
void resize(size_t n)
Definition Gmres2D.h:74
std::vector< double > psi
Definition Gmres2D.h:72
std::vector< double > delta
Definition Gmres2D.h:69
std::vector< double > alpha
Definition Gmres2D.h:66
std::vector< double > gamma
Definition Gmres2D.h:68
std::vector< double > xi
Definition Gmres2D.h:71