-
Notifications
You must be signed in to change notification settings - Fork 0
/
pParticles_s_p_w__s.cpp
214 lines (130 loc) · 4.18 KB
/
pParticles_s_p_w__s.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// pParticles
// weigths are used to enforce incompressibility
// Pressure is determined some other way...
// An additional field, s, is used to enforce const moments of inertia
// s is obtained from p here
#undef PRESSURE_PPE
#include"pParticles.h"
#include"linear.h"
#include"simu.h"
sim_data simu;
int main() {
// TODO: read better from parameter file
int init_max_iters; cin >> init_max_iters; // = 40;
FT init_tol2 ; cin >> init_tol2 ; // = 1e-3;
int inner_max_iters; cin >> inner_max_iters; // = 10;
FT disp_tol; cin >> disp_tol; // = 1e-6;
const FT turn_time = 2 * M_PI * 0.2 ; // one whole turn
// const FT total_time = turn_time; // once
const FT total_time = 2 * turn_time; // twice
const std::string particle_file("particles.dat");
const std::string diagram_file("diagram.dat");
Triangulation T;
cout << "Creating point cloud" << endl;
// simu.do_perturb(0.1);
create( T , 1.0 );
number( T );
// set_vels_rotating( T );
// set_vels_Lamb_Oseen( T );
volumes( T );
linear algebra( T );
algebra.copy( sfield_list::vol, sfield_list::vol0);
algebra.copy( sfield_list::I, sfield_list::I0);
// Init loop!
int init_iter=0;
for( ; init_iter < init_max_iters ; ++init_iter) {
volumes( T );
// copy_weights( T ) ;
// algebra.solve_for_weights();
FT dd = lloyds( T ) ;
cout << " init loop , iter " << init_iter << " dd = " << dd << endl;
if( dd < init_tol2) break;
}
volumes( T );
algebra.copy( sfield_list::vol, sfield_list::vol0);
algebra.copy( sfield_list::I, sfield_list::I0);
copy_weights( T ) ;
// copy_weights( T ) ;
cout << "Init loop converged in " << init_iter << " steps " << endl;
set_vels_Gresho( T );
volumes( T );
algebra.copy( sfield_list::vol, sfield_list::vol0);
algebra.copy( sfield_list::I, sfield_list::I0);
FT d0;
FT dt=0.001;
cin >> dt ;
simu.set_dt( dt );
// half-step leapfrog
// FT dt2 = dt / 2.0 ;
FT dt2 = dt / 2.0 ;
// algebra.solve_for_weights();
draw( T , particle_file );
draw_diagram( T , diagram_file );
std::ofstream log_file;
log_file.open("main.log");
log_file << " # step time iters kin_energy L2_velocity " << endl;
do {
simu.next_step();
simu.advance_time( );
cout << "Time " << simu.time() << endl;
// volumes( T );
backup( T );
// displ = move( T , dt2 , d0 );
// algebra.reset_s();
// algebra.reset_p();
algebra.u_star( );
FT displ = 0 ;
int in_iter = 1;
for ( ; in_iter <= inner_max_iters ; in_iter++) {
displ = move( T , dt2 , d0 );
algebra.u_star( );
cout
<< "********" << endl
<< "Iter " << in_iter
<< " . Moved from previous (rel.): " << displ <<
" ; from original (rel.): " << d0
<< endl ;
volumes( T );
algebra.fill_Delta_DD();
// algebra.solve_for_weights();
//algebra.solve_for_moments();
//copy_weights( T ) ;
//volumes( T );
//algebra.fill_Delta_DD();
algebra.clear_vfield( vfield_list::gradp );
//algebra.p_equation_s( dt );
//algebra.p_equation( dt );
//algebra.p_equation_divgrad_div_source( dt2 );
algebra.s_equation_from_p( 1 );
algebra.u_add_s_grad( dt2 );
algebra.p_equation_lapl_div_source( dt2 );
//algebra.u_add_grads( dt2 );
algebra.u_add_press_grad( dt2 );
algebra.copy( vfield_list::Ustar , vfield_list::U );
if( displ < disp_tol ) break;
}
// algebra.u_star( );
// algebra.p_equation_from_s( );
// algebra.p_equation( dt );
// algebra.u_add_press_grad( dt );
displ = move( T , dt , d0 );
update_half_velocity( T );
volumes( T );
cout
<< "Whole step "
<< " : disp " << displ << endl ;
// half-step:
// update_full_vel( T );
draw( T , particle_file );
draw_diagram( T , diagram_file );
log_file
<< simu.current_step() << " "
<< simu.time() << " "
<< in_iter-1 << " "
<< kinetic_E(T) << " "
<< L2_vel_Gresho(T) << " "
<< endl ;
} while ( simu.time() < total_time );
log_file.close();
return 0;
}