-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathODE_solver.cpp
More file actions
198 lines (191 loc) · 6.7 KB
/
Copy pathODE_solver.cpp
File metadata and controls
198 lines (191 loc) · 6.7 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include"ODE_solver.hpp"
#include"parameters.hpp"
#include"force.hpp"
#include<omp.h>
#include<vector>
namespace ODE_solver{
//一次精度で常微分方程式を解く(オイラー法)
void motionVertexFirst(Shape* p_s){
force::CalcTotalForce(p_s,0);
force::OMP_Reduction_Frc(p_s,0);
#ifdef _OPENMP
#pragma omp parallel for num_threads(NUM_THREAD)
#endif
for(int i=0;i<p_s->GetVertex().size();i++){
if(p_s->GetVertex(i)->GetFixFlag()==0){
double viscosity=VISCOSITY;
if(p_s->GetVertex(i)->GetBoundaryFlag()==1)viscosity=BOUNDARY_VISCOSITY;
Vector3<double> v;
v=p_s->GetVertex(i)->GetLoc(0)+p_s->GetVertex(i)->GetForce(0)*(DELTA_TIME)/(viscosity);
p_s->GetVertex(i)->SetLoc(p_s->periodize_vector(v),0);//0に直接代入
}
p_s->GetVertex(i)->resetForce(0);
}
}
//2次精度で微分方程式を解く(中点法).ただし、中点の座標と力は一次精度で求める
void motionVertexSecond(Shape* p_s){
force::CalcTotalForce(p_s,0);
force::OMP_Reduction_Frc(p_s,0);
//Δt/2後の位置を求める
#ifdef _OPENMP
#pragma omp parallel for num_threads(NUM_THREAD)
#endif
for(int i=0;i<p_s->GetVertex().size();i++){
if(p_s->GetVertex(i)->GetFixFlag()==0){
double viscosity=VISCOSITY;
if(p_s->GetVertex(i)->GetBoundaryFlag()==1)viscosity=BOUNDARY_VISCOSITY;
Vector3<double>v;
v=p_s->GetVertex(i)->GetLoc(0)+p_s->GetVertex(i)->GetForce(0)*(DELTA_TIME)/(2.0*viscosity);
p_s->GetVertex(i)->SetLoc(p_s->periodize_vector(v),1);//1に代入
}
p_s->GetVertex(i)->resetForce(0);
}
force::CalcTotalForce(p_s,1);//座標1を基準に
force::OMP_Reduction_Frc(p_s,1);
#ifdef _OPENMP
#pragma omp parallel for num_threads(NUM_THREAD)
#endif
for(int i=0;i<p_s->GetVertex().size();i++){
if(p_s->GetVertex(i)->GetFixFlag()==0){
double viscosity=VISCOSITY;
if(p_s->GetVertex(i)->GetBoundaryFlag()==1)viscosity=BOUNDARY_VISCOSITY;
Vector3<double>v;
v=p_s->GetVertex(i)->GetLoc(0)+p_s->GetVertex(i)->GetForce(1)*(DELTA_TIME)/(viscosity);
p_s->GetVertex(i)->SetLoc(p_s->periodize_vector(v),0);//0
}
p_s->GetVertex(i)->resetForce(1);
}
}
//3次精度(3次のルンゲクッタ)
void motionVertexThird(Shape* p_s){
force::CalcTotalForce(p_s,0);
force::OMP_Reduction_Frc(p_s,0);
//Δt/2後の位置を求める
#ifdef _OPENMP
#pragma omp parallel for num_threads(NUM_THREAD)
#endif
for(int i=0;i<p_s->GetVertex().size();i++){
if(p_s->GetVertex(i)->GetFixFlag()==0){
double viscosity=VISCOSITY;
if(p_s->GetVertex(i)->GetBoundaryFlag()==1){
viscosity=BOUNDARY_VISCOSITY;
}
Vector3<double>v;
v=p_s->GetVertex(i)->GetLoc(0)+p_s->GetVertex(i)->GetForce(0)*(DELTA_TIME)/(2*viscosity);
p_s->GetVertex(i)->SetLoc(p_s->periodize_vector(v),1);
}
//p_s->GetVertex(i)->resetForce(0);
}
force::CalcTotalForce(p_s,1);
force::OMP_Reduction_Frc(p_s,1);
#ifdef _OPENMP
#pragma omp parallel for num_threads(NUM_THREAD)
#endif
for(int i=0;i<p_s->GetVertex().size();i++){
if(p_s->GetVertex(i)->GetFixFlag()==0){
double viscosity=VISCOSITY;
if(p_s->GetVertex(i)->GetBoundaryFlag()==1){
viscosity=BOUNDARY_VISCOSITY;
}
Vector3<double>v;
v=p_s->GetVertex(i)->GetLoc(0)+(2.0*p_s->GetVertex(i)->GetForce(1)-p_s->GetVertex(i)->GetForce(0))*(DELTA_TIME)/(2*viscosity);
p_s->GetVertex(i)->SetLoc(p_s->periodize_vector(v),2);
}
//p_s->GetVertex(i)->resetForce(1);
}
force::CalcTotalForce(p_s,2);
force::OMP_Reduction_Frc(p_s,2);
#ifdef _OPENMP
#pragma omp parallel for num_threads(NUM_THREAD)
#endif
for(int i=0;i<p_s->GetVertex().size();i++){
if(p_s->GetVertex(i)->GetFixFlag()==0){
double viscosity=VISCOSITY;
if(p_s->GetVertex(i)->GetBoundaryFlag()==1){
viscosity=BOUNDARY_VISCOSITY;
}
Vector3<double>v;
v=p_s->GetVertex(i)->GetLoc(0)+(p_s->GetVertex(i)->GetForce(2)/6.0+p_s->GetVertex(i)->GetForce(1)/1.5+p_s->GetVertex(i)->GetForce(0)/6.0)*(DELTA_TIME)/(viscosity);
p_s->GetVertex(i)->SetLoc(p_s->periodize_vector(v),0);
}
p_s->GetVertex(i)->resetForce(1);
p_s->GetVertex(i)->resetForce(0);
p_s->GetVertex(i)->resetForce(2);
}
}
//4次精度(4次のルンゲクッタ)
void motionVertexFourth(Shape* p_s){
force::CalcTotalForce(p_s,0);
force::OMP_Reduction_Frc(p_s,0);
//Δt/2後の位置を求める
#ifdef _OPENMP
#pragma omp parallel for num_threads(NUM_THREAD)
#endif
for(int i=0;i<p_s->GetVertex().size();i++){
if(p_s->GetVertex(i)->GetFixFlag()==0){
double viscosity=VISCOSITY;
if(p_s->GetVertex(i)->GetBoundaryFlag()==1){
viscosity=BOUNDARY_VISCOSITY;
}
Vector3<double>v;
v=p_s->GetVertex(i)->GetLoc(0)+p_s->GetVertex(i)->GetForce(0)*(DELTA_TIME)/(2*viscosity);
p_s->GetVertex(i)->SetLoc(p_s->periodize_vector(v),1);
}
//p_s->GetVertex(i)->resetForce(0);
}
//dt/2後の位置を求める
force::CalcTotalForce(p_s,1);
force::OMP_Reduction_Frc(p_s,1);
#ifdef _OPENMP
#pragma omp parallel for num_threads(NUM_THREAD)
#endif
for(int i=0;i<p_s->GetVertex().size();i++){
if(p_s->GetVertex(i)->GetFixFlag()==0){
double viscosity=VISCOSITY;
if(p_s->GetVertex(i)->GetBoundaryFlag()==1){
viscosity=BOUNDARY_VISCOSITY;
}
Vector3<double>v;
v=p_s->GetVertex(i)->GetLoc(0)+(p_s->GetVertex(i)->GetForce(1))*(DELTA_TIME)/(2*viscosity);
p_s->GetVertex(i)->SetLoc(p_s->periodize_vector(v),2);
}
//p_s->GetVertex(i)->resetForce(1);
}
force::CalcTotalForce(p_s,2);
force::OMP_Reduction_Frc(p_s,2);
#ifdef _OPENMP
#pragma omp parallel for num_threads(NUM_THREAD)
#endif
for(int i=0;i<p_s->GetVertex().size();i++){
if(p_s->GetVertex(i)->GetFixFlag()==0){
double viscosity=VISCOSITY;
if(p_s->GetVertex(i)->GetBoundaryFlag()==1){
viscosity=BOUNDARY_VISCOSITY;
}
Vector3<double>v;
v=p_s->GetVertex(i)->GetLoc(0)+(p_s->GetVertex(i)->GetForce(2))*(DELTA_TIME)/(viscosity);
p_s->GetVertex(i)->SetLoc(p_s->periodize_vector(v),3);
}
}
force::CalcTotalForce(p_s,3);
force::OMP_Reduction_Frc(p_s,3);
#ifdef _OPENMP
#pragma omp parallel for num_threads(NUM_THREAD)
#endif
for(int i=0;i<p_s->GetVertex().size();i++){
if(p_s->GetVertex(i)->GetFixFlag()==0){
double viscosity=VISCOSITY;
if(p_s->GetVertex(i)->GetBoundaryFlag()==1){
viscosity=BOUNDARY_VISCOSITY;
}
Vector3<double>v;
v=p_s->GetVertex(i)->GetLoc(0)+(p_s->GetVertex(i)->GetForce(0)/6.0+p_s->GetVertex(i)->GetForce(1)/3.0+p_s->GetVertex(i)->GetForce(2)/3.0+p_s->GetVertex(i)->GetForce(3)/6.0)*(DELTA_TIME)/(viscosity);
p_s->GetVertex(i)->SetLoc(p_s->periodize_vector(v),0);
}
p_s->GetVertex(i)->resetForce(1);
p_s->GetVertex(i)->resetForce(0);
p_s->GetVertex(i)->resetForce(2);
p_s->GetVertex(i)->resetForce(3);
}
}
}//namespace ODE_solver