-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrag_Queen.hpp
More file actions
130 lines (112 loc) · 4.17 KB
/
Drag_Queen.hpp
File metadata and controls
130 lines (112 loc) · 4.17 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
class drag
{
private:
double _m, _r, _p, _mu, _c, _g, _method_choice, _x, _v;
double A, B;
public:
void input(double m, double r, double p, double mu, double c, double g, double x, double v, double method_choice)
{
_m = m;
_r = r;
_p = p;
_mu = mu;
_c = c;
_g = g;
_x = x;
_v = v;
_method_choice = method_choice;
}
float ono(double A, double v1, double B)
{
return _g - (((_p * 4 * atan(1) * _c * _r * _r) / (2 * _m)) * v1 * v1) - ((6 * 4 * atan(1) * _mu * _r * v1) / _m) - ((4 * _p * _r * _r * _r * 4 * atan(1) * _g) / (3 * _m));
}
float yoko(double A, double x1, double B1)
{
return B1;
}
void b()
{
double in, a;
float h = 0.15;
A = 0;
B = 0;
char *file_name = "drag.dat"; // give a default name to the file
if (_method_choice == 1.0)
{
file_name = "drag_rk4.dat";
}
else if (_method_choice == 2.0)
{
file_name = "drag_euler.dat";
}
else if (_method_choice == 3.0)
{
file_name = "drag_rals.dat";
}
std::ofstream out(file_name);
for (float t = 0.0; t > -1; t += h)
{
a = ono(A, _v, B);
out << t << " " << _x << " " << _v << " " << a << "\n";
if (_method_choice == 1.0)
{
rk4A(std::bind(&drag::yoko, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), _x, _v, A, -h);
rk4A(std::bind(&drag::ono, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), _v, a, A, h);
}
else if (_method_choice == 2.0)
{
eulersA(std::bind(&drag::yoko, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), _x, _v, A, -h);
eulersA(std::bind(&drag::ono, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), _v, a, A, h);
}
else if (_method_choice == 3.0)
{
ralsA(std::bind(&drag::yoko, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), _x, _v, A, -h);
ralsA(std::bind(&drag::ono, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), _v, a, A, h);
}
else
{
std::cout << "ERROR !!Not any Method!! \n";
break;
}
if (_x < 0)
{
break;
}
}
out.close();
// Important if building for both Unix and Windows OS
// Plot the data using gnuplot
#ifdef _WIN32
FILE *gnuplotPipe = _popen("gnuplot -persistent", "w");
#else
FILE *gnuplotPipe = popen("gnuplot -persistent", "w");
#endif
if (!gnuplotPipe)
{
std::cerr << "Error opening pipe to gnuplot" << std::endl;
return;
}
std::string s;
const char *ss = s.append("plot '").append(file_name).append("' using 1:2 with lines title 'Height'\n").c_str();
std::string sss;
const char *ssss = sss.append("replot '").append(file_name).append("' using 1:3 with lines title 'Velocity'\n").c_str();
std::string sssss;
const char *ssssss = sssss.append("replot '").append(file_name).append("' using 1:4 with lines title 'Acceleration'\n").c_str();
fprintf(gnuplotPipe, "set term wxt\n");
fprintf(gnuplotPipe, "set title 'Motion Of Spherical Body'\n");
fprintf(gnuplotPipe, "set xlabel 'Time'\n");
fprintf(gnuplotPipe, "set ylabel 'Height/Velocity/Acceleration'\n");
// fprintf(gnuplotPipe, "plot 'drag1.dat' using 1:2 with lines title 'Height'\n");
// fprintf(gnuplotPipe, "replot 'drag1.dat' using 1:3 with lines title 'Velocity'\n");
// fprintf(gnuplotPipe, "replot 'drag1.dat' using 1:4 with lines title 'Acceleration'\n");
fprintf(gnuplotPipe, ss);
fprintf(gnuplotPipe, ssss);
fprintf(gnuplotPipe, ssssss);
#ifdef _WIN32
_pclose(gnuplotPipe);
#else
pclose(gnuplotPipe);
#endif
return;
}
};