VM2D 1.14
Vortex methods for 2D flows simulation
Loading...
Searching...
No Matches
WakeDataBase2D.cpp
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: WakeDataBase2D.cpp |
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#include "WakeDataBase2D.h"
41
42#include "Airfoil2D.h"
43#include "Boundary2D.h"
44#include "MeasureVP2D.h"
45#include "Mechanics2D.h"
46#include "Preprocessor.h"
47#include "StreamParser.h"
48#include "Velocity2D.h"
49#include "Wake2D.h"
50#include "World2D.h"
51
52using namespace VM2D;
53
54//Считывание вихревого следа из файла
55void WakeDataBase::ReadFromFile(const std::string& dir, const std::string& fileName)
56{
57 std::string filename = dir + fileName;
58 std::ifstream wakeFile, testFile;
59
60 char firstChar = '/', secondChar = '*';
61
62 if (fileExistTest(filename, W.getInfo(), true, { "txt", "TXT" }))
63 {
64 testFile.open(filename);
65 testFile >> firstChar;
66 testFile >> secondChar;
67
68 //std::cout << "CHARS: " << firstChar << " " << secondChar << std::endl;
69 testFile.close();
70 }
71
72
73 //Считывание из словаря
74 if (firstChar == '/' && secondChar == '*')
75 {
76 if (fileExistTest(filename, W.getInfo(), true, { "txt", "TXT" }))
77 {
78 std::stringstream wakeFile(VMlib::Preprocessor(filename).resultString);
79
81 VMlib::StreamParser wakeParser(XXX, "vortex wake file parser", wakeFile);
82
83 wakeParser.get("vtx", vtx);
84 }
85 }
86 else
87 {
88 //Считывание из обычного текстового файла
89 if (fileExistTest(filename, W.getInfo(), true, { "txt", "TXT" }))
90 {
91 wakeFile.open(filename);
92 int nnn;
93 wakeFile >> nnn;
94 vtx.reserve(nnn);
95 for (int i = 0; i < nnn; ++i)
96 {
97 Vortex2D v;
98 wakeFile >> v.r()[0] >> v.r()[1] >> v.g();
99 vtx.push_back(v);
100 }
101
102 wakeFile.close();
103 }
104 }
105
106}//ReadFromFile(...)
107
108
109void WakeDataBase::SaveKadrVtk(const std::string& filePrefix) const
110{
111 W.getTimers().start("Save");
112
114 {
115 std::ofstream outfile;
116 size_t numberNonZero = 0;
117
118 if (vtx.size() > 0)
119 numberNonZero += vtx.size();
120 else
121 for (size_t q = 0; q < W.getNumberOfAirfoil(); ++q)
122 numberNonZero += W.getAirfoil(q).getNumberOfPanels();
123 VMlib::CreateDirectory(W.getPassport().dir, "snapshots");
124
125 if (W.getPassport().timeDiscretizationProperties.fileTypeVtx.second == 0) //text format vtk
126 {
127 std::string fname = VMlib::fileNameStep(filePrefix, W.getPassport().timeDiscretizationProperties.nameLength, W.getCurrentStep(), "vtk");
128 outfile.open(W.getPassport().dir + "snapshots/" + fname);
129
130 outfile << "# vtk DataFile Version 2.0" << std::endl;
131 outfile << "VM2D VTK result: " << (W.getPassport().dir + "snapshots/" + fname).c_str() << " saved " << VMlib::CurrentDataTime() << std::endl;
132 outfile << "ASCII" << std::endl;
133 outfile << "DATASET UNSTRUCTURED_GRID" << std::endl;
134 outfile << "POINTS " << numberNonZero << " float" << std::endl;
135
136
137 if (vtx.size() > 0)
138 for (auto& v : vtx)
139 {
140 const Point2D& r = v.r();
141 outfile << r[0] << " " << r[1] << " " << "0.0" << std::endl;
142 }//for v
143 else
144 for (size_t q = 0; q < W.getNumberOfAirfoil(); ++q)
145 for (size_t s = 0; s < W.getAirfoil(q).getNumberOfPanels(); ++s)
146 {
147 const Point2D& r = W.getAirfoil(q).getR(s);
148 outfile << r[0] << " " << r[1] << " " << "0.0" << std::endl;
149 }
150
151 outfile << "CELLS " << numberNonZero << " " << 2 * numberNonZero << std::endl;
152 for (size_t i = 0; i < numberNonZero; ++i)
153 outfile << "1 " << i << std::endl;
154
155 outfile << "CELL_TYPES " << numberNonZero << std::endl;
156 for (size_t i = 0; i < numberNonZero; ++i)
157 outfile << "1" << std::endl;
158
159 outfile << std::endl;
160 outfile << "POINT_DATA " << numberNonZero << std::endl;
161 outfile << "SCALARS Gamma float 1" << std::endl;
162 outfile << "LOOKUP_TABLE default" << std::endl;
163
164 if (vtx.size() > 0)
165 for (auto& v : vtx)
166 outfile << v.g() << std::endl;
167 else
168 for (size_t q = 0; q < W.getNumberOfAirfoil(); ++q)
169 for (size_t s = 0; s < W.getAirfoil(q).getNumberOfPanels(); ++s)
170 outfile << "0.0" << std::endl;
171
172 outfile.close();
173 }//if fileType = text
174 else if (W.getPassport().timeDiscretizationProperties.fileTypeVtx.second == 1) //binary format vtk
175 {
176 //Тест способа хранения чисел
177 uint16_t x = 0x0001;
178 bool littleEndian = (*((uint8_t*)&x));
179 const char eolnBIN[] = "\n";
180
181 std::string fname = VMlib::fileNameStep(filePrefix, W.getPassport().timeDiscretizationProperties.nameLength, W.getCurrentStep(), "vtk");
182 outfile.open(W.getPassport().dir + "snapshots/" + fname, std::ios::out | std::ios::binary);
183
184 outfile << "# vtk DataFile Version 3.0" << "\r\n" << "VM2D VTK result: " << (W.getPassport().dir + "snapshots/" + fname).c_str() << " saved " << VMlib::CurrentDataTime() << eolnBIN;
185 outfile << "BINARY" << eolnBIN;
186 outfile << "DATASET UNSTRUCTURED_GRID" << eolnBIN << "POINTS " << numberNonZero << " " << "float" << eolnBIN;
187
188 if (vtx.size() > 0)
189 {
190 Eigen::VectorXf rData = Eigen::VectorXf::Zero(vtx.size() * 3);
191 for (size_t i = 0; i < vtx.size(); ++i)
192 {
193 rData(3 * i) = (float)(vtx[i].r())[0];
194 rData(3 * i + 1) = (float)(vtx[i].r())[1];
195 }//for i
196
197 if (littleEndian)
198 for (int i = 0; i < vtx.size() * 3; ++i)
199 VMlib::SwapEnd(rData(i));
200 outfile.write(reinterpret_cast<char*>(rData.data()), vtx.size() * 3 * sizeof(float));
201 }
202 else
203 for (size_t q = 0; q < W.getNumberOfAirfoil(); ++q)
204 {
205 Eigen::VectorXf rData = Eigen::VectorXf::Zero(W.getAirfoil(q).getNumberOfPanels() * 3);
206 for (size_t s = 0; s < W.getAirfoil(q).getNumberOfPanels(); ++s)
207 {
208 rData(3 * s) = (float)(W.getAirfoil(q).getR(s))[0];
209 rData(3 * s + 1) = (float)(W.getAirfoil(q).getR(s))[1];
210 }//for i
211
212 if (littleEndian)
213 for (int i = 0; i < W.getAirfoil(q).getNumberOfPanels() * 3; ++i)
214 VMlib::SwapEnd(rData(i));
215 outfile.write(reinterpret_cast<char*>(rData.data()), W.getAirfoil(q).getNumberOfPanels() * 3 * sizeof(float));
216 }
217
218 // CELLS
219 std::vector<int> cells(2 * numberNonZero);
220 for (size_t i = 0; i < numberNonZero; ++i)
221 {
222 cells[2 * i] = 1;
223 cells[2 * i + 1] = (int)i;
224 }
225
226 std::vector<int> cellsTypes;
227 cellsTypes.resize(numberNonZero, 1);
228
229 if (littleEndian)
230 {
231 for (int i = 0; i < numberNonZero * 2; ++i)
232 VMlib::SwapEnd(cells[i]);
233
234 for (int i = 0; i < numberNonZero; ++i)
235 VMlib::SwapEnd(cellsTypes[i]);
236 }
237
238 outfile << eolnBIN << "CELLS " << numberNonZero << " " << numberNonZero * 2 << eolnBIN;
239 outfile.write(reinterpret_cast<char*>(cells.data()), numberNonZero * 2 * sizeof(int));
240 outfile << eolnBIN << "CELL_TYPES " << numberNonZero << eolnBIN;
241 outfile.write(reinterpret_cast<char*>(cellsTypes.data()), numberNonZero * sizeof(int));
242
243 //gammas
244 outfile << eolnBIN << "POINT_DATA " << numberNonZero << eolnBIN;
245 outfile << eolnBIN << "SCALARS Gamma " << "float" << " 1" << eolnBIN;
246 outfile << "LOOKUP_TABLE default" << eolnBIN;
247
248 if (vtx.size() > 0)
249 {
250 Eigen::VectorXf pData = Eigen::VectorXf::Zero(numberNonZero);
251 for (int s = 0; s < vtx.size(); ++s)
252 pData(s) = (float)vtx[s].g();
253
254 if (littleEndian)
255 for (int i = 0; i < vtx.size(); ++i)
256 VMlib::SwapEnd(pData(i));
257 outfile.write(reinterpret_cast<char*>(pData.data()), vtx.size() * sizeof(float));
258 }
259 else
260 for (size_t q = 0; q < W.getNumberOfAirfoil(); ++q)
261 {
262 Eigen::VectorXf pData = Eigen::VectorXf::Zero(W.getAirfoil(q).getNumberOfPanels());
263 for (int s = 0; s < W.getAirfoil(q).getNumberOfPanels(); ++s)
264 pData(s) = 0;
265
266 if (littleEndian)
267 for (int i = 0; i < W.getAirfoil(q).getNumberOfPanels(); ++i)
268 VMlib::SwapEnd(pData(i));
269 outfile.write(reinterpret_cast<char*>(pData.data()), W.getAirfoil(q).getNumberOfPanels() * sizeof(float));
270 }
271
272 outfile << eolnBIN;
273 outfile.close();
274 }//if binary
276 {
277 std::string fname = VMlib::fileNameStep(filePrefix, W.getPassport().timeDiscretizationProperties.nameLength, W.getCurrentStep(), "csv");
278 outfile.open(W.getPassport().dir + "snapshots/" + fname);
279
280 outfile << "point,x,y,G " << std::endl;
281
282 int counter = 0;
283
284 if (vtx.size() > 0)
285 for (auto& v : vtx)
286 outfile << counter++ << "," << v.r()[0] << "," << v.r()[1] << "," << v.g() << std::endl;
287 else
288 for (size_t q = 0; q < W.getNumberOfAirfoil(); ++q)
289 for (size_t s = 0; s < W.getAirfoil(q).getNumberOfPanels(); ++s)
290 {
291 const Point2D& r = W.getAirfoil(q).getR(s);
292 outfile << counter++ << "," << r[0] << "," << r[1] << "," << "0.0" << std::endl;
293 }
294 outfile.close();
295 }//if fileType = text
296
297 }
298
299 W.getTimers().stop("Save");
300}//SaveKadrVtk()
Заголовочный файл с описанием класса Airfoil.
Заголовочный файл с описанием класса Boundary.
Заголовочный файл с описанием класса MeasureVP.
Заголовочный файл с описанием класса Mechanics.
Заголовочный файл с описанием класса Preprocessor.
Заголовочный файл с описанием класса StreamParser.
Заголовочный файл с описанием класса Velocity.
Заголовочный файл с описанием класса Wake.
Заголовочный файл с описанием класса WakeDataBase.
Заголовочный файл с описанием класса World2D.
const Point2D & getR(size_t q) const
Возврат константной ссылки на вершину профиля
Definition Airfoil2D.h:113
size_t getNumberOfPanels() const
Возврат количества панелей на профиле
Definition Airfoil2D.h:163
std::vector< Vortex2D > vtx
Список вихревых элементов
void ReadFromFile(const std::string &dir, const std::string &fileName)
Считывание вихревого следа из файла
const World2D & W
Константная ссылка на решаемую задачу
void SaveKadrVtk(const std::string &filePrefix="Kadr") const
Сохранение вихревого следа в файл .vtk.
size_t getNumberOfAirfoil() const
Возврат количества профилей в задаче
Definition World2D.h:174
const Airfoil & getAirfoil(size_t i) const
Возврат константной ссылки на объект профиля
Definition World2D.h:157
VMlib::TimersGen & getTimers() const
Возврат ссылки на временную статистику выполнения шага расчета по времени
Definition World2D.h:276
const Passport & getPassport() const
Возврат константной ссылки на паспорт
Definition World2D.h:251
bool ifDivisible(int val) const
Definition World2D.h:278
Класс, определяющий работу с потоком логов
Definition LogStream.h:57
TimeDiscretizationProperties timeDiscretizationProperties
Структура с параметрами процесса интегрирования по времени
std::string dir
Рабочий каталог задачи
Класс, позволяющий выполнять предварительную обработку файлов
Класс, позволяющий выполнять разбор файлов и строк с настройками и параметрами
bool get(const std::string &name, std::vector< Point2D > &res, const std::vector< Point2D > *defValue=nullptr, bool echoDefault=true) const
Считывание вектора из двумерных точек из базы данных
void stop(const std::string &timerLabel)
Останов счетчика
Definition TimesGen.cpp:68
void start(const std::string &timerLabel)
Запуск счетчика
Definition TimesGen.cpp:55
Класс, опеделяющий двумерный вихревой элемент
Definition Vortex2D.h:59
HD Point2D & r()
Функция для доступа к радиус-вектору вихря
Definition Vortex2D.h:87
HD double & g()
Функция для доступа к циркуляции вихря
Definition Vortex2D.h:95
VMlib::LogStream & getInfo() const
Возврат ссылки на объект LogStream Используется в техничеcких целях для организации вывода
Definition WorldGen.h:82
size_t getCurrentStep() const
Возврат константной ссылки на параметры распараллеливания по MPI.
Definition WorldGen.h:99
std::string fileNameStep(const std::string &name, int length, size_t number, const std::string &ext)
Формирование имени файла
Definition defs.h:381
void CreateDirectory(const std::string &dir, const std::string &name)
Создание каталога
Definition defs.h:441
std::string CurrentDataTime()
Формирование строки с текущем временем и датой
Definition defs.cpp:47
void SwapEnd(T &var)
Вспомогательная функция перестановки байт местами (нужно для сохранения бинарных VTK)
Definition defs.h:555
std::pair< std::string, int > fileTypeVtx
Тип файлов для сохранения скорости и давления
Definition PassportGen.h:73
int saveVtxStep
Шаг сохранения кадров в бинарные файлы
Definition PassportGen.h:75
int nameLength
Число разрядов в имени файла
Definition PassportGen.h:70