forked from kamino410/xfoil-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·160 lines (134 loc) · 3.75 KB
/
Copy pathmain.cpp
File metadata and controls
executable file
·160 lines (134 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include "XFoil.h"
int m_Iterations = 0;
int s_IterLim = 100;
bool m_bErrors = false;
bool s_bAutoInitBL = true;
bool iterate(XFoil* foil) {
if (!foil->viscal()) {
foil->lvconv = false;
std::cout
<< "CpCalc: local speed too large\nCompressibility corrections invalid"
<< std::endl;
return false;
}
while (m_Iterations < s_IterLim && !foil->lvconv /*&& !s_bCancel*/) {
if (foil->ViscousIter()) {
// if (m_x0 && m_y0) {
// m_x0->append((double)m_Iterations);
// m_y0->append(foil->rmsbl);
//}
// if (m_x1 && m_y1) {
// m_x1->append((double)m_Iterations);
// m_y1->append(foil->rmxbl);
//}
m_Iterations++;
}
else
m_Iterations = s_IterLim;
}
if (!foil->ViscalEnd()) {
foil->lvconv = false; // point is unconverged
foil->setBLInitialized(false);
foil->lipan = false;
m_bErrors = true;
return true; // to exit loop
}
if (m_Iterations >= s_IterLim && !foil->lvconv) {
if (s_bAutoInitBL) {
foil->setBLInitialized(false);
foil->lipan = false;
}
foil->fcpmin(); // Is it of any use ?
return true;
}
if (!foil->lvconv) {
m_bErrors = true;
foil->fcpmin(); // Is it of any use ?
return false;
}
else {
// converged at last
foil->fcpmin(); // Is it of any use ?
return true;
}
return false;
}
int loadDatFile(std::string filename, double x[604], double y[604]) {
std::ifstream fs(filename);
if (!fs) {
std::cout << "Failed to open dat file" << std::endl;
return -1;
}
std::string line;
std::getline(fs, line);
std::cout << "Foil name : " << line << std::endl;
int cnt = 0;
while (!fs.eof()) {
std::getline(fs, line);
line.erase(0, line.find_first_not_of(" \t"));
int endOfX = line.find_first_of(" \t");
if (endOfX == -1) continue;
std::string sx = line.substr(0, endOfX);
std::string sy = line.substr(endOfX);
x[cnt] = atof(sx.c_str());
y[cnt] = atof(sy.c_str());
cnt++;
}
return cnt;
}
int main() {
double x[604], y[604], nx[604], ny[604];
int n = 0;
std::stringstream ss;
// auto naca = new XFoil();
// naca->naca4(4412, 100 / 2);
// for (int i = 0; i < naca->nb; i++) {
// x[i] = naca->xb[i + 1];
// y[i] = naca->yb[i + 1];
// }
// n = naca->nb;
n = loadDatFile("sample/CLARK_Y.dat", x, y);
if (n == -1) return 1;
XFoil* foil = new XFoil();
if (!foil->initXFoilGeometry(n, x, y, nx, ny)) {
std::cout << "Initialization error!" << std::endl;
return 1;
}
if (!foil->initXFoilAnalysis(100000, 0, 0.0, 9.0, 1.0, 1.0, 1, 1, true, ss)) {
std::cout << "Initialization error!" << std::endl;
return 1;
}
for (double alpha = 0; alpha < 15; alpha += 0.5) {
m_Iterations = 0;
foil->setBLInitialized(false);
foil->lipan = false;
foil->setAlpha(alpha * 3.14159 / 180);
foil->lalfa = true;
foil->setQInf(1.0);
std::cout << "alpha : " << alpha << std::endl;
if (!foil->specal()) {
std::cout << "Invalid Analysis Settings" << std::endl;
return 1;
}
foil->lwake = false;
foil->lvconv = false;
while (!iterate(foil))
;
// std::cout << ss.str() << std::endl;
if (foil->lvconv) {
std::cout << " converged after " << m_Iterations << " iterations"
<< std::endl;
std::cout << " cl : " << foil->cl << ", cd : " << foil->cd
<< ", cm : " << foil->cm << ", xcp : " << foil->xcp
<< std::endl;
}
else {
std::cout << " unconverged" << std::endl;
}
}
return 0;
}