-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
173 lines (144 loc) · 4.52 KB
/
main.cpp
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
161
162
163
164
165
166
167
168
169
170
171
172
173
#include"nhead.h"
#include<fstream>
#include<string>
#include<sstream>
#include<iostream>
const double xl=0;
const double xr=1;
const double yd=0;
const double yu=0.5;
const double d=1/20.0;
const double fac_d_h=1.1;
const double k=2;
const double Re=200;
const double eps=0.15;
const double h=d*fac_d_h;
std::string d2str(double t){
std::stringstream ss;
std::string stime;
ss<<t;
ss>>stime;
return stime;
}
double caldt(SPHfield& f){
double dt1=1,dt2=1,dt3=1,dt=1;
for (int i = 0; i < f.Npx_inner; i++)
{
for (int j = 0; j < f.Npy_inner; j++)
{
dt1=0.25*h/sqrt(gama*f.IP[i][j]->p/f.IP[i][j]->rho)<dt1 ? 0.25*h/sqrt(gama*f.IP[i][j]->p/f.IP[i][j]->rho):dt1;
dt2=0.25*sqrt(h/sqrt(pow(f.IP[i][j]->dtu,2)+pow(f.IP[i][j]->dtv,2)))<dt2 ? 0.25*sqrt(h/sqrt(pow(f.IP[i][j]->dtu,2)+pow(f.IP[i][j]->dtv,2))):dt2;
dt3=eps*pow(h,2)*f.IP[i][j]->rho<dt3 ? eps*pow(h,2)*f.IP[i][j]->rho:dt3;
}
}
dt=dt<dt1 ? dt : dt1;
dt=dt<dt2 ? dt : dt2;
dt=dt<dt3 ? dt : dt3;
return dt;
};
void pre(SPHfield &f1,SPHfield &f2,double dt){
for (int i = 0; i < f1.Npx_inner; i++)
{
for (int j = 0; j < f1.Npy_inner; j++)
{
f2.IP[i][j]->update(f1.IP[i][j]->rho+0.5*dt*f1.IP[i][j]->dtrho,\
f1.IP[i][j]->u+0.5*dt*f1.IP[i][j]->dtu,\
f1.IP[i][j]->v+0.5*dt*f1.IP[i][j]->dtv,\
f1.IP[i][j]->e+0.5*dt*f1.IP[i][j]->dte);
f2.IP[i][j]->x=f1.IP[i][j]->x+0.5*dt*f1.IP[i][j]->u;
f2.IP[i][j]->y=f1.IP[i][j]->y+0.5*dt*f1.IP[i][j]->v;
}
}
f2.get_particle_in_box();
f2.boundarycondition(0);
f2.updatedt();
};
void cor(SPHfield &f1,SPHfield &f2,double dt){
for (int i = 0; i < f1.Npx_inner; i++)
{
for (int j = 0; j < f1.Npy_inner; j++)
{
f2.IP[i][j]->update(f1.IP[i][j]->rho+0.5*dt*(f1.IP[i][j]->dtrho+f2.IP[i][j]->dtrho),\
f1.IP[i][j]->u+0.5*dt*(f1.IP[i][j]->dtu+f2.IP[i][j]->dtu),\
f1.IP[i][j]->v+0.5*dt*(f1.IP[i][j]->dtv+f2.IP[i][j]->dtv),\
f1.IP[i][j]->e+0.5*dt*(f1.IP[i][j]->dte+f2.IP[i][j]->dte));
f2.IP[i][j]->x=f1.IP[i][j]->x+0.5*dt*(f1.IP[i][j]->u+f2.IP[i][j]->u);
f2.IP[i][j]->y=f1.IP[i][j]->y+0.5*dt*(f1.IP[i][j]->v+f2.IP[i][j]->v);
}
}
f2.get_particle_in_box();
f2.boundarycondition(0);
};
void inter(SPHfield &f1,SPHfield &f2){
double x,y;
for (int i = 0; i < f1.Npx_inner; i++)
{
for (int j = 0; j < f1.Npy_inner; j++)
{
x=f1.IP[i][j]->x;
y=f1.IP[i][j]->y;
f1.IP[i][j]->update(f2.reSPHestimate(x,y,4),\
f2.reSPHestimate(x,y,0),\
f2.reSPHestimate(x,y,1),\
f2.reSPHestimate(x,y,5));
}
}
f1.boundarycondition(1);
};
int main(){
//变量初始化
SPHfield f1(xl,xr,yd,yu,d,fac_d_h,k,Re);
SPHfield f2(xl,xr,yd,yu,d,fac_d_h,k,Re);
outputparameters(f1,"para.txt");
//初始流场赋值
int middle=f1.Npx_inner/2;
for (int i = 0; i < middle; i++)
{
for (int j = 0; j < f1.Npy_inner; j++)
{
f1.IP[i][j]->iniset(120/gama,0,0,1/gama/(gama-1));
f2.IP[i][j]->iniset(120/gama,0,0,1/gama/(gama-1));
}
}
for (int i = middle; i < f1.Npx_inner; i++)
{
for (int j = 0; j < f1.Npy_inner; j++)
{
f1.IP[i][j]->iniset(1.2/gama,0,0,1/gama/(gama-1));
f2.IP[i][j]->iniset(1.2/gama,0,0,1/gama/(gama-1));
}
}
f1.boundarycondition(1);
double T=0.05;
double t=0;
double dt;
std::vector<double> dts;
std::vector<double> Markt{0.01,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.09,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1};
std::stringstream ss;
int k=0,kt=0;
while (t<1)
{
f1.updatedt();
dt=caldt(f1);
dts.push_back(dt);
//预估步
pre(f1,f2,dt);
//矫正步
cor(f1,f2,dt);
//插值
inter(f1,f2);
//输出
t+=dt;
k+=1;
std::cout<<"k="<<k<<std::endl;
std::cout<<"t="<<t<<std::endl;
std::cout<<std::endl;
if (t>Markt[kt])
{
outputrho(f1,"rho"+d2str(Markt[kt])+".txt");
kt+=1;
}
}
outputrho(f1,"rho.txt");
outputdt(dts,"dt.txt");
}